What is the meaning of 0.0.0.0 address while receiving broadcast (or other packets)?

被刻印的时光 ゝ 提交于 2021-01-29 13:58:35

问题


I have two scripts, first sends a broadcast, second is receiving UDP packets. It is working only when the receiving script has his IP address set (via bind) to 0.0.0.0. Why? This address should be something like "not existing address", so how can the script have it set like his own address? Why 127.0.0.1 (or exactly 192.168.0.xx) does not work?

Thank you, RA


回答1:


Probably your machine has two or more interfaces with different IPs, as you already know the 127.0.0.1 IP means your local machine and the 192.168.0.xx the local IP sended to you by the router via DHCP or assigned by you statically, the 0.0.0.0 is a special addres that means every IP address of your machine.

So if you bind some service listener in 0.0.0.0 all IPs will be affected.

For example, you need to receive ONLY and JUST ONLY trafic for your localhost, then you set your server on 127.0.0.1, now you also need the trafic from 192.168.0.xx then you bind on this IP. But if you need that trafic goes through all the IPs you bind the 0.0.0.0 address.. if you have two or more interfaces running on your machine with two different IPs, the server will listen on both. Hope I answered your question! Bye!



来源:https://stackoverflow.com/questions/55984824/what-is-the-meaning-of-0-0-0-0-address-while-receiving-broadcast-or-other-packe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!