Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,22 @@ ip.address = function(name, family) {
return res[0].address;
}

var all = Object.keys(interfaces).map(function (nic) {
function priority(name) {
if (name.substring(0, 2) === 'en' || name.substring(0, 3) === 'eth') {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for delay. I've a suggestion, what do you think about either using slice here or RegExp?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@indutny slice works for me!

return 0;
}
if (name.substring(0, 4) === 'wlan') {
return 1;
}

return 2;
}

var sortedInterfaces = Object.keys(interfaces).sort(function(a, b) {
return priority(a) - priority(b);
});

var all = sortedInterfaces.map(function(nic) {
//
// Note: name will only be `public` or `private`
// when this is called.
Expand Down