How to enumerate all IP addresses attached to a machine, in POSIX C?

前端 未结 6 897
遥遥无期
遥遥无期 2021-01-03 03:25

Background:

I\'m writing a daemon that makes outgoing TCP/IP connections. It will be running on machines with multiple (non-loopback) IP addresses.

6条回答
  •  星月不相逢
    2021-01-03 04:07

    are you sure you are using gethostname()/gethostbyname() correctly? check out here, the only problem I see with doing this is that it's possible that a domain name has multiple ip addresses mapped to it. If that's the case then there's no way of knowing what the ip address belonging to the local machine is

提交回复
热议问题