mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
properly filter disconnected interfaces on win32
This commit is contained in:
parent
f229da5468
commit
517ab5d56f
@ -534,44 +534,46 @@ scan_interfaces() {
|
|||||||
if (result == ERROR_SUCCESS) {
|
if (result == ERROR_SUCCESS) {
|
||||||
IP_ADAPTER_ADDRESSES *p = addresses;
|
IP_ADAPTER_ADDRESSES *p = addresses;
|
||||||
while (p != NULL) {
|
while (p != NULL) {
|
||||||
// p->AdapterName appears to be a GUID. Not sure if this is
|
if (p->OperStatus == IfOperStatusUp) {
|
||||||
// actually useful to anyone; we'll store the "friendly name"
|
// p->AdapterName appears to be a GUID. Not sure if this is
|
||||||
// instead.
|
// actually useful to anyone; we'll store the "friendly name"
|
||||||
TextEncoder encoder;
|
// instead.
|
||||||
encoder.set_wtext(wstring(p->FriendlyName));
|
TextEncoder encoder;
|
||||||
string friendly_name = encoder.get_text();
|
encoder.set_wtext(wstring(p->FriendlyName));
|
||||||
|
string friendly_name = encoder.get_text();
|
||||||
|
|
||||||
Interface interface;
|
Interface interface;
|
||||||
interface.set_name(friendly_name);
|
interface.set_name(friendly_name);
|
||||||
|
|
||||||
// Prefixes are a linked list, in the order Network IP,
|
// Prefixes are a linked list, in the order Network IP,
|
||||||
// Adapter IP, Broadcast IP (plus more).
|
// Adapter IP, Broadcast IP (plus more).
|
||||||
NetAddress addresses[3];
|
NetAddress addresses[3];
|
||||||
IP_ADAPTER_PREFIX *m = p->FirstPrefix;
|
IP_ADAPTER_PREFIX *m = p->FirstPrefix;
|
||||||
int mc = 0;
|
int mc = 0;
|
||||||
while (m != NULL && mc < 3) {
|
while (m != NULL && mc < 3) {
|
||||||
addresses[mc] = NetAddress(Socket_Address(*(sockaddr_in *)m->Address.lpSockaddr));
|
addresses[mc] = NetAddress(Socket_Address(*(sockaddr_in *)m->Address.lpSockaddr));
|
||||||
m = m->Next;
|
m = m->Next;
|
||||||
++mc;
|
++mc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mc > 1) {
|
||||||
|
interface.set_ip(addresses[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mc > 2) {
|
||||||
|
interface.set_broadcast(addresses[2]);
|
||||||
|
|
||||||
|
// Now, we can infer the netmask by the difference between the
|
||||||
|
// network address (the first address) and the broadcast
|
||||||
|
// address (the last address).
|
||||||
|
PN_uint32 netmask = addresses[0].get_ip() - addresses[2].get_ip() - 1;
|
||||||
|
Socket_Address sa;
|
||||||
|
sa.set_host(netmask, 0);
|
||||||
|
interface.set_netmask(NetAddress(sa));
|
||||||
|
}
|
||||||
|
|
||||||
|
_interfaces.push_back(interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mc > 1) {
|
|
||||||
interface.set_ip(addresses[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mc > 2) {
|
|
||||||
interface.set_broadcast(addresses[2]);
|
|
||||||
|
|
||||||
// Now, we can infer the netmask by the difference between the
|
|
||||||
// network address (the first address) and the broadcast
|
|
||||||
// address (the last address).
|
|
||||||
PN_uint32 netmask = addresses[0].get_ip() - addresses[2].get_ip() - 1;
|
|
||||||
Socket_Address sa;
|
|
||||||
sa.set_host(netmask, 0);
|
|
||||||
interface.set_netmask(NetAddress(sa));
|
|
||||||
}
|
|
||||||
|
|
||||||
_interfaces.push_back(interface);
|
|
||||||
p = p->Next;
|
p = p->Next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user