Linux 上的 SO_REUSEPORT
我想知道 LINUX 2.6 中是否启用了 SO_REUSEPORT 选项?
如果我尝试使用它并编译我的代码,我会收到以下错误
01.c:72: error: `SO_REUSEPORT' undeclared (first use in this function)
01.c:72: error: (Each undeclared identifier is reported only once
01.c:72: error: for each function it appears in.)
使用上述选项我想我可以将两个不同的套接字绑定到相同的 IPADRESS 和端口号
I want to know if SO_REUSEPORT option is enabled in LINUX 2.6 or not ??
If I try to use it and compile my code I get following error
01.c:72: error: `SO_REUSEPORT' undeclared (first use in this function)
01.c:72: error: (Each undeclared identifier is reported only once
01.c:72: error: for each function it appears in.)
Using the above option I guess I can bind two different sockets to same IPADRESS and PORT NUMBER
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
此选项是在内核 3.9 中完成的,请参阅此 git commit
http ://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c617f398edd4db2b8567a28e899a88f8f574798d
this options was done in kernel 3.9, see this git commit
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c617f398edd4db2b8567a28e899a88f8f574798d
来自
/usr/include/asm-generic/socket.h
:嗯。看起来它尚未定义或处于折旧的最后阶段。
以下是 KernelTrap 上的帖子所说的内容:
From
/usr/include/asm-generic/socket.h
:Hmmm. Looks like it's undefined or on the last stages of being depreciated.
Here's what a post on KernelTrap says:
尝试一下:
如果您要将多个 UDP 侦听器绑定到一个端口,某些平台(其中之一是 OS/X)需要设置此项。
Try this:
Some platforms (OS/X for one) need this to be set if you're e.g. binding multiple UDP listeners to one port.
SO_REUSEPORT 已向后移植到 RHEL6.5 内核 2.6.32。
SO_REUSEPORT was backported to the RHEL6.5 kernel 2.6.32.
它是在 3.9 周期期间由 Tom Herbert 在一系列补丁中添加的,您可以在此处看到,为了更好地支持多线程Web服务器。
如果您想将 SO_REUSEPORT 集成到较旧的内核版本中,可以在此处找到补丁本身。
是的,您可以使用 SO_REUSEPORT 将套接字绑定到与另一个连接相同的地址和端口,只要初始连接也使用 SO_REUSEPORT (以及共享源地址和端口的任何其他连接)。这样做是为了防止恶意应用程序劫持端口。
It was added during the 3.9 cycle in a series of patches by Tom Herbert, as you can see here, in order to better support multithreaded web servers.
The patch itself can be found here if you want to integrate SO_REUSEPORT into an older kernel version.
And yes, you can use SO_REUSEPORT to bind a socket to the same address and port as another connection, as long as the initial connection also uses SO_REUSEPORT (and any other connections sharing the source address and port). This is done to prevent port hijacking by rogue applications.