Open C Sockets: bind method
The bind method binds a name to a socket.
int bind (int s, const struct sockaddr *addr, socklen_t addrlen);
The bind system call assigns the local protocol address to a socket. When a socket is created with socket it exists in an address family space but has no protocol address assigned. The bind system call requests that addr be assigned to the socket.
Following is the usage of bind function:
struct sockaddr_in addr,ss;
unsigned int len;
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(5000);
Note: For maximum portability, you should always zero the socket address structure before populating it and passing it to bind.