2 * iphlpapi dll implementation
4 * Copyright (C) 2003 Juan Lang
5 * 2018 Pierre Schweitzer
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "iphlpapi_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
31 typedef struct _NAME_SERVER_LIST_CONTEXT
{
34 PIP_PER_ADAPTER_INFO pData
;
36 IP_ADDR_STRING
*pLastAddr
;
37 } NAME_SERVER_LIST_CONTEXT
, *PNAME_SERVER_LIST_CONTEXT
;
39 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
42 case DLL_PROCESS_ATTACH
:
43 DisableThreadLibraryCalls( hinstDLL
);
47 case DLL_PROCESS_DETACH
:
54 /******************************************************************
55 * AddIPAddress (IPHLPAPI.@)
64 * NTEInstance [In/Out]
71 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask Netmask
, DWORD IfIndex
, PULONG NteContext
, PULONG NteInstance
)
73 return RtlNtStatusToDosError(addIPAddress(Address
, Netmask
, IfIndex
, NteContext
, NteInstance
));
76 DWORD
getInterfaceGatewayByIndex(DWORD index
)
78 DWORD ndx
, retVal
= 0, numRoutes
= getNumRoutes();
79 RouteTable
*table
= getRouteTable();
82 for (ndx
= 0; ndx
< numRoutes
; ndx
++)
84 if ((table
->routes
[ndx
].ifIndex
== (index
)) && (table
->routes
[ndx
].dest
== 0))
85 retVal
= table
->routes
[ndx
].gateway
;
87 HeapFree(GetProcessHeap(), 0, table
);
91 /******************************************************************
92 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
97 * ppIfTable [Out] -- pointer into which the MIB_IFTABLE is
98 * allocated and returned.
99 * bOrder [In] -- passed to GetIfTable to order the table
100 * heap [In] -- heap from which the table is allocated
101 * flags [In] -- flags to HeapAlloc
103 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
104 * GetIfTable returns otherwise
107 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
108 BOOL bOrder
, HANDLE heap
, DWORD flags
)
112 TRACE("ppIfTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n", ppIfTable
,
113 (DWORD
)bOrder
, (DWORD
)heap
, flags
);
115 ret
= ERROR_INVALID_PARAMETER
;
120 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
121 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
122 *ppIfTable
= (PMIB_IFTABLE
)HeapAlloc(heap
, flags
, dwSize
);
123 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
124 if (ret
!= NO_ERROR
) {
125 HeapFree(heap
, flags
, *ppIfTable
);
130 TRACE("returning %ld\n", ret
);
135 /******************************************************************
136 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
141 * ppIpAddrTable [Out]
142 * bOrder [In] -- passed to GetIpAddrTable to order the table
143 * heap [In] -- heap from which the table is allocated
144 * flags [In] -- flags to HeapAlloc
151 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
152 BOOL bOrder
, HANDLE heap
, DWORD flags
)
156 TRACE("ppIpAddrTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
157 ppIpAddrTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
159 ret
= ERROR_INVALID_PARAMETER
;
163 *ppIpAddrTable
= NULL
;
164 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
165 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
166 *ppIpAddrTable
= (PMIB_IPADDRTABLE
)HeapAlloc(heap
, flags
, dwSize
);
167 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
168 if (ret
!= NO_ERROR
) {
169 HeapFree(heap
, flags
, *ppIpAddrTable
);
170 *ppIpAddrTable
= NULL
;
174 TRACE("returning %ld\n", ret
);
179 /******************************************************************
180 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
183 * ppIpForwardTable [Out] -- pointer into which the MIB_IPFORWARDTABLE is
184 * allocated and returned.
185 * bOrder [In] -- passed to GetIfTable to order the table
186 * heap [In] -- heap from which the table is allocated
187 * flags [In] -- flags to HeapAlloc
189 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
190 * GetIpForwardTable returns otherwise
193 DWORD WINAPI
AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE
*
194 ppIpForwardTable
, BOOL bOrder
, HANDLE heap
, DWORD flags
)
198 TRACE("ppIpForwardTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
199 ppIpForwardTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
200 if (!ppIpForwardTable
)
201 ret
= ERROR_INVALID_PARAMETER
;
205 *ppIpForwardTable
= NULL
;
206 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
207 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
208 *ppIpForwardTable
= (PMIB_IPFORWARDTABLE
)HeapAlloc(heap
, flags
, dwSize
);
209 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
210 if (ret
!= NO_ERROR
) {
211 HeapFree(heap
, flags
, *ppIpForwardTable
);
212 *ppIpForwardTable
= NULL
;
216 TRACE("returning %ld\n", ret
);
221 /******************************************************************
222 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
228 * bOrder [In] -- passed to GetIpNetTable to order the table
229 * heap [In] -- heap from which the table is allocated
230 * flags [In] -- flags to HeapAlloc
237 DWORD WINAPI
AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE
*ppIpNetTable
,
238 BOOL bOrder
, HANDLE heap
, DWORD flags
)
242 TRACE("ppIpNetTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
243 ppIpNetTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
245 ret
= ERROR_INVALID_PARAMETER
;
249 *ppIpNetTable
= NULL
;
250 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
251 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
252 *ppIpNetTable
= (PMIB_IPNETTABLE
)HeapAlloc(heap
, flags
, dwSize
);
253 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
254 if (ret
!= NO_ERROR
) {
255 HeapFree(heap
, flags
, *ppIpNetTable
);
256 *ppIpNetTable
= NULL
;
260 TRACE("returning %ld\n", ret
);
265 /******************************************************************
266 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
272 * bOrder [In] -- passed to GetTcpTable to order the table
273 * heap [In] -- heap from which the table is allocated
274 * flags [In] -- flags to HeapAlloc
281 DWORD WINAPI
AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE
*ppTcpTable
,
282 BOOL bOrder
, HANDLE heap
, DWORD flags
)
286 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
287 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
289 ret
= ERROR_INVALID_PARAMETER
;
294 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
295 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
296 *ppTcpTable
= (PMIB_TCPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
297 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
298 if (ret
!= NO_ERROR
) {
299 HeapFree(heap
, flags
, *ppTcpTable
);
304 TRACE("returning %ld\n", ret
);
309 /******************************************************************
310 * AllocateAndGetTcpExTableFromStack (IPHLPAPI.@)
316 * bOrder [In] -- passed to GetExtendedTcpTable to order the table
317 * heap [In] -- heap from which the table is allocated
318 * flags [In] -- flags to HeapAlloc
319 * family [In] -- passed to GetExtendedTcpTable to select INET family
326 DWORD WINAPI
AllocateAndGetTcpExTableFromStack(PVOID
*ppTcpTable
,
327 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
)
331 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family 0x%08lx\n",
332 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
);
334 ret
= ERROR_INVALID_PARAMETER
;
339 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, TCP_TABLE_OWNER_PID_ALL
, 0);
340 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
341 *ppTcpTable
= (PMIB_TCPTABLE_OWNER_PID
)HeapAlloc(heap
, flags
, dwSize
);
342 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, TCP_TABLE_OWNER_PID_ALL
, 0);
343 if (ret
!= NO_ERROR
) {
344 HeapFree(heap
, flags
, *ppTcpTable
);
349 TRACE("returning %ld\n", ret
);
354 /******************************************************************
355 * AllocateAndGetTcpExTable2FromStack (IPHLPAPI.@)
361 * bOrder [In] -- passed to GetExtendedTcpTable to order the table
362 * heap [In] -- heap from which the table is allocated
363 * flags [In] -- flags to HeapAlloc
364 * family [In] -- passed to GetExtendedTcpTable to select INET family
365 * class [In] -- passed to GetExtendedTcpTable to select information
372 DWORD WINAPI
AllocateAndGetTcpExTable2FromStack(PVOID
*ppTcpTable
,
373 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
, TCP_TABLE_CLASS
class)
377 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family %ld, class %ld\n",
378 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
, class);
380 ret
= ERROR_INVALID_PARAMETER
;
385 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, class, 0);
386 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
387 *ppTcpTable
= HeapAlloc(heap
, flags
, dwSize
);
388 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, class, 0);
389 if (ret
!= NO_ERROR
) {
390 HeapFree(heap
, flags
, *ppTcpTable
);
395 TRACE("returning %ld\n", ret
);
400 /******************************************************************
401 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
407 * bOrder [In] -- passed to GetUdpTable to order the table
408 * heap [In] -- heap from which the table is allocated
409 * flags [In] -- flags to HeapAlloc
416 DWORD WINAPI
AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE
*ppUdpTable
,
417 BOOL bOrder
, HANDLE heap
, DWORD flags
)
421 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
422 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
424 ret
= ERROR_INVALID_PARAMETER
;
429 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
430 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
431 *ppUdpTable
= (PMIB_UDPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
432 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
433 if (ret
!= NO_ERROR
) {
434 HeapFree(heap
, flags
, *ppUdpTable
);
439 TRACE("returning %ld\n", ret
);
444 /******************************************************************
445 * AllocateAndGetUdpExTableFromStack (IPHLPAPI.@)
451 * bOrder [In] -- passed to GetExtendedUdpTable to order the table
452 * heap [In] -- heap from which the table is allocated
453 * flags [In] -- flags to HeapAlloc
454 * family [In] -- passed to GetExtendedUdpTable to select INET family
461 DWORD WINAPI
AllocateAndGetUdpExTableFromStack(PVOID
*ppUdpTable
,
462 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
)
466 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family 0x%08lx\n",
467 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
);
469 ret
= ERROR_INVALID_PARAMETER
;
474 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, UDP_TABLE_OWNER_PID
, 0);
475 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
476 *ppUdpTable
= (PMIB_UDPTABLE_OWNER_PID
)HeapAlloc(heap
, flags
, dwSize
);
477 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, UDP_TABLE_OWNER_PID
, 0);
478 if (ret
!= NO_ERROR
) {
479 HeapFree(heap
, flags
, *ppUdpTable
);
484 TRACE("returning %ld\n", ret
);
489 /******************************************************************
490 * AllocateAndGetUdpExTable2FromStack (IPHLPAPI.@)
496 * bOrder [In] -- passed to GetExtendedUdpTable to order the table
497 * heap [In] -- heap from which the table is allocated
498 * flags [In] -- flags to HeapAlloc
499 * family [In] -- passed to GetExtendedUdpTable to select INET family
500 * class [In] -- passed to GetExtendedUdpTable to select information
507 DWORD WINAPI
AllocateAndGetUdpExTable2FromStack(PVOID
*ppUdpTable
,
508 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
, UDP_TABLE_CLASS
class)
512 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family %ld, class %ld\n",
513 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
, class);
515 ret
= ERROR_INVALID_PARAMETER
;
520 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, class, 0);
521 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
522 *ppUdpTable
= HeapAlloc(heap
, flags
, dwSize
);
523 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, class, 0);
524 if (ret
!= NO_ERROR
) {
525 HeapFree(heap
, flags
, *ppUdpTable
);
530 TRACE("returning %ld\n", ret
);
535 /******************************************************************
536 * CreateIpForwardEntry (IPHLPAPI.@)
548 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
550 return createIpForwardEntry( pRoute
);
554 /******************************************************************
555 * CreateIpNetEntry (IPHLPAPI.@)
567 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
569 TRACE("pArpEntry %p\n", pArpEntry
);
570 /* could use SIOCSARP on systems that support it, not sure I want to */
576 /******************************************************************
577 * CreateProxyArpEntry (IPHLPAPI.@)
591 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
593 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
596 /* marking Win2K+ functions not supported */
597 return ERROR_NOT_SUPPORTED
;
601 /******************************************************************
602 * DeleteIPAddress (IPHLPAPI.@)
614 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
616 TRACE("NTEContext %ld\n", NTEContext
);
617 return RtlNtStatusToDosError(deleteIpAddress(NTEContext
));
621 /******************************************************************
622 * DeleteIpForwardEntry (IPHLPAPI.@)
634 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
636 return deleteIpForwardEntry( pRoute
);
640 /******************************************************************
641 * DeleteIpNetEntry (IPHLPAPI.@)
653 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
655 TRACE("pArpEntry %p\n", pArpEntry
);
656 /* could use SIOCDARP on systems that support it, not sure I want to */
662 /******************************************************************
663 * DeleteProxyArpEntry (IPHLPAPI.@)
677 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
679 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
682 /* marking Win2K+ functions not supported */
683 return ERROR_NOT_SUPPORTED
;
686 /******************************************************************
687 * EnableRouter (IPHLPAPI.@)
693 * pOverlapped [In/Out]
700 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
702 TRACE("pHandle %p, pOverlapped %p\n", pHandle
, pOverlapped
);
704 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
705 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
706 marking Win2K+ functions not supported */
707 return ERROR_NOT_SUPPORTED
;
711 /******************************************************************
712 * FlushIpNetTable (IPHLPAPI.@)
724 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
726 TRACE("dwIfIndex 0x%08lx\n", dwIfIndex
);
728 /* this flushes the arp cache of the given index
729 marking Win2K+ functions not supported */
730 return ERROR_NOT_SUPPORTED
;
734 /******************************************************************
735 * GetAdapterIndex (IPHLPAPI.@)
740 * AdapterName [In/Out]
748 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
750 TRACE("AdapterName %p, IfIndex %p\n", AdapterName
, IfIndex
);
752 /* marking Win2K+ functions not supported */
753 return ERROR_NOT_SUPPORTED
;
757 /******************************************************************
758 * GetAdaptersInfo (IPHLPAPI.@)
763 * pAdapterInfo [In/Out]
764 * pOutBufLen [In/Out]
771 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
777 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
779 ret
= ERROR_INVALID_PARAMETER
;
781 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
783 if (numNonLoopbackInterfaces
> 0) {
784 /* this calculation assumes only one address in the IP_ADDR_STRING lists.
785 that's okay, because:
786 - we don't get multiple addresses per adapter anyway
787 - we don't know about per-adapter gateways
788 - DHCP and WINS servers can have max one entry per list */
789 ULONG size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
791 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
793 ret
= ERROR_BUFFER_OVERFLOW
;
796 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
799 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
800 if (*pOutBufLen
< size
) {
802 ret
= ERROR_INSUFFICIENT_BUFFER
;
807 BOOL winsEnabled
= FALSE
;
808 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
810 memset(pAdapterInfo
, 0, size
);
811 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
812 "Software\\Wine\\Wine\\Config\\Network", 0, KEY_READ
,
813 &hKey
) == ERROR_SUCCESS
) {
814 DWORD size
= sizeof(primaryWINS
.String
);
817 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
818 (PBYTE
)primaryWINS
.String
, &size
);
819 addr
= inet_addr(primaryWINS
.String
);
820 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
822 size
= sizeof(secondaryWINS
.String
);
823 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
824 (PBYTE
)secondaryWINS
.String
, &size
);
825 addr
= inet_addr(secondaryWINS
.String
);
826 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
830 TRACE("num of index is %lu\n", table
->numIndexes
);
831 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
832 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
833 DWORD addrLen
= sizeof(ptr
->Address
), type
;
835 getInterfaceNameByIndex(table
->indexes
[ndx
]);
837 ret
= ERROR_OUTOFMEMORY
;
841 /* on Win98 this is left empty, but whatever */
842 strncpy(ptr
->AdapterName
,ifname
,sizeof(ptr
->AdapterName
));
843 consumeInterfaceName(ifname
);
844 ptr
->AdapterName
[MAX_ADAPTER_NAME_LENGTH
] = '\0';
845 getInterfacePhysicalByIndex(table
->indexes
[ndx
], &addrLen
,
846 ptr
->Address
, &type
);
847 /* MS defines address length and type as UINT in some places and
848 DWORD in others, **sigh**. Don't want to assume that PUINT and
849 PDWORD are equiv (64-bit?) */
850 ptr
->AddressLength
= addrLen
;
852 ptr
->Index
= table
->indexes
[ndx
];
853 toIPAddressString(getInterfaceIPAddrByIndex(table
->indexes
[ndx
]),
854 ptr
->IpAddressList
.IpAddress
.String
);
855 toIPAddressString(getInterfaceMaskByIndex(table
->indexes
[ndx
]),
856 ptr
->IpAddressList
.IpMask
.String
);
857 ptr
->IpAddressList
.Context
= ptr
->Index
;
858 toIPAddressString(getInterfaceGatewayByIndex(table
->indexes
[ndx
]),
859 ptr
->GatewayList
.IpAddress
.String
);
860 getDhcpInfoForAdapter(table
->indexes
[ndx
], &dhcpEnabled
,
861 &dhcpServer
, &ptr
->LeaseObtained
,
863 ptr
->DhcpEnabled
= (DWORD
) dhcpEnabled
;
864 toIPAddressString(dhcpServer
,
865 ptr
->DhcpServer
.IpAddress
.String
);
867 ptr
->HaveWins
= TRUE
;
868 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
869 primaryWINS
.String
, sizeof(primaryWINS
.String
));
870 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
871 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
873 if (ndx
< table
->numIndexes
- 1)
874 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
883 ret
= ERROR_OUTOFMEMORY
;
889 TRACE("returning %ld\n", ret
);
894 /******************************************************************
895 * GetBestInterface (IPHLPAPI.@)
901 * pdwBestIfIndex [In/Out]
908 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
912 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr
, pdwBestIfIndex
);
914 ret
= ERROR_INVALID_PARAMETER
;
916 MIB_IPFORWARDROW ipRow
;
918 ret
= GetBestRoute(dwDestAddr
, 0, &ipRow
);
919 if (ret
== ERROR_SUCCESS
)
920 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
922 TRACE("returning %ld\n", ret
);
927 /******************************************************************
928 * GetBestRoute (IPHLPAPI.@)
942 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
944 PMIB_IPFORWARDTABLE table
;
947 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr
,
948 dwSourceAddr
, pBestRoute
);
950 return ERROR_INVALID_PARAMETER
;
952 AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
954 DWORD ndx
, minMaskSize
, matchedNdx
= 0;
956 for (ndx
= 0, minMaskSize
= 255; ndx
< table
->dwNumEntries
; ndx
++) {
957 if ((dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
958 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
961 if (!_BitScanForward(&hostMaskSize
, ntohl(table
->table
[ndx
].dwForwardMask
)))
965 if (hostMaskSize
< minMaskSize
) {
966 minMaskSize
= hostMaskSize
;
971 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
972 HeapFree(GetProcessHeap(), 0, table
);
976 ret
= ERROR_OUTOFMEMORY
;
977 TRACE("returning %ld\n", ret
);
981 static int TcpTableSorter(const void *a
, const void *b
)
986 PMIB_TCPROW rowA
= (PMIB_TCPROW
)a
, rowB
= (PMIB_TCPROW
)b
;
988 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
990 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
992 ret
= rowA
->dwRemoteAddr
- rowB
->dwRemoteAddr
;
994 ret
= rowA
->dwRemotePort
- rowB
->dwRemotePort
;
1003 /******************************************************************
1004 * GetExtendedTcpTable (IPHLPAPI.@)
1006 * Get the table of TCP endpoints available to the application.
1009 * pTcpTable [Out] table struct with the filtered TCP endpoints available to application
1010 * pdwSize [In/Out] estimated size of the structure returned in pTcpTable, in bytes
1011 * bOrder [In] whether to order the table
1012 * ulAf [in] version of IP used by the TCP endpoints
1013 * TableClass [in] type of the TCP table structure from TCP_TABLE_CLASS
1014 * Reserved [in] reserved - this value must be zero
1018 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
1023 DWORD WINAPI
GetExtendedTcpTable(PVOID pTcpTable
, PDWORD pdwSize
, BOOL bOrder
, ULONG ulAf
, TCP_TABLE_CLASS TableClass
, ULONG Reserved
)
1026 DWORD ret
= NO_ERROR
;
1030 return ERROR_INVALID_PARAMETER
;
1033 if (ulAf
!= AF_INET
)
1036 return ERROR_INVALID_PARAMETER
;
1041 case TCP_TABLE_BASIC_ALL
:
1043 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
1044 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1048 if (sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
1050 *pdwSize
= sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
);
1051 ret
= ERROR_INSUFFICIENT_BUFFER
;
1055 memcpy(pTheirTcpTable
, pOurTcpTable
, sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
));
1058 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1059 sizeof(MIB_TCPROW
), TcpTableSorter
);
1067 case TCP_TABLE_BASIC_CONNECTIONS
:
1069 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
1070 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1074 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1076 if (pOurTcpTable
->table
[i
].State
!= MIB_TCP_STATE_LISTEN
)
1082 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
1084 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
);
1085 ret
= ERROR_INSUFFICIENT_BUFFER
;
1089 pTheirTcpTable
->dwNumEntries
= count
;
1091 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1093 if (pOurTcpTable
->table
[i
].State
!= MIB_TCP_STATE_LISTEN
)
1095 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW
));
1099 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1102 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1103 sizeof(MIB_TCPROW
), TcpTableSorter
);
1111 case TCP_TABLE_BASIC_LISTENER
:
1113 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
1114 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1118 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1120 if (pOurTcpTable
->table
[i
].State
== MIB_TCP_STATE_LISTEN
)
1126 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
1128 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
);
1129 ret
= ERROR_INSUFFICIENT_BUFFER
;
1133 pTheirTcpTable
->dwNumEntries
= count
;
1135 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1137 if (pOurTcpTable
->table
[i
].State
== MIB_TCP_STATE_LISTEN
)
1139 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW
));
1143 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1146 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1147 sizeof(MIB_TCPROW
), TcpTableSorter
);
1155 case TCP_TABLE_OWNER_PID_ALL
:
1157 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
1158 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1162 if (sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
1164 *pdwSize
= sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
);
1165 ret
= ERROR_INSUFFICIENT_BUFFER
;
1169 memcpy(pTheirTcpTable
, pOurTcpTable
, sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
));
1171 /* Don't sort on PID, so use basic helper */
1173 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1174 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1182 case TCP_TABLE_OWNER_PID_CONNECTIONS
:
1184 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
1185 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1189 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1191 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1197 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
1199 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
);
1200 ret
= ERROR_INSUFFICIENT_BUFFER
;
1204 pTheirTcpTable
->dwNumEntries
= count
;
1206 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1208 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1210 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_PID
));
1214 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1216 /* Don't sort on PID, so use basic helper */
1218 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1219 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1227 case TCP_TABLE_OWNER_PID_LISTENER
:
1229 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
1230 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1234 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1236 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1242 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
1244 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
);
1245 ret
= ERROR_INSUFFICIENT_BUFFER
;
1249 pTheirTcpTable
->dwNumEntries
= count
;
1251 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1253 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1255 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_PID
));
1259 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1261 /* Don't sort on PID, so use basic helper */
1263 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1264 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1272 case TCP_TABLE_OWNER_MODULE_ALL
:
1274 PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable
= getOwnerModTcpTable();
1275 PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable
= pTcpTable
;
1279 if (sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_MODULE
) > *pdwSize
|| !pTheirTcpTable
)
1281 *pdwSize
= sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_MODULE
);
1282 ret
= ERROR_INSUFFICIENT_BUFFER
;
1286 memcpy(pTheirTcpTable
, pOurTcpTable
, sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_MODULE
));
1288 /* Don't sort on PID, so use basic helper */
1290 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1291 sizeof(MIB_TCPROW_OWNER_MODULE
), TcpTableSorter
);
1299 case TCP_TABLE_OWNER_MODULE_CONNECTIONS
:
1301 PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable
= getOwnerModTcpTable();
1302 PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable
= pTcpTable
;
1306 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1308 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1314 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_MODULE
) > *pdwSize
|| !pTheirTcpTable
)
1316 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_MODULE
);
1317 ret
= ERROR_INSUFFICIENT_BUFFER
;
1321 pTheirTcpTable
->dwNumEntries
= count
;
1323 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1325 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1327 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_MODULE
));
1331 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1333 /* Don't sort on PID, so use basic helper */
1335 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1336 sizeof(MIB_TCPROW_OWNER_MODULE
), TcpTableSorter
);
1344 case TCP_TABLE_OWNER_MODULE_LISTENER
:
1346 PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable
= getOwnerModTcpTable();
1347 PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable
= pTcpTable
;
1351 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1353 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1359 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_MODULE
) > *pdwSize
|| !pTheirTcpTable
)
1361 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_MODULE
);
1362 ret
= ERROR_INSUFFICIENT_BUFFER
;
1366 pTheirTcpTable
->dwNumEntries
= count
;
1368 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1370 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1372 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_MODULE
));
1376 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1378 /* Don't sort on PID, so use basic helper */
1380 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1381 sizeof(MIB_TCPROW_OWNER_MODULE
), TcpTableSorter
);
1390 ret
= ERROR_INVALID_PARAMETER
;
1398 static int UdpTableSorter(const void *a
, const void *b
)
1403 PMIB_UDPROW rowA
= (PMIB_UDPROW
)a
, rowB
= (PMIB_UDPROW
)b
;
1405 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1407 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1414 /******************************************************************
1415 * GetExtendedUdpTable (IPHLPAPI.@)
1417 * Get the table of UDP endpoints available to the application.
1420 * pUdpTable [Out] table struct with the filtered UDP endpoints available to application
1421 * pdwSize [In/Out] estimated size of the structure returned in pUdpTable, in bytes
1422 * bOrder [In] whether to order the table
1423 * ulAf [in] version of IP used by the UDP endpoints
1424 * TableClass [in] type of the UDP table structure from UDP_TABLE_CLASS
1425 * Reserved [in] reserved - this value must be zero
1429 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
1434 DWORD WINAPI
GetExtendedUdpTable(PVOID pUdpTable
, PDWORD pdwSize
, BOOL bOrder
, ULONG ulAf
, UDP_TABLE_CLASS TableClass
, ULONG Reserved
)
1436 DWORD ret
= NO_ERROR
;
1440 return ERROR_INVALID_PARAMETER
;
1443 if (ulAf
!= AF_INET
)
1446 return ERROR_INVALID_PARAMETER
;
1451 case UDP_TABLE_BASIC
:
1453 PMIB_UDPTABLE pOurUdpTable
= getUdpTable();
1454 PMIB_UDPTABLE pTheirUdpTable
= pUdpTable
;
1458 if (sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW
) > *pdwSize
|| !pTheirUdpTable
)
1460 *pdwSize
= sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW
);
1461 ret
= ERROR_INSUFFICIENT_BUFFER
;
1465 memcpy(pTheirUdpTable
, pOurUdpTable
, sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
));
1468 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1469 sizeof(MIB_UDPROW
), UdpTableSorter
);
1477 case UDP_TABLE_OWNER_PID
:
1479 PMIB_UDPTABLE_OWNER_PID pOurUdpTable
= getOwnerUdpTable();
1480 PMIB_UDPTABLE_OWNER_PID pTheirUdpTable
= pUdpTable
;
1484 if (sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
) > *pdwSize
|| !pTheirUdpTable
)
1486 *pdwSize
= sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
);
1487 ret
= ERROR_INSUFFICIENT_BUFFER
;
1491 memcpy(pTheirUdpTable
, pOurUdpTable
, sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
));
1494 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1495 sizeof(MIB_UDPROW_OWNER_PID
), UdpTableSorter
);
1503 case UDP_TABLE_OWNER_MODULE
:
1505 PMIB_UDPTABLE_OWNER_MODULE pOurUdpTable
= getOwnerModUdpTable();
1506 PMIB_UDPTABLE_OWNER_MODULE pTheirUdpTable
= pUdpTable
;
1510 if (sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_MODULE
) > *pdwSize
|| !pTheirUdpTable
)
1512 *pdwSize
= sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_MODULE
);
1513 ret
= ERROR_INSUFFICIENT_BUFFER
;
1517 memcpy(pTheirUdpTable
, pOurUdpTable
, sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_MODULE
));
1520 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1521 sizeof(MIB_UDPROW_OWNER_MODULE
), UdpTableSorter
);
1530 ret
= ERROR_INVALID_PARAMETER
;
1538 /******************************************************************
1539 * GetFriendlyIfIndex (IPHLPAPI.@)
1551 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
1553 /* windows doesn't validate these, either, just makes sure the top byte is
1554 cleared. I assume my ifenum module never gives an index with the top
1556 TRACE("returning %ld\n", IfIndex
);
1561 /******************************************************************
1562 * GetIcmpStatistics (IPHLPAPI.@)
1574 DWORD WINAPI
GetIcmpStatistics(PMIB_ICMP pStats
)
1578 TRACE("pStats %p\n", pStats
);
1579 ret
= getICMPStats(pStats
);
1580 TRACE("returning %ld\n", ret
);
1585 /******************************************************************
1586 * GetIfEntry (IPHLPAPI.@)
1598 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
1603 TRACE("pIfRow %p\n", pIfRow
);
1605 return ERROR_INVALID_PARAMETER
;
1607 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
);
1609 ret
= getInterfaceEntryByIndex(pIfRow
->dwIndex
, pIfRow
);
1610 if (ret
== NO_ERROR
)
1611 ret
= getInterfaceStatsByName(name
, pIfRow
);
1612 consumeInterfaceName(name
);
1615 ret
= ERROR_INVALID_DATA
;
1616 TRACE("returning %ld\n", ret
);
1621 static int IfTableSorter(const void *a
, const void *b
)
1626 ret
= ((PMIB_IFROW
)a
)->dwIndex
- ((PMIB_IFROW
)b
)->dwIndex
;
1633 /******************************************************************
1634 * GetIfTable (IPHLPAPI.@)
1648 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
1652 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize
, pdwSize
,
1655 ret
= ERROR_INVALID_PARAMETER
;
1657 DWORD numInterfaces
= getNumInterfaces();
1659 TRACE("GetIfTable: numInterfaces = %d\n", (int)numInterfaces
);
1660 size
= sizeof(MIB_IFTABLE
) + (numInterfaces
- 1) * sizeof(MIB_IFROW
);
1662 if (!pIfTable
|| *pdwSize
< size
) {
1664 ret
= ERROR_INSUFFICIENT_BUFFER
;
1667 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1670 size
= sizeof(MIB_IFTABLE
) + (table
->numIndexes
- 1) *
1672 if (*pdwSize
< size
) {
1674 ret
= ERROR_INSUFFICIENT_BUFFER
;
1679 pIfTable
->dwNumEntries
= 0;
1680 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1681 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1682 GetIfEntry(&pIfTable
->table
[ndx
]);
1683 pIfTable
->dwNumEntries
++;
1686 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
1693 ret
= ERROR_OUTOFMEMORY
;
1696 TRACE("returning %ld\n", ret
);
1701 /******************************************************************
1702 * GetInterfaceInfo (IPHLPAPI.@)
1708 * dwOutBufLen [In/Out]
1715 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1719 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1721 ret
= ERROR_INVALID_PARAMETER
;
1723 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
1725 TRACE("numNonLoopbackInterfaces == 0x%x\n", numNonLoopbackInterfaces
);
1726 size
= sizeof(IP_INTERFACE_INFO
) + (numNonLoopbackInterfaces
) *
1727 sizeof(IP_ADAPTER_INDEX_MAP
);
1729 if (!pIfTable
|| *dwOutBufLen
< size
) {
1730 *dwOutBufLen
= size
;
1731 ret
= ERROR_INSUFFICIENT_BUFFER
;
1734 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
1737 TRACE("table->numIndexes == 0x%x\n", table
->numIndexes
);
1738 size
= sizeof(IP_INTERFACE_INFO
) + (table
->numIndexes
) *
1739 sizeof(IP_ADAPTER_INDEX_MAP
);
1740 if (*dwOutBufLen
< size
) {
1741 *dwOutBufLen
= size
;
1742 ret
= ERROR_INSUFFICIENT_BUFFER
;
1747 pIfTable
->NumAdapters
= 0;
1748 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1749 const char *walker
, *name
;
1752 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1753 name
= getInterfaceNameByIndex(table
->indexes
[ndx
]);
1754 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1755 walker
&& *walker
&&
1756 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1757 walker
++, assigner
++)
1758 *assigner
= *walker
;
1760 consumeInterfaceName(name
);
1761 pIfTable
->NumAdapters
++;
1768 ret
= ERROR_OUTOFMEMORY
;
1771 TRACE("returning %ld\n", ret
);
1776 static int IpAddrTableSorter(const void *a
, const void *b
)
1781 ret
= ((PMIB_IPADDRROW
)a
)->dwAddr
- ((PMIB_IPADDRROW
)b
)->dwAddr
;
1788 /******************************************************************
1789 * GetIpAddrTable (IPHLPAPI.@)
1794 * pIpAddrTable [In/Out]
1803 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1807 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable
, pdwSize
,
1810 ret
= ERROR_INVALID_PARAMETER
;
1812 DWORD numInterfaces
= getNumInterfaces();
1813 ULONG size
= sizeof(MIB_IPADDRTABLE
) + (numInterfaces
- 1) *
1814 sizeof(MIB_IPADDRROW
);
1816 if (!pIpAddrTable
|| *pdwSize
< size
) {
1818 ret
= ERROR_INSUFFICIENT_BUFFER
;
1821 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1824 size
= sizeof(MIB_IPADDRTABLE
) + (table
->numIndexes
- 1) *
1825 sizeof(MIB_IPADDRROW
);
1826 if (*pdwSize
< size
) {
1828 ret
= ERROR_INSUFFICIENT_BUFFER
;
1833 pIpAddrTable
->dwNumEntries
= 0;
1834 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1835 pIpAddrTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1836 pIpAddrTable
->table
[ndx
].dwAddr
=
1837 getInterfaceIPAddrByIndex(table
->indexes
[ndx
]);
1838 pIpAddrTable
->table
[ndx
].dwMask
=
1839 getInterfaceMaskByIndex(table
->indexes
[ndx
]);
1840 /* the dwBCastAddr member isn't the broadcast address, it indicates
1841 * whether the interface uses the 1's broadcast address (1) or the
1842 * 0's broadcast address (0).
1844 bcast
= getInterfaceBCastAddrByIndex(table
->indexes
[ndx
]);
1845 pIpAddrTable
->table
[ndx
].dwBCastAddr
=
1846 (bcast
& pIpAddrTable
->table
[ndx
].dwMask
) ? 1 : 0;
1847 /* FIXME: hardcoded reasm size, not sure where to get it */
1848 pIpAddrTable
->table
[ndx
].dwReasmSize
= 65535;
1849 pIpAddrTable
->table
[ndx
].unused1
= 0;
1850 pIpAddrTable
->table
[ndx
].wType
= 0; /* aka unused2 */
1851 pIpAddrTable
->dwNumEntries
++;
1854 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1855 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1861 ret
= ERROR_OUTOFMEMORY
;
1864 TRACE("returning %ld\n", ret
);
1869 static int IpForwardTableSorter(const void *a
, const void *b
)
1874 PMIB_IPFORWARDROW rowA
= (PMIB_IPFORWARDROW
)a
, rowB
= (PMIB_IPFORWARDROW
)b
;
1876 ret
= rowA
->dwForwardDest
- rowB
->dwForwardDest
;
1878 ret
= rowA
->dwForwardProto
- rowB
->dwForwardProto
;
1880 ret
= rowA
->dwForwardPolicy
- rowB
->dwForwardPolicy
;
1882 ret
= rowA
->dwForwardNextHop
- rowB
->dwForwardNextHop
;
1892 /******************************************************************
1893 * GetIpForwardTable (IPHLPAPI.@)
1898 * pIpForwardTable [In/Out]
1907 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1911 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable
,
1912 pdwSize
, (DWORD
)bOrder
);
1914 ret
= ERROR_INVALID_PARAMETER
;
1916 DWORD numRoutes
= getNumRoutes();
1917 ULONG sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (numRoutes
- 1) *
1918 sizeof(MIB_IPFORWARDROW
);
1920 if (!pIpForwardTable
|| *pdwSize
< sizeNeeded
) {
1921 *pdwSize
= sizeNeeded
;
1922 ret
= ERROR_INSUFFICIENT_BUFFER
;
1925 RouteTable
*table
= getRouteTable();
1927 sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (table
->numRoutes
- 1) *
1928 sizeof(MIB_IPFORWARDROW
);
1929 if (*pdwSize
< sizeNeeded
) {
1930 *pdwSize
= sizeNeeded
;
1931 ret
= ERROR_INSUFFICIENT_BUFFER
;
1936 pIpForwardTable
->dwNumEntries
= table
->numRoutes
;
1937 for (ndx
= 0; ndx
< numRoutes
; ndx
++) {
1938 pIpForwardTable
->table
[ndx
].dwForwardIfIndex
=
1939 table
->routes
[ndx
].ifIndex
;
1940 pIpForwardTable
->table
[ndx
].dwForwardDest
=
1941 table
->routes
[ndx
].dest
;
1942 pIpForwardTable
->table
[ndx
].dwForwardMask
=
1943 table
->routes
[ndx
].mask
;
1944 pIpForwardTable
->table
[ndx
].dwForwardPolicy
= 0;
1945 pIpForwardTable
->table
[ndx
].dwForwardNextHop
=
1946 table
->routes
[ndx
].gateway
;
1947 /* FIXME: this type is appropriate for local interfaces; may not
1948 always be appropriate */
1949 pIpForwardTable
->table
[ndx
].dwForwardType
= MIB_IPROUTE_TYPE_DIRECT
;
1950 /* FIXME: other protos might be appropriate, e.g. the default route
1951 is typically set with MIB_IPPROTO_NETMGMT instead */
1952 pIpForwardTable
->table
[ndx
].dwForwardProto
= MIB_IPPROTO_LOCAL
;
1953 /* punt on age and AS */
1954 pIpForwardTable
->table
[ndx
].dwForwardAge
= 0;
1955 pIpForwardTable
->table
[ndx
].dwForwardNextHopAS
= 0;
1956 pIpForwardTable
->table
[ndx
].dwForwardMetric1
=
1957 table
->routes
[ndx
].metric
;
1958 /* rest of the metrics are 0.. */
1959 pIpForwardTable
->table
[ndx
].dwForwardMetric2
= 0;
1960 pIpForwardTable
->table
[ndx
].dwForwardMetric3
= 0;
1961 pIpForwardTable
->table
[ndx
].dwForwardMetric4
= 0;
1962 pIpForwardTable
->table
[ndx
].dwForwardMetric5
= 0;
1965 qsort(pIpForwardTable
->table
, pIpForwardTable
->dwNumEntries
,
1966 sizeof(MIB_IPFORWARDROW
), IpForwardTableSorter
);
1969 HeapFree(GetProcessHeap(), 0, table
);
1972 ret
= ERROR_OUTOFMEMORY
;
1975 TRACE("returning %ld\n", ret
);
1980 static int IpNetTableSorter(const void *a
, const void *b
)
1985 ret
= ((PMIB_IPNETROW
)a
)->dwAddr
- ((PMIB_IPNETROW
)b
)->dwAddr
;
1992 /******************************************************************
1993 * GetIpNetTable (IPHLPAPI.@)
1998 * pIpNetTable [In/Out]
2007 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
2009 DWORD ret
= NO_ERROR
;
2011 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
,
2014 ret
= ERROR_INVALID_PARAMETER
;
2016 DWORD numEntries
= getNumArpEntries();
2017 ULONG size
= sizeof(MIB_IPNETTABLE
);
2020 size
+= (numEntries
- 1) * sizeof(MIB_IPNETROW
);
2021 if (!pIpNetTable
|| *pdwSize
< size
) {
2023 ret
= ERROR_INSUFFICIENT_BUFFER
;
2026 PMIB_IPNETTABLE table
= getArpTable();
2028 size
= sizeof(MIB_IPNETTABLE
);
2029 if (table
->dwNumEntries
> 1)
2030 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPNETROW
);
2031 if (*pdwSize
< size
) {
2033 ret
= ERROR_INSUFFICIENT_BUFFER
;
2037 memcpy(pIpNetTable
, table
, size
);
2039 qsort(pIpNetTable
->table
, pIpNetTable
->dwNumEntries
,
2040 sizeof(MIB_IPNETROW
), IpNetTableSorter
);
2043 HeapFree(GetProcessHeap(), 0, table
);
2047 TRACE("returning %d\n", ret
);
2052 /******************************************************************
2053 * GetIpStatistics (IPHLPAPI.@)
2065 DWORD WINAPI
GetIpStatistics(PMIB_IPSTATS pStats
)
2067 return GetIpStatisticsEx(pStats
, PF_INET
);
2070 /******************************************************************
2071 * GetIpStatisticsEx (IPHLPAPI.@)
2084 DWORD WINAPI
GetIpStatisticsEx(PMIB_IPSTATS pStats
, DWORD dwFamily
)
2088 TRACE("pStats %p\n", pStats
);
2089 ret
= getIPStats(pStats
, dwFamily
);
2090 TRACE("returning %ld\n", ret
);
2094 /******************************************************************
2095 * GetNetworkParams (IPHLPAPI.@)
2100 * pFixedInfo [In/Out]
2101 * pOutBufLen [In/Out]
2108 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
2110 DWORD ret
, size
, type
;
2113 PIPHLP_RES_INFO resInfo
;
2115 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
2117 return ERROR_INVALID_PARAMETER
;
2119 resInfo
= getResInfo();
2121 return ERROR_OUTOFMEMORY
;
2123 size
= sizeof(FIXED_INFO
) + (resInfo
->riCount
> 1 ? (resInfo
->riCount
-1) *
2124 sizeof(IP_ADDR_STRING
) : 0);
2125 if (!pFixedInfo
|| *pOutBufLen
< size
) {
2127 disposeResInfo( resInfo
);
2128 return ERROR_BUFFER_OVERFLOW
;
2131 memset(pFixedInfo
, 0, size
);
2132 /* Check for DhcpHostname and DhcpDomain first */
2133 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2134 "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
2138 if (regReturn
== ERROR_SUCCESS
) {
2139 /* Windows doesn't honor DHCP option 12 even if RFC requires it if it is returned by DHCP server! */
2142 size
= sizeof(pFixedInfo
->HostName
);
2143 regReturn
= RegQueryValueExA(hKey
,
2147 (LPBYTE
)pFixedInfo
->HostName
,
2149 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
2153 size
= sizeof(pFixedInfo
->HostName
);
2154 regReturn
= RegQueryValueExA(hKey
,
2158 (LPBYTE
)pFixedInfo
->HostName
,
2165 size
= sizeof(pFixedInfo
->DomainName
);
2166 regReturn
= RegQueryValueExA(hKey
,
2170 (LPBYTE
)pFixedInfo
->DomainName
,
2172 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
2175 size
= sizeof(pFixedInfo
->DomainName
);
2176 regReturn
= RegQueryValueExA(hKey
,
2180 (LPBYTE
)pFixedInfo
->DomainName
,
2186 TRACE("GetComputerNameExA: %s\n", pFixedInfo
->DomainName
);
2188 if (resInfo
->riCount
> 0)
2190 CopyMemory(&pFixedInfo
->DnsServerList
, resInfo
->DnsList
, sizeof(IP_ADDR_STRING
));
2191 if (resInfo
->riCount
> 1)
2193 IP_ADDR_STRING
*pSrc
= resInfo
->DnsList
->Next
;
2194 IP_ADDR_STRING
*pTarget
= (struct _IP_ADDR_STRING
*)((char*)pFixedInfo
+ sizeof(FIXED_INFO
));
2196 pFixedInfo
->DnsServerList
.Next
= pTarget
;
2200 CopyMemory(pTarget
, pSrc
, sizeof(IP_ADDR_STRING
));
2202 if (resInfo
->riCount
> 1)
2204 pTarget
->Next
= (IP_ADDR_STRING
*)((char*)pTarget
+ sizeof(IP_ADDR_STRING
));
2205 pTarget
= pTarget
->Next
;
2210 pTarget
->Next
= NULL
;
2218 pFixedInfo
->DnsServerList
.Next
= NULL
;
2222 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
2223 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2224 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
2225 if (regReturn
!= ERROR_SUCCESS
)
2226 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2227 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
2229 if (regReturn
== ERROR_SUCCESS
)
2231 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
2233 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (PBYTE
)pFixedInfo
->ScopeId
, &size
);
2237 disposeResInfo( resInfo
);
2238 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
2239 I suppose could also check for a listener on port 53 to set EnableDns */
2241 TRACE("returning %ld\n", ret
);
2247 /******************************************************************
2248 * GetNumberOfInterfaces (IPHLPAPI.@)
2260 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
2264 TRACE("pdwNumIf %p\n", pdwNumIf
);
2266 ret
= ERROR_INVALID_PARAMETER
;
2268 *pdwNumIf
= getNumInterfaces();
2271 TRACE("returning %ld\n", ret
);
2276 /******************************************************************
2277 * GetOwnerModuleFromTcpEntry (IPHLPAPI.@)
2279 * Get data about the module that issued the context bind for a specific IPv4 TCP endpoint in a MIB table row
2282 * pTcpEntry [in] pointer to a MIB_TCPROW_OWNER_MODULE structure
2283 * Class [in] TCPIP_OWNER_MODULE_INFO_CLASS enumeration value
2284 * Buffer [out] pointer a buffer containing a TCPIP_OWNER_MODULE_BASIC_INFO structure with the owner module data.
2285 * pdwSize [in, out] estimated size of the structure returned in Buffer, in bytes
2289 * Failure: ERROR_INSUFFICIENT_BUFFER, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY
2290 * ERROR_NOT_FOUND or ERROR_PARTIAL_COPY
2293 * The type of data returned in Buffer is indicated by the value of the Class parameter.
2295 DWORD WINAPI
GetOwnerModuleFromTcpEntry( PMIB_TCPROW_OWNER_MODULE pTcpEntry
, TCPIP_OWNER_MODULE_INFO_CLASS Class
, PVOID Buffer
, PDWORD pdwSize
)
2298 DWORD FileLen
, PathLen
;
2299 WCHAR File
[MAX_PATH
], Path
[MAX_PATH
];
2300 PTCPIP_OWNER_MODULE_BASIC_INFO BasicInfo
;
2302 if (pTcpEntry
->dwOwningPid
== 0)
2304 return ERROR_NOT_FOUND
;
2307 Process
= OpenProcess(PROCESS_QUERY_INFORMATION
| PROCESS_VM_READ
, FALSE
, pTcpEntry
->dwOwningPid
);
2308 if (Process
== NULL
)
2310 return GetLastError();
2313 FileLen
= GetModuleBaseNameW(Process
, NULL
, File
, MAX_PATH
);
2316 PathLen
= GetModuleFileNameExW(Process
, NULL
, Path
, MAX_PATH
);
2319 CloseHandle(Process
);
2320 return GetLastError();
2326 PathLen
*= sizeof(WCHAR
);
2327 FileLen
*= sizeof(WCHAR
);
2329 else if (GetLastError() == ERROR_PARTIAL_COPY
)
2331 wcscpy(File
, L
"System");
2332 wcscpy(Path
, L
"System");
2334 PathLen
= sizeof(L
"System");
2335 FileLen
= sizeof(L
"System");
2338 CloseHandle(Process
);
2340 if (*pdwSize
< sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
) + PathLen
+ FileLen
)
2342 *pdwSize
= sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
) + PathLen
+ FileLen
;
2343 return ERROR_INSUFFICIENT_BUFFER
;
2347 BasicInfo
->pModuleName
= (PVOID
)((ULONG_PTR
)BasicInfo
+ sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
));
2348 BasicInfo
->pModulePath
= (PVOID
)((ULONG_PTR
)BasicInfo
->pModuleName
+ FileLen
);
2349 wcscpy(BasicInfo
->pModuleName
, File
);
2350 wcscpy(BasicInfo
->pModulePath
, Path
);
2351 *pdwSize
= sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
) + PathLen
+ FileLen
;
2356 static void CreateNameServerListEnumNamesFunc( PWCHAR Interface
, PWCHAR Server
, PVOID Data
)
2358 IP_ADDR_STRING
*pNext
;
2359 PNAME_SERVER_LIST_CONTEXT Context
= (PNAME_SERVER_LIST_CONTEXT
)Data
;
2361 if (!Context
->NumServers
)
2363 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
2365 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, Context
->pData
->DnsServerList
.IpAddress
.String
, 16, NULL
, NULL
);
2366 Context
->pData
->DnsServerList
.IpAddress
.String
[15] = '\0';
2367 Context
->pLastAddr
= &Context
->pData
->DnsServerList
;
2372 Context
->uSizeRequired
+= sizeof(IP_ADDR_STRING
);
2373 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
2375 pNext
= (IP_ADDR_STRING
*)(((char*)Context
->pLastAddr
) + sizeof(IP_ADDR_STRING
));
2376 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, pNext
->IpAddress
.String
, 16, NULL
, NULL
);
2377 pNext
->IpAddress
.String
[15] = '\0';
2378 Context
->pLastAddr
->Next
= pNext
;
2379 Context
->pLastAddr
= pNext
;
2383 Context
->NumServers
++;
2386 /******************************************************************
2387 * GetPerAdapterInfo (IPHLPAPI.@)
2393 * pPerAdapterInfo [In/Out]
2394 * pOutBufLen [In/Out]
2401 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
2406 NAME_SERVER_LIST_CONTEXT Context
;
2407 WCHAR keyname
[200] = L
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
2410 return ERROR_INVALID_PARAMETER
;
2412 if (!pPerAdapterInfo
|| *pOutBufLen
< sizeof(IP_PER_ADAPTER_INFO
))
2414 *pOutBufLen
= sizeof(IP_PER_ADAPTER_INFO
);
2415 return ERROR_BUFFER_OVERFLOW
;
2418 ifName
= getInterfaceNameByIndex(IfIndex
);
2420 return ERROR_INVALID_PARAMETER
;
2422 MultiByteToWideChar(CP_ACP
, 0, ifName
, -1, &keyname
[62], sizeof(keyname
)/sizeof(WCHAR
) - 63);
2423 HeapFree(GetProcessHeap(), 0, (LPVOID
)ifName
);
2425 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keyname
, 0, KEY_READ
, &hkey
) != ERROR_SUCCESS
)
2427 return ERROR_NOT_SUPPORTED
;
2429 Context
.NumServers
= 0;
2430 Context
.uSizeAvailable
= *pOutBufLen
;
2431 Context
.uSizeRequired
= sizeof(IP_PER_ADAPTER_INFO
);
2432 Context
.pData
= pPerAdapterInfo
;
2434 if (*pOutBufLen
>= sizeof(IP_PER_ADAPTER_INFO
))
2435 ZeroMemory(pPerAdapterInfo
, sizeof(IP_PER_ADAPTER_INFO
));
2437 EnumNameServers(hkey
, &keyname
[62], &Context
, CreateNameServerListEnumNamesFunc
);
2439 if (Context
.uSizeRequired
> Context
.uSizeAvailable
)
2441 *pOutBufLen
= Context
.uSizeRequired
;
2443 return ERROR_BUFFER_OVERFLOW
;
2446 if(RegQueryValueExW(hkey
, L
"NameServer", NULL
, NULL
, NULL
, &dwSize
) == ERROR_SUCCESS
)
2448 pPerAdapterInfo
->AutoconfigActive
= FALSE
;
2452 pPerAdapterInfo
->AutoconfigActive
= TRUE
;
2460 /******************************************************************
2461 * GetRTTAndHopCount (IPHLPAPI.@)
2466 * DestIpAddress [In]
2476 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
2478 TRACE("DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p\n",
2479 DestIpAddress
, HopCount
, MaxHops
, RTT
);
2485 /******************************************************************
2486 * GetTcpStatisticsEx (IPHLPAPI.@)
2499 DWORD WINAPI
GetTcpStatisticsEx(PMIB_TCPSTATS pStats
, DWORD dwFamily
)
2503 TRACE("pStats %p\n", pStats
);
2504 ret
= getTCPStats(pStats
, dwFamily
);
2505 TRACE("returning %ld\n", ret
);
2509 /******************************************************************
2510 * GetTcpStatistics (IPHLPAPI.@)
2522 DWORD WINAPI
GetTcpStatistics(PMIB_TCPSTATS pStats
)
2524 return GetTcpStatisticsEx(pStats
, PF_INET
);
2528 /******************************************************************
2529 * GetTcpTable (IPHLPAPI.@)
2531 * Get the table of active TCP connections.
2534 * pTcpTable [Out] buffer for TCP connections table
2535 * pdwSize [In/Out] length of output buffer
2536 * bOrder [In] whether to order the table
2540 * Failure: error code from winerror.h
2543 * If pdwSize is less than required, the function will return
2544 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
2545 * the required byte size.
2546 * If bOrder is true, the returned table will be sorted, first by
2547 * local address and port number, then by remote address and port
2550 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
2552 return GetExtendedTcpTable(pTcpTable
, pdwSize
, bOrder
, AF_INET
, TCP_TABLE_BASIC_ALL
, 0);
2556 /******************************************************************
2557 * GetUdpStatisticsEx (IPHLPAPI.@)
2570 DWORD WINAPI
GetUdpStatisticsEx(PMIB_UDPSTATS pStats
, DWORD dwFamily
)
2574 TRACE("pStats %p\n", pStats
);
2575 ret
= getUDPStats(pStats
, dwFamily
);
2576 TRACE("returning %ld\n", ret
);
2580 /******************************************************************
2581 * GetUdpStatistics (IPHLPAPI.@)
2593 DWORD WINAPI
GetUdpStatistics(PMIB_UDPSTATS pStats
)
2595 return GetUdpStatisticsEx(pStats
, PF_INET
);
2599 /******************************************************************
2600 * GetUdpTable (IPHLPAPI.@)
2605 * pUdpTable [In/Out]
2614 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
2616 return GetExtendedUdpTable(pUdpTable
, pdwSize
, bOrder
, AF_INET
, UDP_TABLE_BASIC
, 0);
2620 /******************************************************************
2621 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
2623 * This is a Win98-only function to get information on "unidirectional"
2624 * adapters. Since this is pretty nonsensical in other contexts, it
2625 * never returns anything.
2628 * pIPIfInfo [Out] buffer for adapter infos
2629 * dwOutBufLen [Out] length of the output buffer
2633 * Failure: error code from winerror.h
2636 * Stub, returns ERROR_NOT_SUPPORTED.
2638 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
2640 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
2641 /* a unidirectional adapter?? not bloody likely! */
2642 return ERROR_NOT_SUPPORTED
;
2646 /******************************************************************
2647 * IpReleaseAddress (IPHLPAPI.@)
2649 * Release an IP obtained through DHCP,
2652 * AdapterInfo [In] adapter to release IP address
2656 * Failure: error code from winerror.h
2659 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2661 DWORD Status
, Version
= 0;
2664 return ERROR_INVALID_PARAMETER
;
2666 /* Maybe we should do this in DllMain */
2667 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2668 return ERROR_PROC_NOT_FOUND
;
2670 if (DhcpReleaseIpAddressLease(AdapterInfo
->Index
))
2671 Status
= ERROR_SUCCESS
;
2673 Status
= ERROR_PROC_NOT_FOUND
;
2681 /******************************************************************
2682 * IpRenewAddress (IPHLPAPI.@)
2684 * Renew an IP obtained through DHCP.
2687 * AdapterInfo [In] adapter to renew IP address
2691 * Failure: error code from winerror.h
2693 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2695 DWORD Status
, Version
= 0;
2698 return ERROR_INVALID_PARAMETER
;
2700 /* Maybe we should do this in DllMain */
2701 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2702 return ERROR_PROC_NOT_FOUND
;
2704 if (DhcpRenewIpAddressLease(AdapterInfo
->Index
))
2705 Status
= ERROR_SUCCESS
;
2707 Status
= ERROR_PROC_NOT_FOUND
;
2715 /******************************************************************
2716 * NotifyAddrChange (IPHLPAPI.@)
2718 * Notify caller whenever the ip-interface map is changed.
2721 * Handle [Out] handle usable in asynchronous notification
2722 * overlapped [In] overlapped structure that notifies the caller
2726 * Failure: error code from winerror.h
2729 * Stub, returns ERROR_NOT_SUPPORTED.
2731 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2733 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2734 if (Handle
) *Handle
= INVALID_HANDLE_VALUE
;
2735 if (overlapped
) ((IO_STATUS_BLOCK
*) overlapped
)->Status
= STATUS_PENDING
;
2736 return ERROR_IO_PENDING
;
2740 /******************************************************************
2741 * NotifyRouteChange (IPHLPAPI.@)
2743 * Notify caller whenever the ip routing table is changed.
2746 * Handle [Out] handle usable in asynchronous notification
2747 * overlapped [In] overlapped structure that notifies the caller
2751 * Failure: error code from winerror.h
2754 * Stub, returns ERROR_NOT_SUPPORTED.
2756 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2758 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2759 return ERROR_NOT_SUPPORTED
;
2762 /******************************************************************
2763 * SendARP (IPHLPAPI.@)
2765 * Send an ARP request.
2768 * DestIP [In] attempt to obtain this IP
2769 * SrcIP [In] optional sender IP address
2770 * pMacAddr [Out] buffer for the mac address
2771 * PhyAddrLen [In/Out] length of the output buffer
2775 * Failure: error code from winerror.h
2777 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
2782 if (IsBadWritePtr(pMacAddr
, sizeof(ULONG
)) || IsBadWritePtr(PhyAddrLen
, sizeof(ULONG
)))
2783 return ERROR_INVALID_PARAMETER
;
2788 return TCPSendIoctl(INVALID_HANDLE_VALUE
, IOCTL_QUERY_IP_HW_ADDRESS
, IPs
, &Size
, pMacAddr
, PhyAddrLen
);
2792 /******************************************************************
2793 * SetIfEntry (IPHLPAPI.@)
2795 * Set the administrative status of an interface.
2798 * pIfRow [In] dwAdminStatus member specifies the new status.
2802 * Failure: error code from winerror.h
2805 * Stub, returns ERROR_NOT_SUPPORTED.
2807 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
2809 FIXME("(pIfRow %p): stub\n", pIfRow
);
2810 /* this is supposed to set an interface administratively up or down.
2811 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2812 this sort of down is indistinguishable from other sorts of down (e.g. no
2814 return ERROR_NOT_SUPPORTED
;
2818 /******************************************************************
2819 * SetIpForwardEntry (IPHLPAPI.@)
2821 * Modify an existing route.
2824 * pRoute [In] route with the new information
2828 * Failure: error code from winerror.h
2831 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
2833 return setIpForwardEntry( pRoute
);
2837 /******************************************************************
2838 * SetIpNetEntry (IPHLPAPI.@)
2840 * Modify an existing ARP entry.
2843 * pArpEntry [In] ARP entry with the new information
2847 * Failure: error code from winerror.h
2849 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
2853 TCP_REQUEST_SET_INFORMATION_EX_ARP_ENTRY req
=
2854 TCP_REQUEST_SET_INFORMATION_INIT
;
2857 PMIB_IPNETROW arpBuff
;
2860 return ERROR_INVALID_PARAMETER
;
2862 if (!NT_SUCCESS(openTcpFile( &tcpFile
, FILE_READ_DATA
| FILE_WRITE_DATA
)))
2863 return ERROR_NOT_SUPPORTED
;
2865 if (!NT_SUCCESS(getNthIpEntity( tcpFile
, pArpEntry
->dwIndex
, &id
)))
2867 closeTcpFile(tcpFile
);
2868 return ERROR_INVALID_PARAMETER
;
2871 req
.Req
.ID
.toi_class
= INFO_CLASS_PROTOCOL
;
2872 req
.Req
.ID
.toi_type
= INFO_TYPE_PROVIDER
;
2873 req
.Req
.ID
.toi_id
= IP_MIB_ARPTABLE_ENTRY_ID
;
2874 req
.Req
.ID
.toi_entity
.tei_instance
= id
.tei_instance
;
2875 req
.Req
.ID
.toi_entity
.tei_entity
= AT_ENTITY
;
2876 req
.Req
.BufferSize
= sizeof(MIB_IPNETROW
);
2877 arpBuff
= (PMIB_IPNETROW
)&req
.Req
.Buffer
[0];
2879 RtlCopyMemory(arpBuff
, pArpEntry
, sizeof(MIB_IPNETROW
));
2881 status
= DeviceIoControl( tcpFile
,
2882 IOCTL_TCP_SET_INFORMATION_EX
,
2890 closeTcpFile(tcpFile
);
2895 return ERROR_INVALID_PARAMETER
;
2899 /******************************************************************
2900 * SetIpStatistics (IPHLPAPI.@)
2902 * Toggle IP forwarding and det the default TTL value.
2905 * pIpStats [In] IP statistics with the new information
2909 * Failure: error code from winerror.h
2912 * Stub, returns NO_ERROR.
2914 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
2916 FIXME("(pIpStats %p): stub\n", pIpStats
);
2921 /******************************************************************
2922 * SetIpTTL (IPHLPAPI.@)
2924 * Set the default TTL value.
2927 * nTTL [In] new TTL value
2931 * Failure: error code from winerror.h
2934 * Stub, returns NO_ERROR.
2936 DWORD WINAPI
SetIpTTL(UINT nTTL
)
2938 FIXME("(nTTL %d): stub\n", nTTL
);
2943 /******************************************************************
2944 * SetTcpEntry (IPHLPAPI.@)
2946 * Set the state of a TCP connection.
2949 * pTcpRow [In] specifies connection with new state
2953 * Failure: error code from winerror.h
2956 * Stub, returns NO_ERROR.
2958 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
2960 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
2965 /******************************************************************
2966 * UnenableRouter (IPHLPAPI.@)
2968 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2969 * if it reaches zero.
2972 * pOverlapped [In/Out] should be the same as in EnableRouter()
2973 * lpdwEnableCount [Out] optional, receives reference count
2977 * Failure: error code from winerror.h
2980 * Stub, returns ERROR_NOT_SUPPORTED.
2982 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
2984 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
2986 return ERROR_NOT_SUPPORTED
;
2992 DWORD WINAPI
GetIpErrorString(IP_STATUS ErrorCode
,PWCHAR Buffer
,PDWORD Size
)
3002 PIP_ADAPTER_ORDER_MAP WINAPI
GetAdapterOrderMap(VOID
)
3011 #ifdef GetAdaptersAddressesV1
3012 DWORD WINAPI DECLSPEC_HOTPATCH
GetAdaptersAddresses(ULONG Family
,ULONG Flags
,PVOID Reserved
,PIP_ADAPTER_ADDRESSES pAdapterAddresses
,PULONG pOutBufLen
)
3014 InterfaceIndexTable
*indexTable
;
3017 ULONG ret
, requiredSize
= 0;
3018 PIP_ADAPTER_ADDRESSES currentAddress
;
3019 PUCHAR currentLocation
;
3022 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
3023 if (Reserved
) return ERROR_INVALID_PARAMETER
;
3025 indexTable
= getInterfaceIndexTable();
3027 return ERROR_NOT_ENOUGH_MEMORY
;
3029 ret
= openTcpFile(&tcpFile
, FILE_READ_DATA
);
3030 if (!NT_SUCCESS(ret
))
3031 return ERROR_NO_DATA
;
3033 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
3035 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
3037 indexTable
->indexes
[i
],
3040 /* The whole struct */
3041 requiredSize
+= sizeof(IP_ADAPTER_ADDRESSES
);
3044 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
3045 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1; //FIXME
3048 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
3050 /* Unicast address */
3051 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
3052 requiredSize
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
3054 /* FIXME: Implement multicast, anycast, and dns server stuff */
3056 /* FIXME: Implement dns suffix and description */
3057 requiredSize
+= 2 * sizeof(WCHAR
);
3059 /* We're only going to implement what's required for XP SP0 */
3062 TRACE("size: %d, requiredSize: %d\n", *pOutBufLen
, requiredSize
);
3063 if (!pAdapterAddresses
|| *pOutBufLen
< requiredSize
)
3065 *pOutBufLen
= requiredSize
;
3066 closeTcpFile(tcpFile
);
3068 return ERROR_BUFFER_OVERFLOW
;
3071 RtlZeroMemory(pAdapterAddresses
, requiredSize
);
3073 /* Let's set up the pointers */
3074 currentAddress
= pAdapterAddresses
;
3075 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
3077 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
3079 indexTable
->indexes
[i
],
3082 currentLocation
= (PUCHAR
)currentAddress
+ (ULONG_PTR
)sizeof(IP_ADAPTER_ADDRESSES
);
3084 /* FIXME: Friendly name */
3085 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
3087 currentAddress
->FriendlyName
= (PVOID
)currentLocation
;
3088 currentLocation
+= sizeof(WCHAR
);
3092 currentAddress
->AdapterName
= (PVOID
)currentLocation
;
3093 currentLocation
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
3095 /* Unicast address */
3096 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
3098 currentAddress
->FirstUnicastAddress
= (PVOID
)currentLocation
;
3099 currentLocation
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
3100 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
= (PVOID
)currentLocation
;
3101 currentLocation
+= sizeof(struct sockaddr
);
3104 /* FIXME: Implement multicast, anycast, and dns server stuff */
3106 /* FIXME: Implement dns suffix and description */
3107 currentAddress
->DnsSuffix
= (PVOID
)currentLocation
;
3108 currentLocation
+= sizeof(WCHAR
);
3110 currentAddress
->Description
= (PVOID
)currentLocation
;
3111 currentLocation
+= sizeof(WCHAR
);
3113 currentAddress
->Next
= (PVOID
)currentLocation
;
3114 /* Terminate the last address correctly */
3116 currentAddress
->Next
= NULL
;
3118 /* We're only going to implement what's required for XP SP0 */
3120 currentAddress
= currentAddress
->Next
;
3124 /* Now again, for real this time */
3126 currentAddress
= pAdapterAddresses
;
3127 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
3129 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
3131 indexTable
->indexes
[i
],
3134 /* Make sure we're not looping more than we hoped for */
3135 ASSERT(currentAddress
);
3137 /* Alignment information */
3138 currentAddress
->Length
= sizeof(IP_ADAPTER_ADDRESSES
);
3139 currentAddress
->IfIndex
= indexTable
->indexes
[i
];
3142 strcpy(currentAddress
->AdapterName
, (char *)ifInfo
.if_info
.ent
.if_descr
);
3144 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
3146 currentAddress
->FirstUnicastAddress
->Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
3147 currentAddress
->FirstUnicastAddress
->Flags
= 0; //FIXME
3148 currentAddress
->FirstUnicastAddress
->Next
= NULL
; //FIXME: Support more than one address per adapter
3149 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_family
= AF_INET
;
3150 memcpy(currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_data
,
3151 &ifInfo
.ip_addr
.iae_addr
,
3152 sizeof(ifInfo
.ip_addr
.iae_addr
));
3153 currentAddress
->FirstUnicastAddress
->Address
.iSockaddrLength
= sizeof(ifInfo
.ip_addr
.iae_addr
) + sizeof(USHORT
);
3154 currentAddress
->FirstUnicastAddress
->PrefixOrigin
= IpPrefixOriginOther
; //FIXME
3155 currentAddress
->FirstUnicastAddress
->SuffixOrigin
= IpPrefixOriginOther
; //FIXME
3156 currentAddress
->FirstUnicastAddress
->DadState
= IpDadStatePreferred
; //FIXME
3157 currentAddress
->FirstUnicastAddress
->ValidLifetime
= 0xFFFFFFFF; //FIXME
3158 currentAddress
->FirstUnicastAddress
->PreferredLifetime
= 0xFFFFFFFF; //FIXME
3159 currentAddress
->FirstUnicastAddress
->LeaseLifetime
= 0xFFFFFFFF; //FIXME
3162 /* FIXME: Implement multicast, anycast, and dns server stuff */
3163 currentAddress
->FirstAnycastAddress
= NULL
;
3164 currentAddress
->FirstMulticastAddress
= NULL
;
3165 currentAddress
->FirstDnsServerAddress
= NULL
;
3167 /* FIXME: Implement dns suffix, description, and friendly name */
3168 currentAddress
->DnsSuffix
[0] = UNICODE_NULL
;
3169 currentAddress
->Description
[0] = UNICODE_NULL
;
3170 currentAddress
->FriendlyName
[0] = UNICODE_NULL
;
3172 /* Physical Address */
3173 memcpy(currentAddress
->PhysicalAddress
, ifInfo
.if_info
.ent
.if_physaddr
, ifInfo
.if_info
.ent
.if_physaddrlen
);
3174 currentAddress
->PhysicalAddressLength
= ifInfo
.if_info
.ent
.if_physaddrlen
;
3177 currentAddress
->Flags
= 0; //FIXME
3180 currentAddress
->Mtu
= ifInfo
.if_info
.ent
.if_mtu
;
3182 /* Interface type */
3183 currentAddress
->IfType
= ifInfo
.if_info
.ent
.if_type
;
3185 /* Operational status */
3186 if(ifInfo
.if_info
.ent
.if_operstatus
>= IF_OPER_STATUS_CONNECTING
)
3187 currentAddress
->OperStatus
= IfOperStatusUp
;
3189 currentAddress
->OperStatus
= IfOperStatusDown
;
3191 /* We're only going to implement what's required for XP SP0 */
3193 /* Move to the next address */
3194 currentAddress
= currentAddress
->Next
;
3198 closeTcpFile(tcpFile
);
3208 BOOL WINAPI
CancelIPChangeNotify(LPOVERLAPPED notifyOverlapped
)
3217 DWORD WINAPI
GetBestInterfaceEx(struct sockaddr
*pDestAddr
,PDWORD pdwBestIfIndex
)
3226 DWORD WINAPI
NhpAllocateAndGetInterfaceInfoFromStack(IP_INTERFACE_NAME_INFO
**ppTable
,PDWORD pdwCount
,BOOL bOrder
,HANDLE hHeap
,DWORD dwFlags
)
3235 DWORD WINAPI
GetIcmpStatisticsEx(PMIB_ICMP_EX pStats
,DWORD dwFamily
)
3240 return ERROR_INVALID_PARAMETER
;
3242 if (dwFamily
!= AF_INET
&& dwFamily
!= AF_INET6
)
3243 return ERROR_INVALID_PARAMETER
;
3249 SetIpForwardEntryToStack(PMIB_IPFORWARDROW pRoute
)
3251 FIXME("SetIpForwardEntryToStack() stub\n");
3255 DWORD
GetInterfaceNameInternal(_In_
const GUID
* pInterfaceGUID
,
3256 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3257 _Inout_ PULONG pOutBufLen
)
3259 UNICODE_STRING GuidString
;
3261 WCHAR szKeyName
[2*MAX_PATH
];
3265 if (pInterfaceGUID
== NULL
|| pOutBufLen
== NULL
)
3266 return ERROR_INVALID_PARAMETER
;
3268 result
= RtlStringFromGUID(pInterfaceGUID
, &GuidString
);
3270 if (!NT_SUCCESS(result
))
3272 // failed to convert guid to string
3273 return RtlNtStatusToDosError(result
);
3276 hr
= StringCbPrintfW(szKeyName
, sizeof(szKeyName
), L
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", GuidString
.Buffer
);
3277 RtlFreeUnicodeString(&GuidString
);
3281 // key name is too long
3282 return ERROR_BUFFER_OVERFLOW
;
3285 result
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szKeyName
, 0, KEY_READ
, &hKey
);
3287 if (result
!= ERROR_SUCCESS
)
3289 // failed to find adapter entry
3290 return ERROR_NOT_FOUND
;
3293 result
= RegQueryValueExW(hKey
, L
"Name", NULL
, &type
, (PVOID
)pInterfaceName
, pOutBufLen
);
3297 if (result
== ERROR_MORE_DATA
)
3299 *pOutBufLen
= MAX_INTERFACE_NAME_LEN
* 2;
3300 return ERROR_INSUFFICIENT_BUFFER
;
3303 if (result
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
3305 // failed to read adapter name
3306 return ERROR_NO_DATA
;
3308 return ERROR_SUCCESS
;
3315 NhGetInterfaceNameFromDeviceGuid(_In_
const GUID
* pInterfaceGUID
,
3316 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3317 _Inout_ PULONG pOutBufLen
,
3321 SetLastError(ERROR_SUCCESS
);
3323 if (pInterfaceName
== NULL
)
3324 return ERROR_INVALID_PARAMETER
;
3326 return GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
3333 NhGetInterfaceNameFromGuid(_In_
const GUID
* pInterfaceGUID
,
3334 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3335 _Inout_ PULONG pOutBufLen
,
3341 result
= GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
3343 if (result
== ERROR_NOT_FOUND
)
3344 SetLastError(ERROR_PATH_NOT_FOUND
);