summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2017-09-30 09:03:07 +0200
committersilverwind <me@silverwind.io>2017-09-30 09:03:07 +0200
commit8a3e5afdd26d0b8ad6ba94101c71e6f27d9800d7 (patch)
treebd45067e7397e646493efef727cda3f7f237ce4a
parent009f2606dae85182ac84d12b11b3da2cea26d15d (diff)
downloadinternal-ip-8a3e5afdd26d0b8ad6ba94101c71e6f27d9800d7.tar
internal-ip-8a3e5afdd26d0b8ad6ba94101c71e6f27d9800d7.tar.gz
minor refactor
-rw-r--r--index.js8
1 files changed, 4 insertions, 4 deletions
diff --git a/index.js b/index.js
index 2e7b805..fe94208 100644
--- a/index.js
+++ b/index.js
@@ -11,7 +11,7 @@ const defaults = {
function findIp(gateway, family) {
const interfaces = os.networkInterfaces();
const gatewayIp = ipaddr.parse(gateway);
- let ret;
+ let ip;
// Look for the matching interface in all local interfaces
Object.keys(interfaces).some(name => {
@@ -19,15 +19,15 @@ function findIp(gateway, family) {
const prefix = ipaddr.parse(addr.netmask).prefixLengthFromSubnetMask();
const net = ipaddr.parseCIDR(`${addr.address}/${prefix}`);
- if (net[0].kind() === gatewayIp.kind() && gatewayIp.match(net)) {
- ret = net[0].toString();
+ if (net[0] && net[0].kind() === gatewayIp.kind() && gatewayIp.match(net)) {
+ ip = net[0].toString();
}
return Boolean(ret);
});
});
- return ret ? ret : defaults[family];
+ return ip || defaults[family];
}
function promise(family) {