In this case, you call bind() as follows:
bind(s, name, namelen);
In the communications domain AF_INET, name comprises a 4-byte IPv4 address and a port number. name is passed in a variable of the type struct sockaddr_in (see section "sockaddr_in address structure of the AF_INET address family"). namelen contains the length of the data structure that defines the name.
In the communications domain AF_INET6, name comprises a 16-byte IPv6 address and a port number. name is passed in a variable of the type struct sockaddr_in6 (see section "sockaddr_in6 address structure of the AF_INET6 address family"). namelen contains the length of the data structure that defines the name.
In the communications domain AF_ISO, name comprises a network selector and a transport selector. name is passed in a variable of the type struct sockaddr_iso (see section "sockaddr_iso address structure for the AF_ISO address family"). namelen contains the length of the data structure that defines the name.
Assigning an address explicitly in the domains AF_INET and AF_INET6
Assigning an address explicitly in AF_INET
The following program extract illustrates how a name is assigned to a socket in the AF_INET domain.
#include <sys.types.h> #include <netinet.in.h> ... struct sockaddr_in sin; int s; ... sin.sin_family = AF_INET; sin.sin_port = 0; sin.sin_addr.s_addr = INADDR_ANY; ... bind(s, &sin, sizeof sin);
Assigning an address explicitly in AF_INET6
#include <sys.types.h> #include <netinet.in.h> ... struct sockaddr_in6 sin6; struct in6_addr in6addr_any = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int s; ... sin6.sin6_family = AF_INET6; sin6.sin6_port = 0; memcpy(sin6.sin6_addr.s6_addr,in6addr_any.s6_addr,16); ... bind(s, &sin6, sizeof sin6);
You must note the following when selecting the port number:
Port numbers lower than PRIVPORT# (see the “BCAM Volume 1/2” manual) are reserved for privileged users (default: 2050).
Certain port numbers are reserved for some standard applications:
Port number 3161 is used by the SNMP Basic Agent BS2000 is used for internal communications between the master agent and subagents (see the “SNMP Management for BS2000” manual).
Port number 1235 is required by the Domain Name Service (DNS) (see the “interNet Services” administration manual).
Note should be made of other well-known, registered, dynamic and/or private port numbers, which are documented on the IANA website at “http://www.iana.org/assignments/port-numbers”.
Assigning an address explicitly in the AF_ISO domain
The following program section illustrates how a name is assigned to a socket in the AF_ISO domain.
#include <sys.types.h> #include <iso.h> ... .. struct sockaddr_iso sin; int s; ... .. /* The statements which supply sin with a network selector and a transport selector must be inserted here.*/ ... .. bind(s, &sin, sizeof sin);