开发者

bind with INADDR_ANY

开发者 https://www.devze.com 2023-04-10 05:13 出处:网络
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开发者_StackOverflow

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开发者_StackOverflow社区 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 ?


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 no 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.


Yes it will accept connections on newly created or newly configured interfaces.

You can try it yourself, by creating a dummy interface:

/sbin/ifconfig dummy0 172.17.42.99 netmask 255.255.255.255

Or something; then try to connect to that IP.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号