linux - socket programming with getaddrinfo -


i'm using getaddrinfo in socket programming in linux. have created client , server. client has hardcoded static port number. works fine.

but want system dynamically assign port number client whenever connects server. how do using getaddrinfo? i'm using tcp socket.

just don't call bind before calling connect , tcp stack assign client "random" source port. if need know port you're connecting (and don't), can call getsockaddr after calling connect.

alternatively, can call bind specifying port 0. in case, again, stack assign client "random" unused source port connect from. option preferred if don't want special case allowing implementation select port or if need specify local ip address reason.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -