Skip to content

fix(network_info_plus): Fix subnet mask and broadcast on Linux - #3942

Open
source-creator wants to merge 2 commits into
fluttercommunity:mainfrom
source-creator:network_info_plus_subnet_broadcast_mask
Open

fix(network_info_plus): Fix subnet mask and broadcast on Linux#3942
source-creator wants to merge 2 commits into
fluttercommunity:mainfrom
source-creator:network_info_plus_subnet_broadcast_mask

Conversation

@source-creator

@source-creator source-creator commented Jul 30, 2026

Copy link
Copy Markdown

Description

On Linux, an incorrect subnet mask and broadcast mask is returned if the network prefix is not byte aligned.

For example, a prefix of /24 works, but /22 doesn't.
This is due to incorrect bit operations in addition to incorrect byte ordering in the Linux Dart code, where network byte order should rather be used.

The current code:

  final prefix = 22;
  final mask = 0xffffffff >> (32 - prefix);
  // mask == 4194303 == 0.63.255.255

The updated code:

  final prefix = 22;
  final mask = (0xffffffff << (32 - prefix)) & 0xffffffff;
  // mask == 4294966272 == 255.255.252.0

The network byte order is defined to always be big-endian, which may differ from the host byte order on a particular machine. Using network byte ordering for data exchanged between hosts allows hosts using different architectures to exchange address information without confusion because of byte ordering.

Source: https://www.ibm.com/docs/en/zvm/7.4.0?topic=domains-network-byte-order-host-byte-order

Related Issues

fixes: #3941

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: network_info_plus Linux getWifiSubmask wrong for /22

1 participant