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

Method interfaceName

dds/DCPS/RTPS/GuidGenerator.cpp:100–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100int
101GuidGenerator::interfaceName(const char* iface)
102{
103 // A shortcut to determine if a *valid* interface was already checked.
104 // The shortcut value (interface_name_) is stored IFF the method returns 0.
105 if (interface_name_ == iface) {
106 return 0;
107 }
108
109 // See ace/OS_NS_netdb.cpp ACE_OS::getmacaddress()
110#if defined ACE_WIN32 && !defined ACE_HAS_WINCE
111 ULONG size;
112 if (::GetAdaptersAddresses(AF_UNSPEC, 0, 0, 0, &size)
113 != ERROR_BUFFER_OVERFLOW) {
114 return -1;
115 }
116 ACE_Allocator* const alloc = DCPS::SafetyProfilePool::instance();
117 IP_ADAPTER_ADDRESSES* const addrs =
118 static_cast<IP_ADAPTER_ADDRESSES*>(alloc->malloc(size));
119 if (!addrs) {
120 return -1;
121 }
122 if (::GetAdaptersAddresses(AF_UNSPEC, 0, 0, addrs, &size) != NO_ERROR) {
123 alloc->free(addrs);
124 return -1;
125 }
126
127 bool found = false;
128 for (IP_ADAPTER_ADDRESSES* iter = addrs; iter && !found; iter = iter->Next) {
129 if (ACE_Wide_To_Ascii(iter->FriendlyName).char_rep() == iface) {
130 std::memcpy(node_id_, iter->PhysicalAddress,
131 std::min(static_cast<size_t>(iter->PhysicalAddressLength),
132 sizeof node_id_));
133 found = true;
134 }
135 }
136
137 alloc->free(addrs);
138 if (found) {
139 interface_name_ = iface;
140 return 0;
141 } else {
142 return -1;
143 }
144
145#elif defined ACE_LINUX || defined ACE_ANDROID
146 ifreq ifr;
147 // Guarantee that iface will fit in ifr.ifr_name and still be null terminated
148 // ifr.ifr_name is sized to IFNAMSIZ
149 if (std::strlen(iface) >= sizeof(ifr.ifr_name)) {
150 if (DCPS::log_level >= DCPS::LogLevel::Error) {
151 ACE_ERROR((LM_ERROR, "(%P|%t) ERROR: GuidGenerator::interfaceName: "
152 "Interface name %C exceeds max allowable length, must be < %d.\n",
153 iface, IFNAMSIZ));
154 }
155 return -1;
156 }
157 std::strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));

Callers 3

TESTFunction · 0.80

Calls 4

instanceFunction · 0.85
closeFunction · 0.85
mallocMethod · 0.45
freeMethod · 0.45

Tested by

no test coverage detected