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

Is socket a hardware or software?

0 Answers  


Why do I keep getting EINTR from the socket calls?

1 Answers  


When should I use shutdown()?

1 Answers   Wipro,


How come select says there is data, but read returns zero?

1 Answers  


Is tcp or unix socket faster?

0 Answers  






What is difference between socket and websocket?

0 Answers  


What is a socket connection?

0 Answers  


Why do I get connection refused when the server is not running?

1 Answers  


What is a socket file?

0 Answers  


What is the difference between read() and recv()?

0 Answers  


What pieces of information make up a socket?

0 Answers  


What is Mac, and how is it different from PC? Which one is better for professional users, and why

1 Answers   Evolving Systems, IBM,


Categories