2 * iphlpapi dll implementation
4 * Copyright (C) 2003 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "iphlpapi_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
29 typedef struct _NAME_SERVER_LIST_CONTEXT
{
32 PIP_PER_ADAPTER_INFO pData
;
34 IP_ADDR_STRING
*pLastAddr
;
35 } NAME_SERVER_LIST_CONTEXT
, *PNAME_SERVER_LIST_CONTEXT
;
37 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
40 case DLL_PROCESS_ATTACH
:
41 DisableThreadLibraryCalls( hinstDLL
);
45 case DLL_PROCESS_DETACH
:
52 /******************************************************************
53 * AddIPAddress (IPHLPAPI.@)
62 * NTEInstance [In/Out]
69 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask Netmask
, DWORD IfIndex
, PULONG NteContext
, PULONG NteInstance
)
71 return RtlNtStatusToDosError(addIPAddress(Address
, Netmask
, IfIndex
, NteContext
, NteInstance
));
74 DWORD
getInterfaceGatewayByIndex(DWORD index
)
76 DWORD ndx
, retVal
= 0, numRoutes
= getNumRoutes();
77 RouteTable
*table
= getRouteTable();
80 for (ndx
= 0; ndx
< numRoutes
; ndx
++)
82 if ((table
->routes
[ndx
].ifIndex
== (index
)) && (table
->routes
[ndx
].dest
== 0))
83 retVal
= table
->routes
[ndx
].gateway
;
85 HeapFree(GetProcessHeap(), 0, table
);
89 /******************************************************************
90 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
95 * ppIfTable [Out] -- pointer into which the MIB_IFTABLE is
96 * allocated and returned.
97 * bOrder [In] -- passed to GetIfTable to order the table
98 * heap [In] -- heap from which the table is allocated
99 * flags [In] -- flags to HeapAlloc
101 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
102 * GetIfTable returns otherwise
105 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
106 BOOL bOrder
, HANDLE heap
, DWORD flags
)
110 TRACE("ppIfTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n", ppIfTable
,
111 (DWORD
)bOrder
, (DWORD
)heap
, flags
);
113 ret
= ERROR_INVALID_PARAMETER
;
118 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
119 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
120 *ppIfTable
= (PMIB_IFTABLE
)HeapAlloc(heap
, flags
, dwSize
);
121 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
122 if (ret
!= NO_ERROR
) {
123 HeapFree(heap
, flags
, *ppIfTable
);
128 TRACE("returning %ld\n", ret
);
133 /******************************************************************
134 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
139 * ppIpAddrTable [Out]
140 * bOrder [In] -- passed to GetIpAddrTable to order the table
141 * heap [In] -- heap from which the table is allocated
142 * flags [In] -- flags to HeapAlloc
149 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
150 BOOL bOrder
, HANDLE heap
, DWORD flags
)
154 TRACE("ppIpAddrTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
155 ppIpAddrTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
157 ret
= ERROR_INVALID_PARAMETER
;
161 *ppIpAddrTable
= NULL
;
162 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
163 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
164 *ppIpAddrTable
= (PMIB_IPADDRTABLE
)HeapAlloc(heap
, flags
, dwSize
);
165 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
166 if (ret
!= NO_ERROR
) {
167 HeapFree(heap
, flags
, *ppIpAddrTable
);
168 *ppIpAddrTable
= NULL
;
172 TRACE("returning %ld\n", ret
);
177 /******************************************************************
178 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
181 * ppIpForwardTable [Out] -- pointer into which the MIB_IPFORWARDTABLE is
182 * allocated and returned.
183 * bOrder [In] -- passed to GetIfTable to order the table
184 * heap [In] -- heap from which the table is allocated
185 * flags [In] -- flags to HeapAlloc
187 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
188 * GetIpForwardTable returns otherwise
191 DWORD WINAPI
AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE
*
192 ppIpForwardTable
, BOOL bOrder
, HANDLE heap
, DWORD flags
)
196 TRACE("ppIpForwardTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
197 ppIpForwardTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
198 if (!ppIpForwardTable
)
199 ret
= ERROR_INVALID_PARAMETER
;
203 *ppIpForwardTable
= NULL
;
204 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
205 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
206 *ppIpForwardTable
= (PMIB_IPFORWARDTABLE
)HeapAlloc(heap
, flags
, dwSize
);
207 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
208 if (ret
!= NO_ERROR
) {
209 HeapFree(heap
, flags
, *ppIpForwardTable
);
210 *ppIpForwardTable
= NULL
;
214 TRACE("returning %ld\n", ret
);
219 /******************************************************************
220 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
226 * bOrder [In] -- passed to GetIpNetTable to order the table
227 * heap [In] -- heap from which the table is allocated
228 * flags [In] -- flags to HeapAlloc
235 DWORD WINAPI
AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE
*ppIpNetTable
,
236 BOOL bOrder
, HANDLE heap
, DWORD flags
)
240 TRACE("ppIpNetTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
241 ppIpNetTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
243 ret
= ERROR_INVALID_PARAMETER
;
247 *ppIpNetTable
= NULL
;
248 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
249 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
250 *ppIpNetTable
= (PMIB_IPNETTABLE
)HeapAlloc(heap
, flags
, dwSize
);
251 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
252 if (ret
!= NO_ERROR
) {
253 HeapFree(heap
, flags
, *ppIpNetTable
);
254 *ppIpNetTable
= NULL
;
258 TRACE("returning %ld\n", ret
);
263 /******************************************************************
264 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
270 * bOrder [In] -- passed to GetTcpTable to order the table
271 * heap [In] -- heap from which the table is allocated
272 * flags [In] -- flags to HeapAlloc
279 DWORD WINAPI
AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE
*ppTcpTable
,
280 BOOL bOrder
, HANDLE heap
, DWORD flags
)
284 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
285 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
287 ret
= ERROR_INVALID_PARAMETER
;
292 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
293 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
294 *ppTcpTable
= (PMIB_TCPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
295 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
296 if (ret
!= NO_ERROR
) {
297 HeapFree(heap
, flags
, *ppTcpTable
);
302 TRACE("returning %ld\n", ret
);
307 /******************************************************************
308 * AllocateAndGetTcpExTableFromStack (IPHLPAPI.@)
314 * bOrder [In] -- passed to GetExtendedTcpTable to order the table
315 * heap [In] -- heap from which the table is allocated
316 * flags [In] -- flags to HeapAlloc
317 * family [In] -- passed to GetExtendedTcpTable to select INET family
324 DWORD WINAPI
AllocateAndGetTcpExTableFromStack(PVOID
*ppTcpTable
,
325 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
)
329 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family 0x%08lx\n",
330 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
);
332 ret
= ERROR_INVALID_PARAMETER
;
337 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, TCP_TABLE_OWNER_PID_ALL
, 0);
338 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
339 *ppTcpTable
= (PMIB_TCPTABLE_OWNER_PID
)HeapAlloc(heap
, flags
, dwSize
);
340 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, TCP_TABLE_OWNER_PID_ALL
, 0);
341 if (ret
!= NO_ERROR
) {
342 HeapFree(heap
, flags
, *ppTcpTable
);
347 TRACE("returning %ld\n", ret
);
352 /******************************************************************
353 * AllocateAndGetTcpExTable2FromStack (IPHLPAPI.@)
359 * bOrder [In] -- passed to GetExtendedTcpTable to order the table
360 * heap [In] -- heap from which the table is allocated
361 * flags [In] -- flags to HeapAlloc
362 * family [In] -- passed to GetExtendedTcpTable to select INET family
363 * class [In] -- passed to GetExtendedTcpTable to select information
370 DWORD WINAPI
AllocateAndGetTcpExTable2FromStack(PVOID
*ppTcpTable
,
371 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
, TCP_TABLE_CLASS
class)
375 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family %ld, class %ld\n",
376 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
, class);
378 ret
= ERROR_INVALID_PARAMETER
;
383 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, class, 0);
384 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
385 *ppTcpTable
= HeapAlloc(heap
, flags
, dwSize
);
386 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, class, 0);
387 if (ret
!= NO_ERROR
) {
388 HeapFree(heap
, flags
, *ppTcpTable
);
393 TRACE("returning %ld\n", ret
);
398 /******************************************************************
399 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
405 * bOrder [In] -- passed to GetUdpTable to order the table
406 * heap [In] -- heap from which the table is allocated
407 * flags [In] -- flags to HeapAlloc
414 DWORD WINAPI
AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE
*ppUdpTable
,
415 BOOL bOrder
, HANDLE heap
, DWORD flags
)
419 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
420 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
422 ret
= ERROR_INVALID_PARAMETER
;
427 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
428 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
429 *ppUdpTable
= (PMIB_UDPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
430 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
431 if (ret
!= NO_ERROR
) {
432 HeapFree(heap
, flags
, *ppUdpTable
);
437 TRACE("returning %ld\n", ret
);
442 /******************************************************************
443 * AllocateAndGetUdpExTableFromStack (IPHLPAPI.@)
449 * bOrder [In] -- passed to GetExtendedUdpTable to order the table
450 * heap [In] -- heap from which the table is allocated
451 * flags [In] -- flags to HeapAlloc
452 * family [In] -- passed to GetExtendedUdpTable to select INET family
459 DWORD WINAPI
AllocateAndGetUdpExTableFromStack(PVOID
*ppUdpTable
,
460 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
)
464 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family 0x%08lx\n",
465 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
);
467 ret
= ERROR_INVALID_PARAMETER
;
472 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, UDP_TABLE_OWNER_PID
, 0);
473 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
474 *ppUdpTable
= (PMIB_UDPTABLE_OWNER_PID
)HeapAlloc(heap
, flags
, dwSize
);
475 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, UDP_TABLE_OWNER_PID
, 0);
476 if (ret
!= NO_ERROR
) {
477 HeapFree(heap
, flags
, *ppUdpTable
);
482 TRACE("returning %ld\n", ret
);
487 /******************************************************************
488 * AllocateAndGetUdpExTable2FromStack (IPHLPAPI.@)
494 * bOrder [In] -- passed to GetExtendedUdpTable to order the table
495 * heap [In] -- heap from which the table is allocated
496 * flags [In] -- flags to HeapAlloc
497 * family [In] -- passed to GetExtendedUdpTable to select INET family
498 * class [In] -- passed to GetExtendedUdpTable to select information
505 DWORD WINAPI
AllocateAndGetUdpExTable2FromStack(PVOID
*ppUdpTable
,
506 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
, UDP_TABLE_CLASS
class)
510 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family %ld, class %ld\n",
511 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
, class);
513 ret
= ERROR_INVALID_PARAMETER
;
518 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, class, 0);
519 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
520 *ppUdpTable
= HeapAlloc(heap
, flags
, dwSize
);
521 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, class, 0);
522 if (ret
!= NO_ERROR
) {
523 HeapFree(heap
, flags
, *ppUdpTable
);
528 TRACE("returning %ld\n", ret
);
533 /******************************************************************
534 * CreateIpForwardEntry (IPHLPAPI.@)
546 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
548 return createIpForwardEntry( pRoute
);
552 /******************************************************************
553 * CreateIpNetEntry (IPHLPAPI.@)
565 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
567 TRACE("pArpEntry %p\n", pArpEntry
);
568 /* could use SIOCSARP on systems that support it, not sure I want to */
574 /******************************************************************
575 * CreateProxyArpEntry (IPHLPAPI.@)
589 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
591 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
594 /* marking Win2K+ functions not supported */
595 return ERROR_NOT_SUPPORTED
;
599 /******************************************************************
600 * DeleteIPAddress (IPHLPAPI.@)
612 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
614 TRACE("NTEContext %ld\n", NTEContext
);
615 return RtlNtStatusToDosError(deleteIpAddress(NTEContext
));
619 /******************************************************************
620 * DeleteIpForwardEntry (IPHLPAPI.@)
632 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
634 return deleteIpForwardEntry( pRoute
);
638 /******************************************************************
639 * DeleteIpNetEntry (IPHLPAPI.@)
651 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
653 TRACE("pArpEntry %p\n", pArpEntry
);
654 /* could use SIOCDARP on systems that support it, not sure I want to */
660 /******************************************************************
661 * DeleteProxyArpEntry (IPHLPAPI.@)
675 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
677 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
680 /* marking Win2K+ functions not supported */
681 return ERROR_NOT_SUPPORTED
;
684 /******************************************************************
685 * EnableRouter (IPHLPAPI.@)
691 * pOverlapped [In/Out]
698 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
700 TRACE("pHandle %p, pOverlapped %p\n", pHandle
, pOverlapped
);
702 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
703 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
704 marking Win2K+ functions not supported */
705 return ERROR_NOT_SUPPORTED
;
709 /******************************************************************
710 * FlushIpNetTable (IPHLPAPI.@)
722 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
724 TRACE("dwIfIndex 0x%08lx\n", dwIfIndex
);
726 /* this flushes the arp cache of the given index
727 marking Win2K+ functions not supported */
728 return ERROR_NOT_SUPPORTED
;
732 /******************************************************************
733 * GetAdapterIndex (IPHLPAPI.@)
738 * AdapterName [In/Out]
746 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
748 TRACE("AdapterName %p, IfIndex %p\n", AdapterName
, IfIndex
);
750 /* marking Win2K+ functions not supported */
751 return ERROR_NOT_SUPPORTED
;
755 /******************************************************************
756 * GetAdaptersInfo (IPHLPAPI.@)
761 * pAdapterInfo [In/Out]
762 * pOutBufLen [In/Out]
769 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
775 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
777 ret
= ERROR_INVALID_PARAMETER
;
779 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
781 if (numNonLoopbackInterfaces
> 0) {
782 /* this calculation assumes only one address in the IP_ADDR_STRING lists.
783 that's okay, because:
784 - we don't get multiple addresses per adapter anyway
785 - we don't know about per-adapter gateways
786 - DHCP and WINS servers can have max one entry per list */
787 ULONG size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
789 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
791 ret
= ERROR_BUFFER_OVERFLOW
;
794 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
797 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
798 if (*pOutBufLen
< size
) {
800 ret
= ERROR_INSUFFICIENT_BUFFER
;
805 BOOL winsEnabled
= FALSE
;
806 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
808 memset(pAdapterInfo
, 0, size
);
809 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
810 "Software\\Wine\\Wine\\Config\\Network", 0, KEY_READ
,
811 &hKey
) == ERROR_SUCCESS
) {
812 DWORD size
= sizeof(primaryWINS
.String
);
815 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
816 (PBYTE
)primaryWINS
.String
, &size
);
817 addr
= inet_addr(primaryWINS
.String
);
818 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
820 size
= sizeof(secondaryWINS
.String
);
821 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
822 (PBYTE
)secondaryWINS
.String
, &size
);
823 addr
= inet_addr(secondaryWINS
.String
);
824 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
828 TRACE("num of index is %lu\n", table
->numIndexes
);
829 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
830 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
831 DWORD addrLen
= sizeof(ptr
->Address
), type
;
833 getInterfaceNameByIndex(table
->indexes
[ndx
]);
835 ret
= ERROR_OUTOFMEMORY
;
839 /* on Win98 this is left empty, but whatever */
840 strncpy(ptr
->AdapterName
,ifname
,sizeof(ptr
->AdapterName
));
841 consumeInterfaceName(ifname
);
842 ptr
->AdapterName
[MAX_ADAPTER_NAME_LENGTH
] = '\0';
843 getInterfacePhysicalByIndex(table
->indexes
[ndx
], &addrLen
,
844 ptr
->Address
, &type
);
845 /* MS defines address length and type as UINT in some places and
846 DWORD in others, **sigh**. Don't want to assume that PUINT and
847 PDWORD are equiv (64-bit?) */
848 ptr
->AddressLength
= addrLen
;
850 ptr
->Index
= table
->indexes
[ndx
];
851 toIPAddressString(getInterfaceIPAddrByIndex(table
->indexes
[ndx
]),
852 ptr
->IpAddressList
.IpAddress
.String
);
853 toIPAddressString(getInterfaceMaskByIndex(table
->indexes
[ndx
]),
854 ptr
->IpAddressList
.IpMask
.String
);
855 ptr
->IpAddressList
.Context
= ptr
->Index
;
856 toIPAddressString(getInterfaceGatewayByIndex(table
->indexes
[ndx
]),
857 ptr
->GatewayList
.IpAddress
.String
);
858 getDhcpInfoForAdapter(table
->indexes
[ndx
], &dhcpEnabled
,
859 &dhcpServer
, &ptr
->LeaseObtained
,
861 ptr
->DhcpEnabled
= (DWORD
) dhcpEnabled
;
862 toIPAddressString(dhcpServer
,
863 ptr
->DhcpServer
.IpAddress
.String
);
865 ptr
->HaveWins
= TRUE
;
866 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
867 primaryWINS
.String
, sizeof(primaryWINS
.String
));
868 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
869 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
871 if (ndx
< table
->numIndexes
- 1)
872 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
881 ret
= ERROR_OUTOFMEMORY
;
887 TRACE("returning %ld\n", ret
);
892 /******************************************************************
893 * GetBestInterface (IPHLPAPI.@)
899 * pdwBestIfIndex [In/Out]
906 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
910 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr
, pdwBestIfIndex
);
912 ret
= ERROR_INVALID_PARAMETER
;
914 MIB_IPFORWARDROW ipRow
;
916 ret
= GetBestRoute(dwDestAddr
, 0, &ipRow
);
917 if (ret
== ERROR_SUCCESS
)
918 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
920 TRACE("returning %ld\n", ret
);
925 /******************************************************************
926 * GetBestRoute (IPHLPAPI.@)
940 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
942 PMIB_IPFORWARDTABLE table
;
945 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr
,
946 dwSourceAddr
, pBestRoute
);
948 return ERROR_INVALID_PARAMETER
;
950 AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
952 DWORD ndx
, minMaskSize
, matchedNdx
= 0;
954 for (ndx
= 0, minMaskSize
= 255; ndx
< table
->dwNumEntries
; ndx
++) {
955 if ((dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
956 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
959 if (!_BitScanForward(&hostMaskSize
, ntohl(table
->table
[ndx
].dwForwardMask
)))
963 if (hostMaskSize
< minMaskSize
) {
964 minMaskSize
= hostMaskSize
;
969 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
970 HeapFree(GetProcessHeap(), 0, table
);
974 ret
= ERROR_OUTOFMEMORY
;
975 TRACE("returning %ld\n", ret
);
979 static int TcpTableSorter(const void *a
, const void *b
)
984 PMIB_TCPROW rowA
= (PMIB_TCPROW
)a
, rowB
= (PMIB_TCPROW
)b
;
986 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
988 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
990 ret
= rowA
->dwRemoteAddr
- rowB
->dwRemoteAddr
;
992 ret
= rowA
->dwRemotePort
- rowB
->dwRemotePort
;
1001 /******************************************************************
1002 * GetExtendedTcpTable (IPHLPAPI.@)
1004 * Get the table of TCP endpoints available to the application.
1007 * pTcpTable [Out] table struct with the filtered TCP endpoints available to application
1008 * pdwSize [In/Out] estimated size of the structure returned in pTcpTable, in bytes
1009 * bOrder [In] whether to order the table
1010 * ulAf [in] version of IP used by the TCP endpoints
1011 * TableClass [in] type of the TCP table structure from TCP_TABLE_CLASS
1012 * Reserved [in] reserved - this value must be zero
1016 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
1021 DWORD WINAPI
GetExtendedTcpTable(PVOID pTcpTable
, PDWORD pdwSize
, BOOL bOrder
, ULONG ulAf
, TCP_TABLE_CLASS TableClass
, ULONG Reserved
)
1024 DWORD ret
= NO_ERROR
;
1028 return ERROR_INVALID_PARAMETER
;
1031 if (ulAf
!= AF_INET
)
1034 return ERROR_INVALID_PARAMETER
;
1039 case TCP_TABLE_BASIC_ALL
:
1041 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
1042 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1046 if (sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
1048 *pdwSize
= sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
);
1049 ret
= ERROR_INSUFFICIENT_BUFFER
;
1053 memcpy(pTheirTcpTable
, pOurTcpTable
, sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
));
1056 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1057 sizeof(MIB_TCPROW
), TcpTableSorter
);
1065 case TCP_TABLE_BASIC_CONNECTIONS
:
1067 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
1068 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1072 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1074 if (pOurTcpTable
->table
[i
].State
!= MIB_TCP_STATE_LISTEN
)
1080 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
1082 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
);
1083 ret
= ERROR_INSUFFICIENT_BUFFER
;
1087 pTheirTcpTable
->dwNumEntries
= count
;
1089 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1091 if (pOurTcpTable
->table
[i
].State
!= MIB_TCP_STATE_LISTEN
)
1093 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW
));
1097 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1100 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1101 sizeof(MIB_TCPROW
), TcpTableSorter
);
1109 case TCP_TABLE_BASIC_LISTENER
:
1111 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
1112 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1116 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1118 if (pOurTcpTable
->table
[i
].State
== MIB_TCP_STATE_LISTEN
)
1124 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
1126 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
);
1127 ret
= ERROR_INSUFFICIENT_BUFFER
;
1131 pTheirTcpTable
->dwNumEntries
= count
;
1133 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1135 if (pOurTcpTable
->table
[i
].State
== MIB_TCP_STATE_LISTEN
)
1137 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW
));
1141 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1144 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1145 sizeof(MIB_TCPROW
), TcpTableSorter
);
1153 case TCP_TABLE_OWNER_PID_ALL
:
1155 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
1156 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1160 if (sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
1162 *pdwSize
= sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
);
1163 ret
= ERROR_INSUFFICIENT_BUFFER
;
1167 memcpy(pTheirTcpTable
, pOurTcpTable
, sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
));
1169 /* Don't sort on PID, so use basic helper */
1171 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1172 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1180 case TCP_TABLE_OWNER_PID_CONNECTIONS
:
1182 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
1183 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1187 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1189 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1195 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
1197 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
);
1198 ret
= ERROR_INSUFFICIENT_BUFFER
;
1202 pTheirTcpTable
->dwNumEntries
= count
;
1204 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1206 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1208 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_PID
));
1212 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1214 /* Don't sort on PID, so use basic helper */
1216 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1217 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1225 case TCP_TABLE_OWNER_PID_LISTENER
:
1227 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
1228 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1232 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1234 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1240 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
1242 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
);
1243 ret
= ERROR_INSUFFICIENT_BUFFER
;
1247 pTheirTcpTable
->dwNumEntries
= count
;
1249 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1251 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1253 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_PID
));
1257 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1259 /* Don't sort on PID, so use basic helper */
1261 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1262 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1270 case TCP_TABLE_OWNER_MODULE_ALL
:
1272 PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable
= getOwnerModTcpTable();
1273 PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable
= pTcpTable
;
1277 if (sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_MODULE
) > *pdwSize
|| !pTheirTcpTable
)
1279 *pdwSize
= sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_MODULE
);
1280 ret
= ERROR_INSUFFICIENT_BUFFER
;
1284 memcpy(pTheirTcpTable
, pOurTcpTable
, sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_MODULE
));
1286 /* Don't sort on PID, so use basic helper */
1288 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1289 sizeof(MIB_TCPROW_OWNER_MODULE
), TcpTableSorter
);
1297 case TCP_TABLE_OWNER_MODULE_CONNECTIONS
:
1299 PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable
= getOwnerModTcpTable();
1300 PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable
= pTcpTable
;
1304 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1306 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1312 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_MODULE
) > *pdwSize
|| !pTheirTcpTable
)
1314 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_MODULE
);
1315 ret
= ERROR_INSUFFICIENT_BUFFER
;
1319 pTheirTcpTable
->dwNumEntries
= count
;
1321 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1323 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1325 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_MODULE
));
1329 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1331 /* Don't sort on PID, so use basic helper */
1333 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1334 sizeof(MIB_TCPROW_OWNER_MODULE
), TcpTableSorter
);
1342 case TCP_TABLE_OWNER_MODULE_LISTENER
:
1344 PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable
= getOwnerModTcpTable();
1345 PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable
= pTcpTable
;
1349 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1351 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1357 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_MODULE
) > *pdwSize
|| !pTheirTcpTable
)
1359 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_MODULE
);
1360 ret
= ERROR_INSUFFICIENT_BUFFER
;
1364 pTheirTcpTable
->dwNumEntries
= count
;
1366 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1368 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1370 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_MODULE
));
1374 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1376 /* Don't sort on PID, so use basic helper */
1378 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1379 sizeof(MIB_TCPROW_OWNER_MODULE
), TcpTableSorter
);
1388 ret
= ERROR_INVALID_PARAMETER
;
1396 static int UdpTableSorter(const void *a
, const void *b
)
1401 PMIB_UDPROW rowA
= (PMIB_UDPROW
)a
, rowB
= (PMIB_UDPROW
)b
;
1403 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1405 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1412 /******************************************************************
1413 * GetExtendedUdpTable (IPHLPAPI.@)
1415 * Get the table of UDP endpoints available to the application.
1418 * pUdpTable [Out] table struct with the filtered UDP endpoints available to application
1419 * pdwSize [In/Out] estimated size of the structure returned in pUdpTable, in bytes
1420 * bOrder [In] whether to order the table
1421 * ulAf [in] version of IP used by the UDP endpoints
1422 * TableClass [in] type of the UDP table structure from UDP_TABLE_CLASS
1423 * Reserved [in] reserved - this value must be zero
1427 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
1432 DWORD WINAPI
GetExtendedUdpTable(PVOID pUdpTable
, PDWORD pdwSize
, BOOL bOrder
, ULONG ulAf
, UDP_TABLE_CLASS TableClass
, ULONG Reserved
)
1434 DWORD ret
= NO_ERROR
;
1438 return ERROR_INVALID_PARAMETER
;
1441 if (ulAf
!= AF_INET
)
1444 return ERROR_INVALID_PARAMETER
;
1449 case UDP_TABLE_BASIC
:
1451 PMIB_UDPTABLE pOurUdpTable
= getUdpTable();
1452 PMIB_UDPTABLE pTheirUdpTable
= pUdpTable
;
1456 if (sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW
) > *pdwSize
|| !pTheirUdpTable
)
1458 *pdwSize
= sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW
);
1459 ret
= ERROR_INSUFFICIENT_BUFFER
;
1463 memcpy(pTheirUdpTable
, pOurUdpTable
, sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
));
1466 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1467 sizeof(MIB_UDPROW
), UdpTableSorter
);
1475 case UDP_TABLE_OWNER_PID
:
1477 PMIB_UDPTABLE_OWNER_PID pOurUdpTable
= getOwnerUdpTable();
1478 PMIB_UDPTABLE_OWNER_PID pTheirUdpTable
= pUdpTable
;
1482 if (sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
) > *pdwSize
|| !pTheirUdpTable
)
1484 *pdwSize
= sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
);
1485 ret
= ERROR_INSUFFICIENT_BUFFER
;
1489 memcpy(pTheirUdpTable
, pOurUdpTable
, sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
));
1492 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1493 sizeof(MIB_UDPROW_OWNER_PID
), UdpTableSorter
);
1501 case UDP_TABLE_OWNER_MODULE
:
1503 PMIB_UDPTABLE_OWNER_MODULE pOurUdpTable
= getOwnerModUdpTable();
1504 PMIB_UDPTABLE_OWNER_MODULE pTheirUdpTable
= pUdpTable
;
1508 if (sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_MODULE
) > *pdwSize
|| !pTheirUdpTable
)
1510 *pdwSize
= sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_MODULE
);
1511 ret
= ERROR_INSUFFICIENT_BUFFER
;
1515 memcpy(pTheirUdpTable
, pOurUdpTable
, sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_MODULE
));
1518 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1519 sizeof(MIB_UDPROW_OWNER_MODULE
), UdpTableSorter
);
1528 ret
= ERROR_INVALID_PARAMETER
;
1536 /******************************************************************
1537 * GetFriendlyIfIndex (IPHLPAPI.@)
1549 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
1551 /* windows doesn't validate these, either, just makes sure the top byte is
1552 cleared. I assume my ifenum module never gives an index with the top
1554 TRACE("returning %ld\n", IfIndex
);
1559 /******************************************************************
1560 * GetIcmpStatistics (IPHLPAPI.@)
1572 DWORD WINAPI
GetIcmpStatistics(PMIB_ICMP pStats
)
1576 TRACE("pStats %p\n", pStats
);
1577 ret
= getICMPStats(pStats
);
1578 TRACE("returning %ld\n", ret
);
1583 /******************************************************************
1584 * GetIfEntry (IPHLPAPI.@)
1596 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
1601 TRACE("pIfRow %p\n", pIfRow
);
1603 return ERROR_INVALID_PARAMETER
;
1605 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
);
1607 ret
= getInterfaceEntryByIndex(pIfRow
->dwIndex
, pIfRow
);
1608 if (ret
== NO_ERROR
)
1609 ret
= getInterfaceStatsByName(name
, pIfRow
);
1610 consumeInterfaceName(name
);
1613 ret
= ERROR_INVALID_DATA
;
1614 TRACE("returning %ld\n", ret
);
1619 static int IfTableSorter(const void *a
, const void *b
)
1624 ret
= ((PMIB_IFROW
)a
)->dwIndex
- ((PMIB_IFROW
)b
)->dwIndex
;
1631 /******************************************************************
1632 * GetIfTable (IPHLPAPI.@)
1646 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
1650 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize
, pdwSize
,
1653 ret
= ERROR_INVALID_PARAMETER
;
1655 DWORD numInterfaces
= getNumInterfaces();
1657 TRACE("GetIfTable: numInterfaces = %d\n", (int)numInterfaces
);
1658 size
= sizeof(MIB_IFTABLE
) + (numInterfaces
- 1) * sizeof(MIB_IFROW
);
1660 if (!pIfTable
|| *pdwSize
< size
) {
1662 ret
= ERROR_INSUFFICIENT_BUFFER
;
1665 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1668 size
= sizeof(MIB_IFTABLE
) + (table
->numIndexes
- 1) *
1670 if (*pdwSize
< size
) {
1672 ret
= ERROR_INSUFFICIENT_BUFFER
;
1677 pIfTable
->dwNumEntries
= 0;
1678 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1679 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1680 GetIfEntry(&pIfTable
->table
[ndx
]);
1681 pIfTable
->dwNumEntries
++;
1684 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
1691 ret
= ERROR_OUTOFMEMORY
;
1694 TRACE("returning %ld\n", ret
);
1699 /******************************************************************
1700 * GetInterfaceInfo (IPHLPAPI.@)
1706 * dwOutBufLen [In/Out]
1713 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1717 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1719 ret
= ERROR_INVALID_PARAMETER
;
1721 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
1723 TRACE("numNonLoopbackInterfaces == 0x%x\n", numNonLoopbackInterfaces
);
1724 size
= sizeof(IP_INTERFACE_INFO
) + (numNonLoopbackInterfaces
) *
1725 sizeof(IP_ADAPTER_INDEX_MAP
);
1727 if (!pIfTable
|| *dwOutBufLen
< size
) {
1728 *dwOutBufLen
= size
;
1729 ret
= ERROR_INSUFFICIENT_BUFFER
;
1732 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
1735 TRACE("table->numIndexes == 0x%x\n", table
->numIndexes
);
1736 size
= sizeof(IP_INTERFACE_INFO
) + (table
->numIndexes
) *
1737 sizeof(IP_ADAPTER_INDEX_MAP
);
1738 if (*dwOutBufLen
< size
) {
1739 *dwOutBufLen
= size
;
1740 ret
= ERROR_INSUFFICIENT_BUFFER
;
1745 pIfTable
->NumAdapters
= 0;
1746 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1747 const char *walker
, *name
;
1750 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1751 name
= getInterfaceNameByIndex(table
->indexes
[ndx
]);
1752 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1753 walker
&& *walker
&&
1754 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1755 walker
++, assigner
++)
1756 *assigner
= *walker
;
1758 consumeInterfaceName(name
);
1759 pIfTable
->NumAdapters
++;
1766 ret
= ERROR_OUTOFMEMORY
;
1769 TRACE("returning %ld\n", ret
);
1774 static int IpAddrTableSorter(const void *a
, const void *b
)
1779 ret
= ((PMIB_IPADDRROW
)a
)->dwAddr
- ((PMIB_IPADDRROW
)b
)->dwAddr
;
1786 /******************************************************************
1787 * GetIpAddrTable (IPHLPAPI.@)
1792 * pIpAddrTable [In/Out]
1801 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1805 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable
, pdwSize
,
1808 ret
= ERROR_INVALID_PARAMETER
;
1810 DWORD numInterfaces
= getNumInterfaces();
1811 ULONG size
= sizeof(MIB_IPADDRTABLE
) + (numInterfaces
- 1) *
1812 sizeof(MIB_IPADDRROW
);
1814 if (!pIpAddrTable
|| *pdwSize
< size
) {
1816 ret
= ERROR_INSUFFICIENT_BUFFER
;
1819 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1822 size
= sizeof(MIB_IPADDRTABLE
) + (table
->numIndexes
- 1) *
1823 sizeof(MIB_IPADDRROW
);
1824 if (*pdwSize
< size
) {
1826 ret
= ERROR_INSUFFICIENT_BUFFER
;
1831 pIpAddrTable
->dwNumEntries
= 0;
1832 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1833 pIpAddrTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1834 pIpAddrTable
->table
[ndx
].dwAddr
=
1835 getInterfaceIPAddrByIndex(table
->indexes
[ndx
]);
1836 pIpAddrTable
->table
[ndx
].dwMask
=
1837 getInterfaceMaskByIndex(table
->indexes
[ndx
]);
1838 /* the dwBCastAddr member isn't the broadcast address, it indicates
1839 * whether the interface uses the 1's broadcast address (1) or the
1840 * 0's broadcast address (0).
1842 bcast
= getInterfaceBCastAddrByIndex(table
->indexes
[ndx
]);
1843 pIpAddrTable
->table
[ndx
].dwBCastAddr
=
1844 (bcast
& pIpAddrTable
->table
[ndx
].dwMask
) ? 1 : 0;
1845 /* FIXME: hardcoded reasm size, not sure where to get it */
1846 pIpAddrTable
->table
[ndx
].dwReasmSize
= 65535;
1847 pIpAddrTable
->table
[ndx
].unused1
= 0;
1848 pIpAddrTable
->table
[ndx
].wType
= 0; /* aka unused2 */
1849 pIpAddrTable
->dwNumEntries
++;
1852 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1853 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1859 ret
= ERROR_OUTOFMEMORY
;
1862 TRACE("returning %ld\n", ret
);
1867 static int IpForwardTableSorter(const void *a
, const void *b
)
1872 PMIB_IPFORWARDROW rowA
= (PMIB_IPFORWARDROW
)a
, rowB
= (PMIB_IPFORWARDROW
)b
;
1874 ret
= rowA
->dwForwardDest
- rowB
->dwForwardDest
;
1876 ret
= rowA
->dwForwardProto
- rowB
->dwForwardProto
;
1878 ret
= rowA
->dwForwardPolicy
- rowB
->dwForwardPolicy
;
1880 ret
= rowA
->dwForwardNextHop
- rowB
->dwForwardNextHop
;
1890 /******************************************************************
1891 * GetIpForwardTable (IPHLPAPI.@)
1896 * pIpForwardTable [In/Out]
1905 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1909 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable
,
1910 pdwSize
, (DWORD
)bOrder
);
1912 ret
= ERROR_INVALID_PARAMETER
;
1914 DWORD numRoutes
= getNumRoutes();
1915 ULONG sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (numRoutes
- 1) *
1916 sizeof(MIB_IPFORWARDROW
);
1918 if (!pIpForwardTable
|| *pdwSize
< sizeNeeded
) {
1919 *pdwSize
= sizeNeeded
;
1920 ret
= ERROR_INSUFFICIENT_BUFFER
;
1923 RouteTable
*table
= getRouteTable();
1925 sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (table
->numRoutes
- 1) *
1926 sizeof(MIB_IPFORWARDROW
);
1927 if (*pdwSize
< sizeNeeded
) {
1928 *pdwSize
= sizeNeeded
;
1929 ret
= ERROR_INSUFFICIENT_BUFFER
;
1934 pIpForwardTable
->dwNumEntries
= table
->numRoutes
;
1935 for (ndx
= 0; ndx
< numRoutes
; ndx
++) {
1936 pIpForwardTable
->table
[ndx
].dwForwardIfIndex
=
1937 table
->routes
[ndx
].ifIndex
;
1938 pIpForwardTable
->table
[ndx
].dwForwardDest
=
1939 table
->routes
[ndx
].dest
;
1940 pIpForwardTable
->table
[ndx
].dwForwardMask
=
1941 table
->routes
[ndx
].mask
;
1942 pIpForwardTable
->table
[ndx
].dwForwardPolicy
= 0;
1943 pIpForwardTable
->table
[ndx
].dwForwardNextHop
=
1944 table
->routes
[ndx
].gateway
;
1945 /* FIXME: this type is appropriate for local interfaces; may not
1946 always be appropriate */
1947 pIpForwardTable
->table
[ndx
].dwForwardType
= MIB_IPROUTE_TYPE_DIRECT
;
1948 /* FIXME: other protos might be appropriate, e.g. the default route
1949 is typically set with MIB_IPPROTO_NETMGMT instead */
1950 pIpForwardTable
->table
[ndx
].dwForwardProto
= MIB_IPPROTO_LOCAL
;
1951 /* punt on age and AS */
1952 pIpForwardTable
->table
[ndx
].dwForwardAge
= 0;
1953 pIpForwardTable
->table
[ndx
].dwForwardNextHopAS
= 0;
1954 pIpForwardTable
->table
[ndx
].dwForwardMetric1
=
1955 table
->routes
[ndx
].metric
;
1956 /* rest of the metrics are 0.. */
1957 pIpForwardTable
->table
[ndx
].dwForwardMetric2
= 0;
1958 pIpForwardTable
->table
[ndx
].dwForwardMetric3
= 0;
1959 pIpForwardTable
->table
[ndx
].dwForwardMetric4
= 0;
1960 pIpForwardTable
->table
[ndx
].dwForwardMetric5
= 0;
1963 qsort(pIpForwardTable
->table
, pIpForwardTable
->dwNumEntries
,
1964 sizeof(MIB_IPFORWARDROW
), IpForwardTableSorter
);
1967 HeapFree(GetProcessHeap(), 0, table
);
1970 ret
= ERROR_OUTOFMEMORY
;
1973 TRACE("returning %ld\n", ret
);
1978 static int IpNetTableSorter(const void *a
, const void *b
)
1983 ret
= ((PMIB_IPNETROW
)a
)->dwAddr
- ((PMIB_IPNETROW
)b
)->dwAddr
;
1990 /******************************************************************
1991 * GetIpNetTable (IPHLPAPI.@)
1996 * pIpNetTable [In/Out]
2005 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
2007 DWORD ret
= NO_ERROR
;
2009 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
,
2012 ret
= ERROR_INVALID_PARAMETER
;
2014 DWORD numEntries
= getNumArpEntries();
2015 ULONG size
= sizeof(MIB_IPNETTABLE
);
2018 size
+= (numEntries
- 1) * sizeof(MIB_IPNETROW
);
2019 if (!pIpNetTable
|| *pdwSize
< size
) {
2021 ret
= ERROR_INSUFFICIENT_BUFFER
;
2024 PMIB_IPNETTABLE table
= getArpTable();
2026 size
= sizeof(MIB_IPNETTABLE
);
2027 if (table
->dwNumEntries
> 1)
2028 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPNETROW
);
2029 if (*pdwSize
< size
) {
2031 ret
= ERROR_INSUFFICIENT_BUFFER
;
2035 memcpy(pIpNetTable
, table
, size
);
2037 qsort(pIpNetTable
->table
, pIpNetTable
->dwNumEntries
,
2038 sizeof(MIB_IPNETROW
), IpNetTableSorter
);
2041 HeapFree(GetProcessHeap(), 0, table
);
2045 TRACE("returning %d\n", ret
);
2050 /******************************************************************
2051 * GetIpStatistics (IPHLPAPI.@)
2063 DWORD WINAPI
GetIpStatistics(PMIB_IPSTATS pStats
)
2065 return GetIpStatisticsEx(pStats
, PF_INET
);
2068 /******************************************************************
2069 * GetIpStatisticsEx (IPHLPAPI.@)
2082 DWORD WINAPI
GetIpStatisticsEx(PMIB_IPSTATS pStats
, DWORD dwFamily
)
2086 TRACE("pStats %p\n", pStats
);
2087 ret
= getIPStats(pStats
, dwFamily
);
2088 TRACE("returning %ld\n", ret
);
2092 /******************************************************************
2093 * GetNetworkParams (IPHLPAPI.@)
2098 * pFixedInfo [In/Out]
2099 * pOutBufLen [In/Out]
2106 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
2108 DWORD ret
, size
, type
;
2111 PIPHLP_RES_INFO resInfo
;
2113 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
2115 return ERROR_INVALID_PARAMETER
;
2117 resInfo
= getResInfo();
2119 return ERROR_OUTOFMEMORY
;
2121 size
= sizeof(FIXED_INFO
) + (resInfo
->riCount
> 1 ? (resInfo
->riCount
-1) *
2122 sizeof(IP_ADDR_STRING
) : 0);
2123 if (!pFixedInfo
|| *pOutBufLen
< size
) {
2125 disposeResInfo( resInfo
);
2126 return ERROR_BUFFER_OVERFLOW
;
2129 memset(pFixedInfo
, 0, size
);
2130 /* Check for DhcpHostname and DhcpDomain first */
2131 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2132 "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
2136 if (regReturn
== ERROR_SUCCESS
) {
2137 /* Windows doesn't honor DHCP option 12 even if RFC requires it if it is returned by DHCP server! */
2140 size
= sizeof(pFixedInfo
->HostName
);
2141 regReturn
= RegQueryValueExA(hKey
,
2145 (LPBYTE
)pFixedInfo
->HostName
,
2147 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
2151 size
= sizeof(pFixedInfo
->HostName
);
2152 regReturn
= RegQueryValueExA(hKey
,
2156 (LPBYTE
)pFixedInfo
->HostName
,
2163 size
= sizeof(pFixedInfo
->DomainName
);
2164 regReturn
= RegQueryValueExA(hKey
,
2168 (LPBYTE
)pFixedInfo
->DomainName
,
2170 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
2173 size
= sizeof(pFixedInfo
->DomainName
);
2174 regReturn
= RegQueryValueExA(hKey
,
2178 (LPBYTE
)pFixedInfo
->DomainName
,
2184 TRACE("GetComputerNameExA: %s\n", pFixedInfo
->DomainName
);
2186 if (resInfo
->riCount
> 0)
2188 CopyMemory(&pFixedInfo
->DnsServerList
, resInfo
->DnsList
, sizeof(IP_ADDR_STRING
));
2189 if (resInfo
->riCount
> 1)
2191 IP_ADDR_STRING
*pSrc
= resInfo
->DnsList
->Next
;
2192 IP_ADDR_STRING
*pTarget
= (struct _IP_ADDR_STRING
*)((char*)pFixedInfo
+ sizeof(FIXED_INFO
));
2194 pFixedInfo
->DnsServerList
.Next
= pTarget
;
2198 CopyMemory(pTarget
, pSrc
, sizeof(IP_ADDR_STRING
));
2200 if (resInfo
->riCount
> 1)
2202 pTarget
->Next
= (IP_ADDR_STRING
*)((char*)pTarget
+ sizeof(IP_ADDR_STRING
));
2203 pTarget
= pTarget
->Next
;
2208 pTarget
->Next
= NULL
;
2216 pFixedInfo
->DnsServerList
.Next
= NULL
;
2220 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
2221 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2222 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
2223 if (regReturn
!= ERROR_SUCCESS
)
2224 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2225 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
2227 if (regReturn
== ERROR_SUCCESS
)
2229 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
2231 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (PBYTE
)pFixedInfo
->ScopeId
, &size
);
2235 disposeResInfo( resInfo
);
2236 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
2237 I suppose could also check for a listener on port 53 to set EnableDns */
2239 TRACE("returning %ld\n", ret
);
2245 /******************************************************************
2246 * GetNumberOfInterfaces (IPHLPAPI.@)
2258 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
2262 TRACE("pdwNumIf %p\n", pdwNumIf
);
2264 ret
= ERROR_INVALID_PARAMETER
;
2266 *pdwNumIf
= getNumInterfaces();
2269 TRACE("returning %ld\n", ret
);
2274 /******************************************************************
2275 * GetOwnerModuleFromTcpEntry (IPHLPAPI.@)
2277 * Get data about the module that issued the context bind for a specific IPv4 TCP endpoint in a MIB table row
2280 * pTcpEntry [in] pointer to a MIB_TCPROW_OWNER_MODULE structure
2281 * Class [in] TCPIP_OWNER_MODULE_INFO_CLASS enumeration value
2282 * Buffer [out] pointer a buffer containing a TCPIP_OWNER_MODULE_BASIC_INFO structure with the owner module data.
2283 * pdwSize [in, out] estimated size of the structure returned in Buffer, in bytes
2287 * Failure: ERROR_INSUFFICIENT_BUFFER, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY
2288 * ERROR_NOT_FOUND or ERROR_PARTIAL_COPY
2291 * The type of data returned in Buffer is indicated by the value of the Class parameter.
2293 DWORD WINAPI
GetOwnerModuleFromTcpEntry( PMIB_TCPROW_OWNER_MODULE pTcpEntry
, TCPIP_OWNER_MODULE_INFO_CLASS Class
, PVOID Buffer
, PDWORD pdwSize
)
2295 DWORD ret
= NO_ERROR
;
2300 static void CreateNameServerListEnumNamesFunc( PWCHAR Interface
, PWCHAR Server
, PVOID Data
)
2302 IP_ADDR_STRING
*pNext
;
2303 PNAME_SERVER_LIST_CONTEXT Context
= (PNAME_SERVER_LIST_CONTEXT
)Data
;
2305 if (!Context
->NumServers
)
2307 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
2309 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, Context
->pData
->DnsServerList
.IpAddress
.String
, 16, NULL
, NULL
);
2310 Context
->pData
->DnsServerList
.IpAddress
.String
[15] = '\0';
2311 Context
->pLastAddr
= &Context
->pData
->DnsServerList
;
2316 Context
->uSizeRequired
+= sizeof(IP_ADDR_STRING
);
2317 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
2319 pNext
= (IP_ADDR_STRING
*)(((char*)Context
->pLastAddr
) + sizeof(IP_ADDR_STRING
));
2320 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, pNext
->IpAddress
.String
, 16, NULL
, NULL
);
2321 pNext
->IpAddress
.String
[15] = '\0';
2322 Context
->pLastAddr
->Next
= pNext
;
2323 Context
->pLastAddr
= pNext
;
2327 Context
->NumServers
++;
2330 /******************************************************************
2331 * GetPerAdapterInfo (IPHLPAPI.@)
2337 * pPerAdapterInfo [In/Out]
2338 * pOutBufLen [In/Out]
2345 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
2350 NAME_SERVER_LIST_CONTEXT Context
;
2351 WCHAR keyname
[200] = L
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
2354 return ERROR_INVALID_PARAMETER
;
2356 if (!pPerAdapterInfo
|| *pOutBufLen
< sizeof(IP_PER_ADAPTER_INFO
))
2358 *pOutBufLen
= sizeof(IP_PER_ADAPTER_INFO
);
2359 return ERROR_BUFFER_OVERFLOW
;
2362 ifName
= getInterfaceNameByIndex(IfIndex
);
2364 return ERROR_INVALID_PARAMETER
;
2366 MultiByteToWideChar(CP_ACP
, 0, ifName
, -1, &keyname
[62], sizeof(keyname
)/sizeof(WCHAR
) - 63);
2367 HeapFree(GetProcessHeap(), 0, (LPVOID
)ifName
);
2369 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keyname
, 0, KEY_READ
, &hkey
) != ERROR_SUCCESS
)
2371 return ERROR_NOT_SUPPORTED
;
2373 Context
.NumServers
= 0;
2374 Context
.uSizeAvailable
= *pOutBufLen
;
2375 Context
.uSizeRequired
= sizeof(IP_PER_ADAPTER_INFO
);
2376 Context
.pData
= pPerAdapterInfo
;
2378 if (*pOutBufLen
>= sizeof(IP_PER_ADAPTER_INFO
))
2379 ZeroMemory(pPerAdapterInfo
, sizeof(IP_PER_ADAPTER_INFO
));
2381 EnumNameServers(hkey
, &keyname
[62], &Context
, CreateNameServerListEnumNamesFunc
);
2383 if (Context
.uSizeRequired
> Context
.uSizeAvailable
)
2385 *pOutBufLen
= Context
.uSizeRequired
;
2387 return ERROR_BUFFER_OVERFLOW
;
2390 if(RegQueryValueExW(hkey
, L
"NameServer", NULL
, NULL
, NULL
, &dwSize
) == ERROR_SUCCESS
)
2392 pPerAdapterInfo
->AutoconfigActive
= FALSE
;
2396 pPerAdapterInfo
->AutoconfigActive
= TRUE
;
2404 /******************************************************************
2405 * GetRTTAndHopCount (IPHLPAPI.@)
2410 * DestIpAddress [In]
2420 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
2422 TRACE("DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p\n",
2423 DestIpAddress
, HopCount
, MaxHops
, RTT
);
2429 /******************************************************************
2430 * GetTcpStatisticsEx (IPHLPAPI.@)
2443 DWORD WINAPI
GetTcpStatisticsEx(PMIB_TCPSTATS pStats
, DWORD dwFamily
)
2447 TRACE("pStats %p\n", pStats
);
2448 ret
= getTCPStats(pStats
, dwFamily
);
2449 TRACE("returning %ld\n", ret
);
2453 /******************************************************************
2454 * GetTcpStatistics (IPHLPAPI.@)
2466 DWORD WINAPI
GetTcpStatistics(PMIB_TCPSTATS pStats
)
2468 return GetTcpStatisticsEx(pStats
, PF_INET
);
2472 /******************************************************************
2473 * GetTcpTable (IPHLPAPI.@)
2475 * Get the table of active TCP connections.
2478 * pTcpTable [Out] buffer for TCP connections table
2479 * pdwSize [In/Out] length of output buffer
2480 * bOrder [In] whether to order the table
2484 * Failure: error code from winerror.h
2487 * If pdwSize is less than required, the function will return
2488 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
2489 * the required byte size.
2490 * If bOrder is true, the returned table will be sorted, first by
2491 * local address and port number, then by remote address and port
2494 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
2496 return GetExtendedTcpTable(pTcpTable
, pdwSize
, bOrder
, AF_INET
, TCP_TABLE_BASIC_ALL
, 0);
2500 /******************************************************************
2501 * GetUdpStatisticsEx (IPHLPAPI.@)
2514 DWORD WINAPI
GetUdpStatisticsEx(PMIB_UDPSTATS pStats
, DWORD dwFamily
)
2518 TRACE("pStats %p\n", pStats
);
2519 ret
= getUDPStats(pStats
, dwFamily
);
2520 TRACE("returning %ld\n", ret
);
2524 /******************************************************************
2525 * GetUdpStatistics (IPHLPAPI.@)
2537 DWORD WINAPI
GetUdpStatistics(PMIB_UDPSTATS pStats
)
2539 return GetUdpStatisticsEx(pStats
, PF_INET
);
2543 /******************************************************************
2544 * GetUdpTable (IPHLPAPI.@)
2549 * pUdpTable [In/Out]
2558 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
2560 return GetExtendedUdpTable(pUdpTable
, pdwSize
, bOrder
, AF_INET
, UDP_TABLE_BASIC
, 0);
2564 /******************************************************************
2565 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
2567 * This is a Win98-only function to get information on "unidirectional"
2568 * adapters. Since this is pretty nonsensical in other contexts, it
2569 * never returns anything.
2572 * pIPIfInfo [Out] buffer for adapter infos
2573 * dwOutBufLen [Out] length of the output buffer
2577 * Failure: error code from winerror.h
2580 * Stub, returns ERROR_NOT_SUPPORTED.
2582 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
2584 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
2585 /* a unidirectional adapter?? not bloody likely! */
2586 return ERROR_NOT_SUPPORTED
;
2590 /******************************************************************
2591 * IpReleaseAddress (IPHLPAPI.@)
2593 * Release an IP obtained through DHCP,
2596 * AdapterInfo [In] adapter to release IP address
2600 * Failure: error code from winerror.h
2603 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2605 DWORD Status
, Version
= 0;
2608 return ERROR_INVALID_PARAMETER
;
2610 /* Maybe we should do this in DllMain */
2611 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2612 return ERROR_PROC_NOT_FOUND
;
2614 if (DhcpReleaseIpAddressLease(AdapterInfo
->Index
))
2615 Status
= ERROR_SUCCESS
;
2617 Status
= ERROR_PROC_NOT_FOUND
;
2625 /******************************************************************
2626 * IpRenewAddress (IPHLPAPI.@)
2628 * Renew an IP obtained through DHCP.
2631 * AdapterInfo [In] adapter to renew IP address
2635 * Failure: error code from winerror.h
2637 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2639 DWORD Status
, Version
= 0;
2642 return ERROR_INVALID_PARAMETER
;
2644 /* Maybe we should do this in DllMain */
2645 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2646 return ERROR_PROC_NOT_FOUND
;
2648 if (DhcpRenewIpAddressLease(AdapterInfo
->Index
))
2649 Status
= ERROR_SUCCESS
;
2651 Status
= ERROR_PROC_NOT_FOUND
;
2659 /******************************************************************
2660 * NotifyAddrChange (IPHLPAPI.@)
2662 * Notify caller whenever the ip-interface map is changed.
2665 * Handle [Out] handle usable in asynchronous notification
2666 * overlapped [In] overlapped structure that notifies the caller
2670 * Failure: error code from winerror.h
2673 * Stub, returns ERROR_NOT_SUPPORTED.
2675 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2677 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2678 if (Handle
) *Handle
= INVALID_HANDLE_VALUE
;
2679 if (overlapped
) ((IO_STATUS_BLOCK
*) overlapped
)->Status
= STATUS_PENDING
;
2680 return ERROR_IO_PENDING
;
2684 /******************************************************************
2685 * NotifyRouteChange (IPHLPAPI.@)
2687 * Notify caller whenever the ip routing table is changed.
2690 * Handle [Out] handle usable in asynchronous notification
2691 * overlapped [In] overlapped structure that notifies the caller
2695 * Failure: error code from winerror.h
2698 * Stub, returns ERROR_NOT_SUPPORTED.
2700 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2702 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2703 return ERROR_NOT_SUPPORTED
;
2706 /******************************************************************
2707 * SendARP (IPHLPAPI.@)
2709 * Send an ARP request.
2712 * DestIP [In] attempt to obtain this IP
2713 * SrcIP [In] optional sender IP address
2714 * pMacAddr [Out] buffer for the mac address
2715 * PhyAddrLen [In/Out] length of the output buffer
2719 * Failure: error code from winerror.h
2721 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
2726 if (IsBadWritePtr(pMacAddr
, sizeof(ULONG
)) || IsBadWritePtr(PhyAddrLen
, sizeof(ULONG
)))
2727 return ERROR_INVALID_PARAMETER
;
2732 return TCPSendIoctl(INVALID_HANDLE_VALUE
, IOCTL_QUERY_IP_HW_ADDRESS
, IPs
, &Size
, pMacAddr
, PhyAddrLen
);
2736 /******************************************************************
2737 * SetIfEntry (IPHLPAPI.@)
2739 * Set the administrative status of an interface.
2742 * pIfRow [In] dwAdminStatus member specifies the new status.
2746 * Failure: error code from winerror.h
2749 * Stub, returns ERROR_NOT_SUPPORTED.
2751 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
2753 FIXME("(pIfRow %p): stub\n", pIfRow
);
2754 /* this is supposed to set an interface administratively up or down.
2755 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2756 this sort of down is indistinguishable from other sorts of down (e.g. no
2758 return ERROR_NOT_SUPPORTED
;
2762 /******************************************************************
2763 * SetIpForwardEntry (IPHLPAPI.@)
2765 * Modify an existing route.
2768 * pRoute [In] route with the new information
2772 * Failure: error code from winerror.h
2775 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
2777 return setIpForwardEntry( pRoute
);
2781 /******************************************************************
2782 * SetIpNetEntry (IPHLPAPI.@)
2784 * Modify an existing ARP entry.
2787 * pArpEntry [In] ARP entry with the new information
2791 * Failure: error code from winerror.h
2793 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
2797 TCP_REQUEST_SET_INFORMATION_EX_ARP_ENTRY req
=
2798 TCP_REQUEST_SET_INFORMATION_INIT
;
2801 PMIB_IPNETROW arpBuff
;
2804 return ERROR_INVALID_PARAMETER
;
2806 if (!NT_SUCCESS(openTcpFile( &tcpFile
, FILE_READ_DATA
| FILE_WRITE_DATA
)))
2807 return ERROR_NOT_SUPPORTED
;
2809 if (!NT_SUCCESS(getNthIpEntity( tcpFile
, pArpEntry
->dwIndex
, &id
)))
2811 closeTcpFile(tcpFile
);
2812 return ERROR_INVALID_PARAMETER
;
2815 req
.Req
.ID
.toi_class
= INFO_CLASS_PROTOCOL
;
2816 req
.Req
.ID
.toi_type
= INFO_TYPE_PROVIDER
;
2817 req
.Req
.ID
.toi_id
= IP_MIB_ARPTABLE_ENTRY_ID
;
2818 req
.Req
.ID
.toi_entity
.tei_instance
= id
.tei_instance
;
2819 req
.Req
.ID
.toi_entity
.tei_entity
= AT_ENTITY
;
2820 req
.Req
.BufferSize
= sizeof(MIB_IPNETROW
);
2821 arpBuff
= (PMIB_IPNETROW
)&req
.Req
.Buffer
[0];
2823 RtlCopyMemory(arpBuff
, pArpEntry
, sizeof(MIB_IPNETROW
));
2825 status
= DeviceIoControl( tcpFile
,
2826 IOCTL_TCP_SET_INFORMATION_EX
,
2834 closeTcpFile(tcpFile
);
2839 return ERROR_INVALID_PARAMETER
;
2843 /******************************************************************
2844 * SetIpStatistics (IPHLPAPI.@)
2846 * Toggle IP forwarding and det the default TTL value.
2849 * pIpStats [In] IP statistics with the new information
2853 * Failure: error code from winerror.h
2856 * Stub, returns NO_ERROR.
2858 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
2860 FIXME("(pIpStats %p): stub\n", pIpStats
);
2865 /******************************************************************
2866 * SetIpTTL (IPHLPAPI.@)
2868 * Set the default TTL value.
2871 * nTTL [In] new TTL value
2875 * Failure: error code from winerror.h
2878 * Stub, returns NO_ERROR.
2880 DWORD WINAPI
SetIpTTL(UINT nTTL
)
2882 FIXME("(nTTL %d): stub\n", nTTL
);
2887 /******************************************************************
2888 * SetTcpEntry (IPHLPAPI.@)
2890 * Set the state of a TCP connection.
2893 * pTcpRow [In] specifies connection with new state
2897 * Failure: error code from winerror.h
2900 * Stub, returns NO_ERROR.
2902 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
2904 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
2909 /******************************************************************
2910 * UnenableRouter (IPHLPAPI.@)
2912 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2913 * if it reaches zero.
2916 * pOverlapped [In/Out] should be the same as in EnableRouter()
2917 * lpdwEnableCount [Out] optional, receives reference count
2921 * Failure: error code from winerror.h
2924 * Stub, returns ERROR_NOT_SUPPORTED.
2926 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
2928 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
2930 return ERROR_NOT_SUPPORTED
;
2936 DWORD WINAPI
GetIpErrorString(IP_STATUS ErrorCode
,PWCHAR Buffer
,PDWORD Size
)
2946 PIP_ADAPTER_ORDER_MAP WINAPI
GetAdapterOrderMap(VOID
)
2955 #ifdef GetAdaptersAddressesV1
2956 DWORD WINAPI DECLSPEC_HOTPATCH
GetAdaptersAddresses(ULONG Family
,ULONG Flags
,PVOID Reserved
,PIP_ADAPTER_ADDRESSES pAdapterAddresses
,PULONG pOutBufLen
)
2958 InterfaceIndexTable
*indexTable
;
2961 ULONG ret
, requiredSize
= 0;
2962 PIP_ADAPTER_ADDRESSES currentAddress
;
2963 PUCHAR currentLocation
;
2966 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
2967 if (Reserved
) return ERROR_INVALID_PARAMETER
;
2969 indexTable
= getInterfaceIndexTable();
2971 return ERROR_NOT_ENOUGH_MEMORY
;
2973 ret
= openTcpFile(&tcpFile
, FILE_READ_DATA
);
2974 if (!NT_SUCCESS(ret
))
2975 return ERROR_NO_DATA
;
2977 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
2979 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
2981 indexTable
->indexes
[i
],
2984 /* The whole struct */
2985 requiredSize
+= sizeof(IP_ADAPTER_ADDRESSES
);
2988 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
2989 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1; //FIXME
2992 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
2994 /* Unicast address */
2995 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
2996 requiredSize
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
2998 /* FIXME: Implement multicast, anycast, and dns server stuff */
3000 /* FIXME: Implement dns suffix and description */
3001 requiredSize
+= 2 * sizeof(WCHAR
);
3003 /* We're only going to implement what's required for XP SP0 */
3006 TRACE("size: %d, requiredSize: %d\n", *pOutBufLen
, requiredSize
);
3007 if (!pAdapterAddresses
|| *pOutBufLen
< requiredSize
)
3009 *pOutBufLen
= requiredSize
;
3010 closeTcpFile(tcpFile
);
3012 return ERROR_BUFFER_OVERFLOW
;
3015 RtlZeroMemory(pAdapterAddresses
, requiredSize
);
3017 /* Let's set up the pointers */
3018 currentAddress
= pAdapterAddresses
;
3019 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
3021 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
3023 indexTable
->indexes
[i
],
3026 currentLocation
= (PUCHAR
)currentAddress
+ (ULONG_PTR
)sizeof(IP_ADAPTER_ADDRESSES
);
3028 /* FIXME: Friendly name */
3029 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
3031 currentAddress
->FriendlyName
= (PVOID
)currentLocation
;
3032 currentLocation
+= sizeof(WCHAR
);
3036 currentAddress
->AdapterName
= (PVOID
)currentLocation
;
3037 currentLocation
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
3039 /* Unicast address */
3040 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
3042 currentAddress
->FirstUnicastAddress
= (PVOID
)currentLocation
;
3043 currentLocation
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
3044 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
= (PVOID
)currentLocation
;
3045 currentLocation
+= sizeof(struct sockaddr
);
3048 /* FIXME: Implement multicast, anycast, and dns server stuff */
3050 /* FIXME: Implement dns suffix and description */
3051 currentAddress
->DnsSuffix
= (PVOID
)currentLocation
;
3052 currentLocation
+= sizeof(WCHAR
);
3054 currentAddress
->Description
= (PVOID
)currentLocation
;
3055 currentLocation
+= sizeof(WCHAR
);
3057 currentAddress
->Next
= (PVOID
)currentLocation
;
3058 /* Terminate the last address correctly */
3060 currentAddress
->Next
= NULL
;
3062 /* We're only going to implement what's required for XP SP0 */
3064 currentAddress
= currentAddress
->Next
;
3068 /* Now again, for real this time */
3070 currentAddress
= pAdapterAddresses
;
3071 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
3073 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
3075 indexTable
->indexes
[i
],
3078 /* Make sure we're not looping more than we hoped for */
3079 ASSERT(currentAddress
);
3081 /* Alignment information */
3082 currentAddress
->Length
= sizeof(IP_ADAPTER_ADDRESSES
);
3083 currentAddress
->IfIndex
= indexTable
->indexes
[i
];
3086 strcpy(currentAddress
->AdapterName
, (char *)ifInfo
.if_info
.ent
.if_descr
);
3088 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
3090 currentAddress
->FirstUnicastAddress
->Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
3091 currentAddress
->FirstUnicastAddress
->Flags
= 0; //FIXME
3092 currentAddress
->FirstUnicastAddress
->Next
= NULL
; //FIXME: Support more than one address per adapter
3093 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_family
= AF_INET
;
3094 memcpy(currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_data
,
3095 &ifInfo
.ip_addr
.iae_addr
,
3096 sizeof(ifInfo
.ip_addr
.iae_addr
));
3097 currentAddress
->FirstUnicastAddress
->Address
.iSockaddrLength
= sizeof(ifInfo
.ip_addr
.iae_addr
) + sizeof(USHORT
);
3098 currentAddress
->FirstUnicastAddress
->PrefixOrigin
= IpPrefixOriginOther
; //FIXME
3099 currentAddress
->FirstUnicastAddress
->SuffixOrigin
= IpPrefixOriginOther
; //FIXME
3100 currentAddress
->FirstUnicastAddress
->DadState
= IpDadStatePreferred
; //FIXME
3101 currentAddress
->FirstUnicastAddress
->ValidLifetime
= 0xFFFFFFFF; //FIXME
3102 currentAddress
->FirstUnicastAddress
->PreferredLifetime
= 0xFFFFFFFF; //FIXME
3103 currentAddress
->FirstUnicastAddress
->LeaseLifetime
= 0xFFFFFFFF; //FIXME
3106 /* FIXME: Implement multicast, anycast, and dns server stuff */
3107 currentAddress
->FirstAnycastAddress
= NULL
;
3108 currentAddress
->FirstMulticastAddress
= NULL
;
3109 currentAddress
->FirstDnsServerAddress
= NULL
;
3111 /* FIXME: Implement dns suffix, description, and friendly name */
3112 currentAddress
->DnsSuffix
[0] = UNICODE_NULL
;
3113 currentAddress
->Description
[0] = UNICODE_NULL
;
3114 currentAddress
->FriendlyName
[0] = UNICODE_NULL
;
3116 /* Physical Address */
3117 memcpy(currentAddress
->PhysicalAddress
, ifInfo
.if_info
.ent
.if_physaddr
, ifInfo
.if_info
.ent
.if_physaddrlen
);
3118 currentAddress
->PhysicalAddressLength
= ifInfo
.if_info
.ent
.if_physaddrlen
;
3121 currentAddress
->Flags
= 0; //FIXME
3124 currentAddress
->Mtu
= ifInfo
.if_info
.ent
.if_mtu
;
3126 /* Interface type */
3127 currentAddress
->IfType
= ifInfo
.if_info
.ent
.if_type
;
3129 /* Operational status */
3130 if(ifInfo
.if_info
.ent
.if_operstatus
>= IF_OPER_STATUS_CONNECTING
)
3131 currentAddress
->OperStatus
= IfOperStatusUp
;
3133 currentAddress
->OperStatus
= IfOperStatusDown
;
3135 /* We're only going to implement what's required for XP SP0 */
3137 /* Move to the next address */
3138 currentAddress
= currentAddress
->Next
;
3142 closeTcpFile(tcpFile
);
3152 BOOL WINAPI
CancelIPChangeNotify(LPOVERLAPPED notifyOverlapped
)
3161 DWORD WINAPI
GetBestInterfaceEx(struct sockaddr
*pDestAddr
,PDWORD pdwBestIfIndex
)
3170 DWORD WINAPI
NhpAllocateAndGetInterfaceInfoFromStack(IP_INTERFACE_NAME_INFO
**ppTable
,PDWORD pdwCount
,BOOL bOrder
,HANDLE hHeap
,DWORD dwFlags
)
3179 DWORD WINAPI
GetIcmpStatisticsEx(PMIB_ICMP_EX pStats
,DWORD dwFamily
)
3184 return ERROR_INVALID_PARAMETER
;
3186 if (dwFamily
!= AF_INET
&& dwFamily
!= AF_INET6
)
3187 return ERROR_INVALID_PARAMETER
;
3193 SetIpForwardEntryToStack(PMIB_IPFORWARDROW pRoute
)
3195 FIXME("SetIpForwardEntryToStack() stub\n");
3199 DWORD
GetInterfaceNameInternal(_In_
const GUID
* pInterfaceGUID
,
3200 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3201 _Inout_ PULONG pOutBufLen
)
3203 UNICODE_STRING GuidString
;
3205 WCHAR szKeyName
[2*MAX_PATH
];
3209 if (pInterfaceGUID
== NULL
|| pOutBufLen
== NULL
)
3210 return ERROR_INVALID_PARAMETER
;
3212 result
= RtlStringFromGUID(pInterfaceGUID
, &GuidString
);
3214 if (!NT_SUCCESS(result
))
3216 // failed to convert guid to string
3217 return RtlNtStatusToDosError(result
);
3220 hr
= StringCbPrintfW(szKeyName
, sizeof(szKeyName
), L
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", GuidString
.Buffer
);
3221 RtlFreeUnicodeString(&GuidString
);
3225 // key name is too long
3226 return ERROR_BUFFER_OVERFLOW
;
3229 result
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szKeyName
, 0, KEY_READ
, &hKey
);
3231 if (result
!= ERROR_SUCCESS
)
3233 // failed to find adapter entry
3234 return ERROR_NOT_FOUND
;
3237 result
= RegQueryValueExW(hKey
, L
"Name", NULL
, &type
, (PVOID
)pInterfaceName
, pOutBufLen
);
3241 if (result
== ERROR_MORE_DATA
)
3243 *pOutBufLen
= MAX_INTERFACE_NAME_LEN
* 2;
3244 return ERROR_INSUFFICIENT_BUFFER
;
3247 if (result
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
3249 // failed to read adapter name
3250 return ERROR_NO_DATA
;
3252 return ERROR_SUCCESS
;
3259 NhGetInterfaceNameFromDeviceGuid(_In_
const GUID
* pInterfaceGUID
,
3260 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3261 _Inout_ PULONG pOutBufLen
,
3265 SetLastError(ERROR_SUCCESS
);
3267 if (pInterfaceName
== NULL
)
3268 return ERROR_INVALID_PARAMETER
;
3270 return GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
3277 NhGetInterfaceNameFromGuid(_In_
const GUID
* pInterfaceGUID
,
3278 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3279 _Inout_ PULONG pOutBufLen
,
3285 result
= GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
3287 if (result
== ERROR_NOT_FOUND
)
3288 SetLastError(ERROR_PATH_NOT_FOUND
);