c - socket编程中AF_INET和PF_INET有什么区别?

socket编程中AF_INET和PF_INET有什么区别?

我对在 socket()bind() 中使用 AF_INET 和 PF_INET 感到困惑。

另外,如何在 sin_addr 字段中给出 ip-address?

最佳答案

Beej's famous network programming guide给出了一个很好的解释:

In some documentation, you'll see mention of a mystical "PF_INET". This is a weird etherial beast that is rarely seen in nature, but I might as well clarify it a bit here. Once a long time ago, it was thought that maybe a address family (what the "AF" in "AF_INET" stands for) might support several protocols that were referenced by their protocol family (what the "PF" in "PF_INET" stands for).
That didn't happen. Oh well. So the correct thing to do is to use AF_INET in your struct sockaddr_in and PF_INET in your call to socket(). But practically speaking, you can use AF_INET everywhere. And, since that's what W. Richard Stevens does in his book, that's what I'll do here.

https://stackoverflow.com/questions/6729366/

相关文章:

python - 如何在类中调用函数?

linux - 如何包含管道 |在我的 linux 中找到 -exec 命令?

linux - 有效地测试一个端口是否在 Linux 上打开?

linux - 在 Unix/Linux 中判断两个文件是否具有相同内容的最快方法?

python - 仅列出当前目录中的文件

python - 在 Python 中换行

linux - 如何在 Linux 中为每个输出行列出一个文件名?

linux - 创建 zip 文件并忽略目录结构

python - 如何理解 Python 循环的 `else` 子句?

python - 转置列表列表