InterviewSolution
| 1. |
What Is With The Second Parameter In Bind()? |
|
Answer» 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: 1.sin_family Set this to AF_INET. 2.sin_port The network byte-ordered 16 BIT port number 3.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. 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: 1.sin_family Set this to AF_INET. 2.sin_port The network byte-ordered 16 bit port number 3.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. |
|