From 53a387a5ab301047f5ce4ec32ecb982a8d774e28 Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 3 Aug 2020 19:28:21 +0200 Subject: [PATCH] Simplify cidr retrieval os.networkInterfaces() does support a new .cidr property since version 8.5.0 which is below the minimum 10.0.0 required by this module so use it. Ref: /~https://github.com/nodejs/node/pull/14307 --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 0ab197d..a04e358 100644 --- a/index.js +++ b/index.js @@ -8,9 +8,8 @@ function findIp(gateway) { // Look for the matching interface in all local interfaces. for (const addresses of Object.values(networkInterfaces())) { - for (const address of addresses) { - const prefix = parse(address.netmask).prefixLengthFromSubnetMask(); - const net = parseCIDR(`${address.address}/${prefix}`); + for (const {cidr} of addresses) { + const net = parseCIDR(cidr); if (net[0] && net[0].kind() === gatewayIp.kind() && gatewayIp.match(net)) { return net[0].toString();