Graphics Programs Reference
In-Depth Information
From /usr/include/bits/socket.h
/* Get the definition of the macro to define the common sockaddr members. */
#include <bits/sockaddr.h>
/* Structure describing a generic socket address. */
struct sockaddr
{
__SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
char sa_data[14]; /* Address data. */
};
The macro for SOCKADDR_COMMON is defined in the included bits/sockaddr.h
file, which basically translates to an unsigned short int. This value defines
the address family of the address, and the rest of the structure is saved for
address data. Since sockets can communicate using a variety of protocol
families, each with their own way of defining endpoint addresses, the defini-
tion of an address must also be variable, depending on the address family.
The possible address families are also defined in bits/socket.h; they usually
translate directly to the corresponding protocol families.
From /usr/include/bits/socket.h
/* Address families. */
#define AF_UNSPEC PF_UNSPEC
#define AF_LOCAL PF_LOCAL
#define AF_UNIX PF_UNIX
#define AF_FILE PF_FILE
#define AF_INET PF_INET
#define AF_AX25 PF_AX25
#define AF_IPX PF_IPX
#define AF_APPLETALK PF_APPLETALK
#define AF_NETROM PF_NETROM
#define AF_BRIDGE PF_BRIDGE
#define AF_ATMPVC PF_ATMPVC
#define AF_X25 PF_X25
#define AF_INET6 PF_INET6
...
Since an address can contain different types of information, depending
on the address family, there are several other address structures that contain,
in the address data section, common elements from the sockaddr structure as
well as information specific to the address family. These structures are also
the same size, so they can be typecast to and from each other. This means
that a socket() function will simply accept a pointer to a sockaddr structure,
which can in fact point to an address structure for IPv4, IPv6, or X.25. This
allows the socket functions to operate on a variety of protocols.
In this topic we are going to deal with Internet Protocol version 4, which
is the protocol family PF_INET , using the address family AF_INET . The parallel
socket address structure for AF_INET is defined in the netinet/in.h file.
Search WWH ::




Custom Search