This is the mail archive of the
ecos-maintainers@sources.redhat.com
mailing list for the eCos project.
bsp_connect function in packages/net/bsd_tcpip/current/src/sys/kern/sockio.c improvement proposal
- From: Philippe Vandermersch <phil at equator dot com>
- To: ecos-maintainers at ecos dot sourceware dot org
- Date: Thu, 08 Jan 2004 16:16:40 -0800
- Subject: bsp_connect function in packages/net/bsd_tcpip/current/src/sys/kern/sockio.c improvement proposal
Hi,
I found out an annoying problem in this function.
bsd_connect completely ignores the parameter len in the prototype but
instead relies on the field sa->sin_len.
If sa->sin_len is not initialized which is usally the case when the
connection of the socket failed with error 22
For example, this will fail on eCos but not on Linux or VxWorks :
static void transfer( )
{
Int sock;
struct sockaddr_in addr;
Int status;
UInt32 peerHostId;
if (sendMode) {
if (hostName) {
peerHostId = getIPAddr(hostName);
}
else {
__SYSLOG("Hostname have to be provided\n");
exit(-1);
}
// addr.sin_len = sizeof (struct sockaddr_in); <-- This
line must be uncommented to work on eCos
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = peerHostId;
addr.sin_port = htons(portNr);
do {
#ifdef TCP
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
#else
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
#endif
status = connect(sock, (Pointer)&addr, sizeof (struct
sockaddr_in)); ===> FAILED with errno = 22
For the sake of the software compatibility, I think it would be good to
add this in this function :
sa->sin_len = len;
or at least return a better code than EINVAL. It took me sometime to
find out from where this error was coming.
======================== IMPLEMENTATION
PROPOSAL=================================
static int
bsd_connect(cyg_file *fp, const sockaddr *sa, socklen_t len)
{
struct socket *so;
int error, s;
sa->sin_len = len ; // <----- Improvement proposal
so = (struct socket *)fp->f_data;
if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING))
return (EALREADY);
error = soconnect(so, (struct sockaddr *)sa, 0);
if (error)
goto bad;
if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) {
return (EINPROGRESS);
}
s = splsoftnet();
while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
error = tsleep((caddr_t)&so->so_timeo, PSOCK | PCATCH,
"netcon", 0);
if (error)
break;
}
if (error == 0) {
error = so->so_error;
so->so_error = 0;
}
splx(s);
bad:
so->so_state &= ~SS_ISCONNECTING;
return error;
}
Regards,
**********************************************
Philippe Vandermersch
Software Development Engineer
Equator Technologies, Inc.
Tel: 408-369-5404
Email: phil@equator.com
http://www.equator.com
PIXELS TO PACKETS
Enabling Multi-Format High-Definition Video
**********************************************