Ξ Notes

Recent Notes

Created bymagnumon September 11, 2012 12:38:00
Last update: September 11, 2012 12:38:00

From bind man page:
SYNOPSIS
#include <sys/types.h>
...
The bind call assigns an address and a port to a socket. That's it. There's no mention of client or server, so it can be used on a client socket or a server socket. But it's necessary for a server socket, otherwise clients do not know how to contact the server.
For a client socket, the call is optional. When a client connects to a server or sends a message for the first time, a dynamic port is assigned to the client if there's no port assigned to it. If a port is bind beforehand, there's no dynamic assignment.
Test code:
int print_sock_info(int sockfd) {
struct so...
Prints:
Local addr: 0.0.0.0, port: 0
Local addr: 0.0.0....