|
struct sockaddr_in { sa_family_t sin_family; /* Address family - Must contain the value AF_INET */ in_port_t sin_port; /* Internet Port # - a 2 bytes port number */ struct in_addr sin_addr; /* Internet Address (IP-address) - a 4 bytes IP address */ }; |
Facts:
|
|
|
A wild card IP address will match to any IP address
|
Example:
in_addr.sin_family = AF_INET; /* Protocol domain */ in_addr.sin_addr.s_addr = htonl(INADDR_ANY); /* Use wild card IP address */ in_addr.sin_port = htons(PortNumber); /* UDP port # of socket */ /* -------------------------------- Bind socket to socket address -------------------------------- */ if ( bind(s, (struct sockaddr *)&in_addr, sizeof(in_addr)) != 0 ) perror("Bind error: "); |
Result:
|
Notes:
|
Example:
cheung@compute(1011)> udp2 8000 OK: bind to port = 9000 SUCCESS **** Bind was successful.... Socket is bind to: addr = 0 port = 8000 |