|
a/libupnpp/getsyshwaddr.c |
|
b/libupnpp/getsyshwaddr.c |
|
... |
|
... |
89 |
int ifnamelen = 0;
|
89 |
int ifnamelen = 0;
|
90 |
|
90 |
|
91 |
if (iface && *iface) {
|
91 |
if (iface && *iface) {
|
92 |
ifnamelen = strnlen(iface, 200);
|
92 |
ifnamelen = strnlen(iface, 200);
|
93 |
}
|
93 |
}
|
|
|
94 |
// fprintf(stderr, "getsyshwaddr: [%s](%d), ilen %d hlen %d, ifreporter %p\n",
|
|
|
95 |
// iface, ifnamelen, ilen, hlen, ifreporter);
|
94 |
|
96 |
|
95 |
//fprintf(stderr, "getsyshwaddr: iface [%s], ip %p, hwaddr %p, ifaces %p\n",
|
|
|
96 |
// iface.c_str(), ip, hwaddr, ifaces);
|
|
|
97 |
|
97 |
|
98 |
memset(&mac, 0, sizeof(mac));
|
98 |
memset(&mac, 0, sizeof(mac));
|
99 |
|
99 |
|
100 |
#ifndef WIN32
|
100 |
#ifndef WIN32
|
101 |
#if HAVE_GETIFADDRS
|
101 |
#if HAVE_GETIFADDRS
|
|
... |
|
... |
115 |
|
115 |
|
116 |
if (ifreporter && strcmp(p->ifa_name , "lo")) {
|
116 |
if (ifreporter && strcmp(p->ifa_name , "lo")) {
|
117 |
ifreporter(tok, p->ifa_name);
|
117 |
ifreporter(tok, p->ifa_name);
|
118 |
}
|
118 |
}
|
119 |
|
119 |
|
120 |
if (ifnamelen && strncmp(iface, p->ifa_name, ifnamelen) != 0 )
|
120 |
if (ifnamelen && strcmp(iface, p->ifa_name))
|
121 |
continue;
|
121 |
continue;
|
122 |
|
122 |
|
123 |
addr_in = (struct sockaddr_in *)p->ifa_addr;
|
123 |
addr_in = (struct sockaddr_in *)p->ifa_addr;
|
124 |
a = (htonl(addr_in->sin_addr.s_addr) >> 0x18) & 0xFF;
|
124 |
a = (htonl(addr_in->sin_addr.s_addr) >> 0x18) & 0xFF;
|
125 |
if (a == 127)
|
125 |
if (a == 127)
|
|
... |
|
... |
174 |
for (if_idx = ifaces; if_idx->if_index; if_idx++)
|
174 |
for (if_idx = ifaces; if_idx->if_index; if_idx++)
|
175 |
{
|
175 |
{
|
176 |
if (ifreporter && strcmp(if_idx->if_name , "lo")) {
|
176 |
if (ifreporter && strcmp(if_idx->if_name , "lo")) {
|
177 |
ifreporter(tok, if_idx->if_name);
|
177 |
ifreporter(tok, if_idx->if_name);
|
178 |
}
|
178 |
}
|
179 |
if (ifnamelen && strncmp(name, if_idx->if_name, ifnamelen) != 0 )
|
179 |
if (ifnamelen && strcmp(name, if_idx->if_name))
|
180 |
continue;
|
180 |
continue;
|
181 |
|
181 |
|
182 |
strncpy(ifr.ifr_name, if_idx->if_name, IFNAMSIZ);
|
182 |
strncpy(ifr.ifr_name, if_idx->if_name, IFNAMSIZ);
|
183 |
if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0)
|
183 |
if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0)
|
184 |
continue;
|
184 |
continue;
|
|
... |
|
... |
225 |
|
225 |
|
226 |
// Get the full list and walk it
|
226 |
// Get the full list and walk it
|
227 |
if (GetAdaptersInfo(pAdapterInfo, &dwBufLen) == NO_ERROR) {
|
227 |
if (GetAdaptersInfo(pAdapterInfo, &dwBufLen) == NO_ERROR) {
|
228 |
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
|
228 |
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
|
229 |
for (; pAdapter != NULL; pAdapter = pAdapter->Next) {
|
229 |
for (; pAdapter != NULL; pAdapter = pAdapter->Next) {
|
230 |
|
230 |
if (pAdapter == NULL)
|
|
|
231 |
break;
|
231 |
//fprintf(stderr, "Testing adapter name [%s] Description [%s] "
|
232 |
// fprintf(stderr, "Adapter name [%s] Description [%s] "
|
232 |
// "against input [%s]\n", pAdapter->AdapterName,
|
233 |
// "input [%s]\n", pAdapter->AdapterName,
|
233 |
// pAdapter->Description, iface.c_str());
|
234 |
// pAdapter->Description, iface);
|
234 |
|
235 |
|
235 |
/* CurrentIpAddress->IpAddress.String stores the IPv4 address
|
236 |
/* CurrentIpAddress->IpAddress.String stores the IPv4 address
|
236 |
as a char string in dotted notation */
|
237 |
as a char string in dotted notation */
|
237 |
/* Skip localhost ? */
|
238 |
/* Skip localhost ? */
|
|
|
239 |
const char *firstipstr = pAdapter->IpAddressList.IpAddress.String;
|
|
|
240 |
#if 0
|
|
|
241 |
IP_ADDR_STRING *nextip = &pAdapter->IpAddressList;
|
|
|
242 |
while (nextip != 0) {
|
|
|
243 |
fprintf(stderr, "IP: [%s]\n", nextip->IpAddress.String);
|
|
|
244 |
nextip = nextip->Next;
|
|
|
245 |
}
|
|
|
246 |
#endif
|
238 |
if (!strncmp("127.0.0",
|
247 |
if (!strncmp("127.0.0", firstipstr, 7)) {
|
239 |
pAdapter->CurrentIpAddress->IpAddress.String, 7)) {
|
|
|
240 |
continue;
|
248 |
continue;
|
241 |
}
|
249 |
}
|
242 |
|
250 |
|
243 |
// Note: AdapterName is a GUID which as far as I can see
|
251 |
// Note: AdapterName is a GUID which as far as I can see
|
244 |
// appears nowhere in the GUI. Description is something
|
252 |
// appears nowhere in the GUI. Description is something
|
|
... |
|
... |
247 |
if (ifreporter) {
|
255 |
if (ifreporter) {
|
248 |
ifreporter(tok, pAdapter->Description);
|
256 |
ifreporter(tok, pAdapter->Description);
|
249 |
}
|
257 |
}
|
250 |
|
258 |
|
251 |
/* If the interface name was specified, check it */
|
259 |
/* If the interface name was specified, check it */
|
252 |
if (ifnamelen &&
|
260 |
if (ifnamelen && strcmp(iface, pAdapter->Description))
|
253 |
strncmp(iface, pAdapter->Description, ifnamelen) != 0)
|
|
|
254 |
continue;
|
261 |
continue;
|
255 |
|
262 |
|
256 |
/* Store the IP address in dotted notation format */
|
263 |
/* Store the IP address in dotted notation format */
|
257 |
if (ip) {
|
264 |
if (ip) {
|
258 |
strncpy(ip, pAdapter->CurrentIpAddress->IpAddress.String, ilen);
|
265 |
strncpy(ip, firstipstr, ilen);
|
259 |
ip[ilen-1] = 0;
|
266 |
ip[ilen-1] = 0;
|
260 |
}
|
267 |
}
|
261 |
|
268 |
|
262 |
/* The MAC is in the pAdapter->Address char array */
|
269 |
/* The MAC is in the pAdapter->Address char array */
|
263 |
memcpy(mac, pAdapter->Address, 6);
|
270 |
memcpy(mac, pAdapter->Address, 6);
|