The difference between pf_inet and af_inet

Source: Internet
Author: User

When writing a network program, establish a TCP socket:

Sock = socket (pf_inet, sock_stream, 0);

Then bind the address or connect to the remote address when you need to initialize the SOCKADDR_IN structure, which specifies address family when the general settings asked Af_inet, that is, the use of IP.

The associated header file definition:

AF = Address Family

PF = Protocol Family

Af_inet = Pf_inet

So in Windows, Af_inet and pf_inet are exactly the same, and in the Unix/linux system, there is a slight difference between the two in different versions. For BSD, it is AF, for POSIX is PF.

In theory, the socket is a specified protocol, should be used pf_xxxx, set the address should be used af_xxxx. Of course the values of af_inet and pf_inet are the same, and mixing is not too much of a problem.

In the function Socketpair with the socket's domain parameter, there is

Af_unix, Af_local, Af_inet, Pf_unix, pf_local, pf_inet

These parameters are Af_unix = af_local, Pf_unix = pf_local, af_local = pf_local, af_inet = pf_inet

Recommendation: The Pf_local series is used for the domain parameter of the Socketpair and socket, and af_local is used when initializing the socket interface address structure.

For example:

z = socket (pf_local, sock_stream, 0); adr_unix.sin_family = af_local;

The difference between pf_inet and af_inet

Related Article

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.