MCPcopy Create free account
hub / github.com/OpenDDS/OpenDDS / update_interfaces

Method update_interfaces

dds/DCPS/NetworkConfigModifier.cpp:39–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39void NetworkConfigModifier::update_interfaces()
40{
41 if (DCPS_debug_level >= 1) {
42 ACE_DEBUG((LM_DEBUG, "(%P|%t) NetworkConfigModifier::update_interfaces: enumerating interfaces.\n"));
43 }
44
45 ifaddrs* p_ifa = 0;
46 ifaddrs* p_if = 0;
47
48 if (::getifaddrs(&p_ifa) != 0) {
49 if (log_level >= LogLevel::Error) {
50 ACE_ERROR((LM_ERROR, "(%P|%t) ERROR: NetworkConfigModifier::update_interfaces: %p\n",
51 "getifaddrs error"));
52 }
53
54 return;
55 }
56
57 // Using logic from ACE::get_ip_interfaces_getifaddrs
58 // but need ifa_name which is not returned by it
59 List nia_list;
60
61 // Pull the address out of each INET interface.
62 for (p_if = p_ifa; p_if != 0; p_if = p_if->ifa_next) {
63 if (p_if->ifa_addr == 0)
64 continue;
65
66 // Check to see if it's up.
67 if ((p_if->ifa_flags & IFF_UP) != IFF_UP)
68 continue;
69
70 if (p_if->ifa_addr->sa_family == AF_INET) {
71 struct sockaddr_in* addr = reinterpret_cast<sockaddr_in*> (p_if->ifa_addr);
72
73 // Sometimes the kernel returns 0.0.0.0 as the interface
74 // address, skip those...
75 if (addr->sin_addr.s_addr != INADDR_ANY) {
76 ACE_INET_Addr address;
77 address.set((u_short) 0, addr->sin_addr.s_addr, 0);
78
79 nia_list.push_back(NetworkInterfaceAddress(p_if->ifa_name, p_if->ifa_flags & (IFF_MULTICAST | IFF_LOOPBACK), NetworkAddress(address)));
80 }
81 }
82# if defined (ACE_HAS_IPV6)
83 else if (p_if->ifa_addr->sa_family == AF_INET6) {
84 struct sockaddr_in6 *addr = reinterpret_cast<sockaddr_in6 *> (p_if->ifa_addr);
85
86 // Skip the ANY address
87 if (!IN6_IS_ADDR_UNSPECIFIED(&addr->sin6_addr)) {
88 ACE_INET_Addr address;
89 address.set(reinterpret_cast<struct sockaddr_in *> (addr), sizeof(sockaddr_in6));
90
91 nia_list.push_back(NetworkInterfaceAddress(p_if->ifa_name, p_if->ifa_flags & (IFF_MULTICAST | IFF_LOOPBACK), NetworkAddress(address)));
92 }
93 }
94# endif /* ACE_HAS_IPV6 */
95 }
96

Callers

nothing calls this directly

Calls 3

NetworkInterfaceAddressFunction · 0.85
setFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected