From 43238cd0569573837d4b48a27b3063d287d2968b Mon Sep 17 00:00:00 2001 From: Daniil Yastremskiy Date: Sun, 30 Oct 2016 23:08:37 +0000 Subject: [PATCH] Workaround for Windows 10 WSL --- index.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f3225f8..fed6055 100644 --- a/index.js +++ b/index.js @@ -31,8 +31,21 @@ function parallel(tasks, done) { } lib.networkInterfaces = function () { - var ifaces = os.networkInterfaces(); var allAddresses = {}; + + try { + var ifaces = os.networkInterfaces(); + } catch (e) { + // At October 2016 WSL does not support os.networkInterfaces() and throws + // Return empty object as if no interfaces were found + // https://github.com/Microsoft/BashOnWindows/issues/468 + if (e.syscall === 'uv_interface_addresses') { + return allAddresses; + } else { + throw e; + }; + }; + Object.keys(ifaces).forEach(function (iface) { var addresses = {}; var hasAddresses = false; @@ -67,7 +80,7 @@ switch (os.platform()) { case 'sunos': _getMacAddress = require('./lib/unix.js'); break; - + default: console.warn("node-macaddress: Unkown os.platform(), defaulting to `unix'."); _getMacAddress = require('./lib/unix.js');