Windows API Reference

Winsock Address Family

The address family defines the protocol family or set of protocols that a socket can use. Winsock supports multiple address families, allowing applications to be protocol-independent.

AF_INET

Represents the Internet Protocol version 4 (IPv4) address family. This is the most common address family used for TCP/IP networking.

Constants:

Example Usage:

struct sockaddr_in sa;
sa.sin_family = AF_INET;
sa.sin_port = htons(80);
sa.sin_addr.s_addr = inet_addr("192.168.1.1");

AF_INET6

Represents the Internet Protocol version 6 (IPv6) address family. This is used for IPv6 addresses, offering a larger address space compared to IPv4.

Constants:

Example Usage:

struct sockaddr_in6 sa6;
sa6.sin6_family = AF_INET6;
sa6.sin6_port = htons(8080);
// ... IPv6 address assignment ...

AF_UNSPEC

An unspecified address family. This allows the system to select an appropriate address family based on the protocol specified. It is often used when the protocol is unknown or when binding to any available address.

Constants:

Other Address Families

Winsock may also support other address families depending on the underlying network protocols installed on the system. These can include:

It is recommended to use AF_INET or AF_INET6 for modern network programming.

Selecting an Address Family

The choice of address family depends on the network protocol you intend to use. For standard internet communication, AF_INET (for IPv4) or AF_INET6 (for IPv6) are the appropriate choices.

Related Functions