Sort interfaces by priority when searching an IP address#82
Sort interfaces by priority when searching an IP address#82camilojd wants to merge 5 commits intoindutny:mainfrom
Conversation
|
I ran into this same problem, this seems valuable |
lib/ip.js
Outdated
| } | ||
|
|
||
| var all = Object.keys(interfaces).map(function (nic) { | ||
| function priority (name) { |
There was a problem hiding this comment.
should remove space before (name for consistency with the rest of the codebase
lib/ip.js
Outdated
| a = priority(a); | ||
| b = priority(b); | ||
|
|
||
| return a - b; |
There was a problem hiding this comment.
why not just return priority(a) - priority(b)?
There was a problem hiding this comment.
@brentvatne you're right :-) I did that to debug my code.
lib/ip.js
Outdated
| return a - b; | ||
| }); | ||
|
|
||
| var all = sortedInterfaces.map(function (nic) { |
There was a problem hiding this comment.
should remove space between function and (nic)
|
@brentvatne just pushed a commit addressing your comments. Thanks for the review! |
|
@brentvatne travis is green 🚀 |
|
@camilojd - I would merge this if I were a maintainer for the project! alas I am not ;) |
indutny
left a comment
There was a problem hiding this comment.
LGTM, with a minor suggestion.
lib/ip.js
Outdated
|
|
||
| var all = Object.keys(interfaces).map(function (nic) { | ||
| function priority(name) { | ||
| if (name.substring(0, 2) === 'en' || name.substring(0, 3) === 'eth') { |
There was a problem hiding this comment.
Sorry for delay. I've a suggestion, what do you think about either using slice here or RegExp?
|
@indutny sorry, I forgot to ping you after the change. Do you think this is good to go? |
Currently
ip.address()will search in all interfaces given byos.networkInterfaces(). This needs to take into account that multiple valid IPs can be found, and some of them may be preferable to others, depending on the type of network adapter.For example, when
os.networkInterfaces()returns:The proper value for
ip.address()should be192.168.1.72, and NOT10.200.10.1, as currently returned by node v8.1.3 on macOS 10.12.6.