socket编程中AF_INET和PF_INET有什么区别? [英] What is the difference between AF_INET and PF_INET in socket programming?

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

问题描述

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

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

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

I'm confused between using AF_INET and PF_INET in socket() and bind().

另外,如何在sin_addr字段中给出ip地址?

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

推荐答案

Beej 著名的网络编程指南 给出了很好的解释:

在某些文档中,您会看到提到了神秘的PF_INET".这是自然界中很少见的怪异灵兽,但我不妨在这里澄清一下.很久以前,它是认为可能是一个地址族(AF_INET"中的AF"代表什么for) 可能支持被他们引用的几个协议协议族(PF_INET"中的PF"代表什么).
那没有发生.那好吧.所以正确的做法是在你的struct sockaddr_in 和 PF_INET 在您对 socket() 的调用中.但实际上,您可以在任何地方使用 AF_INET.而且,由于这就是 W. Richard Stevens 在他的书中所做的,这就是我要做的在这里.

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天全站免登陆