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.
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 should keep you busy for a while.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.
I still don't see why you aren't naiming your own port number though.
Quzah.
Hope is the first step on the road to disappointment.
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.).
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.
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.
Environment: OS X, GCC / G++
Codes: Java, C#, C/C++
AOL IM: neandrake, Email: neandrake (at) gmail (dot) com