os: add mac address to networkInterfaces() output
This commit is contained in:
parent
a622bde9e6
commit
30701d6e74
@ -128,24 +128,28 @@ Example inspection of os.cpus:
|
|||||||
|
|
||||||
Get a list of network interfaces:
|
Get a list of network interfaces:
|
||||||
|
|
||||||
{ lo0:
|
{ lo:
|
||||||
[ { address: 'fe80::1', netmask: 'ffff:ffff:ffff:ffff::',
|
[ { address: '127.0.0.1',
|
||||||
family: 'IPv6', internal: true },
|
netmask: '255.0.0.0',
|
||||||
{ address: '127.0.0.1', netmask: '255.0.0.0',
|
family: 'IPv4',
|
||||||
family: 'IPv4', internal: true },
|
mac: '00:00:00:00:00:00',
|
||||||
{ address: '::1', netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
|
internal: true },
|
||||||
family: 'IPv6', internal: true } ],
|
{ address: '::1',
|
||||||
en1:
|
netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
|
||||||
[ { address: 'fe80::226:8ff:fedc:1dd', netmask: 'ffff:ffff:ffff:ffff::',
|
family: 'IPv6',
|
||||||
family: 'IPv6', internal: false },
|
mac: '00:00:00:00:00:00',
|
||||||
{ address: '10.0.1.6', netmask: '255.255.255.0',
|
internal: true } ],
|
||||||
family: 'IPv4', internal: false } ],
|
eth0:
|
||||||
vmnet1:
|
[ { address: '192.168.1.108',
|
||||||
[ { address: '192.168.252.1', netmask: '255.255.255.0',
|
netmask: '255.255.255.0',
|
||||||
family: 'IPv4', internal: false } ],
|
family: 'IPv4',
|
||||||
vmnet8:
|
mac: '01:02:03:0a:0b:0c',
|
||||||
[ { address: '192.168.207.1', netmask: '255.255.255.0',
|
internal: false },
|
||||||
family: 'IPv4', internal: false } ] }
|
{ address: 'fe80::a00:27ff:fe4e:66a1',
|
||||||
|
netmask: 'ffff:ffff:ffff:ffff::',
|
||||||
|
family: 'IPv6',
|
||||||
|
mac: '01:02:03:0a:0b:0c',
|
||||||
|
internal: false } ] }
|
||||||
|
|
||||||
## os.EOL
|
## os.EOL
|
||||||
|
|
||||||
|
@ -208,6 +208,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
|
|||||||
int count, i;
|
int count, i;
|
||||||
char ip[INET6_ADDRSTRLEN];
|
char ip[INET6_ADDRSTRLEN];
|
||||||
char netmask[INET6_ADDRSTRLEN];
|
char netmask[INET6_ADDRSTRLEN];
|
||||||
|
char mac[18];
|
||||||
Local<Object> ret, o;
|
Local<Object> ret, o;
|
||||||
Local<String> name, family;
|
Local<String> name, family;
|
||||||
Local<Array> ifarr;
|
Local<Array> ifarr;
|
||||||
@ -228,6 +229,16 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
|
|||||||
ret->Set(name, ifarr);
|
ret->Set(name, ifarr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snprintf(mac,
|
||||||
|
18,
|
||||||
|
"%02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
|
static_cast<unsigned char>(interfaces[i].phys_addr[0]),
|
||||||
|
static_cast<unsigned char>(interfaces[i].phys_addr[1]),
|
||||||
|
static_cast<unsigned char>(interfaces[i].phys_addr[2]),
|
||||||
|
static_cast<unsigned char>(interfaces[i].phys_addr[3]),
|
||||||
|
static_cast<unsigned char>(interfaces[i].phys_addr[4]),
|
||||||
|
static_cast<unsigned char>(interfaces[i].phys_addr[5]));
|
||||||
|
|
||||||
if (interfaces[i].address.address4.sin_family == AF_INET) {
|
if (interfaces[i].address.address4.sin_family == AF_INET) {
|
||||||
uv_ip4_name(&interfaces[i].address.address4, ip, sizeof(ip));
|
uv_ip4_name(&interfaces[i].address.address4, ip, sizeof(ip));
|
||||||
uv_ip4_name(&interfaces[i].netmask.netmask4, netmask, sizeof(netmask));
|
uv_ip4_name(&interfaces[i].netmask.netmask4, netmask, sizeof(netmask));
|
||||||
@ -245,6 +256,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
|
|||||||
o->Set(String::New("address"), String::New(ip));
|
o->Set(String::New("address"), String::New(ip));
|
||||||
o->Set(String::New("netmask"), String::New(netmask));
|
o->Set(String::New("netmask"), String::New(netmask));
|
||||||
o->Set(String::New("family"), family);
|
o->Set(String::New("family"), family);
|
||||||
|
o->Set(String::New("mac"), String::New(mac));
|
||||||
|
|
||||||
const bool internal = interfaces[i].is_internal;
|
const bool internal = interfaces[i].is_internal;
|
||||||
o->Set(String::New("internal"),
|
o->Set(String::New("internal"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user