SO_REUSEADDR的用途? [英] Uses of SO_REUSEADDR?

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

问题描述

我已经使用SO_REUSEADDR有我的服务器,得到终止了抱怨插座已在使用中重新启动。我在想,如果有SO_REUSEADDR的其他用途?有没有人使用套接字选项以外的所述目的?

I have used SO_REUSEADDR to have my server which got terminated to restart with out complaining that the socket is already is in use. I was wondering if there are other uses of SO_REUSEADDR? Have anyone used the socket option for other than the said purpose?

推荐答案

对于TCP:的主要目的是重新启动在同一地址的封闭/杀害的过程。

For TCP: the primary purpose is to restart a closed/killed process on the same address.

是必须的标志,因为端口进入一个TIME_WAIT状态,以确保所有数据转移。

The flag is needed because the port goes into a TIME_WAIT state to ensure all data is transfered.

如果两个插座绑定到相同的接口和端口,是同一个组播组的成员,数据将被传递到两个插座。

If two sockets are bound to the same interface and port and are members of the same multicast group, data will be delivered to both sockets.

我猜一个替代的使用将是一个安全攻击,试图拦截数据。

I guess an alternative use would be a security attack to try to intercept data.

来源


对于UDP: SO_REUSEADDR用于多播

For UDP: SO_REUSEADDR is used for multicast

一个以上的过程可以结合到
  如果同一SOCK_DGRAM UDP端口的绑定()
  是$ P $由pceded:

More than one process may bind to the same SOCK_DGRAM UDP port if the bind() is preceded by:

INT 1 = 1; setsockopt的(袜子,
  SOL_SOCKET,SO_REUSEADDR,&安培;一,
  的sizeof(一个))

int one = 1; setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))

在这种情况下,每一个接收组播
  或广播UDP数据报注定
  共享端口被递送到所有
  套接字绑定到的端口。

In this case, every incoming multicast or broadcast UDP datagram destined to the shared port is delivered to all sockets bound to the port.

来源

这篇关于SO_REUSEADDR的用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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