* bsp_connect function in packages/net/bsd_tcpip/current/src/sys/kern/sockio.c improvement proposal
@ 2004-01-09 0:16 Philippe Vandermersch
0 siblings, 0 replies; only message in thread
From: Philippe Vandermersch @ 2004-01-09 0:16 UTC (permalink / raw)
To: ecos-maintainers
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
**********************************************
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-01-09 0:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-09 0:16 bsp_connect function in packages/net/bsd_tcpip/current/src/sys/kern/sockio.c improvement proposal Philippe Vandermersch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).