The nuances of af_inet and pf_inet

Source: Internet
Author: User

In the write NetworkProgramTCP socket:

Sock = socket (pf_inet, sock_stream, 0 );

Then bind the local address or connect to the remote address. The sockaddr_in structure needs to be initialized. When the address family is specified, af_inet is usually set to use the IP address.

Related header file definition: AF = address family

PF = protocol family

Af_inet = pf_inet

In Windows, af_inet and pf_inet are exactly the same, but in Unix/Linux systems, there are minor differences between them in different versions. For BSD, It is Af, and for POSIX it is PF.

Theoretically, the Protocol is specified when the socket is established. pf_xxxx should be used, and af_xxxx should be used when the address is set. Of course, the af_inet and pf_inet values are the same, and mixed use will not be too problematic.

In the domain parameters of the socketpair and socket functions

Af_unix, af_local, af_inet, pf_unix, pf_local, pf_inet

Af_unix = af_local, pf_unix = pf_local, af_local = pf_local, af_inet = pf_inet

** Suggestion: for the domain parameters of socketpair and socket, use the pf_local series, and use af_local when initializing the interface address structure.

For example:

Z = socket (pf_local, sock_stream, 0 );

Adr_unix.sin_family = af_local;

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/ixidof/archive/2010/07/26/5767228.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.