Comparing version 0.2.1 to 0.2.2
var dgram = require('dgram'), | ||
util = require('util'), | ||
os = require('os'), | ||
net = require('net'), | ||
netroute = require('netroute'), | ||
ip = require('ip'), | ||
EventEmitter = require('events').EventEmitter; | ||
@@ -131,3 +134,3 @@ | ||
Ssdp.prototype.parseResponse = function parseResponse(response, address) { | ||
Ssdp.prototype.parseResponse = function parseResponse(response, addr, remote) { | ||
response = response.split(/\r\n/g); | ||
@@ -152,3 +155,38 @@ | ||
this.emit('_device', headers, address); | ||
var interfaces = os.networkInterfaces(), | ||
routes = netroute.getInfo(), | ||
local; | ||
local = routes.IPv4.concat(routes.IPv6).filter(function(route) { | ||
if (route.gateway) { | ||
if (ip.isEqual(remote.address, route.gateway)) return true; | ||
} | ||
if (route.destination && route.netmask) { | ||
return ip.isEqual(ip.mask(remote.address, route.netmask), | ||
ip.mask(route.destination, route.netmask)); | ||
} | ||
if (route.destination) { | ||
return ip.isEqual(remote.address, route.destination) || | ||
ip.isEqual(route.destination, '::'); | ||
} | ||
}).map(function(route) { | ||
return interfaces[route.interface].filter(function(addr) { | ||
return net.isIP(addr.address) === net.isIP(route.gateway) || | ||
net.isIP(addr.address) === net.isIP(route.destination) || | ||
ip.isEqual(ip.mask(addr.address, route.netmask), | ||
ip.mask(route.gateway, route.netmask)); | ||
}).map(function(addr) { | ||
return addr.address; | ||
}); | ||
}).reduce(function(prev, next) { | ||
return prev.concat(next); | ||
}); | ||
if (local.length === 0) { | ||
local = addr; | ||
} else { | ||
local = local[0]; | ||
} | ||
this.emit('_device', headers, local); | ||
}; | ||
@@ -155,0 +193,0 @@ |
{ | ||
"name": "nat-upnp", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"main": "lib/nat-upnp", | ||
@@ -20,4 +20,6 @@ "author": "Fedor Indutny <fedor@indutny.com>", | ||
"request": "~2.10.0", | ||
"async": "~0.1.22" | ||
"async": "~0.1.22", | ||
"netroute": "~0.2.2", | ||
"ip": "~0.0.1" | ||
} | ||
} |
@@ -17,3 +17,3 @@ # NAT UPnP | ||
}, function(err) { | ||
// Will be called on success | ||
// Will be called once finished | ||
}); | ||
@@ -20,0 +20,0 @@ |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
19529
544
5
4
+ Addedip@~0.0.1
+ Addednetroute@~0.2.2
+ Addedbindings@1.0.0(transitive)
+ Addedip@0.0.5(transitive)
+ Addednan@1.9.0(transitive)
+ Addednetroute@0.2.5(transitive)