Socket Programming ..help [Archive] - C Board

PDA

View Full Version : Socket Programming ..help


RoshanX
10-14-2003, 07:20 PM
Is there a library routine in BSD Sockets to get the port no from the of the socket if we let BIND() assign a port number for us. ?
Thanks in advance.

quzah
10-14-2003, 07:27 PM
Originally posted by RoshanX
Is there a library routine in BSD Sockets to get the port no from the of the socket if we let BIND() assign a port number for us. ?
Thanks in advance.
Why aren't you specifying your own port number? I don't see the point. If you need the socket number, specify it. This (http://www.developerweb.net/sock-faq/) should keep you busy for a while.

I still don't see why you aren't naiming your own port number though.

Quzah.

RoshanX
10-14-2003, 07:38 PM
If I use an arbitrary port number, that port might be in use so it can't be binded to that port. What I want to do is , bind to a port ( arbitrary) then announce the port. ( This is just a test applicatoin. Not a big one.).

BillBoeBaggins
10-15-2003, 11:47 AM
I don't remember the exact range of ports, but start at lets say 3000 and then create your socket... attempt to bind to it.. if it fails the bind.. then increment the port and try again.. I haven't seen any callback functions in API for detecting used ports... this might run faster anyways.

neandrake
11-17-2003, 04:43 PM
Wouldn't the port number be in the sockaddr struct? I'm just guessing, if one wasn't supplied, wouldn't it assign one to the struct and then attempt the bind? Check that and tell us what happens, I'm interested to know what happens.