Graphics Programs Reference
In-Depth Information
From /usr/include/bits/socket.h
/* Protocol families. */
#define PF_UNSPEC 0 /* Unspecified. */
#define PF_LOCAL 1 /* Local to host (pipes and file-domain). */
#define PF_UNIX PF_LOCAL /* Old BSD name for PF_LOCAL. */
#define PF_FILE PF_LOCAL /* Another nonstandard name for PF_LOCAL. */
#define PF_INET 2 /* IP protocol family. */
#define PF_AX25 3 /* Amateur Radio AX.25. */
#define PF_IPX 4 /* Novell Internet Protocol. */
#define PF_APPLETALK 5 /* Appletalk DDP. */
#define PF_NETROM 6 /* Amateur radio NetROM. */
#define PF_BRIDGE 7 /* Multiprotocol bridge. */
#define PF_ATMPVC 8 /* ATM PVCs. */
#define PF_X25 9 /* Reserved for X.25 project. */
#define PF_INET6 10 /* IP version 6. */
...
As mentioned before, there are several types of sockets, although stream
sockets and datagram sockets are the most commonly used. The types of sockets
are also defined in bits/socket.h. (The /* comments */ in the code above are
just another style that comments out everything between the asterisks.)
From /usr/include/bits/socket.h
/* Types of sockets. */
enum __socket_type
{
SOCK_STREAM = 1, /* Sequenced, reliable, connection-based byte streams. */
#define SOCK_STREAM SOCK_STREAM
SOCK_DGRAM = 2, /* Connectionless, unreliable datagrams of fixed maximum length. */
#define SOCK_DGRAM SOCK_DGRAM
...
The final argument for the socket() function is the protocol, which should
almost always be 0 . The specification allows for multiple protocols within a
protocol family, so this argument is used to select one of the protocols from
the family. In practice, however, most protocol families only have one pro-
tocol, which means this should usually be set for 0 ; the first and only protocol
in the enumeration of the family. This is the case for everything we will do
with sockets in this topic, so this argument will always be 0 in our examples.
0x422
Socket Addresses
Many of the socket functions reference a sockaddr structure to pass address
information that defines a host. This structure is also defined in bits/socket.h,
as shown on the following page.
Search WWH ::




Custom Search