getsockname use the generic data
struct sockaddr * to represent a pointer to a socket
address. You can't use this data type effectively to interpret an
address or construct one; for that, you must use the proper data type
for the socket's namespace.
Thus, the usual practice is to construct an address in the proper
namespace-specific type, then cast a pointer to
struct sockaddr *
when you call
The one piece of information that you can get from the
sockaddr data type is the address format designator which tells
you which data type to use to understand the address fully.
The symbols in this section are defined in the header file `sys/socket.h'.
struct sockaddrtype itself has the following members:
short int sa_family
sa_datais essentially arbitrary.
Each address format has a symbolic name which starts with `AF_'. Each of them corresponds to a `PF_' symbol which designates the corresponding namespace. Here is a list of address format names:
PF_FILEis the name of that namespace.) See section Details of File Namespace, for information about this address format.
AF_FILE, for compatibility. (
PF_UNIXis likewise a synonym for
PF_INETis the name of that namespace.) See section Internet Socket Address Formats.
AF_INET, but refers to the IPv6 protocol. (
PF_INET6is the name of the corresponding namespace.)
PF_UNSPECexists for completeness, but there is no reason to use it in a program.
`sys/socket.h' defines symbols starting with `AF_' for many different kinds of networks, all or most of which are not actually implemented. We will document those that really work, as we receive information about how to use them.
Go to the first, previous, next, last section, table of contents.