Bug 1526591 - Remove devtools.inspector.shapesHighlighter.enabled pref. r=rcaliman
[gecko.git] / netwerk / base / NetworkInfoServiceWindows.cpp
blobc67dd70801f6f5eafd3feeb8e6075265e2849b61
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include <winsock2.h>
8 #include <ws2ipdef.h>
9 #include <iphlpapi.h>
11 #include "mozilla/UniquePtr.h"
13 #include "NetworkInfoServiceImpl.h"
15 namespace mozilla {
16 namespace net {
18 nsresult DoListAddresses(AddrMapType& aAddrMap) {
19 UniquePtr<MIB_IPADDRTABLE> ipAddrTable;
20 DWORD size = sizeof(MIB_IPADDRTABLE);
22 ipAddrTable.reset((MIB_IPADDRTABLE*)malloc(size));
23 if (!ipAddrTable) {
24 return NS_ERROR_FAILURE;
27 DWORD retVal = GetIpAddrTable(ipAddrTable.get(), &size, 0);
28 if (retVal == ERROR_INSUFFICIENT_BUFFER) {
29 ipAddrTable.reset((MIB_IPADDRTABLE*)malloc(size));
30 if (!ipAddrTable) {
31 return NS_ERROR_FAILURE;
33 retVal = GetIpAddrTable(ipAddrTable.get(), &size, 0);
35 if (retVal != NO_ERROR) {
36 return NS_ERROR_FAILURE;
39 for (DWORD i = 0; i < ipAddrTable->dwNumEntries; i++) {
40 int index = ipAddrTable->table[i].dwIndex;
41 uint32_t addrVal = (uint32_t)ipAddrTable->table[i].dwAddr;
43 nsCString indexString;
44 indexString.AppendInt(index, 10);
46 nsCString addrString;
47 addrString.AppendPrintf("%d.%d.%d.%d", (addrVal >> 0) & 0xff,
48 (addrVal >> 8) & 0xff, (addrVal >> 16) & 0xff,
49 (addrVal >> 24) & 0xff);
51 aAddrMap.Put(indexString, addrString);
54 return NS_OK;
57 } // namespace net
58 } // namespace mozilla