什么时候需要 IPPROTO_UDP? [英] when is IPPROTO_UDP required?

查看:72
本文介绍了什么时候需要 IPPROTO_UDP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么时候需要 IPPROTO_UDP?

When is IPPROTO_UDP required?

是否有过 UDP 不是 SOCK_DGRAM 的默认协议的情况?(真实案例,不是假设的它可能是",拜托了)

Is there ever a case where UDP is not the default protocol for SOCK_DGRAM? (real cases, not hypothetical "it might be", please")

即,以下两行在哪些情况下不会产生相同的行为?

i.e., what are the situations where the following two lines would not produce identical behavior?

if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
if ((s=socket(AF_INET, SOCK_DGRAM, 0))==-1)

推荐答案

鉴于这些声明:

tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
raw_socket = socket(AF_INET, SOCK_RAW, protocol);

Linux 中的 ip(7) 手册页说:

the ip(7) manual page in linux says:

协议的唯一有效值是0 和 IPPROTO_TCP 用于 TCP 套接字,以及0 和 IPPROTO_UDP 用于 UDP 套接字.对于 SOCK_RAW,您可以指定一个有效的RFC 1700 中定义的 IANA IP 协议分配的号码.

The only valid values for protocol are 0 and IPPROTO_TCP for TCP sockets, and 0 and IPPROTO_UDP for UDP sockets. For SOCK_RAW you may specify a valid IANA IP protocol defined in RFC 1700 assigned numbers.

问题中的这两行总是会产生相同的结果.

Those two lines in your questions will always produce the same result.

这篇关于什么时候需要 IPPROTO_UDP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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