Sockets - Using INADDR_ANY on client side

前端 未结 4 1801
长情又很酷
长情又很酷 2020-12-09 13:38

I recently ran into this blog post which describes a TCP server client using libev. The sever uses INADDR_ANY to bind to an interface which is something I\'m fa

4条回答
  •  粉色の甜心
    2020-12-09 14:25

    This is the answer as provided by nos in a comment. If nos comes back and posts it as an answer, I will mark nos' post as the answer and delete this one.

    INADDR_ANY is normally defined as 0. That is the IP address 0.0.0.0. RFC 1122 says that means "This host on this network". The linux IP stack seems to just route this to the loopback interface. (e.g. try ping 0.0.0.0 or even just ping 0). I'd say the author made a typo, and should have used INADDR_LOOPBACK.

提交回复
热议问题