Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
# Use Unicode for all projects.
add_definitions(-DUNICODE -D_UNICODE)

# Newer MSVC (VS 2026) turns the deprecation of <experimental/coroutine> into a
# hard error. permission_handler_windows still uses it, so silence it for all
# targets (including plugins) until that package is updated.
add_definitions(-D_SILENCE_EXPERIMENTAL_COROUTINE_DEPRECATION_WARNINGS)

# Compilation settings that should be applied to most targets.
function(APPLY_STANDARD_SETTINGS TARGET)
target_compile_features(${TARGET} PUBLIC cxx_std_17)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ class NetworkInfoPlusLinuxPlugin extends NetworkInfoPlatform {
}

String? _getSubnetMask(List<Map<String, dynamic>>? data) {
final prefix = data?.firstOrNull?['prefix'] as int;
final prefix = data?.firstOrNull?['prefix'] as int?;
if (prefix == null) return null;
final mask = (0xffffffff << (32 - prefix)) & 0xffffffff;
return mask.toIpString();
}

String? _getBroadcast(List<Map<String, dynamic>>? data) {
final ip = _getIpAddress(data)?.toIpInt() ?? 0;
final mask = _getSubnetMask(data)?.toIpInt() ?? 0;
final ip = _getIpAddress(data)?.toIpInt();
final mask = _getSubnetMask(data)?.toIpInt();
if (ip == null || mask == null) return null;
return (ip | (mask ^ 0xffffffff)).toIpString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
for (final (address, prefix, mask, broadcast) in cases) {
test('$address/$prefix', () async {
final plugin = NetworkInfoPlusLinuxPlugin()
..createClient = () => _FakeClient(address: address, prefix: prefix);
..createClient = () => _FakeClient.withAddress(address, prefix);

expect(await plugin.getWifiSubmask(), mask);
expect(await plugin.getWifiBroadcast(), broadcast);
Expand All @@ -36,15 +36,36 @@ void main() {

test('wifi IP and gateway are passed through', () async {
final plugin = NetworkInfoPlusLinuxPlugin()
..createClient = () => _FakeClient(address: '192.168.1.10', prefix: 22);
..createClient = () => _FakeClient.withAddress('192.168.1.10', 22);

expect(await plugin.getWifiIP(), '192.168.1.10');
expect(await plugin.getWifiGatewayIP(), '192.168.0.1');
});

group('missing IPv4 data returns null', () {
final cases = <String, NetworkManagerActiveConnection? Function()>{
'primaryConnection is null': () => null,
'ip4Config is null': () => _FakeConnection(null),
'addressData is empty': () => _FakeConnection(_FakeIp4Config([])),
};

for (final MapEntry(key: description, value: connection) in cases.entries) {
test(description, () async {
final plugin = NetworkInfoPlusLinuxPlugin()
..createClient = () => _FakeClient(connection());

expect(await plugin.getWifiSubmask(), isNull);
expect(await plugin.getWifiBroadcast(), isNull);
expect(await plugin.getWifiIP(), isNull);
});
}
});
}

class _FakeClient extends Fake implements NetworkManagerClient {
_FakeClient({required String address, required int prefix})
_FakeClient(this.primaryConnection);

_FakeClient.withAddress(String address, int prefix)
: primaryConnection = _FakeConnection(
_FakeIp4Config([
{'address': address, 'prefix': prefix},
Expand Down
Loading