Addressing

The most obvious difference between different transport protocols is the way in which each uses transport addresses, or "sockaddrs" in Windows Sockets terms. Virtually all transport protocols expose different address formats to applications, the one exception being NetBIOS protocols which all use the same address format.

A number of Windows Sockets APIs take sockaddrs as input or output parameters, including bind(), ccept(), sendto(), recvfrom(), getsockname(), and getpeername(). For all these APIs a sockaddr is really two arguments: a pointer to the sockaddfr structure itself and a length integer which gives the number of bytes in the sockaddr. For many transport protocols the length of a sockaddr is always the same, but sockaddr lengths may differ between transport protocols. For example, a TCP/IP sockaddr has 16 bytes and an IPX/SPX sockaddr has 14 bytes.

The format of sockaddr structures used by a transport protocol is specified in the af or "address family" argument to the socket() API. All TCP/IP sockets (including both TCP and UDP sockets) are opened with the AF_INET address family, while IPX/SPX sockets are opened with AF_IPX. Other transport protocols use different address family values as defined in the header file winsock.h.

It is up to an application to fill in a sockaddr when bind()ing to a local address or connect()ing to a remote address, and also to interpret the sockaddrs returned from the accept(), sendto(), recvfrom, getpeername(), and getsockname() APIs.