Choosing the interface in multi-homed hosts

◇◆丶佛笑我妖孽 提交于 2019-12-05 20:52:37

Maybe you want to set node as NULL. Set it to the IP address of the interface you want.

socket_result = getaddrinfo(NULL, port_num_string, &hints, &sock_addr_list);

to

socket_result = getaddrinfo("192.168.1.10", port_num_string, &hints, &sock_addr_list);

From the man page:

There are several reasons why the linked list may have more than one addrinfo structure, including: the network host is multihomed, accessible over multiple protocols (e.g. both AF_INET and AF_INET6); or the same service is available from multiple socket types (one SOCK_STREAM address and another SOCK_DGRAM address, for example).

Use getifaddr to search through all interfaces manually.

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