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