linux 端口号 限制,nginx是如何搞定端口号限制的?

我不清楚其他unix和bsd是什么样,linux的socket设置了SO_REUSEADDR,只有在已有的bind的socket是TCP_LISTEN的状态下才会报错,具体的可以去看内核代码

你引文的第4项,unpv3原文是

SO_REUSEADDR allows completely duplicate bindings: a bind of an IP address and port, when that same IP address and port are already bound to another socket, if the transport protocol supports it. Normally this feature is supported only for UDP sockets.

This feature is used with multicasting to allow the same application to be run multiple times on the same host. When a UDP datagram is received for one of these multiply bound sockets, the rule is that if the datagram is destined for either a broadcast address or a multicast address, one copy of the datagram is delivered to each matching socket. But if the datagram is destined for a unicast address, the datagram is delivered to only one socket. If, in the case of a unicast datagram, there are multiple sockets that match the datagram, the choice of which socket receives the datagram is implementation-dependent.

netcat不同平台下很可能不一样,linux的nc是做不到绑定统一ip:port的,如果mac下的可以,建议你用strace看一下,再把结果贴出来

另外,希望lz不要老是怀疑和猜测,软件这玩意特别是大部分软件都是开源的情况下还有什么不确定性的话最好自己认真去看看去查查。

【 在 chunhui 的大作中提到: 】

: resuseadd不能解决,而且它说的已经排除了我试的情况,可见端口是本机范围内的不可重用资源貌似是rfc里的约定。等有空我去看一下是否有明确说明。总之,四元组不同就可以区分连接,这个说法有点陷阱。

: SO_REUSEADDR可以用在以下四种情况下。

: (摘自《Unix网络编程》卷一,即UNPv1)

: ...................

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值