[ee122] gathering info with random unused ports (sin_port == 0)

Richard Schmidt huntingtonsurfca at gmail.com
Sun Nov 25 22:47:49 PST 2007


So Beej told me that if I want to bind a socket to a random port number, I
can just set the sAddr_in.port to 0. Then the kernel will decide which port
that is.

>From there, though, how do I figure out what port the kernel chose? Did it
overwrite the value? Is there a function analogous to getpeername() where
the struct gets filled in with info?

I need to advertise the second (incoming on the initiator side) socket to
the reciever if he is intending to send things back, but I can't find where
to get my random port number for the socket I'm using.

Thanks,
Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ICSI.Berkeley.EDU/pipermail/ee122/attachments/20071125/21e61594/attachment.html 


More information about the ee122 mailing list