This function converts textual representation of a network address to either IPv4 or IPv6 binary address, so that dst
points to either in_addr
or in6_addr
.
This is to support the paradigm that the networking layer in an application can be generic and handle both IPv4 and IPv6 protocols simultaneously. Such an application would store the network addresses in a storage of size sufficient for both in_addr
or in6_addr
, along with the address family, e.g.:
struct generic_in_addr
{
int af;
union {
in_addr v4;
in6_addr v6;
} addr;
};
And would use the same multi-protocol functions such as socket
, connect
, accept
passing the network address along with its family and size.
Generic network programming in C.