From owner-freebsd-hackers Sun Dec 6 08:17:29 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id IAA10340 for freebsd-hackers-outgoing; Sun, 6 Dec 1998 08:17:29 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from whizzo.transsys.com (whizzo.TransSys.COM [144.202.42.10]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA10322; Sun, 6 Dec 1998 08:17:27 -0800 (PST) (envelope-from louie@whizzo.transsys.com) Received: from whizzo.transsys.com (localhost.transsys.com [127.0.0.1]) by whizzo.transsys.com (8.9.1/8.9.1) with ESMTP id LAA54526; Sun, 6 Dec 1998 11:17:23 -0500 (EST) (envelope-from louie@whizzo.transsys.com) Message-Id: <199812061617.LAA54526@whizzo.transsys.com> X-Mailer: exmh version 2.0.2 2/24/98 To: "Jim Flowers" cc: freebsd-hackers@FreeBSD.ORG, freebsd-net@FreeBSD.ORG From: "Louis A. Mamakos" Subject: Re: Help with TCP listen() function References: <000d01be213b$625d6eb0$848266ce@crocus.ezo.net> In-reply-to: Your message of "Sun, 06 Dec 1998 12:10:53 EST." <000d01be213b$625d6eb0$848266ce@crocus.ezo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 06 Dec 1998 11:17:22 -0500 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 > > > //------------------------------------------------------------ > // 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 > > > > > > http-equiv=3DContent-Type> > > > >
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.
>
 
>
The program runs up to the point of setting up a TCP = > socket to=20 > request a login sequence using functions:
>
 
>
socket()
>
htons()
>
bind()
>
listen()
>
 
>
and then quits with errnum for "Operation not=20 > supported".
>
 
>
The function calls seem to be correctly written and = > do not=20 > return any errors when called (except for listen()).
>
 
>
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 to run on FreeBSD?  = > References=20 > for the correct way to write code to establish tcp = > connections?
>
 
>
If a review of the code segment would be helpful, it = > is brief=20 > and follows.
>
 
>
Thanks
>
Jim Flowers < href=3D"mailto:jflowers@ezo.net">jflowers@ezo.net>
>
 
>
 
>
size=3D2>//------------------------------------------------------------ R>//=20 > RRListen() - Creates a listen socket for session status=20 > and
//          &nbs= > p;  =20 > restart requests
int RRListen(unsigned short=20 > *listenport)
{
 unsigned short port;
   int=20 > s;
   struct sockaddr_in saddr;
>
 
>
   if ((s =3D socket = > (AF_INET,=20 > SOCK_DGRAM, 0)) < 0) {
      = > syslog(LOG_ERR,=20 > "Error creating listen socket: = > %m");
     =20 > return -1;
   }
>
 
>
 // Bind first available port = > starting at=20 > 7770
   port =3D 7770;
   saddr.sin_family =3D = > > AF_INET;
   saddr.sin_addr.s_addr =3D = > INADDR_ANY;
   do=20 > {
    saddr.sin_port =3D=20 > htons(port);
      errno =3D=20 > 0;
      if (bind(s, (struct sockaddr *) = > &saddr,=20 > sizeof(struct sockaddr_in)) < 0) {
 if (errno !=3D = > EADDRINUSE)=20 > {
          =20 > syslog(LOG_ERR, "Error binding listen socket:=20 > %m");
          = > ;=20 > close(s);
          = > return=20 > -1;
         } else=20 > {
   =20 > port++;
        =20 > }
      }
 } while (errno =3D=3D=20 > EADDRINUSE);
>
 
>
 if (listen(s, 1) < 0)=20 > {
     syslog(LOG_ERR, "Error listening on = > socket:=20 > %m");
     = > close(s);
    =20 > return -1;
   }
>
 
>
   *listenport =3D = > port;
  =20 > syslog(LOG_INFO, "Established listener on port: %i",=20 > port);
   return s;
)
>
size=3D2>----------------------------------------------------------------= > ---------------
> > ------=_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