究竟应该是AF_INET还是PF_INET.

xx2j 2003-04-22 12:25:34
socket的第一个参数究竟应该是AF_INET还是PF_INET,虽然它们的值都是2。

我觉得应该是PF_INET,但我看大家用的多的还是AF_INET。
...全文
327 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xx2j 2003-04-26
  • 打赏
  • 举报
回复
我不同意 Eagle2004(Eagle) 。我觉得标准应该用PF_INET,只是后来微软的人搞错了,才会出现AF_INET。

sockaddr_in.sin_famiry = AF_INET
这里才是用AF_INET.
yins 2003-04-26
  • 打赏
  • 举报
回复
同意 Eagle2004(Eagle)
Eagle2004 2003-04-25
  • 打赏
  • 举报
回复
标准的用法是SOCKET的第一个参数用:AF_INET.
现在用PF_INET也可以,但它们是有区别的.
以后就不知道能不能混用了.
blue_fairy 2003-04-25
  • 打赏
  • 举报
回复
因为在头文件里定义了二者相同的值。
lang_ren 2003-04-25
  • 打赏
  • 举报
回复
一样的!
xx2j 2003-04-25
  • 打赏
  • 举报
回复
up
xx2j 2003-04-22
  • 打赏
  • 举报
回复
可为什么大家都用AF_INET,我还以为是我看的书是错的呢。
还有windows里是这样声明的
SOCKET socket(int af,int type,int protocol);
kaitty 2003-04-22
  • 打赏
  • 举报
回复
|> | AF = address family. These constants go into the sin_family member of the
|> | socket address structure.
|> |
|> | PF = protocol family. These constants are the first argument to socket().
|>
|> There is a little more to it than that. Although I don't have the ancient
|> sources handy to check (and my memory of this particular aspect is fading),
|> I recall that the original socket code (4.1c/2.8/2.9BSD) employed a protocol
|> structure similar in concept to the sockaddr structure. The protocol
|> structure contained a family element and a family-specific protocol number.
|> The PF_ constants were used for the family element of the protocol structure.
|> A protocol structure (or, rather, the address of one) could be passed to the
|> socket() call to serve a purpose similar to that of the last (integer)
|> argument
|> of the current socket() call. (Keep in mind that the old socket() call did
|> not
|> take a family/domain argument at all, so interpretation of the protocol
|> number
|> would not have been possible without the PF_ cue.) Originally, then, the PF_
|> and AF_ constants had a much more parallel purpose as structure tags. When
|> socket() started requiring a family/domain argument, the protocol structure
|> was dropped.
|
| Well, actually your memory is a bit off.

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧