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/. */
11 #include "mozilla/UniquePtr.h"
13 #include "NetworkInfoServiceImpl.h"
18 nsresult
DoListAddresses(AddrMapType
& aAddrMap
) {
19 UniquePtr
<MIB_IPADDRTABLE
> ipAddrTable
;
20 DWORD size
= sizeof(MIB_IPADDRTABLE
);
22 ipAddrTable
.reset((MIB_IPADDRTABLE
*)malloc(size
));
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
));
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);
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
);
58 } // namespace mozilla