mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
get_mac_address()
This commit is contained in:
parent
0a167d9bfb
commit
c50dcd9195
@ -534,17 +534,21 @@ 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
|
||||||
|
// actually useful to anyone; we'll store the "friendly name"
|
||||||
|
// instead.
|
||||||
|
TextEncoder encoder;
|
||||||
|
encoder.set_wtext(wstring(p->FriendlyName));
|
||||||
|
string friendly_name = encoder.get_text();
|
||||||
|
|
||||||
|
Interface interface;
|
||||||
|
interface.set_name(friendly_name);
|
||||||
|
|
||||||
|
if (p->PhysicalAddressLength > 0) {
|
||||||
|
interface.set_mac_address(format_mac_address((const unsigned char *)p->PhysicalAddress, p->PhysicalAddressLength));
|
||||||
|
}
|
||||||
|
|
||||||
if (p->OperStatus == IfOperStatusUp) {
|
if (p->OperStatus == IfOperStatusUp) {
|
||||||
// p->AdapterName appears to be a GUID. Not sure if this is
|
|
||||||
// actually useful to anyone; we'll store the "friendly name"
|
|
||||||
// instead.
|
|
||||||
TextEncoder encoder;
|
|
||||||
encoder.set_wtext(wstring(p->FriendlyName));
|
|
||||||
string friendly_name = encoder.get_text();
|
|
||||||
|
|
||||||
Interface interface;
|
|
||||||
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];
|
||||||
@ -571,9 +575,9 @@ scan_interfaces() {
|
|||||||
sa.set_host(netmask, 0);
|
sa.set_host(netmask, 0);
|
||||||
interface.set_netmask(NetAddress(sa));
|
interface.set_netmask(NetAddress(sa));
|
||||||
}
|
}
|
||||||
|
|
||||||
_interfaces.push_back(interface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_interfaces.push_back(interface);
|
||||||
p = p->Next;
|
p = p->Next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -777,6 +781,24 @@ remove_writer(ConnectionWriter *writer) {
|
|||||||
_writers.erase(writer);
|
_writers.erase(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: ConnectionManager::format_mac_address
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Formats a device's MAC address into a string.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
string ConnectionManager::
|
||||||
|
format_mac_address(const unsigned char *data, int data_size) {
|
||||||
|
stringstream strm;
|
||||||
|
for (int di = 0; di < data_size; ++di) {
|
||||||
|
if (di != 0) {
|
||||||
|
strm << "-";
|
||||||
|
}
|
||||||
|
strm << hex << setw(2) << setfill('0') << (unsigned int)data[di];
|
||||||
|
}
|
||||||
|
|
||||||
|
return strm.str();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: ConnectionManager::Interface::Output
|
// Function: ConnectionManager::Interface::Output
|
||||||
// Access: Published
|
// Access: Published
|
||||||
|
@ -70,6 +70,7 @@ PUBLISHED:
|
|||||||
class Interface {
|
class Interface {
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
const string &get_name() const { return _name; }
|
const string &get_name() const { return _name; }
|
||||||
|
const string &get_mac_address() const { return _mac_address; }
|
||||||
bool has_ip() const { return (_flags & F_has_ip) != 0; }
|
bool has_ip() const { return (_flags & F_has_ip) != 0; }
|
||||||
const NetAddress &get_ip() const { return _ip; }
|
const NetAddress &get_ip() const { return _ip; }
|
||||||
bool has_netmask() const { return (_flags & F_has_netmask) != 0; }
|
bool has_netmask() const { return (_flags & F_has_netmask) != 0; }
|
||||||
@ -84,6 +85,7 @@ PUBLISHED:
|
|||||||
public:
|
public:
|
||||||
Interface() { _flags = 0; }
|
Interface() { _flags = 0; }
|
||||||
void set_name(const string &name) { _name = name; }
|
void set_name(const string &name) { _name = name; }
|
||||||
|
void set_mac_address(const string &mac_address) { _mac_address = mac_address; }
|
||||||
void set_ip(const NetAddress &ip) { _ip = ip; _flags |= F_has_ip; }
|
void set_ip(const NetAddress &ip) { _ip = ip; _flags |= F_has_ip; }
|
||||||
void set_netmask(const NetAddress &ip) { _netmask = ip; _flags |= F_has_netmask; }
|
void set_netmask(const NetAddress &ip) { _netmask = ip; _flags |= F_has_netmask; }
|
||||||
void set_broadcast(const NetAddress &ip) { _broadcast = ip; _flags |= F_has_broadcast; }
|
void set_broadcast(const NetAddress &ip) { _broadcast = ip; _flags |= F_has_broadcast; }
|
||||||
@ -91,6 +93,7 @@ PUBLISHED:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
string _name;
|
string _name;
|
||||||
|
string _mac_address;
|
||||||
|
|
||||||
NetAddress _ip;
|
NetAddress _ip;
|
||||||
NetAddress _netmask;
|
NetAddress _netmask;
|
||||||
@ -122,6 +125,8 @@ protected:
|
|||||||
void add_writer(ConnectionWriter *writer);
|
void add_writer(ConnectionWriter *writer);
|
||||||
void remove_writer(ConnectionWriter *writer);
|
void remove_writer(ConnectionWriter *writer);
|
||||||
|
|
||||||
|
string format_mac_address(const unsigned char *data, int data_size);
|
||||||
|
|
||||||
typedef phash_set< PT(Connection) > Connections;
|
typedef phash_set< PT(Connection) > Connections;
|
||||||
typedef phash_set<ConnectionReader *, pointer_hash> Readers;
|
typedef phash_set<ConnectionReader *, pointer_hash> Readers;
|
||||||
typedef phash_set<ConnectionWriter *, pointer_hash> Writers;
|
typedef phash_set<ConnectionWriter *, pointer_hash> Writers;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user