AF_INET sockets, code examples needed.

Doug McCallum mccallum at opus.UUCP
Mon Jul 1 13:04:25 AEST 1985


> My code never works unless I bind a name to the client's socket.
> 
> Actually, this is not surprising, because a name is required.
> 
> Here is part of the code I use to bind a name to a socket:
> 
> 	do {
>                 sin_sync.sin_port = htons( (--portnum));
>         } while( 
> 	     bind( sock_num, (char *)&sin_sync, sizeof(sin_sync) ) < 0
> 	   &&

Actually, setting the port  to zero works as a wildcard.  The bind  will
then select the next free port number available.  The only time something
like  this code sample is needed is if the portnumber desired is in
the priviledged range ( <1024 ).



More information about the Comp.unix mailing list