AF_INET 和 PF_INET 的區別

一個很小很小的紀錄,免得自己忘記
(事實上一定會忘記啦,但是留個紀錄起碼可以再回來查)

從 Linux 裡面的註解來看

AF = Address Family
PF = Protocol Family

但實際使用上根本沒有差別!!原因如下:

linux/include/linux/socket.h

#define AF_INET 2 /* Internet IP Protocol */
/* Protocol families, same as address families. */
#define PF_INET AF_INET

很明顯的,從 Linux Kernel 的註解來看,Linux 已經完全不打算去區分這兩的差別了。

附錄:
Manual page socket(2)

POSIX.1-2001 does not require the inclusion of , and this header file is not required on Linux. However, some historical (BSD) implementations required this header file, and portable applications are probably wise to include it.

The manifest constants used under 4.x BSD for protocol families are PF_UNIX, PF_INET, etc., while AF_UNIX etc. are used for address families. However, already the BSD man page promises: "The protocol family generally is the same as the address family", and subsequent standards use AF_* everywhere.

The header file is only required for libc4 or earlier. Some packages, like util-linux, claim portability to all Linux versions and libraries. They certainly need this header file.

留言

這個網誌中的熱門文章

我弟家的新居感恩禮拜分享:善頌善禱

如何將Linux打造成OpenFlow Switch:Openvswitch

Openssl 範例程式:建立SSL連線