Enumerating each IP address assigned to network interfaces

后端 未结 4 1391
栀梦
栀梦 2021-01-03 11:10

I think there is no way to enumerate each network interface on my system and their assigned IP address using just sockets. Is this correct?

I mean, in Linux this cou

4条回答
  •  不知归路
    2021-01-03 11:45

    Use gethostname() to retreive the machine's local DNS name, and then pass that name to gethostbyname() to get its local IP addresses.

    If the OS supports IPv6, then look at the getaddrinfo() function instead of gethostbyname().

提交回复
热议问题