我认为:用AF_INET好,用PF_INET也行。winsock.h里:
#define AF_INET  2
#define PF_INET  AF_INET
#define PF_UNIX  AF_UNIX
上面这样的宏定义有26行。
In practice, though, the PF_ and AF_ macros for the built-in protocols have the same values (in both Linux and Windows).
下面的例子都是用AF_的:
https://www.man7.org/linux/man-pages/man7/socket.7.html
#include <sys/socket.h>
sockfd = socket(int socket_family, int socket_type, int protocol); // fd: file descriptor
socket_family可以是AF_INET, AF_UNIX, AF_IPX, and AF_PACKET等。打个不太恰当的比方:同一个地址192.168.0.100上可以有HTTP和FTP等多个协议。
https://www.ibm.com/docs/en/ztpf/1.1.0.15?topic=considerations-unix-domain-sockets
#define SOCK_PATH  "tpf_unix_sock.server"
server_sock = socket(AF_UNIX, SOCK_STREAM, 0);
struct sockaddr_un server_sockaddr;
server_sockaddr.sun_family = AF_UNIX;   
strcpy(server_sockaddr.sun_path, SOCK_PATH); 
https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/
Beginning in Windows 10 Insider Build 17063, you'll be able to use the unix socket (AF_UNIX) address family on Windows to communicate between Win32 processes. Unix sockets allow inter-process communication (IPC) between processes on the same machine.
IPX is a networking protocol. Originally used by the Novell NetWare operating system and it was later adopted by Windows.
https://www.opensourceforu.com/2015/03/a-guide-to-using-raw-sockets/
For a raw socket, the socket family is AF_PACKET, the socket type is SOCK_RAW and for the protocol, see the if_ether.h header file.
历史
Berkeley sockets is an application programming interface (API) for Internet sockets and Unix domain sockets, used for inter-process communication (IPC). It is commonly implemented as a library of linkable modules. It originated with the 4.2BSD Unix operating system, released in 1983.
Berkeley sockets evolved with little modification from a de facto standard into a component of the POSIX specification. The term POSIX sockets is essentially synonymous with Berkeley sockets, but they are also known as BSD sockets, acknowledging the first implementation in the Berkeley Software Distribution.
As the Berkeley socket API evolved and ultimately yielded the POSIX socket API, certain functions were deprecated or removed and replaced by others. The POSIX API is also designed to be reentrant.
inet_aton, inet_ntoa, gethostbyname, gethostbyaddr, getservbyname, getservbyport, gethostbyaddr, getservbyport are BSD functions. inet_pton, inet_ntop, getaddrinfo, getnameinfo是POSIX函数。
All modern operating systems implement a version of the Berkeley socket interface. It became the standard interface for applications running in the Internet. Even the Winsock implementation for MS Windows, created by unaffiliated developers, closely follows the standard.
The function socket creates an endpoint for communication and returns a file descriptor for the socket. It uses three arguments:
domain [又拽名词], which specifies the protocol [没用address] family of the created socket. For example:
- AF_INET for network protocol IPv4 (IPv4-only)
- AF_INET6 for IPv6 (and in some cases, backward compatible with IPv4)
- AF_UNIX for local socket (using a special filesystem node)
type, one of:
- SOCK_STREAM (reliable stream-oriented service or Stream Sockets)
- SOCK_DGRAM (datagram service or Datagram Sockets)
- SOCK_SEQPACKET (reliable sequenced packet service)
- SOCK_RAW (raw protocols atop the network layer)
protocol specifying the actual transport protocol to use. The most common are IPPROTO_TCP, IPPROTO_SCTP, IPPROTO_UDP, IPPROTO_DCCP. These protocols are specified in file netinet/in.h. The value 0 may be used to select a default protocol from the selected domain and type.
The following lists a sampling of protocol families (preceded by the standard symbolic identifier) defined in a modern Linux or BSD implementation:
- PF_LOCAL, PF_UNIX, PF_FILE Local to host (pipes and file-domain)
- PF_INET Internet Protocol version 4
- ...
- PF_BLUETOOTH Bluetooth sockets
A socket for communications is created with the socket function, by specifying the desired protocol family (PF_-identifier) as an argument.
socket(int socket_family, int socket_type, int protocol)换socket(domain, type, protocol)后,domain family, DF_或DOMAIN_不好吗?PF_很容易让人以为是传递给protocol的。而且"as an argument",socket有3个参数,as which argument? 真是有人编程有人添乱。
六级/考研单词: protocol, socket, domain, implement, evolve, modify, component, synonym, hardware, yield, backward, compatible, pack, atop, default, precede, desire
补充:首先我没有搞明白protocol family的意思。其次搞明白后我依然认为很不高明。求绝对值有fabs和abs两个函数,输入分别是浮点和整数。sin, sqrt等都只有一个参数,不是sqrt(DOUBLE, 2)。无符号32位整数有40亿个,一个参数表示不了protocol,还要再多个参数?咋不: 真核域、动物界、后生动物亚界、后口动物总门、脊索动物门、脊椎动物亚门、羊膜总纲、哺乳纲、兽亚纲、真兽次亚纲、灵长目、真灵长半目、直鼻猴亚目、人猿次目、狭鼻下目、真狭鼻小目、人猿超科、人科、人亚科、人族、人属、人亚属、智人种?!family: (动植物的)科。
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号