What is with the second parameter in bind()?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What's better 6pt or 12pt sockets?

479


Can multiple clients connect to same socket?

518


How many socket connections can a server handle?

470


Why do I get EPROTO from read()?

1008


Are unix sockets faster than tcp?

494






What is socket address with example?

493


How is a socket created?

507


What is active unix domain sockets?

550


What is a socket set used for?

504


What pieces of information make up a socket?

545


How can I tell when a socket is closed on the other end?

973


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

1593


What is a socket address?

520


Are sockets files?

500


What is a socket connection?

504