Mirror: Best-effort discovery of the machine's local network using just Node.js dgram sockets

fix: Mark `bridge*` interfaces as internal by default to deprioritize them (#15)

* Deprioritize bridge interfaces as internal

* Add changeset

Changed files
+57 -2
.changeset
src
+5
.changeset/social-islands-bet.md
···
···
+
---
+
'lan-network': patch
+
---
+
+
Deprioritize `bridge*` interfaces as internal networks
+47
src/__tests__/network.test.ts
···
]
`);
});
});
describe(matchAssignment, () => {
···
]
`);
});
+
+
it('deprioritizes bridge interfaces', () => {
+
networkInterfaces.mockReturnValueOnce({
+
bridge0: [
+
{
+
address: '100.0.0.11',
+
netmask: '255.255.255.0',
+
family: 'IPv4',
+
mac: '10:00:00:00:00:00',
+
internal: false,
+
cidr: '',
+
},
+
],
+
en1: [
+
{
+
address: '10.0.0.10',
+
netmask: '255.255.255.0',
+
family: 'IPv4',
+
mac: '10:00:00:00:00:00',
+
internal: false,
+
cidr: '',
+
},
+
],
+
});
+
expect(interfaceAssignments()).toMatchInlineSnapshot(`
+
[
+
{
+
"address": "10.0.0.10",
+
"cidr": "",
+
"family": "IPv4",
+
"iname": "en1",
+
"internal": false,
+
"mac": "10:00:00:00:00:00",
+
"netmask": "255.255.255.0",
+
},
+
{
+
"address": "100.0.0.11",
+
"cidr": "",
+
"family": "IPv4",
+
"iname": "bridge0",
+
"internal": false,
+
"mac": "10:00:00:00:00:00",
+
"netmask": "255.255.255.0",
+
},
+
]
+
`);
+
});
});
describe(matchAssignment, () => {
+5 -2
src/network.ts
···
} else if (mac[0] === 0 && mac[1] === 21 && mac[2] === 93) {
// NOTE(@kitten): Microsoft virtual interface
return true;
-
} else if (assignment.iname.includes('vEthernet')) {
-
// NOTE(@kitten): Other Windows virtual interfaces
return true;
} else {
return false;
···
} else if (mac[0] === 0 && mac[1] === 21 && mac[2] === 93) {
// NOTE(@kitten): Microsoft virtual interface
return true;
+
} else if (
+
assignment.iname.includes('vEthernet') ||
+
/^bridge\d+$/.test(assignment.iname)
+
) {
+
// NOTE(@kitten): Other Windows virtual interfaces, or Linux bridge interfaces
return true;
} else {
return false;