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(PMIB_TCPTABLE_OWNER_PID
*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(PMIB_UDPTABLE_OWNER_PID
*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 * CreateIpForwardEntry (IPHLPAPI.@)
500 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
502 return createIpForwardEntry( pRoute
);
506 /******************************************************************
507 * CreateIpNetEntry (IPHLPAPI.@)
519 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
521 TRACE("pArpEntry %p\n", pArpEntry
);
522 /* could use SIOCSARP on systems that support it, not sure I want to */
528 /******************************************************************
529 * CreateProxyArpEntry (IPHLPAPI.@)
543 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
545 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
548 /* marking Win2K+ functions not supported */
549 return ERROR_NOT_SUPPORTED
;
553 /******************************************************************
554 * DeleteIPAddress (IPHLPAPI.@)
566 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
568 TRACE("NTEContext %ld\n", NTEContext
);
569 return RtlNtStatusToDosError(deleteIpAddress(NTEContext
));
573 /******************************************************************
574 * DeleteIpForwardEntry (IPHLPAPI.@)
586 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
588 return deleteIpForwardEntry( pRoute
);
592 /******************************************************************
593 * DeleteIpNetEntry (IPHLPAPI.@)
605 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
607 TRACE("pArpEntry %p\n", pArpEntry
);
608 /* could use SIOCDARP on systems that support it, not sure I want to */
614 /******************************************************************
615 * DeleteProxyArpEntry (IPHLPAPI.@)
629 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
631 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
634 /* marking Win2K+ functions not supported */
635 return ERROR_NOT_SUPPORTED
;
638 /******************************************************************
639 * EnableRouter (IPHLPAPI.@)
645 * pOverlapped [In/Out]
652 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
654 TRACE("pHandle %p, pOverlapped %p\n", pHandle
, pOverlapped
);
656 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
657 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
658 marking Win2K+ functions not supported */
659 return ERROR_NOT_SUPPORTED
;
663 /******************************************************************
664 * FlushIpNetTable (IPHLPAPI.@)
676 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
678 TRACE("dwIfIndex 0x%08lx\n", dwIfIndex
);
680 /* this flushes the arp cache of the given index
681 marking Win2K+ functions not supported */
682 return ERROR_NOT_SUPPORTED
;
686 /******************************************************************
687 * GetAdapterIndex (IPHLPAPI.@)
692 * AdapterName [In/Out]
700 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
702 TRACE("AdapterName %p, IfIndex %p\n", AdapterName
, IfIndex
);
704 /* marking Win2K+ functions not supported */
705 return ERROR_NOT_SUPPORTED
;
709 /******************************************************************
710 * GetAdaptersInfo (IPHLPAPI.@)
715 * pAdapterInfo [In/Out]
716 * pOutBufLen [In/Out]
723 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
729 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
731 ret
= ERROR_INVALID_PARAMETER
;
733 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
735 if (numNonLoopbackInterfaces
> 0) {
736 /* this calculation assumes only one address in the IP_ADDR_STRING lists.
737 that's okay, because:
738 - we don't get multiple addresses per adapter anyway
739 - we don't know about per-adapter gateways
740 - DHCP and WINS servers can have max one entry per list */
741 ULONG size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
743 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
745 ret
= ERROR_BUFFER_OVERFLOW
;
748 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
751 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
752 if (*pOutBufLen
< size
) {
754 ret
= ERROR_INSUFFICIENT_BUFFER
;
759 BOOL winsEnabled
= FALSE
;
760 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
762 memset(pAdapterInfo
, 0, size
);
763 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
764 "Software\\Wine\\Wine\\Config\\Network", 0, KEY_READ
,
765 &hKey
) == ERROR_SUCCESS
) {
766 DWORD size
= sizeof(primaryWINS
.String
);
769 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
770 (PBYTE
)primaryWINS
.String
, &size
);
771 addr
= inet_addr(primaryWINS
.String
);
772 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
774 size
= sizeof(secondaryWINS
.String
);
775 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
776 (PBYTE
)secondaryWINS
.String
, &size
);
777 addr
= inet_addr(secondaryWINS
.String
);
778 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
782 TRACE("num of index is %lu\n", table
->numIndexes
);
783 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
784 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
785 DWORD addrLen
= sizeof(ptr
->Address
), type
;
787 getInterfaceNameByIndex(table
->indexes
[ndx
]);
789 ret
= ERROR_OUTOFMEMORY
;
793 /* on Win98 this is left empty, but whatever */
794 strncpy(ptr
->AdapterName
,ifname
,sizeof(ptr
->AdapterName
));
795 consumeInterfaceName(ifname
);
796 ptr
->AdapterName
[MAX_ADAPTER_NAME_LENGTH
] = '\0';
797 getInterfacePhysicalByIndex(table
->indexes
[ndx
], &addrLen
,
798 ptr
->Address
, &type
);
799 /* MS defines address length and type as UINT in some places and
800 DWORD in others, **sigh**. Don't want to assume that PUINT and
801 PDWORD are equiv (64-bit?) */
802 ptr
->AddressLength
= addrLen
;
804 ptr
->Index
= table
->indexes
[ndx
];
805 toIPAddressString(getInterfaceIPAddrByIndex(table
->indexes
[ndx
]),
806 ptr
->IpAddressList
.IpAddress
.String
);
807 toIPAddressString(getInterfaceMaskByIndex(table
->indexes
[ndx
]),
808 ptr
->IpAddressList
.IpMask
.String
);
809 ptr
->IpAddressList
.Context
= ptr
->Index
;
810 toIPAddressString(getInterfaceGatewayByIndex(table
->indexes
[ndx
]),
811 ptr
->GatewayList
.IpAddress
.String
);
812 getDhcpInfoForAdapter(table
->indexes
[ndx
], &dhcpEnabled
,
813 &dhcpServer
, &ptr
->LeaseObtained
,
815 ptr
->DhcpEnabled
= (DWORD
) dhcpEnabled
;
816 toIPAddressString(dhcpServer
,
817 ptr
->DhcpServer
.IpAddress
.String
);
819 ptr
->HaveWins
= TRUE
;
820 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
821 primaryWINS
.String
, sizeof(primaryWINS
.String
));
822 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
823 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
825 if (ndx
< table
->numIndexes
- 1)
826 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
835 ret
= ERROR_OUTOFMEMORY
;
841 TRACE("returning %ld\n", ret
);
846 /******************************************************************
847 * GetBestInterface (IPHLPAPI.@)
853 * pdwBestIfIndex [In/Out]
860 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
864 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr
, pdwBestIfIndex
);
866 ret
= ERROR_INVALID_PARAMETER
;
868 MIB_IPFORWARDROW ipRow
;
870 ret
= GetBestRoute(dwDestAddr
, 0, &ipRow
);
871 if (ret
== ERROR_SUCCESS
)
872 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
874 TRACE("returning %ld\n", ret
);
879 /******************************************************************
880 * GetBestRoute (IPHLPAPI.@)
894 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
896 PMIB_IPFORWARDTABLE table
;
899 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr
,
900 dwSourceAddr
, pBestRoute
);
902 return ERROR_INVALID_PARAMETER
;
904 AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
906 DWORD ndx
, minMaskSize
, matchedNdx
= 0;
908 for (ndx
= 0, minMaskSize
= 255; ndx
< table
->dwNumEntries
; ndx
++) {
909 if ((dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
910 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
913 if (!_BitScanForward(&hostMaskSize
, ntohl(table
->table
[ndx
].dwForwardMask
)))
917 if (hostMaskSize
< minMaskSize
) {
918 minMaskSize
= hostMaskSize
;
923 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
924 HeapFree(GetProcessHeap(), 0, table
);
928 ret
= ERROR_OUTOFMEMORY
;
929 TRACE("returning %ld\n", ret
);
933 static int TcpTableSorter(const void *a
, const void *b
)
938 PMIB_TCPROW rowA
= (PMIB_TCPROW
)a
, rowB
= (PMIB_TCPROW
)b
;
940 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
942 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
944 ret
= rowA
->dwRemoteAddr
- rowB
->dwRemoteAddr
;
946 ret
= rowA
->dwRemotePort
- rowB
->dwRemotePort
;
955 /******************************************************************
956 * GetExtendedTcpTable (IPHLPAPI.@)
958 * Get the table of TCP endpoints available to the application.
961 * pTcpTable [Out] table struct with the filtered TCP endpoints available to application
962 * pdwSize [In/Out] estimated size of the structure returned in pTcpTable, in bytes
963 * bOrder [In] whether to order the table
964 * ulAf [in] version of IP used by the TCP endpoints
965 * TableClass [in] type of the TCP table structure from TCP_TABLE_CLASS
966 * Reserved [in] reserved - this value must be zero
970 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
975 DWORD WINAPI
GetExtendedTcpTable(PVOID pTcpTable
, PDWORD pdwSize
, BOOL bOrder
, ULONG ulAf
, TCP_TABLE_CLASS TableClass
, ULONG Reserved
)
978 DWORD ret
= NO_ERROR
;
982 return ERROR_INVALID_PARAMETER
;
988 return ERROR_INVALID_PARAMETER
;
993 case TCP_TABLE_BASIC_ALL
:
995 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
996 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1000 if (sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
1002 *pdwSize
= sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
);
1003 ret
= ERROR_INSUFFICIENT_BUFFER
;
1007 memcpy(pTheirTcpTable
, pOurTcpTable
, sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
));
1010 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1011 sizeof(MIB_TCPROW
), TcpTableSorter
);
1019 case TCP_TABLE_BASIC_CONNECTIONS
:
1021 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
1022 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1026 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1028 if (pOurTcpTable
->table
[i
].State
!= MIB_TCP_STATE_LISTEN
)
1034 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
1036 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
);
1037 ret
= ERROR_INSUFFICIENT_BUFFER
;
1041 pTheirTcpTable
->dwNumEntries
= count
;
1043 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1045 if (pOurTcpTable
->table
[i
].State
!= MIB_TCP_STATE_LISTEN
)
1047 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW
));
1051 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1054 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1055 sizeof(MIB_TCPROW
), TcpTableSorter
);
1063 case TCP_TABLE_BASIC_LISTENER
:
1065 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
1066 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1070 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1072 if (pOurTcpTable
->table
[i
].State
== MIB_TCP_STATE_LISTEN
)
1078 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
1080 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
);
1081 ret
= ERROR_INSUFFICIENT_BUFFER
;
1085 pTheirTcpTable
->dwNumEntries
= count
;
1087 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1089 if (pOurTcpTable
->table
[i
].State
== MIB_TCP_STATE_LISTEN
)
1091 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW
));
1095 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1098 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1099 sizeof(MIB_TCPROW
), TcpTableSorter
);
1107 case TCP_TABLE_OWNER_PID_ALL
:
1109 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
1110 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1114 if (sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
1116 *pdwSize
= sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
);
1117 ret
= ERROR_INSUFFICIENT_BUFFER
;
1121 memcpy(pTheirTcpTable
, pOurTcpTable
, sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
));
1123 /* Don't sort on PID, so use basic helper */
1125 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1126 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1134 case TCP_TABLE_OWNER_PID_CONNECTIONS
:
1136 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
1137 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1141 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1143 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1149 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
1151 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
);
1152 ret
= ERROR_INSUFFICIENT_BUFFER
;
1156 pTheirTcpTable
->dwNumEntries
= count
;
1158 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1160 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1162 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_PID
));
1166 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1168 /* Don't sort on PID, so use basic helper */
1170 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1171 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1179 case TCP_TABLE_OWNER_PID_LISTENER
:
1181 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
1182 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1186 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1188 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1194 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
1196 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
);
1197 ret
= ERROR_INSUFFICIENT_BUFFER
;
1201 pTheirTcpTable
->dwNumEntries
= count
;
1203 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1205 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1207 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_PID
));
1211 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1213 /* Don't sort on PID, so use basic helper */
1215 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1216 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1226 ret
= ERROR_INVALID_PARAMETER
;
1234 static int UdpTableSorter(const void *a
, const void *b
)
1239 PMIB_UDPROW rowA
= (PMIB_UDPROW
)a
, rowB
= (PMIB_UDPROW
)b
;
1241 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1243 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1250 /******************************************************************
1251 * GetExtendedUdpTable (IPHLPAPI.@)
1253 * Get the table of UDP endpoints available to the application.
1256 * pUdpTable [Out] table struct with the filtered UDP endpoints available to application
1257 * pdwSize [In/Out] estimated size of the structure returned in pUdpTable, in bytes
1258 * bOrder [In] whether to order the table
1259 * ulAf [in] version of IP used by the UDP endpoints
1260 * TableClass [in] type of the UDP table structure from UDP_TABLE_CLASS
1261 * Reserved [in] reserved - this value must be zero
1265 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
1270 DWORD WINAPI
GetExtendedUdpTable(PVOID pUdpTable
, PDWORD pdwSize
, BOOL bOrder
, ULONG ulAf
, UDP_TABLE_CLASS TableClass
, ULONG Reserved
)
1272 DWORD ret
= NO_ERROR
;
1276 return ERROR_INVALID_PARAMETER
;
1279 if (ulAf
!= AF_INET
)
1282 return ERROR_INVALID_PARAMETER
;
1287 case UDP_TABLE_BASIC
:
1289 PMIB_UDPTABLE pOurUdpTable
= getUdpTable();
1290 PMIB_UDPTABLE pTheirUdpTable
= pUdpTable
;
1294 if (sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW
) > *pdwSize
|| !pTheirUdpTable
)
1296 *pdwSize
= sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW
);
1297 ret
= ERROR_INSUFFICIENT_BUFFER
;
1301 memcpy(pTheirUdpTable
, pOurUdpTable
, sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
));
1304 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1305 sizeof(MIB_UDPROW
), UdpTableSorter
);
1313 case UDP_TABLE_OWNER_PID
:
1315 PMIB_UDPTABLE_OWNER_PID pOurUdpTable
= getOwnerUdpTable();
1316 PMIB_UDPTABLE_OWNER_PID pTheirUdpTable
= pUdpTable
;
1320 if (sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
) > *pdwSize
|| !pTheirUdpTable
)
1322 *pdwSize
= sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
);
1323 ret
= ERROR_INSUFFICIENT_BUFFER
;
1327 memcpy(pTheirUdpTable
, pOurUdpTable
, sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
));
1330 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1331 sizeof(MIB_UDPROW_OWNER_PID
), UdpTableSorter
);
1341 ret
= ERROR_INVALID_PARAMETER
;
1349 /******************************************************************
1350 * GetFriendlyIfIndex (IPHLPAPI.@)
1362 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
1364 /* windows doesn't validate these, either, just makes sure the top byte is
1365 cleared. I assume my ifenum module never gives an index with the top
1367 TRACE("returning %ld\n", IfIndex
);
1372 /******************************************************************
1373 * GetIcmpStatistics (IPHLPAPI.@)
1385 DWORD WINAPI
GetIcmpStatistics(PMIB_ICMP pStats
)
1389 TRACE("pStats %p\n", pStats
);
1390 ret
= getICMPStats(pStats
);
1391 TRACE("returning %ld\n", ret
);
1396 /******************************************************************
1397 * GetIfEntry (IPHLPAPI.@)
1409 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
1414 TRACE("pIfRow %p\n", pIfRow
);
1416 return ERROR_INVALID_PARAMETER
;
1418 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
);
1420 ret
= getInterfaceEntryByIndex(pIfRow
->dwIndex
, pIfRow
);
1421 if (ret
== NO_ERROR
)
1422 ret
= getInterfaceStatsByName(name
, pIfRow
);
1423 consumeInterfaceName(name
);
1426 ret
= ERROR_INVALID_DATA
;
1427 TRACE("returning %ld\n", ret
);
1432 static int IfTableSorter(const void *a
, const void *b
)
1437 ret
= ((PMIB_IFROW
)a
)->dwIndex
- ((PMIB_IFROW
)b
)->dwIndex
;
1444 /******************************************************************
1445 * GetIfTable (IPHLPAPI.@)
1459 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
1463 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize
, pdwSize
,
1466 ret
= ERROR_INVALID_PARAMETER
;
1468 DWORD numInterfaces
= getNumInterfaces();
1470 TRACE("GetIfTable: numInterfaces = %d\n", (int)numInterfaces
);
1471 size
= sizeof(MIB_IFTABLE
) + (numInterfaces
- 1) * sizeof(MIB_IFROW
);
1473 if (!pIfTable
|| *pdwSize
< size
) {
1475 ret
= ERROR_INSUFFICIENT_BUFFER
;
1478 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1481 size
= sizeof(MIB_IFTABLE
) + (table
->numIndexes
- 1) *
1483 if (*pdwSize
< size
) {
1485 ret
= ERROR_INSUFFICIENT_BUFFER
;
1490 pIfTable
->dwNumEntries
= 0;
1491 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1492 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1493 GetIfEntry(&pIfTable
->table
[ndx
]);
1494 pIfTable
->dwNumEntries
++;
1497 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
1504 ret
= ERROR_OUTOFMEMORY
;
1507 TRACE("returning %ld\n", ret
);
1512 /******************************************************************
1513 * GetInterfaceInfo (IPHLPAPI.@)
1519 * dwOutBufLen [In/Out]
1526 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1530 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1532 ret
= ERROR_INVALID_PARAMETER
;
1534 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
1536 TRACE("numNonLoopbackInterfaces == 0x%x\n", numNonLoopbackInterfaces
);
1537 size
= sizeof(IP_INTERFACE_INFO
) + (numNonLoopbackInterfaces
) *
1538 sizeof(IP_ADAPTER_INDEX_MAP
);
1540 if (!pIfTable
|| *dwOutBufLen
< size
) {
1541 *dwOutBufLen
= size
;
1542 ret
= ERROR_INSUFFICIENT_BUFFER
;
1545 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
1548 TRACE("table->numIndexes == 0x%x\n", table
->numIndexes
);
1549 size
= sizeof(IP_INTERFACE_INFO
) + (table
->numIndexes
) *
1550 sizeof(IP_ADAPTER_INDEX_MAP
);
1551 if (*dwOutBufLen
< size
) {
1552 *dwOutBufLen
= size
;
1553 ret
= ERROR_INSUFFICIENT_BUFFER
;
1558 pIfTable
->NumAdapters
= 0;
1559 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1560 const char *walker
, *name
;
1563 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1564 name
= getInterfaceNameByIndex(table
->indexes
[ndx
]);
1565 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1566 walker
&& *walker
&&
1567 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1568 walker
++, assigner
++)
1569 *assigner
= *walker
;
1571 consumeInterfaceName(name
);
1572 pIfTable
->NumAdapters
++;
1579 ret
= ERROR_OUTOFMEMORY
;
1582 TRACE("returning %ld\n", ret
);
1587 static int IpAddrTableSorter(const void *a
, const void *b
)
1592 ret
= ((PMIB_IPADDRROW
)a
)->dwAddr
- ((PMIB_IPADDRROW
)b
)->dwAddr
;
1599 /******************************************************************
1600 * GetIpAddrTable (IPHLPAPI.@)
1605 * pIpAddrTable [In/Out]
1614 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1618 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable
, pdwSize
,
1621 ret
= ERROR_INVALID_PARAMETER
;
1623 DWORD numInterfaces
= getNumInterfaces();
1624 ULONG size
= sizeof(MIB_IPADDRTABLE
) + (numInterfaces
- 1) *
1625 sizeof(MIB_IPADDRROW
);
1627 if (!pIpAddrTable
|| *pdwSize
< size
) {
1629 ret
= ERROR_INSUFFICIENT_BUFFER
;
1632 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1635 size
= sizeof(MIB_IPADDRTABLE
) + (table
->numIndexes
- 1) *
1636 sizeof(MIB_IPADDRROW
);
1637 if (*pdwSize
< size
) {
1639 ret
= ERROR_INSUFFICIENT_BUFFER
;
1644 pIpAddrTable
->dwNumEntries
= 0;
1645 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1646 pIpAddrTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1647 pIpAddrTable
->table
[ndx
].dwAddr
=
1648 getInterfaceIPAddrByIndex(table
->indexes
[ndx
]);
1649 pIpAddrTable
->table
[ndx
].dwMask
=
1650 getInterfaceMaskByIndex(table
->indexes
[ndx
]);
1651 /* the dwBCastAddr member isn't the broadcast address, it indicates
1652 * whether the interface uses the 1's broadcast address (1) or the
1653 * 0's broadcast address (0).
1655 bcast
= getInterfaceBCastAddrByIndex(table
->indexes
[ndx
]);
1656 pIpAddrTable
->table
[ndx
].dwBCastAddr
=
1657 (bcast
& pIpAddrTable
->table
[ndx
].dwMask
) ? 1 : 0;
1658 /* FIXME: hardcoded reasm size, not sure where to get it */
1659 pIpAddrTable
->table
[ndx
].dwReasmSize
= 65535;
1660 pIpAddrTable
->table
[ndx
].unused1
= 0;
1661 pIpAddrTable
->table
[ndx
].wType
= 0; /* aka unused2 */
1662 pIpAddrTable
->dwNumEntries
++;
1665 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1666 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1672 ret
= ERROR_OUTOFMEMORY
;
1675 TRACE("returning %ld\n", ret
);
1680 static int IpForwardTableSorter(const void *a
, const void *b
)
1685 PMIB_IPFORWARDROW rowA
= (PMIB_IPFORWARDROW
)a
, rowB
= (PMIB_IPFORWARDROW
)b
;
1687 ret
= rowA
->dwForwardDest
- rowB
->dwForwardDest
;
1689 ret
= rowA
->dwForwardProto
- rowB
->dwForwardProto
;
1691 ret
= rowA
->dwForwardPolicy
- rowB
->dwForwardPolicy
;
1693 ret
= rowA
->dwForwardNextHop
- rowB
->dwForwardNextHop
;
1703 /******************************************************************
1704 * GetIpForwardTable (IPHLPAPI.@)
1709 * pIpForwardTable [In/Out]
1718 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1722 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable
,
1723 pdwSize
, (DWORD
)bOrder
);
1725 ret
= ERROR_INVALID_PARAMETER
;
1727 DWORD numRoutes
= getNumRoutes();
1728 ULONG sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (numRoutes
- 1) *
1729 sizeof(MIB_IPFORWARDROW
);
1731 if (!pIpForwardTable
|| *pdwSize
< sizeNeeded
) {
1732 *pdwSize
= sizeNeeded
;
1733 ret
= ERROR_INSUFFICIENT_BUFFER
;
1736 RouteTable
*table
= getRouteTable();
1738 sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (table
->numRoutes
- 1) *
1739 sizeof(MIB_IPFORWARDROW
);
1740 if (*pdwSize
< sizeNeeded
) {
1741 *pdwSize
= sizeNeeded
;
1742 ret
= ERROR_INSUFFICIENT_BUFFER
;
1747 pIpForwardTable
->dwNumEntries
= table
->numRoutes
;
1748 for (ndx
= 0; ndx
< numRoutes
; ndx
++) {
1749 pIpForwardTable
->table
[ndx
].dwForwardIfIndex
=
1750 table
->routes
[ndx
].ifIndex
;
1751 pIpForwardTable
->table
[ndx
].dwForwardDest
=
1752 table
->routes
[ndx
].dest
;
1753 pIpForwardTable
->table
[ndx
].dwForwardMask
=
1754 table
->routes
[ndx
].mask
;
1755 pIpForwardTable
->table
[ndx
].dwForwardPolicy
= 0;
1756 pIpForwardTable
->table
[ndx
].dwForwardNextHop
=
1757 table
->routes
[ndx
].gateway
;
1758 /* FIXME: this type is appropriate for local interfaces; may not
1759 always be appropriate */
1760 pIpForwardTable
->table
[ndx
].dwForwardType
= MIB_IPROUTE_TYPE_DIRECT
;
1761 /* FIXME: other protos might be appropriate, e.g. the default route
1762 is typically set with MIB_IPPROTO_NETMGMT instead */
1763 pIpForwardTable
->table
[ndx
].dwForwardProto
= MIB_IPPROTO_LOCAL
;
1764 /* punt on age and AS */
1765 pIpForwardTable
->table
[ndx
].dwForwardAge
= 0;
1766 pIpForwardTable
->table
[ndx
].dwForwardNextHopAS
= 0;
1767 pIpForwardTable
->table
[ndx
].dwForwardMetric1
=
1768 table
->routes
[ndx
].metric
;
1769 /* rest of the metrics are 0.. */
1770 pIpForwardTable
->table
[ndx
].dwForwardMetric2
= 0;
1771 pIpForwardTable
->table
[ndx
].dwForwardMetric3
= 0;
1772 pIpForwardTable
->table
[ndx
].dwForwardMetric4
= 0;
1773 pIpForwardTable
->table
[ndx
].dwForwardMetric5
= 0;
1776 qsort(pIpForwardTable
->table
, pIpForwardTable
->dwNumEntries
,
1777 sizeof(MIB_IPFORWARDROW
), IpForwardTableSorter
);
1780 HeapFree(GetProcessHeap(), 0, table
);
1783 ret
= ERROR_OUTOFMEMORY
;
1786 TRACE("returning %ld\n", ret
);
1791 static int IpNetTableSorter(const void *a
, const void *b
)
1796 ret
= ((PMIB_IPNETROW
)a
)->dwAddr
- ((PMIB_IPNETROW
)b
)->dwAddr
;
1803 /******************************************************************
1804 * GetIpNetTable (IPHLPAPI.@)
1809 * pIpNetTable [In/Out]
1818 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
1820 DWORD ret
= NO_ERROR
;
1822 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
,
1825 ret
= ERROR_INVALID_PARAMETER
;
1827 DWORD numEntries
= getNumArpEntries();
1828 ULONG size
= sizeof(MIB_IPNETTABLE
);
1831 size
+= (numEntries
- 1) * sizeof(MIB_IPNETROW
);
1832 if (!pIpNetTable
|| *pdwSize
< size
) {
1834 ret
= ERROR_INSUFFICIENT_BUFFER
;
1837 PMIB_IPNETTABLE table
= getArpTable();
1839 size
= sizeof(MIB_IPNETTABLE
);
1840 if (table
->dwNumEntries
> 1)
1841 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPNETROW
);
1842 if (*pdwSize
< size
) {
1844 ret
= ERROR_INSUFFICIENT_BUFFER
;
1848 memcpy(pIpNetTable
, table
, size
);
1850 qsort(pIpNetTable
->table
, pIpNetTable
->dwNumEntries
,
1851 sizeof(MIB_IPNETROW
), IpNetTableSorter
);
1854 HeapFree(GetProcessHeap(), 0, table
);
1858 TRACE("returning %d\n", ret
);
1863 /******************************************************************
1864 * GetIpStatistics (IPHLPAPI.@)
1876 DWORD WINAPI
GetIpStatistics(PMIB_IPSTATS pStats
)
1878 return GetIpStatisticsEx(pStats
, PF_INET
);
1881 /******************************************************************
1882 * GetIpStatisticsEx (IPHLPAPI.@)
1895 DWORD WINAPI
GetIpStatisticsEx(PMIB_IPSTATS pStats
, DWORD dwFamily
)
1899 TRACE("pStats %p\n", pStats
);
1900 ret
= getIPStats(pStats
, dwFamily
);
1901 TRACE("returning %ld\n", ret
);
1905 /******************************************************************
1906 * GetNetworkParams (IPHLPAPI.@)
1911 * pFixedInfo [In/Out]
1912 * pOutBufLen [In/Out]
1919 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
1921 DWORD ret
, size
, type
;
1924 PIPHLP_RES_INFO resInfo
;
1926 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
1928 return ERROR_INVALID_PARAMETER
;
1930 resInfo
= getResInfo();
1932 return ERROR_OUTOFMEMORY
;
1934 size
= sizeof(FIXED_INFO
) + (resInfo
->riCount
> 1 ? (resInfo
->riCount
-1) *
1935 sizeof(IP_ADDR_STRING
) : 0);
1936 if (!pFixedInfo
|| *pOutBufLen
< size
) {
1938 disposeResInfo( resInfo
);
1939 return ERROR_BUFFER_OVERFLOW
;
1942 memset(pFixedInfo
, 0, size
);
1943 /* Check for DhcpHostname and DhcpDomain first */
1944 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1945 "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
1949 if (regReturn
== ERROR_SUCCESS
) {
1950 /* Windows doesn't honor DHCP option 12 even if RFC requires it if it is returned by DHCP server! */
1953 size
= sizeof(pFixedInfo
->HostName
);
1954 regReturn
= RegQueryValueExA(hKey
,
1958 (LPBYTE
)pFixedInfo
->HostName
,
1960 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
1964 size
= sizeof(pFixedInfo
->HostName
);
1965 regReturn
= RegQueryValueExA(hKey
,
1969 (LPBYTE
)pFixedInfo
->HostName
,
1976 size
= sizeof(pFixedInfo
->DomainName
);
1977 regReturn
= RegQueryValueExA(hKey
,
1981 (LPBYTE
)pFixedInfo
->DomainName
,
1983 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
1986 size
= sizeof(pFixedInfo
->DomainName
);
1987 regReturn
= RegQueryValueExA(hKey
,
1991 (LPBYTE
)pFixedInfo
->DomainName
,
1997 TRACE("GetComputerNameExA: %s\n", pFixedInfo
->DomainName
);
1999 if (resInfo
->riCount
> 0)
2001 CopyMemory(&pFixedInfo
->DnsServerList
, resInfo
->DnsList
, sizeof(IP_ADDR_STRING
));
2002 if (resInfo
->riCount
> 1)
2004 IP_ADDR_STRING
*pSrc
= resInfo
->DnsList
->Next
;
2005 IP_ADDR_STRING
*pTarget
= (struct _IP_ADDR_STRING
*)((char*)pFixedInfo
+ sizeof(FIXED_INFO
));
2007 pFixedInfo
->DnsServerList
.Next
= pTarget
;
2011 CopyMemory(pTarget
, pSrc
, sizeof(IP_ADDR_STRING
));
2013 if (resInfo
->riCount
> 1)
2015 pTarget
->Next
= (IP_ADDR_STRING
*)((char*)pTarget
+ sizeof(IP_ADDR_STRING
));
2016 pTarget
= pTarget
->Next
;
2021 pTarget
->Next
= NULL
;
2029 pFixedInfo
->DnsServerList
.Next
= NULL
;
2033 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
2034 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2035 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
2036 if (regReturn
!= ERROR_SUCCESS
)
2037 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2038 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
2040 if (regReturn
== ERROR_SUCCESS
)
2042 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
2044 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (PBYTE
)pFixedInfo
->ScopeId
, &size
);
2048 disposeResInfo( resInfo
);
2049 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
2050 I suppose could also check for a listener on port 53 to set EnableDns */
2052 TRACE("returning %ld\n", ret
);
2058 /******************************************************************
2059 * GetNumberOfInterfaces (IPHLPAPI.@)
2071 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
2075 TRACE("pdwNumIf %p\n", pdwNumIf
);
2077 ret
= ERROR_INVALID_PARAMETER
;
2079 *pdwNumIf
= getNumInterfaces();
2082 TRACE("returning %ld\n", ret
);
2087 /******************************************************************
2088 * GetOwnerModuleFromTcpEntry (IPHLPAPI.@)
2090 * Get data about the module that issued the context bind for a specific IPv4 TCP endpoint in a MIB table row
2093 * pTcpEntry [in] pointer to a MIB_TCPROW_OWNER_MODULE structure
2094 * Class [in] TCPIP_OWNER_MODULE_INFO_CLASS enumeration value
2095 * Buffer [out] pointer a buffer containing a TCPIP_OWNER_MODULE_BASIC_INFO structure with the owner module data.
2096 * pdwSize [in, out] estimated size of the structure returned in Buffer, in bytes
2100 * Failure: ERROR_INSUFFICIENT_BUFFER, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY
2101 * ERROR_NOT_FOUND or ERROR_PARTIAL_COPY
2104 * The type of data returned in Buffer is indicated by the value of the Class parameter.
2106 DWORD WINAPI
GetOwnerModuleFromTcpEntry( PMIB_TCPROW_OWNER_MODULE pTcpEntry
, TCPIP_OWNER_MODULE_INFO_CLASS Class
, PVOID Buffer
, PDWORD pdwSize
)
2108 DWORD ret
= NO_ERROR
;
2113 static void CreateNameServerListEnumNamesFunc( PWCHAR Interface
, PWCHAR Server
, PVOID Data
)
2115 IP_ADDR_STRING
*pNext
;
2116 PNAME_SERVER_LIST_CONTEXT Context
= (PNAME_SERVER_LIST_CONTEXT
)Data
;
2118 if (!Context
->NumServers
)
2120 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
2122 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, Context
->pData
->DnsServerList
.IpAddress
.String
, 16, NULL
, NULL
);
2123 Context
->pData
->DnsServerList
.IpAddress
.String
[15] = '\0';
2124 Context
->pLastAddr
= &Context
->pData
->DnsServerList
;
2129 Context
->uSizeRequired
+= sizeof(IP_ADDR_STRING
);
2130 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
2132 pNext
= (IP_ADDR_STRING
*)(((char*)Context
->pLastAddr
) + sizeof(IP_ADDR_STRING
));
2133 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, pNext
->IpAddress
.String
, 16, NULL
, NULL
);
2134 pNext
->IpAddress
.String
[15] = '\0';
2135 Context
->pLastAddr
->Next
= pNext
;
2136 Context
->pLastAddr
= pNext
;
2140 Context
->NumServers
++;
2143 /******************************************************************
2144 * GetPerAdapterInfo (IPHLPAPI.@)
2150 * pPerAdapterInfo [In/Out]
2151 * pOutBufLen [In/Out]
2158 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
2163 NAME_SERVER_LIST_CONTEXT Context
;
2164 WCHAR keyname
[200] = L
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
2167 return ERROR_INVALID_PARAMETER
;
2169 if (!pPerAdapterInfo
|| *pOutBufLen
< sizeof(IP_PER_ADAPTER_INFO
))
2171 *pOutBufLen
= sizeof(IP_PER_ADAPTER_INFO
);
2172 return ERROR_BUFFER_OVERFLOW
;
2175 ifName
= getInterfaceNameByIndex(IfIndex
);
2177 return ERROR_INVALID_PARAMETER
;
2179 MultiByteToWideChar(CP_ACP
, 0, ifName
, -1, &keyname
[62], sizeof(keyname
)/sizeof(WCHAR
) - 63);
2180 HeapFree(GetProcessHeap(), 0, (LPVOID
)ifName
);
2182 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keyname
, 0, KEY_READ
, &hkey
) != ERROR_SUCCESS
)
2184 return ERROR_NOT_SUPPORTED
;
2186 Context
.NumServers
= 0;
2187 Context
.uSizeAvailable
= *pOutBufLen
;
2188 Context
.uSizeRequired
= sizeof(IP_PER_ADAPTER_INFO
);
2189 Context
.pData
= pPerAdapterInfo
;
2191 if (*pOutBufLen
>= sizeof(IP_PER_ADAPTER_INFO
))
2192 ZeroMemory(pPerAdapterInfo
, sizeof(IP_PER_ADAPTER_INFO
));
2194 EnumNameServers(hkey
, &keyname
[62], &Context
, CreateNameServerListEnumNamesFunc
);
2196 if (Context
.uSizeRequired
> Context
.uSizeAvailable
)
2198 *pOutBufLen
= Context
.uSizeRequired
;
2200 return ERROR_BUFFER_OVERFLOW
;
2203 if(RegQueryValueExW(hkey
, L
"NameServer", NULL
, NULL
, NULL
, &dwSize
) == ERROR_SUCCESS
)
2205 pPerAdapterInfo
->AutoconfigActive
= FALSE
;
2209 pPerAdapterInfo
->AutoconfigActive
= TRUE
;
2217 /******************************************************************
2218 * GetRTTAndHopCount (IPHLPAPI.@)
2223 * DestIpAddress [In]
2233 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
2235 TRACE("DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p\n",
2236 DestIpAddress
, HopCount
, MaxHops
, RTT
);
2242 /******************************************************************
2243 * GetTcpStatisticsEx (IPHLPAPI.@)
2256 DWORD WINAPI
GetTcpStatisticsEx(PMIB_TCPSTATS pStats
, DWORD dwFamily
)
2260 TRACE("pStats %p\n", pStats
);
2261 ret
= getTCPStats(pStats
, dwFamily
);
2262 TRACE("returning %ld\n", ret
);
2266 /******************************************************************
2267 * GetTcpStatistics (IPHLPAPI.@)
2279 DWORD WINAPI
GetTcpStatistics(PMIB_TCPSTATS pStats
)
2281 return GetTcpStatisticsEx(pStats
, PF_INET
);
2285 /******************************************************************
2286 * GetTcpTable (IPHLPAPI.@)
2288 * Get the table of active TCP connections.
2291 * pTcpTable [Out] buffer for TCP connections table
2292 * pdwSize [In/Out] length of output buffer
2293 * bOrder [In] whether to order the table
2297 * Failure: error code from winerror.h
2300 * If pdwSize is less than required, the function will return
2301 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
2302 * the required byte size.
2303 * If bOrder is true, the returned table will be sorted, first by
2304 * local address and port number, then by remote address and port
2307 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
2309 return GetExtendedTcpTable(pTcpTable
, pdwSize
, bOrder
, AF_INET
, TCP_TABLE_BASIC_ALL
, 0);
2313 /******************************************************************
2314 * GetUdpStatisticsEx (IPHLPAPI.@)
2327 DWORD WINAPI
GetUdpStatisticsEx(PMIB_UDPSTATS pStats
, DWORD dwFamily
)
2331 TRACE("pStats %p\n", pStats
);
2332 ret
= getUDPStats(pStats
, dwFamily
);
2333 TRACE("returning %ld\n", ret
);
2337 /******************************************************************
2338 * GetUdpStatistics (IPHLPAPI.@)
2350 DWORD WINAPI
GetUdpStatistics(PMIB_UDPSTATS pStats
)
2352 return GetUdpStatisticsEx(pStats
, PF_INET
);
2356 /******************************************************************
2357 * GetUdpTable (IPHLPAPI.@)
2362 * pUdpTable [In/Out]
2371 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
2373 return GetExtendedUdpTable(pUdpTable
, pdwSize
, bOrder
, AF_INET
, UDP_TABLE_BASIC
, 0);
2377 /******************************************************************
2378 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
2380 * This is a Win98-only function to get information on "unidirectional"
2381 * adapters. Since this is pretty nonsensical in other contexts, it
2382 * never returns anything.
2385 * pIPIfInfo [Out] buffer for adapter infos
2386 * dwOutBufLen [Out] length of the output buffer
2390 * Failure: error code from winerror.h
2393 * Stub, returns ERROR_NOT_SUPPORTED.
2395 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
2397 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
2398 /* a unidirectional adapter?? not bloody likely! */
2399 return ERROR_NOT_SUPPORTED
;
2403 /******************************************************************
2404 * IpReleaseAddress (IPHLPAPI.@)
2406 * Release an IP obtained through DHCP,
2409 * AdapterInfo [In] adapter to release IP address
2413 * Failure: error code from winerror.h
2416 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2418 DWORD Status
, Version
= 0;
2421 return ERROR_INVALID_PARAMETER
;
2423 /* Maybe we should do this in DllMain */
2424 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2425 return ERROR_PROC_NOT_FOUND
;
2427 if (DhcpReleaseIpAddressLease(AdapterInfo
->Index
))
2428 Status
= ERROR_SUCCESS
;
2430 Status
= ERROR_PROC_NOT_FOUND
;
2438 /******************************************************************
2439 * IpRenewAddress (IPHLPAPI.@)
2441 * Renew an IP obtained through DHCP.
2444 * AdapterInfo [In] adapter to renew IP address
2448 * Failure: error code from winerror.h
2450 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2452 DWORD Status
, Version
= 0;
2455 return ERROR_INVALID_PARAMETER
;
2457 /* Maybe we should do this in DllMain */
2458 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2459 return ERROR_PROC_NOT_FOUND
;
2461 if (DhcpRenewIpAddressLease(AdapterInfo
->Index
))
2462 Status
= ERROR_SUCCESS
;
2464 Status
= ERROR_PROC_NOT_FOUND
;
2472 /******************************************************************
2473 * NotifyAddrChange (IPHLPAPI.@)
2475 * Notify caller whenever the ip-interface map is changed.
2478 * Handle [Out] handle usable in asynchronous notification
2479 * overlapped [In] overlapped structure that notifies the caller
2483 * Failure: error code from winerror.h
2486 * Stub, returns ERROR_NOT_SUPPORTED.
2488 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2490 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2491 if (Handle
) *Handle
= INVALID_HANDLE_VALUE
;
2492 if (overlapped
) ((IO_STATUS_BLOCK
*) overlapped
)->Status
= STATUS_PENDING
;
2493 return ERROR_IO_PENDING
;
2497 /******************************************************************
2498 * NotifyRouteChange (IPHLPAPI.@)
2500 * Notify caller whenever the ip routing table is changed.
2503 * Handle [Out] handle usable in asynchronous notification
2504 * overlapped [In] overlapped structure that notifies the caller
2508 * Failure: error code from winerror.h
2511 * Stub, returns ERROR_NOT_SUPPORTED.
2513 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2515 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2516 return ERROR_NOT_SUPPORTED
;
2519 /******************************************************************
2520 * SendARP (IPHLPAPI.@)
2522 * Send an ARP request.
2525 * DestIP [In] attempt to obtain this IP
2526 * SrcIP [In] optional sender IP address
2527 * pMacAddr [Out] buffer for the mac address
2528 * PhyAddrLen [In/Out] length of the output buffer
2532 * Failure: error code from winerror.h
2534 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
2539 if (IsBadWritePtr(pMacAddr
, sizeof(ULONG
)) || IsBadWritePtr(PhyAddrLen
, sizeof(ULONG
)))
2540 return ERROR_INVALID_PARAMETER
;
2545 return TCPSendIoctl(INVALID_HANDLE_VALUE
, IOCTL_QUERY_IP_HW_ADDRESS
, IPs
, &Size
, pMacAddr
, PhyAddrLen
);
2549 /******************************************************************
2550 * SetIfEntry (IPHLPAPI.@)
2552 * Set the administrative status of an interface.
2555 * pIfRow [In] dwAdminStatus member specifies the new status.
2559 * Failure: error code from winerror.h
2562 * Stub, returns ERROR_NOT_SUPPORTED.
2564 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
2566 FIXME("(pIfRow %p): stub\n", pIfRow
);
2567 /* this is supposed to set an interface administratively up or down.
2568 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2569 this sort of down is indistinguishable from other sorts of down (e.g. no
2571 return ERROR_NOT_SUPPORTED
;
2575 /******************************************************************
2576 * SetIpForwardEntry (IPHLPAPI.@)
2578 * Modify an existing route.
2581 * pRoute [In] route with the new information
2585 * Failure: error code from winerror.h
2588 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
2590 return setIpForwardEntry( pRoute
);
2594 /******************************************************************
2595 * SetIpNetEntry (IPHLPAPI.@)
2597 * Modify an existing ARP entry.
2600 * pArpEntry [In] ARP entry with the new information
2604 * Failure: error code from winerror.h
2606 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
2610 TCP_REQUEST_SET_INFORMATION_EX_ARP_ENTRY req
=
2611 TCP_REQUEST_SET_INFORMATION_INIT
;
2614 PMIB_IPNETROW arpBuff
;
2617 return ERROR_INVALID_PARAMETER
;
2619 if (!NT_SUCCESS(openTcpFile( &tcpFile
, FILE_READ_DATA
| FILE_WRITE_DATA
)))
2620 return ERROR_NOT_SUPPORTED
;
2622 if (!NT_SUCCESS(getNthIpEntity( tcpFile
, pArpEntry
->dwIndex
, &id
)))
2624 closeTcpFile(tcpFile
);
2625 return ERROR_INVALID_PARAMETER
;
2628 req
.Req
.ID
.toi_class
= INFO_CLASS_PROTOCOL
;
2629 req
.Req
.ID
.toi_type
= INFO_TYPE_PROVIDER
;
2630 req
.Req
.ID
.toi_id
= IP_MIB_ARPTABLE_ENTRY_ID
;
2631 req
.Req
.ID
.toi_entity
.tei_instance
= id
.tei_instance
;
2632 req
.Req
.ID
.toi_entity
.tei_entity
= AT_ENTITY
;
2633 req
.Req
.BufferSize
= sizeof(MIB_IPNETROW
);
2634 arpBuff
= (PMIB_IPNETROW
)&req
.Req
.Buffer
[0];
2636 RtlCopyMemory(arpBuff
, pArpEntry
, sizeof(MIB_IPNETROW
));
2638 status
= DeviceIoControl( tcpFile
,
2639 IOCTL_TCP_SET_INFORMATION_EX
,
2647 closeTcpFile(tcpFile
);
2652 return ERROR_INVALID_PARAMETER
;
2656 /******************************************************************
2657 * SetIpStatistics (IPHLPAPI.@)
2659 * Toggle IP forwarding and det the default TTL value.
2662 * pIpStats [In] IP statistics with the new information
2666 * Failure: error code from winerror.h
2669 * Stub, returns NO_ERROR.
2671 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
2673 FIXME("(pIpStats %p): stub\n", pIpStats
);
2678 /******************************************************************
2679 * SetIpTTL (IPHLPAPI.@)
2681 * Set the default TTL value.
2684 * nTTL [In] new TTL value
2688 * Failure: error code from winerror.h
2691 * Stub, returns NO_ERROR.
2693 DWORD WINAPI
SetIpTTL(UINT nTTL
)
2695 FIXME("(nTTL %d): stub\n", nTTL
);
2700 /******************************************************************
2701 * SetTcpEntry (IPHLPAPI.@)
2703 * Set the state of a TCP connection.
2706 * pTcpRow [In] specifies connection with new state
2710 * Failure: error code from winerror.h
2713 * Stub, returns NO_ERROR.
2715 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
2717 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
2722 /******************************************************************
2723 * UnenableRouter (IPHLPAPI.@)
2725 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2726 * if it reaches zero.
2729 * pOverlapped [In/Out] should be the same as in EnableRouter()
2730 * lpdwEnableCount [Out] optional, receives reference count
2734 * Failure: error code from winerror.h
2737 * Stub, returns ERROR_NOT_SUPPORTED.
2739 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
2741 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
2743 return ERROR_NOT_SUPPORTED
;
2749 DWORD WINAPI
GetIpErrorString(IP_STATUS ErrorCode
,PWCHAR Buffer
,PDWORD Size
)
2759 PIP_ADAPTER_ORDER_MAP WINAPI
GetAdapterOrderMap(VOID
)
2768 #ifdef GetAdaptersAddressesV1
2769 DWORD WINAPI DECLSPEC_HOTPATCH
GetAdaptersAddresses(ULONG Family
,ULONG Flags
,PVOID Reserved
,PIP_ADAPTER_ADDRESSES pAdapterAddresses
,PULONG pOutBufLen
)
2771 InterfaceIndexTable
*indexTable
;
2774 ULONG ret
, requiredSize
= 0;
2775 PIP_ADAPTER_ADDRESSES currentAddress
;
2776 PUCHAR currentLocation
;
2779 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
2780 if (Reserved
) return ERROR_INVALID_PARAMETER
;
2782 indexTable
= getInterfaceIndexTable();
2784 return ERROR_NOT_ENOUGH_MEMORY
;
2786 ret
= openTcpFile(&tcpFile
, FILE_READ_DATA
);
2787 if (!NT_SUCCESS(ret
))
2788 return ERROR_NO_DATA
;
2790 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
2792 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
2794 indexTable
->indexes
[i
],
2797 /* The whole struct */
2798 requiredSize
+= sizeof(IP_ADAPTER_ADDRESSES
);
2801 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
2802 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1; //FIXME
2805 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
2807 /* Unicast address */
2808 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
2809 requiredSize
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
2811 /* FIXME: Implement multicast, anycast, and dns server stuff */
2813 /* FIXME: Implement dns suffix and description */
2814 requiredSize
+= 2 * sizeof(WCHAR
);
2816 /* We're only going to implement what's required for XP SP0 */
2819 TRACE("size: %d, requiredSize: %d\n", *pOutBufLen
, requiredSize
);
2820 if (!pAdapterAddresses
|| *pOutBufLen
< requiredSize
)
2822 *pOutBufLen
= requiredSize
;
2823 closeTcpFile(tcpFile
);
2825 return ERROR_BUFFER_OVERFLOW
;
2828 RtlZeroMemory(pAdapterAddresses
, requiredSize
);
2830 /* Let's set up the pointers */
2831 currentAddress
= pAdapterAddresses
;
2832 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
2834 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
2836 indexTable
->indexes
[i
],
2839 currentLocation
= (PUCHAR
)currentAddress
+ (ULONG_PTR
)sizeof(IP_ADAPTER_ADDRESSES
);
2841 /* FIXME: Friendly name */
2842 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
2844 currentAddress
->FriendlyName
= (PVOID
)currentLocation
;
2845 currentLocation
+= sizeof(WCHAR
);
2849 currentAddress
->AdapterName
= (PVOID
)currentLocation
;
2850 currentLocation
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
2852 /* Unicast address */
2853 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
2855 currentAddress
->FirstUnicastAddress
= (PVOID
)currentLocation
;
2856 currentLocation
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
2857 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
= (PVOID
)currentLocation
;
2858 currentLocation
+= sizeof(struct sockaddr
);
2861 /* FIXME: Implement multicast, anycast, and dns server stuff */
2863 /* FIXME: Implement dns suffix and description */
2864 currentAddress
->DnsSuffix
= (PVOID
)currentLocation
;
2865 currentLocation
+= sizeof(WCHAR
);
2867 currentAddress
->Description
= (PVOID
)currentLocation
;
2868 currentLocation
+= sizeof(WCHAR
);
2870 currentAddress
->Next
= (PVOID
)currentLocation
;
2871 /* Terminate the last address correctly */
2873 currentAddress
->Next
= NULL
;
2875 /* We're only going to implement what's required for XP SP0 */
2877 currentAddress
= currentAddress
->Next
;
2881 /* Now again, for real this time */
2883 currentAddress
= pAdapterAddresses
;
2884 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
2886 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
2888 indexTable
->indexes
[i
],
2891 /* Make sure we're not looping more than we hoped for */
2892 ASSERT(currentAddress
);
2894 /* Alignment information */
2895 currentAddress
->Length
= sizeof(IP_ADAPTER_ADDRESSES
);
2896 currentAddress
->IfIndex
= indexTable
->indexes
[i
];
2899 strcpy(currentAddress
->AdapterName
, (char *)ifInfo
.if_info
.ent
.if_descr
);
2901 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
2903 currentAddress
->FirstUnicastAddress
->Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
2904 currentAddress
->FirstUnicastAddress
->Flags
= 0; //FIXME
2905 currentAddress
->FirstUnicastAddress
->Next
= NULL
; //FIXME: Support more than one address per adapter
2906 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_family
= AF_INET
;
2907 memcpy(currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_data
,
2908 &ifInfo
.ip_addr
.iae_addr
,
2909 sizeof(ifInfo
.ip_addr
.iae_addr
));
2910 currentAddress
->FirstUnicastAddress
->Address
.iSockaddrLength
= sizeof(ifInfo
.ip_addr
.iae_addr
) + sizeof(USHORT
);
2911 currentAddress
->FirstUnicastAddress
->PrefixOrigin
= IpPrefixOriginOther
; //FIXME
2912 currentAddress
->FirstUnicastAddress
->SuffixOrigin
= IpPrefixOriginOther
; //FIXME
2913 currentAddress
->FirstUnicastAddress
->DadState
= IpDadStatePreferred
; //FIXME
2914 currentAddress
->FirstUnicastAddress
->ValidLifetime
= 0xFFFFFFFF; //FIXME
2915 currentAddress
->FirstUnicastAddress
->PreferredLifetime
= 0xFFFFFFFF; //FIXME
2916 currentAddress
->FirstUnicastAddress
->LeaseLifetime
= 0xFFFFFFFF; //FIXME
2919 /* FIXME: Implement multicast, anycast, and dns server stuff */
2920 currentAddress
->FirstAnycastAddress
= NULL
;
2921 currentAddress
->FirstMulticastAddress
= NULL
;
2922 currentAddress
->FirstDnsServerAddress
= NULL
;
2924 /* FIXME: Implement dns suffix, description, and friendly name */
2925 currentAddress
->DnsSuffix
[0] = UNICODE_NULL
;
2926 currentAddress
->Description
[0] = UNICODE_NULL
;
2927 currentAddress
->FriendlyName
[0] = UNICODE_NULL
;
2929 /* Physical Address */
2930 memcpy(currentAddress
->PhysicalAddress
, ifInfo
.if_info
.ent
.if_physaddr
, ifInfo
.if_info
.ent
.if_physaddrlen
);
2931 currentAddress
->PhysicalAddressLength
= ifInfo
.if_info
.ent
.if_physaddrlen
;
2934 currentAddress
->Flags
= 0; //FIXME
2937 currentAddress
->Mtu
= ifInfo
.if_info
.ent
.if_mtu
;
2939 /* Interface type */
2940 currentAddress
->IfType
= ifInfo
.if_info
.ent
.if_type
;
2942 /* Operational status */
2943 if(ifInfo
.if_info
.ent
.if_operstatus
>= IF_OPER_STATUS_CONNECTING
)
2944 currentAddress
->OperStatus
= IfOperStatusUp
;
2946 currentAddress
->OperStatus
= IfOperStatusDown
;
2948 /* We're only going to implement what's required for XP SP0 */
2950 /* Move to the next address */
2951 currentAddress
= currentAddress
->Next
;
2955 closeTcpFile(tcpFile
);
2965 BOOL WINAPI
CancelIPChangeNotify(LPOVERLAPPED notifyOverlapped
)
2974 DWORD WINAPI
GetBestInterfaceEx(struct sockaddr
*pDestAddr
,PDWORD pdwBestIfIndex
)
2983 DWORD WINAPI
NhpAllocateAndGetInterfaceInfoFromStack(IP_INTERFACE_NAME_INFO
**ppTable
,PDWORD pdwCount
,BOOL bOrder
,HANDLE hHeap
,DWORD dwFlags
)
2992 DWORD WINAPI
GetIcmpStatisticsEx(PMIB_ICMP_EX pStats
,DWORD dwFamily
)
2997 return ERROR_INVALID_PARAMETER
;
2999 if (dwFamily
!= AF_INET
&& dwFamily
!= AF_INET6
)
3000 return ERROR_INVALID_PARAMETER
;
3006 SetIpForwardEntryToStack(PMIB_IPFORWARDROW pRoute
)
3008 FIXME("SetIpForwardEntryToStack() stub\n");
3012 DWORD
GetInterfaceNameInternal(_In_
const GUID
* pInterfaceGUID
,
3013 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3014 _Inout_ PULONG pOutBufLen
)
3016 UNICODE_STRING GuidString
;
3018 WCHAR szKeyName
[2*MAX_PATH
];
3022 if (pInterfaceGUID
== NULL
|| pOutBufLen
== NULL
)
3023 return ERROR_INVALID_PARAMETER
;
3025 result
= RtlStringFromGUID(pInterfaceGUID
, &GuidString
);
3027 if (!NT_SUCCESS(result
))
3029 // failed to convert guid to string
3030 return RtlNtStatusToDosError(result
);
3033 hr
= StringCbPrintfW(szKeyName
, sizeof(szKeyName
), L
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", GuidString
.Buffer
);
3034 RtlFreeUnicodeString(&GuidString
);
3038 // key name is too long
3039 return ERROR_BUFFER_OVERFLOW
;
3042 result
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szKeyName
, 0, KEY_READ
, &hKey
);
3044 if (result
!= ERROR_SUCCESS
)
3046 // failed to find adapter entry
3047 return ERROR_NOT_FOUND
;
3050 result
= RegQueryValueExW(hKey
, L
"Name", NULL
, &type
, (PVOID
)pInterfaceName
, pOutBufLen
);
3054 if (result
== ERROR_MORE_DATA
)
3056 *pOutBufLen
= MAX_INTERFACE_NAME_LEN
* 2;
3057 return ERROR_INSUFFICIENT_BUFFER
;
3060 if (result
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
3062 // failed to read adapter name
3063 return ERROR_NO_DATA
;
3065 return ERROR_SUCCESS
;
3072 NhGetInterfaceNameFromDeviceGuid(_In_
const GUID
* pInterfaceGUID
,
3073 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3074 _Inout_ PULONG pOutBufLen
,
3078 SetLastError(ERROR_SUCCESS
);
3080 if (pInterfaceName
== NULL
)
3081 return ERROR_INVALID_PARAMETER
;
3083 return GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
3090 NhGetInterfaceNameFromGuid(_In_
const GUID
* pInterfaceGUID
,
3091 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3092 _Inout_ PULONG pOutBufLen
,
3098 result
= GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
3100 if (result
== ERROR_NOT_FOUND
)
3101 SetLastError(ERROR_PATH_NOT_FOUND
);