是什么在socket编程AF_INET和PF_INET之间的区别? [英] What is the difference between AF_INET and PF_INET in socket programming?

查看:127
本文介绍了是什么在socket编程AF_INET和PF_INET之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是套接字编程AF_INET和PF_INET区别?

What is the difference between AF_INET and PF_INET in socket programming?

我在插座中使用AF_INET和PF_INET()之间的混淆绑定()

另外,如何在 sin_addr 字段给IP地址?

Also, how to give ip-address in sin_addr field?

推荐答案

Beej著名的网络编程指南给出了一个漂亮的解释:

Beej's famous network programming guide gives a nice explanation:

在一些文件,你会看到一个神秘的PF_INET的提及。
  这是一个奇怪的野兽灵气本质上是很少见的,但我
  还不如在这里澄清一下。一旦在很久以前,它是
  想,也许一个地址族(什么是AF,在AF_INET代表
  为)可能会支持被引用的几个协议的
  协议族(是什么PF中的PF_INET表示)。结果
  这并没有发生。好吧。所以,做正确的事情就是在使用你的AF_INET
  结构SOCKADDR_IN和PF_INET在调用插座()。但
  实际上来说,你可以在任何地方使用AF_INET。而且,由于
  这就是理查德·史蒂文斯确实在他的书,这就是我会做
  在这里。

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.

这篇关于是什么在socket编程AF_INET和PF_INET之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆