AF_INET address family

来源:互联网 发布:ge矩阵分析法 编辑:程序博客网 时间:2024/06/05 02:31

This address family provides Inter Process Communications between processesthat run on the same system or on different systems. Addresses for AF_INETsockets are IP addresses and port number. You can specify an IP address foran AF_INET socket either as an IP address, such as 130.99.128.1, or in its32–bit form, X'82638001'.

For a socket application that uses the Internet Protocol version4 (IPv4), the AF_INET address family uses the sockaddr_in address structure. When you use _XOPEN_SOURCE macro, the AF_INET addressstructure changes to be compatible with BSD 4.4/UNIX 98 specifications. Forthe sockaddr_in address structure, these differences are summarized in thetable:

Table 4. Differences between BSD 4.3 and BSD 4.4/UNIX 98 for sockaddr_in address structureBSD 4.3 sockaddr_in address structureBSD 4.4/UNIX 98 sockaddr_in addressstructure
struct sockaddr_in {
short sin_family;
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};
struct sockaddr_in {
uint8_t sin_len;
sa_family_t sin_family;
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};

Table 5. AF_INET address structureAddress structure fieldDefinitionsin_lenThis field contains the length of the address for UNIX® 98 specifications.
Note:
The: sin_len field is only providedfor BSD 4.4 compatibility. It is not necessary to use this field even whenusing BSD 4.4/UNIX 98 compatibility. The field is ignored on input addresses.
sin_familyThis field contains the address family, which is alwaysAF_INET when TCP or UDP is used.sin_portThis field contains the port number.sin_addrThis field contains the Internet address.sin_zeroThis field is reserved. Set this field to hexadecimalzeros.

 

AF_INET address family sockets can be either connection-oriented (type SOCK_STREAM)or they can be connectionless (type SOCK_DGRAM). Connection-oriented AF_INETsockets use TCP as the transport protocol. Connectionless AF_INET socketsuse UDP as the transport protocol. When you create an AF_INET domain socket,you specify AF_INET for the address family in the socket program. AF_INETsockets can also use a type of SOCK_RAW. If this type is set, the applicationconnects directly to the IP layer and does not use either the TCP or UDP transports.

 

 

原创粉丝点击