What is with the second parameter in bind()?



What is with the second parameter in bind()?..

Answer / chaitanya

The man page shows it as "struct sockaddr *my_addr". The sockaddr struct though is just a place holder for the structure it really wants. You have to pass different structures depending on what kind of socket you have. For an AF_INET socket, you need the sockaddr_in structure. It has three fields of interest:

sin_family

Set this to AF_INET.

sin_port

The network byte-ordered 16 bit port number

sin_addr

The host's ip number.

This is a struct in_addr,

which contains only one field,

s_addr which is a u_long.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Unix Socket Programming Interview Questions

What is with the second parameter in bind()?

1 Answers  


Whats the difference between select() and poll()?

0 Answers  


How does unix socket work?

0 Answers  


How do I use TCP_NODELAY?

0 Answers  


Can multiple clients connect to same socket?

0 Answers  






How can my client work through a firewall/proxy server?

1 Answers  


Can multiple sockets use the same port?

0 Answers  


What is a deep well socket?

0 Answers  


What exactly does SO_KEEPALIVE do?

1 Answers  


Is a socket a file?

0 Answers  


Can a single socket port be used for multiple applications?

0 Answers  


Explain the TIME_WAIT state.

1 Answers  


Categories