lkml.org 
[lkml]   [1996]   [Mar]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectpossible socket bug in 1.3.>=61
Alan,

A bug in socket handling appears to have been introduced with 1.3.61.
(1.3.60 is ok.) Connect() fails if nonblocking IO is set on the socket.
A test program is included: "foo" works on 1.3.x for all x, "foo -"
works for x<=60 and fails with "connect: Operation now in progress"
for x>=61 (up to the latest: 71).

I am a novice at socket programming, but according to my SUN 4.1 manuals,
the nonblocking socket IO in the test program should work.

The failing socket connecting sequence occurs in termified mosaic and
netscape.

Context: Slackware 3.0, ELF, term 2.3.5, libt.so.4.5.26-2.2.0

TIA,
Doug


---------------- cut here: foo.c (cc foo.c -o foo) ----------------------
/* test program to show socket bug appearing in 1.3.61 */
/* usage: foo [-] */

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <netinet/in.h>

#define IPADDR "127.0.0.1" /* localhost */

int port; /* IP port */
int termflg=0; /* use sequence from termified mosaic */

main(int argc, char **argv)
{ setbuf(stdout,NULL);
if(argc>1) termflg=1;

listener();
connecter();

printf("Success!\n");
return 0;
}

listener() /* listen on a socket */
{ int s,len;
struct sockaddr_in sa;

if((s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))<0)
perr("listener socket()");

sa.sin_family=AF_INET;
sa.sin_port=0;
sa.sin_addr.s_addr=inet_addr(IPADDR);
if(bind(s,(struct sockaddr *)&sa,sizeof(sa))<0) perr("listener bind()");

len=sizeof(sa);
if(getsockname(s,(struct sockaddr *)&sa,&len)<0)
perr("listener getsockname()");
port=ntohs(sa.sin_port);

if(listen(s,5)<0) perr("listener listen()");
printf("listening on port %d\n",port);
}

connecter() /* connect to socket */
{ int s;
struct sockaddr_in sa;
int nonblock=1;
int on=1;

if((s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))<0)
perr("connecter socket()");

if(termflg) /* set nonblocking io */
{ if(ioctl(s,FIONBIO,&nonblock)<0) perr("connecter ioctl()");
printf("(ioctl)\n");
}

sa.sin_family=AF_INET;
sa.sin_port=htons(port);
sa.sin_addr.s_addr=inet_addr(IPADDR);
if(connect(s,(struct sockaddr *)&sa,sizeof(sa))<0)
perr("connecter connect()");

printf("connected\n");
}

perr(s)
char *s;
{ perror(s);
exit(1);
}
-------------------------- cut here: end of foo.c ------------------------


\
 
 \ /
  Last update: 2005-03-22 13:36    [W:0.105 / U:0.184 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site