calculateNetworkAddress method

List<int> calculateNetworkAddress()

Implementation

List<int> calculateNetworkAddress() {
  int fill = 0;
  List<int> octets = List<int>.filled(4, fill, growable: false);

  // Get only the network bits set to 1
  int invertor = 0;
  for (int i = 0; i < netmask; i++) {
    invertor += pow(2, 31 - i).toInt();
  }
  int lastAddress = address & invertor;

  octets[0] = (lastAddress & (255 << 24)) >> 24;
  octets[1] = (lastAddress & (255 << 16)) >> 16;
  octets[2] = (lastAddress & (255 << 8)) >> 8;
  octets[3] = lastAddress & (255);
  return octets;
}