Skip to content

Commit

Permalink
Implement API for getting ethernet settings
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrancis committed Oct 16, 2024
1 parent dc36a0d commit 4b75352
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"minipass": "^3.3.5",
"mkdirp": "^1.0.4",
"ncp": "^2.0.0",
"netmask": "^2.0.2",
"nocache": "^2.1.0",
"node-fetch": "^2.6.7",
"node-getopt": "^0.3.2",
Expand Down
35 changes: 34 additions & 1 deletion src/platforms/linux-ubuntu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import BasePlatform from './base';
import DBus from 'dbus';
import {LanMode, NetworkAddresses, WirelessNetwork} from './types';
let Netmask = require('netmask').Netmask;

class LinuxUbuntuPlatform extends BasePlatform {

Expand Down Expand Up @@ -137,7 +138,24 @@ class LinuxUbuntuPlatform extends BasePlatform {
reject();
return;
}
resolve(activeConnectionPath);
systemBus.getInterface('org.freedesktop.NetworkManager',
activeConnectionPath,
'org.freedesktop.NetworkManager.Connection.Active',
function(error, iface) {
if (error) {
console.error(error);
reject();
return;
}
iface.getProperty('Connection', function(error, value) {
if (error) {
console.error(error);
reject();
return;
}
resolve(value);
});
});
});
});
});
Expand Down Expand Up @@ -619,6 +637,21 @@ class LinuxUbuntuPlatform extends BasePlatform {
} else if(settings.ipv4.method == 'manual') {
result.mode = 'static';
}
if(settings.ipv4['address-data'][0] &&
settings.ipv4['address-data'][0].hasOwnProperty('address')) {
result.options.ipaddr = settings.ipv4['address-data'][0].address;
}
if(settings.ipv4.hasOwnProperty('gateway')) {
result.options.gateway = settings.ipv4.gateway;
}
if(result.options.ipaddr &&
settings.ipv4['address-data'][0].hasOwnProperty('prefix')) {
// Convert cidr style prefix to dot-decimal netmask
const ip = result.options.ipaddr;
const cidr = settings.ipv4['address-data'][0].prefix;
const block = new Netmask(`${ip}/${cidr}`);
result.options.netmask = block.mask;
}
return result;
}).catch((error) => {
console.error('Error getting LAN mode from Network Manager: ' + error);
Expand Down

0 comments on commit 4b75352

Please sign in to comment.