The GNU C Library - Internet Address Format

Node: Internet Address Format Next: Host Addresses Up: Internet Namespace

Internet Socket Address Format

In the Internet namespace, a socket address consists of a host address and a port on that host. In addition, the protocol you choose serves effectively as a part of the address because local port numbers are meaningful only within a particular protocol.

The data type for representing socket addresses in the Internet namespace is defined in the header file `netinet/in.h'.

Data Type struct sockaddr_in
This is the data type used to represent socket addresses in the Internet namespace. It has the following members:

short int sin_family
This identifies the address family or format of the socket address. You should store the value of AF_INET in this member. See Socket Addresses.

struct in_addr sin_addr
This is the Internet address of the host machine. See Host Addresses, and Host Names, for how to get a value to store here.

unsigned short int sin_port
This is the port number. See Ports.

When you call bind or getsockname , you should specify sizeof (struct sockaddr_in) as the length parameter if you are using an Internet namespace socket address.


Next: Host Addresses Up: Internet Namespace