C automatically assign port

Posted by Gary on Stack Overflow See other posts from Stack Overflow or by Gary
Published on 2010-05-19T03:33:46Z Indexed on 2010/05/19 3:40 UTC
Read the original article Hit count: 275

Filed under:
|

Hi, I just wanted to know how to use C to automatically assign a free port (and see what was used) if a specific port number is not provided.

For example, i'm using this:

struct sockaddr_in address;
address->sin_family = AF_INET;
address->sin_addr.s_addr = INADDR_ANY;
address->sin_port = htons( port );

But how can I replace the sin_port assignment and let C automatically assign for me?

Thanks!

© Stack Overflow or respective owner

Related posts about c

    Related posts about networking