与INADDR_ANY绑定 [英] bind with INADDR_ANY

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

问题描述

如果我将套接字绑定到INADDR_ANY,我知道它将接受服务器上配置的任何IP上的传入连接.可以说,我在进行bind()调用时配置了1个IP,然后配置了一个新IP. bind()还将接受到新配置的IP发起的连接,还是仅对调用bind()时存在的IP有效?

If I bind a socket to INADDR_ANY I know that it will accept incoming connections on any of IPs configured on the server. Lets say I have 1 IP configured when I make the bind() call and then a new IP gets configured. Will be bind() accept connections initiated to the newly configured IP also or does it work only for the IPs that were existing when bind() was called ?

推荐答案

在Linux上,当您绑定到INADDR_ANY时,套接字将保持绑定到0.0.0.0,并且将接受与任何本地IP地址的连接,这关系到如何更改.仅当建立TCP连接时,才将单个连接绑定到在其上接收到的IP地址.仍然可以在任何地址上接收到其他连接.

On Linux when you bind to INADDR_ANY then the socket stays bound to 0.0.0.0 and will accept connection to any local IP address now matter how that changes. Only when a TCP connection is established then the single connection is bound to the IP address it was received on. Other connections may still be received on any address.

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

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