Technical data

SunOS 5.5 Protocols inet(7P)
ADDRESSING IP addresses are four byte quantities, stored in network byte order. IP addresses should
be manipulated usingthe byte order conversion routines (see byteorder(3N)).
Addresses in the Internetprotocol family use the sockaddr_in structure, which has that
following members:
short sin_family;
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
Library routines are provided to manipulate structures of this form; See inet(3N).
The sin_addr field of the sockaddr_in structure specifies a local or remote IP address.
Each network interface has its own uniqueIP address. The special value INADDR_ANY
may be used in this field to effect “wildcard” matching. Given in a bind(3N) call, this
value leaves the local IP address of the socket unspecified, so that the socket will receive
connections or messages directed at any of the validIP addresses of the system. This can
prove useful when a process neither knows nor cares what the local IP address is or when
a process wishes to receive requests using all of its network interfaces. The sockaddr_in
structure given in the bind(3N) call must specify an in_addr value of either
IPADDR_ANY or one of the system’s valid IP addresses. Requests to bind any other
address will elicit the error EADDRNOTAVAI. When a connect(3N) call is made for a
socket that has a wildcard local address, the system sets the sin_addr field of the socket
to the IP address of the network interface that the packets for that connection are routed
via.
The sin_port field of the sockaddr_in structure specifies a port number used byTCP or
UDP. The local port address specified in a bind(3N) call is restricted to be greater than
IPPORT_RESERVED (defined in <netinet/in.h>) unless the creating process is running
as the super-user, providing a space of protected port numbers. In addition, the local
port address must not be in use by any socket of same address family and type. Requests
to bind sockets to port numbers being used by other sockets return the error EAD-
DRINUSE. If the local port address is specified as 0, then the system picks a unique port
address greater than IPPORT_RESERVED. A unique local port address is also picked
when a socket which is not bound is used in a connect(3N) or sendto (see send(3N)) call.
This allows programs which do not care which local port number is used to set up TCP
connections by simply calling socket(3N) and then connect(3N), and to send UDP
datagrams with a socket(3N) call followed by a sendto() call.
modified 3 Jul 1990 7P-143