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 are the types of sockets?

662


What pieces of information make up a socket?

719


What is socket address?

747


What is socket address with example?

638


How can I write a multi-homed server?

1397






Why do I get EPROTO from read()?

1141


How to find other end of unix socket connection?

655


Is a socket a file?

608


system choose one for me on the connect() call? Should I bind() a port number in my client program, or let the?

1295


Is there any advantage to handling the signal, rather than just ignoring it and checking for the EPIPE error? Are there any useful parameters passed to the signal catching function?

1181


How are unix domain sockets implemented?

630


What is the function of socket?

661


Can multiple clients connect to same socket?

644


How can I force a socket to send the data in its buffer?

1255


Is socket a hardware or software?

666