Date: Sun, 06 Dec 1998 11:17:22 -0500 From: "Louis A. Mamakos" <louie@TransSys.COM> To: "Jim Flowers" <jflowers@ezo.net> Cc: freebsd-hackers@FreeBSD.ORG, freebsd-net@FreeBSD.ORG Subject: Re: Help with TCP listen() function Message-ID: <199812061617.LAA54526@whizzo.transsys.com> In-Reply-To: Your message of "Sun, 06 Dec 1998 12:10:53 EST." <000d01be213b$625d6eb0$848266ce@crocus.ezo.net> References: <000d01be213b$625d6eb0$848266ce@crocus.ezo.net>
next in thread | previous in thread | raw e-mail | index | archive | help
The problem is that you're not trying to do a TCP "listen" operation; you're creating a UDP datagram socket, and not a TCP (SOCK_STREAM) type socket. The listen system call isn't defined to work on datagram sockets because there are no new connections to be accepted. This is probably a freebsd-questions mailing list issue for any follow-up. louie > > ------=_NextPart_000_000A_01BE2111.78BC2770 > Content-Type: text/plain; > charset="iso-8859-1" > Content-Transfer-Encoding: quoted-printable > > I am trying to port a cable modem (roadrunner) login program written for = > linux to freebsd 2.2.7 before the Dec 15 deadline. Should have been = > suspicious when it compiled cleanly without error message. > > The program runs up to the point of setting up a TCP socket to request a = > login sequence using functions: > > socket() > htons() > bind() > listen() > > and then quits with errnum for "Operation not supported". > > The function calls seem to be correctly written and do not return any = > errors when called (except for listen()). > > Is this a correct sequence to establish a passive tcp connection? Is = > there a better way to do it? Is there a knowledge base for converting = > linux code to run on FreeBSD? References for the correct way to write = > code to establish tcp connections? > > If a review of the code segment would be helpful, it is brief and = > follows. > > Thanks > Jim Flowers <jflowers@ezo.net> > > > //------------------------------------------------------------ > // RRListen() - Creates a listen socket for session status and > // restart requests > int RRListen(unsigned short *listenport) > { > unsigned short port; > int s; > struct sockaddr_in saddr; > > if ((s =3D socket (AF_INET, SOCK_DGRAM, 0)) < 0) { > syslog(LOG_ERR, "Error creating listen socket: %m"); > return -1; > } > > // Bind first available port starting at 7770 > port =3D 7770; > saddr.sin_family =3D AF_INET; > saddr.sin_addr.s_addr =3D INADDR_ANY; > do { > saddr.sin_port =3D htons(port); > errno =3D 0; > if (bind(s, (struct sockaddr *) &saddr, sizeof(struct = > sockaddr_in)) < 0) { > if (errno !=3D EADDRINUSE) { > syslog(LOG_ERR, "Error binding listen socket: %m"); > close(s); > return -1; > } else { > port++; > } > } > } while (errno =3D=3D EADDRINUSE); > > if (listen(s, 1) < 0) { > syslog(LOG_ERR, "Error listening on socket: %m"); > close(s); > return -1; > } > > *listenport =3D port; > syslog(LOG_INFO, "Established listener on port: %i", port); > return s; > ) > -------------------------------------------------------------------------= > ------ > > ------=_NextPart_000_000A_01BE2111.78BC2770 > Content-Type: text/html; > charset="iso-8859-1" > Content-Transfer-Encoding: quoted-printable > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN"> > <HTML> > <HEAD> > > <META content=3Dtext/html;charset=3Diso-8859-1 = > http-equiv=3DContent-Type> > <META content=3D'"MSHTML 4.72.2106.6"' name=3DGENERATOR> > </HEAD> > <BODY bgColor=3D#ffffff> > <DIV><FONT color=3D#000000 size=3D2>I am trying to port a cable modem = > (roadrunner)=20 > login program written for linux to freebsd 2.2.7 before the Dec 15=20 > deadline. Should have been suspicious when it compiled cleanly = > without=20 > error message.</FONT></DIV> > <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> > <DIV><FONT size=3D2>The program runs up to the point of setting up a TCP = > socket to=20 > request a login sequence using functions:</FONT></DIV> > <DIV><FONT size=3D2></FONT> </DIV> > <DIV><FONT size=3D2>socket()</FONT></DIV> > <DIV><FONT size=3D2>htons()</FONT></DIV> > <DIV><FONT size=3D2>bind()</FONT></DIV> > <DIV><FONT size=3D2>listen()</FONT></DIV> > <DIV><FONT size=3D2></FONT> </DIV> > <DIV><FONT size=3D2>and then quits with errnum for "Operation not=20 > supported".</FONT></DIV> > <DIV><FONT size=3D2></FONT> </DIV> > <DIV><FONT size=3D2>The function calls seem to be correctly written and = > do not=20 > return any errors when called (except for listen()).</FONT></DIV> > <DIV><FONT size=3D2></FONT> </DIV> > <DIV><FONT size=3D2>Is this a correct sequence to establish a passive = > tcp=20 > connection? Is there a better way to do it? Is there a knowledge = > base for=20 > converting linux code </FONT><FONT size=3D2>to run on FreeBSD? = > References=20 > for the correct way to write code to establish tcp = > connections?</FONT></DIV> > <DIV><FONT size=3D2></FONT> </DIV> > <DIV><FONT size=3D2>If a review of the code segment would be helpful, it = > is brief=20 > and follows.</FONT></DIV> > <DIV><FONT size=3D2></FONT> </DIV> > <DIV><FONT size=3D2>Thanks</FONT></DIV> > <DIV><FONT color=3D#000000 size=3D2>Jim Flowers <<A=20 > href=3D"mailto:jflowers@ezo.net">jflowers@ezo.net</A>></FONT></DIV> > <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> > <DIV> </DIV> > <DIV><FONT color=3D#000000=20 > size=3D2>//------------------------------------------------------------<B= > R>//=20 > RRListen() - Creates a listen socket for session status=20 > and<BR>// &nbs= > p; =20 > restart requests<BR>int RRListen(unsigned short=20 > *listenport)<BR>{<BR> unsigned short port;<BR> int=20 > s;<BR> struct sockaddr_in saddr;</FONT></DIV> > <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> > <DIV><FONT color=3D#000000 size=3D2> if ((s =3D socket = > (AF_INET,=20 > SOCK_DGRAM, 0)) < 0) {<BR> = > syslog(LOG_ERR,=20 > "Error creating listen socket: = > %m");<BR> =20 > return -1;<BR> }</FONT></DIV> > <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> > <DIV><FONT color=3D#000000 size=3D2> // Bind first available port = > starting at=20 > 7770<BR> port =3D 7770;<BR> saddr.sin_family =3D = > > AF_INET;<BR> saddr.sin_addr.s_addr =3D = > INADDR_ANY;<BR> do=20 > {<BR> saddr.sin_port =3D=20 > htons(port);<BR> errno =3D=20 > 0;<BR> if (bind(s, (struct sockaddr *) = > &saddr,=20 > sizeof(struct sockaddr_in)) < 0) {<BR> if (errno !=3D = > EADDRINUSE)=20 > {<BR> =20 > syslog(LOG_ERR, "Error binding listen socket:=20 > %m");<BR>  = > ;=20 > close(s);<BR> = > return=20 > -1;<BR> } else=20 > {<BR> =20 > port++;<BR> =20 > }<BR> }<BR> } while (errno =3D=3D=20 > EADDRINUSE);</FONT></DIV> > <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> > <DIV><FONT color=3D#000000 size=3D2> if (listen(s, 1) < 0)=20 > {<BR> syslog(LOG_ERR, "Error listening on = > socket:=20 > %m");<BR> = > close(s);<BR> =20 > return -1;<BR> }</FONT></DIV> > <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> > <DIV><FONT color=3D#000000 size=3D2> *listenport =3D = > port;<BR> =20 > syslog(LOG_INFO, "Established listener on port: %i",=20 > port);<BR> return s;<BR>)</FONT></DIV> > <DIV><FONT color=3D#000000=20 > size=3D2>----------------------------------------------------------------= > ---------------</FONT></DIV></BODY></HTML> > > ------=_NextPart_000_000A_01BE2111.78BC2770-- > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199812061617.LAA54526>