From owner-freebsd-net Sun Dec 6 08:10:06 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id IAA09580 for freebsd-net-outgoing; Sun, 6 Dec 1998 08:10:06 -0800 (PST) (envelope-from owner-freebsd-net@FreeBSD.ORG) Received: from lily.ezo.net (lily.ezo.net [206.102.130.13]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA09575; Sun, 6 Dec 1998 08:10:04 -0800 (PST) (envelope-from jflowers@ezo.net) Received: from crocus (c3-1d196.neo.rr.com [24.93.233.196]) by lily.ezo.net (8.8.7/8.8.7) with SMTP id LAA01244; Sun, 6 Dec 1998 11:09:51 -0500 (EST) Message-ID: <000d01be213b$625d6eb0$848266ce@crocus.ezo.net> From: "Jim Flowers" To: , Subject: Help with TCP listen() function Date: Sun, 6 Dec 1998 12:10:53 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_000A_01BE2111.78BC2770" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.2106.4 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org This is a multi-part message in MIME format. ------=_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
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 <jflowers@ezo.net>
 
 
//------------------------------------------------------------//=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;
)
----------------------------------------------------------------= ---------------
------=_NextPart_000_000A_01BE2111.78BC2770-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message