getWifiGatewayIP method

  1. @override
Future<String?> getWifiGatewayIP()
override

Obtains the gateway IP address of the connected wifi network This is the IP address of the router

Implementation

@override
Future<String?> getWifiGatewayIP() {
  return Future<String?>.value(query((pGuid, pAttributes) {
    final ulSize = calloc<ULONG>();
    Pointer<IP_ADAPTER_ADDRESSES_LH> pIpAdapterAddress = nullptr;
    try {
      GetAdaptersAddresses(AF_INET, 0x80, nullptr, nullptr, ulSize);
      pIpAdapterAddress = HeapAlloc(GetProcessHeap(), 0, ulSize.value).cast();
      GetAdaptersAddresses(AF_INET, 0x80, nullptr, pIpAdapterAddress, ulSize);
      final pAddr = getAdapterAddress(pGuid, pIpAdapterAddress);
      if (pAddr == null) return null;
      if (pAddr.ref.FirstGatewayAddress == nullptr) return null;
      return formatIPAddress(
          pAddr.ref.FirstGatewayAddress.ref.Address.lpSockaddr);
    } finally {
      free(ulSize);
      if (pIpAdapterAddress != nullptr) free(pIpAdapterAddress);
    }
  }));
}