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 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
314 * bOrder [In] -- passed to GetUdpTable to order the table
315 * heap [In] -- heap from which the table is allocated
316 * flags [In] -- flags to HeapAlloc
323 DWORD WINAPI
AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE
*ppUdpTable
,
324 BOOL bOrder
, HANDLE heap
, DWORD flags
)
328 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
329 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
331 ret
= ERROR_INVALID_PARAMETER
;
336 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
337 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
338 *ppUdpTable
= (PMIB_UDPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
339 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
340 if (ret
!= NO_ERROR
) {
341 HeapFree(heap
, flags
, *ppUdpTable
);
346 TRACE("returning %ld\n", ret
);
351 /******************************************************************
352 * CreateIpForwardEntry (IPHLPAPI.@)
364 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
366 return createIpForwardEntry( pRoute
);
370 /******************************************************************
371 * CreateIpNetEntry (IPHLPAPI.@)
383 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
385 TRACE("pArpEntry %p\n", pArpEntry
);
386 /* could use SIOCSARP on systems that support it, not sure I want to */
392 /******************************************************************
393 * CreateProxyArpEntry (IPHLPAPI.@)
407 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
409 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
412 /* marking Win2K+ functions not supported */
413 return ERROR_NOT_SUPPORTED
;
417 /******************************************************************
418 * DeleteIPAddress (IPHLPAPI.@)
430 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
432 TRACE("NTEContext %ld\n", NTEContext
);
433 return RtlNtStatusToDosError(deleteIpAddress(NTEContext
));
437 /******************************************************************
438 * DeleteIpForwardEntry (IPHLPAPI.@)
450 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
452 return deleteIpForwardEntry( pRoute
);
456 /******************************************************************
457 * DeleteIpNetEntry (IPHLPAPI.@)
469 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
471 TRACE("pArpEntry %p\n", pArpEntry
);
472 /* could use SIOCDARP on systems that support it, not sure I want to */
478 /******************************************************************
479 * DeleteProxyArpEntry (IPHLPAPI.@)
493 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
495 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
498 /* marking Win2K+ functions not supported */
499 return ERROR_NOT_SUPPORTED
;
502 /******************************************************************
503 * EnableRouter (IPHLPAPI.@)
509 * pOverlapped [In/Out]
516 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
518 TRACE("pHandle %p, pOverlapped %p\n", pHandle
, pOverlapped
);
520 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
521 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
522 marking Win2K+ functions not supported */
523 return ERROR_NOT_SUPPORTED
;
527 /******************************************************************
528 * FlushIpNetTable (IPHLPAPI.@)
540 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
542 TRACE("dwIfIndex 0x%08lx\n", dwIfIndex
);
544 /* this flushes the arp cache of the given index
545 marking Win2K+ functions not supported */
546 return ERROR_NOT_SUPPORTED
;
550 /******************************************************************
551 * GetAdapterIndex (IPHLPAPI.@)
556 * AdapterName [In/Out]
564 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
566 TRACE("AdapterName %p, IfIndex %p\n", AdapterName
, IfIndex
);
568 /* marking Win2K+ functions not supported */
569 return ERROR_NOT_SUPPORTED
;
573 /******************************************************************
574 * GetAdaptersInfo (IPHLPAPI.@)
579 * pAdapterInfo [In/Out]
580 * pOutBufLen [In/Out]
587 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
593 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
595 ret
= ERROR_INVALID_PARAMETER
;
597 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
599 if (numNonLoopbackInterfaces
> 0) {
600 /* this calculation assumes only one address in the IP_ADDR_STRING lists.
601 that's okay, because:
602 - we don't get multiple addresses per adapter anyway
603 - we don't know about per-adapter gateways
604 - DHCP and WINS servers can have max one entry per list */
605 ULONG size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
607 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
609 ret
= ERROR_BUFFER_OVERFLOW
;
612 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
615 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
616 if (*pOutBufLen
< size
) {
618 ret
= ERROR_INSUFFICIENT_BUFFER
;
623 BOOL winsEnabled
= FALSE
;
624 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
626 memset(pAdapterInfo
, 0, size
);
627 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
628 "Software\\Wine\\Wine\\Config\\Network", 0, KEY_READ
,
629 &hKey
) == ERROR_SUCCESS
) {
630 DWORD size
= sizeof(primaryWINS
.String
);
633 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
634 (PBYTE
)primaryWINS
.String
, &size
);
635 addr
= inet_addr(primaryWINS
.String
);
636 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
638 size
= sizeof(secondaryWINS
.String
);
639 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
640 (PBYTE
)secondaryWINS
.String
, &size
);
641 addr
= inet_addr(secondaryWINS
.String
);
642 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
646 TRACE("num of index is %lu\n", table
->numIndexes
);
647 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
648 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
649 DWORD addrLen
= sizeof(ptr
->Address
), type
;
651 getInterfaceNameByIndex(table
->indexes
[ndx
]);
653 ret
= ERROR_OUTOFMEMORY
;
657 /* on Win98 this is left empty, but whatever */
658 strncpy(ptr
->AdapterName
,ifname
,sizeof(ptr
->AdapterName
));
659 consumeInterfaceName(ifname
);
660 ptr
->AdapterName
[MAX_ADAPTER_NAME_LENGTH
] = '\0';
661 getInterfacePhysicalByIndex(table
->indexes
[ndx
], &addrLen
,
662 ptr
->Address
, &type
);
663 /* MS defines address length and type as UINT in some places and
664 DWORD in others, **sigh**. Don't want to assume that PUINT and
665 PDWORD are equiv (64-bit?) */
666 ptr
->AddressLength
= addrLen
;
668 ptr
->Index
= table
->indexes
[ndx
];
669 toIPAddressString(getInterfaceIPAddrByIndex(table
->indexes
[ndx
]),
670 ptr
->IpAddressList
.IpAddress
.String
);
671 toIPAddressString(getInterfaceMaskByIndex(table
->indexes
[ndx
]),
672 ptr
->IpAddressList
.IpMask
.String
);
673 ptr
->IpAddressList
.Context
= ptr
->Index
;
674 toIPAddressString(getInterfaceGatewayByIndex(table
->indexes
[ndx
]),
675 ptr
->GatewayList
.IpAddress
.String
);
676 getDhcpInfoForAdapter(table
->indexes
[ndx
], &dhcpEnabled
,
677 &dhcpServer
, &ptr
->LeaseObtained
,
679 ptr
->DhcpEnabled
= (DWORD
) dhcpEnabled
;
680 toIPAddressString(dhcpServer
,
681 ptr
->DhcpServer
.IpAddress
.String
);
683 ptr
->HaveWins
= TRUE
;
684 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
685 primaryWINS
.String
, sizeof(primaryWINS
.String
));
686 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
687 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
689 if (ndx
< table
->numIndexes
- 1)
690 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
699 ret
= ERROR_OUTOFMEMORY
;
705 TRACE("returning %ld\n", ret
);
710 /******************************************************************
711 * GetBestInterface (IPHLPAPI.@)
717 * pdwBestIfIndex [In/Out]
724 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
728 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr
, pdwBestIfIndex
);
730 ret
= ERROR_INVALID_PARAMETER
;
732 MIB_IPFORWARDROW ipRow
;
734 ret
= GetBestRoute(dwDestAddr
, 0, &ipRow
);
735 if (ret
== ERROR_SUCCESS
)
736 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
738 TRACE("returning %ld\n", ret
);
743 /******************************************************************
744 * GetBestRoute (IPHLPAPI.@)
758 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
760 PMIB_IPFORWARDTABLE table
;
763 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr
,
764 dwSourceAddr
, pBestRoute
);
766 return ERROR_INVALID_PARAMETER
;
768 AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
770 DWORD ndx
, minMaskSize
, matchedNdx
= 0;
772 for (ndx
= 0, minMaskSize
= 255; ndx
< table
->dwNumEntries
; ndx
++) {
773 if ((dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
774 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
777 if (!_BitScanForward(&hostMaskSize
, ntohl(table
->table
[ndx
].dwForwardMask
)))
781 if (hostMaskSize
< minMaskSize
) {
782 minMaskSize
= hostMaskSize
;
787 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
788 HeapFree(GetProcessHeap(), 0, table
);
792 ret
= ERROR_OUTOFMEMORY
;
793 TRACE("returning %ld\n", ret
);
797 static int TcpTableSorter(const void *a
, const void *b
)
802 PMIB_TCPROW rowA
= (PMIB_TCPROW
)a
, rowB
= (PMIB_TCPROW
)b
;
804 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
806 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
808 ret
= rowA
->dwRemoteAddr
- rowB
->dwRemoteAddr
;
810 ret
= rowA
->dwRemotePort
- rowB
->dwRemotePort
;
819 /******************************************************************
820 * GetExtendedTcpTable (IPHLPAPI.@)
822 * Get the table of TCP endpoints available to the application.
825 * pTcpTable [Out] table struct with the filtered TCP endpoints available to application
826 * pdwSize [In/Out] estimated size of the structure returned in pTcpTable, in bytes
827 * bOrder [In] whether to order the table
828 * ulAf [in] version of IP used by the TCP endpoints
829 * TableClass [in] type of the TCP table structure from TCP_TABLE_CLASS
830 * Reserved [in] reserved - this value must be zero
834 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
839 DWORD WINAPI
GetExtendedTcpTable(PVOID pTcpTable
, PDWORD pdwSize
, BOOL bOrder
, ULONG ulAf
, TCP_TABLE_CLASS TableClass
, ULONG Reserved
)
842 DWORD ret
= NO_ERROR
;
846 return ERROR_INVALID_PARAMETER
;
852 return ERROR_INVALID_PARAMETER
;
857 case TCP_TABLE_BASIC_ALL
:
859 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
860 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
864 if (sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
866 *pdwSize
= sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
);
867 ret
= ERROR_INSUFFICIENT_BUFFER
;
871 memcpy(pTheirTcpTable
, pOurTcpTable
, sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
));
874 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
875 sizeof(MIB_TCPROW
), TcpTableSorter
);
883 case TCP_TABLE_BASIC_CONNECTIONS
:
885 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
886 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
890 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
892 if (pOurTcpTable
->table
[i
].State
!= MIB_TCP_STATE_LISTEN
)
898 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
900 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
);
901 ret
= ERROR_INSUFFICIENT_BUFFER
;
905 pTheirTcpTable
->dwNumEntries
= count
;
907 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
909 if (pOurTcpTable
->table
[i
].State
!= MIB_TCP_STATE_LISTEN
)
911 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW
));
915 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
918 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
919 sizeof(MIB_TCPROW
), TcpTableSorter
);
927 case TCP_TABLE_BASIC_LISTENER
:
929 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
930 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
934 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
936 if (pOurTcpTable
->table
[i
].State
== MIB_TCP_STATE_LISTEN
)
942 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
) > *pdwSize
|| !pTheirTcpTable
)
944 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW
);
945 ret
= ERROR_INSUFFICIENT_BUFFER
;
949 pTheirTcpTable
->dwNumEntries
= count
;
951 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
953 if (pOurTcpTable
->table
[i
].State
== MIB_TCP_STATE_LISTEN
)
955 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW
));
959 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
962 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
963 sizeof(MIB_TCPROW
), TcpTableSorter
);
971 case TCP_TABLE_OWNER_PID_ALL
:
973 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
974 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
978 if (sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
980 *pdwSize
= sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
);
981 ret
= ERROR_INSUFFICIENT_BUFFER
;
985 memcpy(pTheirTcpTable
, pOurTcpTable
, sizeof(DWORD
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
));
987 /* Don't sort on PID, so use basic helper */
989 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
990 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
998 case TCP_TABLE_OWNER_PID_CONNECTIONS
:
1000 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
1001 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1005 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1007 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1013 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
1015 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
);
1016 ret
= ERROR_INSUFFICIENT_BUFFER
;
1020 pTheirTcpTable
->dwNumEntries
= count
;
1022 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1024 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1026 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_PID
));
1030 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1032 /* Don't sort on PID, so use basic helper */
1034 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1035 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1043 case TCP_TABLE_OWNER_PID_LISTENER
:
1045 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getOwnerTcpTable();
1046 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1050 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1052 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1058 if (sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
) > *pdwSize
|| !pTheirTcpTable
)
1060 *pdwSize
= sizeof(DWORD
) + count
* sizeof(MIB_TCPROW_OWNER_PID
);
1061 ret
= ERROR_INSUFFICIENT_BUFFER
;
1065 pTheirTcpTable
->dwNumEntries
= count
;
1067 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1069 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1071 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_PID
));
1075 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1077 /* Don't sort on PID, so use basic helper */
1079 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1080 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1090 ret
= ERROR_INVALID_PARAMETER
;
1098 static int UdpTableSorter(const void *a
, const void *b
)
1103 PMIB_UDPROW rowA
= (PMIB_UDPROW
)a
, rowB
= (PMIB_UDPROW
)b
;
1105 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1107 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1114 /******************************************************************
1115 * GetExtendedUdpTable (IPHLPAPI.@)
1117 * Get the table of UDP endpoints available to the application.
1120 * pUdpTable [Out] table struct with the filtered UDP endpoints available to application
1121 * pdwSize [In/Out] estimated size of the structure returned in pUdpTable, in bytes
1122 * bOrder [In] whether to order the table
1123 * ulAf [in] version of IP used by the UDP endpoints
1124 * TableClass [in] type of the UDP table structure from UDP_TABLE_CLASS
1125 * Reserved [in] reserved - this value must be zero
1129 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
1134 DWORD WINAPI
GetExtendedUdpTable(PVOID pUdpTable
, PDWORD pdwSize
, BOOL bOrder
, ULONG ulAf
, UDP_TABLE_CLASS TableClass
, ULONG Reserved
)
1136 DWORD ret
= NO_ERROR
;
1140 return ERROR_INVALID_PARAMETER
;
1143 if (ulAf
!= AF_INET
)
1146 return ERROR_INVALID_PARAMETER
;
1151 case UDP_TABLE_BASIC
:
1153 PMIB_UDPTABLE pOurUdpTable
= getUdpTable();
1154 PMIB_UDPTABLE pTheirUdpTable
= pUdpTable
;
1158 if (sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW
) > *pdwSize
|| !pTheirUdpTable
)
1160 *pdwSize
= sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW
);
1161 ret
= ERROR_INSUFFICIENT_BUFFER
;
1165 memcpy(pTheirUdpTable
, pOurUdpTable
, sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
));
1168 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1169 sizeof(MIB_UDPROW
), UdpTableSorter
);
1177 case UDP_TABLE_OWNER_PID
:
1179 PMIB_UDPTABLE_OWNER_PID pOurUdpTable
= getOwnerUdpTable();
1180 PMIB_UDPTABLE_OWNER_PID pTheirUdpTable
= pUdpTable
;
1184 if (sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
) > *pdwSize
|| !pTheirUdpTable
)
1186 *pdwSize
= sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
);
1187 ret
= ERROR_INSUFFICIENT_BUFFER
;
1191 memcpy(pTheirUdpTable
, pOurUdpTable
, sizeof(DWORD
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
));
1194 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1195 sizeof(MIB_UDPROW_OWNER_PID
), UdpTableSorter
);
1205 ret
= ERROR_INVALID_PARAMETER
;
1213 /******************************************************************
1214 * GetFriendlyIfIndex (IPHLPAPI.@)
1226 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
1228 /* windows doesn't validate these, either, just makes sure the top byte is
1229 cleared. I assume my ifenum module never gives an index with the top
1231 TRACE("returning %ld\n", IfIndex
);
1236 /******************************************************************
1237 * GetIcmpStatistics (IPHLPAPI.@)
1249 DWORD WINAPI
GetIcmpStatistics(PMIB_ICMP pStats
)
1253 TRACE("pStats %p\n", pStats
);
1254 ret
= getICMPStats(pStats
);
1255 TRACE("returning %ld\n", ret
);
1260 /******************************************************************
1261 * GetIfEntry (IPHLPAPI.@)
1273 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
1278 TRACE("pIfRow %p\n", pIfRow
);
1280 return ERROR_INVALID_PARAMETER
;
1282 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
);
1284 ret
= getInterfaceEntryByIndex(pIfRow
->dwIndex
, pIfRow
);
1285 if (ret
== NO_ERROR
)
1286 ret
= getInterfaceStatsByName(name
, pIfRow
);
1287 consumeInterfaceName(name
);
1290 ret
= ERROR_INVALID_DATA
;
1291 TRACE("returning %ld\n", ret
);
1296 static int IfTableSorter(const void *a
, const void *b
)
1301 ret
= ((PMIB_IFROW
)a
)->dwIndex
- ((PMIB_IFROW
)b
)->dwIndex
;
1308 /******************************************************************
1309 * GetIfTable (IPHLPAPI.@)
1323 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
1327 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize
, pdwSize
,
1330 ret
= ERROR_INVALID_PARAMETER
;
1332 DWORD numInterfaces
= getNumInterfaces();
1334 TRACE("GetIfTable: numInterfaces = %d\n", (int)numInterfaces
);
1335 size
= sizeof(MIB_IFTABLE
) + (numInterfaces
- 1) * sizeof(MIB_IFROW
);
1337 if (!pIfTable
|| *pdwSize
< size
) {
1339 ret
= ERROR_INSUFFICIENT_BUFFER
;
1342 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1345 size
= sizeof(MIB_IFTABLE
) + (table
->numIndexes
- 1) *
1347 if (*pdwSize
< size
) {
1349 ret
= ERROR_INSUFFICIENT_BUFFER
;
1354 pIfTable
->dwNumEntries
= 0;
1355 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1356 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1357 GetIfEntry(&pIfTable
->table
[ndx
]);
1358 pIfTable
->dwNumEntries
++;
1361 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
1368 ret
= ERROR_OUTOFMEMORY
;
1371 TRACE("returning %ld\n", ret
);
1376 /******************************************************************
1377 * GetInterfaceInfo (IPHLPAPI.@)
1383 * dwOutBufLen [In/Out]
1390 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1394 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1396 ret
= ERROR_INVALID_PARAMETER
;
1398 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
1400 TRACE("numNonLoopbackInterfaces == 0x%x\n", numNonLoopbackInterfaces
);
1401 size
= sizeof(IP_INTERFACE_INFO
) + (numNonLoopbackInterfaces
) *
1402 sizeof(IP_ADAPTER_INDEX_MAP
);
1404 if (!pIfTable
|| *dwOutBufLen
< size
) {
1405 *dwOutBufLen
= size
;
1406 ret
= ERROR_INSUFFICIENT_BUFFER
;
1409 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
1412 TRACE("table->numIndexes == 0x%x\n", table
->numIndexes
);
1413 size
= sizeof(IP_INTERFACE_INFO
) + (table
->numIndexes
) *
1414 sizeof(IP_ADAPTER_INDEX_MAP
);
1415 if (*dwOutBufLen
< size
) {
1416 *dwOutBufLen
= size
;
1417 ret
= ERROR_INSUFFICIENT_BUFFER
;
1422 pIfTable
->NumAdapters
= 0;
1423 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1424 const char *walker
, *name
;
1427 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1428 name
= getInterfaceNameByIndex(table
->indexes
[ndx
]);
1429 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1430 walker
&& *walker
&&
1431 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1432 walker
++, assigner
++)
1433 *assigner
= *walker
;
1435 consumeInterfaceName(name
);
1436 pIfTable
->NumAdapters
++;
1443 ret
= ERROR_OUTOFMEMORY
;
1446 TRACE("returning %ld\n", ret
);
1451 static int IpAddrTableSorter(const void *a
, const void *b
)
1456 ret
= ((PMIB_IPADDRROW
)a
)->dwAddr
- ((PMIB_IPADDRROW
)b
)->dwAddr
;
1463 /******************************************************************
1464 * GetIpAddrTable (IPHLPAPI.@)
1469 * pIpAddrTable [In/Out]
1478 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1482 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable
, pdwSize
,
1485 ret
= ERROR_INVALID_PARAMETER
;
1487 DWORD numInterfaces
= getNumInterfaces();
1488 ULONG size
= sizeof(MIB_IPADDRTABLE
) + (numInterfaces
- 1) *
1489 sizeof(MIB_IPADDRROW
);
1491 if (!pIpAddrTable
|| *pdwSize
< size
) {
1493 ret
= ERROR_INSUFFICIENT_BUFFER
;
1496 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1499 size
= sizeof(MIB_IPADDRTABLE
) + (table
->numIndexes
- 1) *
1500 sizeof(MIB_IPADDRROW
);
1501 if (*pdwSize
< size
) {
1503 ret
= ERROR_INSUFFICIENT_BUFFER
;
1508 pIpAddrTable
->dwNumEntries
= 0;
1509 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1510 pIpAddrTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1511 pIpAddrTable
->table
[ndx
].dwAddr
=
1512 getInterfaceIPAddrByIndex(table
->indexes
[ndx
]);
1513 pIpAddrTable
->table
[ndx
].dwMask
=
1514 getInterfaceMaskByIndex(table
->indexes
[ndx
]);
1515 /* the dwBCastAddr member isn't the broadcast address, it indicates
1516 * whether the interface uses the 1's broadcast address (1) or the
1517 * 0's broadcast address (0).
1519 bcast
= getInterfaceBCastAddrByIndex(table
->indexes
[ndx
]);
1520 pIpAddrTable
->table
[ndx
].dwBCastAddr
=
1521 (bcast
& pIpAddrTable
->table
[ndx
].dwMask
) ? 1 : 0;
1522 /* FIXME: hardcoded reasm size, not sure where to get it */
1523 pIpAddrTable
->table
[ndx
].dwReasmSize
= 65535;
1524 pIpAddrTable
->table
[ndx
].unused1
= 0;
1525 pIpAddrTable
->table
[ndx
].wType
= 0; /* aka unused2 */
1526 pIpAddrTable
->dwNumEntries
++;
1529 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1530 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1536 ret
= ERROR_OUTOFMEMORY
;
1539 TRACE("returning %ld\n", ret
);
1544 static int IpForwardTableSorter(const void *a
, const void *b
)
1549 PMIB_IPFORWARDROW rowA
= (PMIB_IPFORWARDROW
)a
, rowB
= (PMIB_IPFORWARDROW
)b
;
1551 ret
= rowA
->dwForwardDest
- rowB
->dwForwardDest
;
1553 ret
= rowA
->dwForwardProto
- rowB
->dwForwardProto
;
1555 ret
= rowA
->dwForwardPolicy
- rowB
->dwForwardPolicy
;
1557 ret
= rowA
->dwForwardNextHop
- rowB
->dwForwardNextHop
;
1567 /******************************************************************
1568 * GetIpForwardTable (IPHLPAPI.@)
1573 * pIpForwardTable [In/Out]
1582 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1586 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable
,
1587 pdwSize
, (DWORD
)bOrder
);
1589 ret
= ERROR_INVALID_PARAMETER
;
1591 DWORD numRoutes
= getNumRoutes();
1592 ULONG sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (numRoutes
- 1) *
1593 sizeof(MIB_IPFORWARDROW
);
1595 if (!pIpForwardTable
|| *pdwSize
< sizeNeeded
) {
1596 *pdwSize
= sizeNeeded
;
1597 ret
= ERROR_INSUFFICIENT_BUFFER
;
1600 RouteTable
*table
= getRouteTable();
1602 sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (table
->numRoutes
- 1) *
1603 sizeof(MIB_IPFORWARDROW
);
1604 if (*pdwSize
< sizeNeeded
) {
1605 *pdwSize
= sizeNeeded
;
1606 ret
= ERROR_INSUFFICIENT_BUFFER
;
1611 pIpForwardTable
->dwNumEntries
= table
->numRoutes
;
1612 for (ndx
= 0; ndx
< numRoutes
; ndx
++) {
1613 pIpForwardTable
->table
[ndx
].dwForwardIfIndex
=
1614 table
->routes
[ndx
].ifIndex
;
1615 pIpForwardTable
->table
[ndx
].dwForwardDest
=
1616 table
->routes
[ndx
].dest
;
1617 pIpForwardTable
->table
[ndx
].dwForwardMask
=
1618 table
->routes
[ndx
].mask
;
1619 pIpForwardTable
->table
[ndx
].dwForwardPolicy
= 0;
1620 pIpForwardTable
->table
[ndx
].dwForwardNextHop
=
1621 table
->routes
[ndx
].gateway
;
1622 /* FIXME: this type is appropriate for local interfaces; may not
1623 always be appropriate */
1624 pIpForwardTable
->table
[ndx
].dwForwardType
= MIB_IPROUTE_TYPE_DIRECT
;
1625 /* FIXME: other protos might be appropriate, e.g. the default route
1626 is typically set with MIB_IPPROTO_NETMGMT instead */
1627 pIpForwardTable
->table
[ndx
].dwForwardProto
= MIB_IPPROTO_LOCAL
;
1628 /* punt on age and AS */
1629 pIpForwardTable
->table
[ndx
].dwForwardAge
= 0;
1630 pIpForwardTable
->table
[ndx
].dwForwardNextHopAS
= 0;
1631 pIpForwardTable
->table
[ndx
].dwForwardMetric1
=
1632 table
->routes
[ndx
].metric
;
1633 /* rest of the metrics are 0.. */
1634 pIpForwardTable
->table
[ndx
].dwForwardMetric2
= 0;
1635 pIpForwardTable
->table
[ndx
].dwForwardMetric3
= 0;
1636 pIpForwardTable
->table
[ndx
].dwForwardMetric4
= 0;
1637 pIpForwardTable
->table
[ndx
].dwForwardMetric5
= 0;
1640 qsort(pIpForwardTable
->table
, pIpForwardTable
->dwNumEntries
,
1641 sizeof(MIB_IPFORWARDROW
), IpForwardTableSorter
);
1644 HeapFree(GetProcessHeap(), 0, table
);
1647 ret
= ERROR_OUTOFMEMORY
;
1650 TRACE("returning %ld\n", ret
);
1655 static int IpNetTableSorter(const void *a
, const void *b
)
1660 ret
= ((PMIB_IPNETROW
)a
)->dwAddr
- ((PMIB_IPNETROW
)b
)->dwAddr
;
1667 /******************************************************************
1668 * GetIpNetTable (IPHLPAPI.@)
1673 * pIpNetTable [In/Out]
1682 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
1684 DWORD ret
= NO_ERROR
;
1686 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
,
1689 ret
= ERROR_INVALID_PARAMETER
;
1691 DWORD numEntries
= getNumArpEntries();
1692 ULONG size
= sizeof(MIB_IPNETTABLE
);
1695 size
+= (numEntries
- 1) * sizeof(MIB_IPNETROW
);
1696 if (!pIpNetTable
|| *pdwSize
< size
) {
1698 ret
= ERROR_INSUFFICIENT_BUFFER
;
1701 PMIB_IPNETTABLE table
= getArpTable();
1703 size
= sizeof(MIB_IPNETTABLE
);
1704 if (table
->dwNumEntries
> 1)
1705 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPNETROW
);
1706 if (*pdwSize
< size
) {
1708 ret
= ERROR_INSUFFICIENT_BUFFER
;
1712 memcpy(pIpNetTable
, table
, size
);
1714 qsort(pIpNetTable
->table
, pIpNetTable
->dwNumEntries
,
1715 sizeof(MIB_IPNETROW
), IpNetTableSorter
);
1718 HeapFree(GetProcessHeap(), 0, table
);
1722 TRACE("returning %d\n", ret
);
1727 /******************************************************************
1728 * GetIpStatistics (IPHLPAPI.@)
1740 DWORD WINAPI
GetIpStatistics(PMIB_IPSTATS pStats
)
1742 return GetIpStatisticsEx(pStats
, PF_INET
);
1745 /******************************************************************
1746 * GetIpStatisticsEx (IPHLPAPI.@)
1759 DWORD WINAPI
GetIpStatisticsEx(PMIB_IPSTATS pStats
, DWORD dwFamily
)
1763 TRACE("pStats %p\n", pStats
);
1764 ret
= getIPStats(pStats
, dwFamily
);
1765 TRACE("returning %ld\n", ret
);
1769 /******************************************************************
1770 * GetNetworkParams (IPHLPAPI.@)
1775 * pFixedInfo [In/Out]
1776 * pOutBufLen [In/Out]
1783 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
1785 DWORD ret
, size
, type
;
1788 PIPHLP_RES_INFO resInfo
;
1790 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
1792 return ERROR_INVALID_PARAMETER
;
1794 resInfo
= getResInfo();
1796 return ERROR_OUTOFMEMORY
;
1798 size
= sizeof(FIXED_INFO
) + (resInfo
->riCount
> 1 ? (resInfo
->riCount
-1) *
1799 sizeof(IP_ADDR_STRING
) : 0);
1800 if (!pFixedInfo
|| *pOutBufLen
< size
) {
1802 disposeResInfo( resInfo
);
1803 return ERROR_BUFFER_OVERFLOW
;
1806 memset(pFixedInfo
, 0, size
);
1807 /* Check for DhcpHostname and DhcpDomain first */
1808 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1809 "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
1813 if (regReturn
== ERROR_SUCCESS
) {
1814 /* Windows doesn't honor DHCP option 12 even if RFC requires it if it is returned by DHCP server! */
1817 size
= sizeof(pFixedInfo
->HostName
);
1818 regReturn
= RegQueryValueExA(hKey
,
1822 (LPBYTE
)pFixedInfo
->HostName
,
1824 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
1828 size
= sizeof(pFixedInfo
->HostName
);
1829 regReturn
= RegQueryValueExA(hKey
,
1833 (LPBYTE
)pFixedInfo
->HostName
,
1840 size
= sizeof(pFixedInfo
->DomainName
);
1841 regReturn
= RegQueryValueExA(hKey
,
1845 (LPBYTE
)pFixedInfo
->DomainName
,
1847 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
1850 size
= sizeof(pFixedInfo
->DomainName
);
1851 regReturn
= RegQueryValueExA(hKey
,
1855 (LPBYTE
)pFixedInfo
->DomainName
,
1861 TRACE("GetComputerNameExA: %s\n", pFixedInfo
->DomainName
);
1863 if (resInfo
->riCount
> 0)
1865 CopyMemory(&pFixedInfo
->DnsServerList
, resInfo
->DnsList
, sizeof(IP_ADDR_STRING
));
1866 if (resInfo
->riCount
> 1)
1868 IP_ADDR_STRING
*pSrc
= resInfo
->DnsList
->Next
;
1869 IP_ADDR_STRING
*pTarget
= (struct _IP_ADDR_STRING
*)((char*)pFixedInfo
+ sizeof(FIXED_INFO
));
1871 pFixedInfo
->DnsServerList
.Next
= pTarget
;
1875 CopyMemory(pTarget
, pSrc
, sizeof(IP_ADDR_STRING
));
1877 if (resInfo
->riCount
> 1)
1879 pTarget
->Next
= (IP_ADDR_STRING
*)((char*)pTarget
+ sizeof(IP_ADDR_STRING
));
1880 pTarget
= pTarget
->Next
;
1885 pTarget
->Next
= NULL
;
1893 pFixedInfo
->DnsServerList
.Next
= NULL
;
1897 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
1898 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1899 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
1900 if (regReturn
!= ERROR_SUCCESS
)
1901 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1902 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
1904 if (regReturn
== ERROR_SUCCESS
)
1906 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
1908 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (PBYTE
)pFixedInfo
->ScopeId
, &size
);
1912 disposeResInfo( resInfo
);
1913 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1914 I suppose could also check for a listener on port 53 to set EnableDns */
1916 TRACE("returning %ld\n", ret
);
1922 /******************************************************************
1923 * GetNumberOfInterfaces (IPHLPAPI.@)
1935 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
1939 TRACE("pdwNumIf %p\n", pdwNumIf
);
1941 ret
= ERROR_INVALID_PARAMETER
;
1943 *pdwNumIf
= getNumInterfaces();
1946 TRACE("returning %ld\n", ret
);
1951 /******************************************************************
1952 * GetOwnerModuleFromTcpEntry (IPHLPAPI.@)
1954 * Get data about the module that issued the context bind for a specific IPv4 TCP endpoint in a MIB table row
1957 * pTcpEntry [in] pointer to a MIB_TCPROW_OWNER_MODULE structure
1958 * Class [in] TCPIP_OWNER_MODULE_INFO_CLASS enumeration value
1959 * Buffer [out] pointer a buffer containing a TCPIP_OWNER_MODULE_BASIC_INFO structure with the owner module data.
1960 * pdwSize [in, out] estimated size of the structure returned in Buffer, in bytes
1964 * Failure: ERROR_INSUFFICIENT_BUFFER, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY
1965 * ERROR_NOT_FOUND or ERROR_PARTIAL_COPY
1968 * The type of data returned in Buffer is indicated by the value of the Class parameter.
1970 DWORD WINAPI
GetOwnerModuleFromTcpEntry( PMIB_TCPROW_OWNER_MODULE pTcpEntry
, TCPIP_OWNER_MODULE_INFO_CLASS Class
, PVOID Buffer
, PDWORD pdwSize
)
1972 DWORD ret
= NO_ERROR
;
1977 static void CreateNameServerListEnumNamesFunc( PWCHAR Interface
, PWCHAR Server
, PVOID Data
)
1979 IP_ADDR_STRING
*pNext
;
1980 PNAME_SERVER_LIST_CONTEXT Context
= (PNAME_SERVER_LIST_CONTEXT
)Data
;
1982 if (!Context
->NumServers
)
1984 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
1986 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, Context
->pData
->DnsServerList
.IpAddress
.String
, 16, NULL
, NULL
);
1987 Context
->pData
->DnsServerList
.IpAddress
.String
[15] = '\0';
1988 Context
->pLastAddr
= &Context
->pData
->DnsServerList
;
1993 Context
->uSizeRequired
+= sizeof(IP_ADDR_STRING
);
1994 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
1996 pNext
= (IP_ADDR_STRING
*)(((char*)Context
->pLastAddr
) + sizeof(IP_ADDR_STRING
));
1997 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, pNext
->IpAddress
.String
, 16, NULL
, NULL
);
1998 pNext
->IpAddress
.String
[15] = '\0';
1999 Context
->pLastAddr
->Next
= pNext
;
2000 Context
->pLastAddr
= pNext
;
2004 Context
->NumServers
++;
2007 /******************************************************************
2008 * GetPerAdapterInfo (IPHLPAPI.@)
2014 * pPerAdapterInfo [In/Out]
2015 * pOutBufLen [In/Out]
2022 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
2027 NAME_SERVER_LIST_CONTEXT Context
;
2028 WCHAR keyname
[200] = L
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
2031 return ERROR_INVALID_PARAMETER
;
2033 if (!pPerAdapterInfo
|| *pOutBufLen
< sizeof(IP_PER_ADAPTER_INFO
))
2035 *pOutBufLen
= sizeof(IP_PER_ADAPTER_INFO
);
2036 return ERROR_BUFFER_OVERFLOW
;
2039 ifName
= getInterfaceNameByIndex(IfIndex
);
2041 return ERROR_INVALID_PARAMETER
;
2043 MultiByteToWideChar(CP_ACP
, 0, ifName
, -1, &keyname
[62], sizeof(keyname
)/sizeof(WCHAR
) - 63);
2044 HeapFree(GetProcessHeap(), 0, (LPVOID
)ifName
);
2046 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keyname
, 0, KEY_READ
, &hkey
) != ERROR_SUCCESS
)
2048 return ERROR_NOT_SUPPORTED
;
2050 Context
.NumServers
= 0;
2051 Context
.uSizeAvailable
= *pOutBufLen
;
2052 Context
.uSizeRequired
= sizeof(IP_PER_ADAPTER_INFO
);
2053 Context
.pData
= pPerAdapterInfo
;
2055 if (*pOutBufLen
>= sizeof(IP_PER_ADAPTER_INFO
))
2056 ZeroMemory(pPerAdapterInfo
, sizeof(IP_PER_ADAPTER_INFO
));
2058 EnumNameServers(hkey
, &keyname
[62], &Context
, CreateNameServerListEnumNamesFunc
);
2060 if (Context
.uSizeRequired
> Context
.uSizeAvailable
)
2062 *pOutBufLen
= Context
.uSizeRequired
;
2064 return ERROR_BUFFER_OVERFLOW
;
2067 if(RegQueryValueExW(hkey
, L
"NameServer", NULL
, NULL
, NULL
, &dwSize
) == ERROR_SUCCESS
)
2069 pPerAdapterInfo
->AutoconfigActive
= FALSE
;
2073 pPerAdapterInfo
->AutoconfigActive
= TRUE
;
2081 /******************************************************************
2082 * GetRTTAndHopCount (IPHLPAPI.@)
2087 * DestIpAddress [In]
2097 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
2099 TRACE("DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p\n",
2100 DestIpAddress
, HopCount
, MaxHops
, RTT
);
2106 /******************************************************************
2107 * GetTcpStatisticsEx (IPHLPAPI.@)
2120 DWORD WINAPI
GetTcpStatisticsEx(PMIB_TCPSTATS pStats
, DWORD dwFamily
)
2124 TRACE("pStats %p\n", pStats
);
2125 ret
= getTCPStats(pStats
, dwFamily
);
2126 TRACE("returning %ld\n", ret
);
2130 /******************************************************************
2131 * GetTcpStatistics (IPHLPAPI.@)
2143 DWORD WINAPI
GetTcpStatistics(PMIB_TCPSTATS pStats
)
2145 return GetTcpStatisticsEx(pStats
, PF_INET
);
2149 /******************************************************************
2150 * GetTcpTable (IPHLPAPI.@)
2152 * Get the table of active TCP connections.
2155 * pTcpTable [Out] buffer for TCP connections table
2156 * pdwSize [In/Out] length of output buffer
2157 * bOrder [In] whether to order the table
2161 * Failure: error code from winerror.h
2164 * If pdwSize is less than required, the function will return
2165 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
2166 * the required byte size.
2167 * If bOrder is true, the returned table will be sorted, first by
2168 * local address and port number, then by remote address and port
2171 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
2173 return GetExtendedTcpTable(pTcpTable
, pdwSize
, bOrder
, AF_INET
, TCP_TABLE_BASIC_ALL
, 0);
2177 /******************************************************************
2178 * GetUdpStatisticsEx (IPHLPAPI.@)
2191 DWORD WINAPI
GetUdpStatisticsEx(PMIB_UDPSTATS pStats
, DWORD dwFamily
)
2195 TRACE("pStats %p\n", pStats
);
2196 ret
= getUDPStats(pStats
, dwFamily
);
2197 TRACE("returning %ld\n", ret
);
2201 /******************************************************************
2202 * GetUdpStatistics (IPHLPAPI.@)
2214 DWORD WINAPI
GetUdpStatistics(PMIB_UDPSTATS pStats
)
2216 return GetUdpStatisticsEx(pStats
, PF_INET
);
2220 /******************************************************************
2221 * GetUdpTable (IPHLPAPI.@)
2226 * pUdpTable [In/Out]
2235 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
2237 return GetExtendedUdpTable(pUdpTable
, pdwSize
, bOrder
, AF_INET
, UDP_TABLE_BASIC
, 0);
2241 /******************************************************************
2242 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
2244 * This is a Win98-only function to get information on "unidirectional"
2245 * adapters. Since this is pretty nonsensical in other contexts, it
2246 * never returns anything.
2249 * pIPIfInfo [Out] buffer for adapter infos
2250 * dwOutBufLen [Out] length of the output buffer
2254 * Failure: error code from winerror.h
2257 * Stub, returns ERROR_NOT_SUPPORTED.
2259 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
2261 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
2262 /* a unidirectional adapter?? not bloody likely! */
2263 return ERROR_NOT_SUPPORTED
;
2267 /******************************************************************
2268 * IpReleaseAddress (IPHLPAPI.@)
2270 * Release an IP obtained through DHCP,
2273 * AdapterInfo [In] adapter to release IP address
2277 * Failure: error code from winerror.h
2280 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2282 DWORD Status
, Version
= 0;
2285 return ERROR_INVALID_PARAMETER
;
2287 /* Maybe we should do this in DllMain */
2288 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2289 return ERROR_PROC_NOT_FOUND
;
2291 if (DhcpReleaseIpAddressLease(AdapterInfo
->Index
))
2292 Status
= ERROR_SUCCESS
;
2294 Status
= ERROR_PROC_NOT_FOUND
;
2302 /******************************************************************
2303 * IpRenewAddress (IPHLPAPI.@)
2305 * Renew an IP obtained through DHCP.
2308 * AdapterInfo [In] adapter to renew IP address
2312 * Failure: error code from winerror.h
2314 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2316 DWORD Status
, Version
= 0;
2319 return ERROR_INVALID_PARAMETER
;
2321 /* Maybe we should do this in DllMain */
2322 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2323 return ERROR_PROC_NOT_FOUND
;
2325 if (DhcpRenewIpAddressLease(AdapterInfo
->Index
))
2326 Status
= ERROR_SUCCESS
;
2328 Status
= ERROR_PROC_NOT_FOUND
;
2336 /******************************************************************
2337 * NotifyAddrChange (IPHLPAPI.@)
2339 * Notify caller whenever the ip-interface map is changed.
2342 * Handle [Out] handle usable in asynchronous notification
2343 * overlapped [In] overlapped structure that notifies the caller
2347 * Failure: error code from winerror.h
2350 * Stub, returns ERROR_NOT_SUPPORTED.
2352 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2354 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2355 if (Handle
) *Handle
= INVALID_HANDLE_VALUE
;
2356 if (overlapped
) ((IO_STATUS_BLOCK
*) overlapped
)->Status
= STATUS_PENDING
;
2357 return ERROR_IO_PENDING
;
2361 /******************************************************************
2362 * NotifyRouteChange (IPHLPAPI.@)
2364 * Notify caller whenever the ip routing table is changed.
2367 * Handle [Out] handle usable in asynchronous notification
2368 * overlapped [In] overlapped structure that notifies the caller
2372 * Failure: error code from winerror.h
2375 * Stub, returns ERROR_NOT_SUPPORTED.
2377 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2379 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2380 return ERROR_NOT_SUPPORTED
;
2383 /******************************************************************
2384 * SendARP (IPHLPAPI.@)
2386 * Send an ARP request.
2389 * DestIP [In] attempt to obtain this IP
2390 * SrcIP [In] optional sender IP address
2391 * pMacAddr [Out] buffer for the mac address
2392 * PhyAddrLen [In/Out] length of the output buffer
2396 * Failure: error code from winerror.h
2398 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
2403 if (IsBadWritePtr(pMacAddr
, sizeof(ULONG
)) || IsBadWritePtr(PhyAddrLen
, sizeof(ULONG
)))
2404 return ERROR_INVALID_PARAMETER
;
2409 return TCPSendIoctl(INVALID_HANDLE_VALUE
, IOCTL_QUERY_IP_HW_ADDRESS
, IPs
, &Size
, pMacAddr
, PhyAddrLen
);
2413 /******************************************************************
2414 * SetIfEntry (IPHLPAPI.@)
2416 * Set the administrative status of an interface.
2419 * pIfRow [In] dwAdminStatus member specifies the new status.
2423 * Failure: error code from winerror.h
2426 * Stub, returns ERROR_NOT_SUPPORTED.
2428 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
2430 FIXME("(pIfRow %p): stub\n", pIfRow
);
2431 /* this is supposed to set an interface administratively up or down.
2432 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2433 this sort of down is indistinguishable from other sorts of down (e.g. no
2435 return ERROR_NOT_SUPPORTED
;
2439 /******************************************************************
2440 * SetIpForwardEntry (IPHLPAPI.@)
2442 * Modify an existing route.
2445 * pRoute [In] route with the new information
2449 * Failure: error code from winerror.h
2452 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
2454 return setIpForwardEntry( pRoute
);
2458 /******************************************************************
2459 * SetIpNetEntry (IPHLPAPI.@)
2461 * Modify an existing ARP entry.
2464 * pArpEntry [In] ARP entry with the new information
2468 * Failure: error code from winerror.h
2470 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
2474 TCP_REQUEST_SET_INFORMATION_EX_ARP_ENTRY req
=
2475 TCP_REQUEST_SET_INFORMATION_INIT
;
2478 PMIB_IPNETROW arpBuff
;
2481 return ERROR_INVALID_PARAMETER
;
2483 if (!NT_SUCCESS(openTcpFile( &tcpFile
, FILE_READ_DATA
| FILE_WRITE_DATA
)))
2484 return ERROR_NOT_SUPPORTED
;
2486 if (!NT_SUCCESS(getNthIpEntity( tcpFile
, pArpEntry
->dwIndex
, &id
)))
2488 closeTcpFile(tcpFile
);
2489 return ERROR_INVALID_PARAMETER
;
2492 req
.Req
.ID
.toi_class
= INFO_CLASS_PROTOCOL
;
2493 req
.Req
.ID
.toi_type
= INFO_TYPE_PROVIDER
;
2494 req
.Req
.ID
.toi_id
= IP_MIB_ARPTABLE_ENTRY_ID
;
2495 req
.Req
.ID
.toi_entity
.tei_instance
= id
.tei_instance
;
2496 req
.Req
.ID
.toi_entity
.tei_entity
= AT_ENTITY
;
2497 req
.Req
.BufferSize
= sizeof(MIB_IPNETROW
);
2498 arpBuff
= (PMIB_IPNETROW
)&req
.Req
.Buffer
[0];
2500 RtlCopyMemory(arpBuff
, pArpEntry
, sizeof(MIB_IPNETROW
));
2502 status
= DeviceIoControl( tcpFile
,
2503 IOCTL_TCP_SET_INFORMATION_EX
,
2511 closeTcpFile(tcpFile
);
2516 return ERROR_INVALID_PARAMETER
;
2520 /******************************************************************
2521 * SetIpStatistics (IPHLPAPI.@)
2523 * Toggle IP forwarding and det the default TTL value.
2526 * pIpStats [In] IP statistics with the new information
2530 * Failure: error code from winerror.h
2533 * Stub, returns NO_ERROR.
2535 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
2537 FIXME("(pIpStats %p): stub\n", pIpStats
);
2542 /******************************************************************
2543 * SetIpTTL (IPHLPAPI.@)
2545 * Set the default TTL value.
2548 * nTTL [In] new TTL value
2552 * Failure: error code from winerror.h
2555 * Stub, returns NO_ERROR.
2557 DWORD WINAPI
SetIpTTL(UINT nTTL
)
2559 FIXME("(nTTL %d): stub\n", nTTL
);
2564 /******************************************************************
2565 * SetTcpEntry (IPHLPAPI.@)
2567 * Set the state of a TCP connection.
2570 * pTcpRow [In] specifies connection with new state
2574 * Failure: error code from winerror.h
2577 * Stub, returns NO_ERROR.
2579 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
2581 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
2586 /******************************************************************
2587 * UnenableRouter (IPHLPAPI.@)
2589 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2590 * if it reaches zero.
2593 * pOverlapped [In/Out] should be the same as in EnableRouter()
2594 * lpdwEnableCount [Out] optional, receives reference count
2598 * Failure: error code from winerror.h
2601 * Stub, returns ERROR_NOT_SUPPORTED.
2603 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
2605 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
2607 return ERROR_NOT_SUPPORTED
;
2613 DWORD WINAPI
GetIpErrorString(IP_STATUS ErrorCode
,PWCHAR Buffer
,PDWORD Size
)
2623 PIP_ADAPTER_ORDER_MAP WINAPI
GetAdapterOrderMap(VOID
)
2632 #ifdef GetAdaptersAddressesV1
2633 DWORD WINAPI DECLSPEC_HOTPATCH
GetAdaptersAddresses(ULONG Family
,ULONG Flags
,PVOID Reserved
,PIP_ADAPTER_ADDRESSES pAdapterAddresses
,PULONG pOutBufLen
)
2635 InterfaceIndexTable
*indexTable
;
2638 ULONG ret
, requiredSize
= 0;
2639 PIP_ADAPTER_ADDRESSES currentAddress
;
2640 PUCHAR currentLocation
;
2643 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
2644 if (Reserved
) return ERROR_INVALID_PARAMETER
;
2646 indexTable
= getInterfaceIndexTable();
2648 return ERROR_NOT_ENOUGH_MEMORY
;
2650 ret
= openTcpFile(&tcpFile
, FILE_READ_DATA
);
2651 if (!NT_SUCCESS(ret
))
2652 return ERROR_NO_DATA
;
2654 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
2656 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
2658 indexTable
->indexes
[i
],
2661 /* The whole struct */
2662 requiredSize
+= sizeof(IP_ADAPTER_ADDRESSES
);
2665 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
2666 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1; //FIXME
2669 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
2671 /* Unicast address */
2672 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
2673 requiredSize
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
2675 /* FIXME: Implement multicast, anycast, and dns server stuff */
2677 /* FIXME: Implement dns suffix and description */
2678 requiredSize
+= 2 * sizeof(WCHAR
);
2680 /* We're only going to implement what's required for XP SP0 */
2683 TRACE("size: %d, requiredSize: %d\n", *pOutBufLen
, requiredSize
);
2684 if (!pAdapterAddresses
|| *pOutBufLen
< requiredSize
)
2686 *pOutBufLen
= requiredSize
;
2687 closeTcpFile(tcpFile
);
2689 return ERROR_BUFFER_OVERFLOW
;
2692 RtlZeroMemory(pAdapterAddresses
, requiredSize
);
2694 /* Let's set up the pointers */
2695 currentAddress
= pAdapterAddresses
;
2696 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
2698 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
2700 indexTable
->indexes
[i
],
2703 currentLocation
= (PUCHAR
)currentAddress
+ (ULONG_PTR
)sizeof(IP_ADAPTER_ADDRESSES
);
2705 /* FIXME: Friendly name */
2706 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
2708 currentAddress
->FriendlyName
= (PVOID
)currentLocation
;
2709 currentLocation
+= sizeof(WCHAR
);
2713 currentAddress
->AdapterName
= (PVOID
)currentLocation
;
2714 currentLocation
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
2716 /* Unicast address */
2717 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
2719 currentAddress
->FirstUnicastAddress
= (PVOID
)currentLocation
;
2720 currentLocation
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
2721 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
= (PVOID
)currentLocation
;
2722 currentLocation
+= sizeof(struct sockaddr
);
2725 /* FIXME: Implement multicast, anycast, and dns server stuff */
2727 /* FIXME: Implement dns suffix and description */
2728 currentAddress
->DnsSuffix
= (PVOID
)currentLocation
;
2729 currentLocation
+= sizeof(WCHAR
);
2731 currentAddress
->Description
= (PVOID
)currentLocation
;
2732 currentLocation
+= sizeof(WCHAR
);
2734 currentAddress
->Next
= (PVOID
)currentLocation
;
2735 /* Terminate the last address correctly */
2737 currentAddress
->Next
= NULL
;
2739 /* We're only going to implement what's required for XP SP0 */
2741 currentAddress
= currentAddress
->Next
;
2745 /* Now again, for real this time */
2747 currentAddress
= pAdapterAddresses
;
2748 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
2750 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
2752 indexTable
->indexes
[i
],
2755 /* Make sure we're not looping more than we hoped for */
2756 ASSERT(currentAddress
);
2758 /* Alignment information */
2759 currentAddress
->Length
= sizeof(IP_ADAPTER_ADDRESSES
);
2760 currentAddress
->IfIndex
= indexTable
->indexes
[i
];
2763 strcpy(currentAddress
->AdapterName
, (char *)ifInfo
.if_info
.ent
.if_descr
);
2765 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
2767 currentAddress
->FirstUnicastAddress
->Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
2768 currentAddress
->FirstUnicastAddress
->Flags
= 0; //FIXME
2769 currentAddress
->FirstUnicastAddress
->Next
= NULL
; //FIXME: Support more than one address per adapter
2770 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_family
= AF_INET
;
2771 memcpy(currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_data
,
2772 &ifInfo
.ip_addr
.iae_addr
,
2773 sizeof(ifInfo
.ip_addr
.iae_addr
));
2774 currentAddress
->FirstUnicastAddress
->Address
.iSockaddrLength
= sizeof(ifInfo
.ip_addr
.iae_addr
) + sizeof(USHORT
);
2775 currentAddress
->FirstUnicastAddress
->PrefixOrigin
= IpPrefixOriginOther
; //FIXME
2776 currentAddress
->FirstUnicastAddress
->SuffixOrigin
= IpPrefixOriginOther
; //FIXME
2777 currentAddress
->FirstUnicastAddress
->DadState
= IpDadStatePreferred
; //FIXME
2778 currentAddress
->FirstUnicastAddress
->ValidLifetime
= 0xFFFFFFFF; //FIXME
2779 currentAddress
->FirstUnicastAddress
->PreferredLifetime
= 0xFFFFFFFF; //FIXME
2780 currentAddress
->FirstUnicastAddress
->LeaseLifetime
= 0xFFFFFFFF; //FIXME
2783 /* FIXME: Implement multicast, anycast, and dns server stuff */
2784 currentAddress
->FirstAnycastAddress
= NULL
;
2785 currentAddress
->FirstMulticastAddress
= NULL
;
2786 currentAddress
->FirstDnsServerAddress
= NULL
;
2788 /* FIXME: Implement dns suffix, description, and friendly name */
2789 currentAddress
->DnsSuffix
[0] = UNICODE_NULL
;
2790 currentAddress
->Description
[0] = UNICODE_NULL
;
2791 currentAddress
->FriendlyName
[0] = UNICODE_NULL
;
2793 /* Physical Address */
2794 memcpy(currentAddress
->PhysicalAddress
, ifInfo
.if_info
.ent
.if_physaddr
, ifInfo
.if_info
.ent
.if_physaddrlen
);
2795 currentAddress
->PhysicalAddressLength
= ifInfo
.if_info
.ent
.if_physaddrlen
;
2798 currentAddress
->Flags
= 0; //FIXME
2801 currentAddress
->Mtu
= ifInfo
.if_info
.ent
.if_mtu
;
2803 /* Interface type */
2804 currentAddress
->IfType
= ifInfo
.if_info
.ent
.if_type
;
2806 /* Operational status */
2807 if(ifInfo
.if_info
.ent
.if_operstatus
>= IF_OPER_STATUS_CONNECTING
)
2808 currentAddress
->OperStatus
= IfOperStatusUp
;
2810 currentAddress
->OperStatus
= IfOperStatusDown
;
2812 /* We're only going to implement what's required for XP SP0 */
2814 /* Move to the next address */
2815 currentAddress
= currentAddress
->Next
;
2819 closeTcpFile(tcpFile
);
2829 BOOL WINAPI
CancelIPChangeNotify(LPOVERLAPPED notifyOverlapped
)
2838 DWORD WINAPI
GetBestInterfaceEx(struct sockaddr
*pDestAddr
,PDWORD pdwBestIfIndex
)
2847 DWORD WINAPI
NhpAllocateAndGetInterfaceInfoFromStack(IP_INTERFACE_NAME_INFO
**ppTable
,PDWORD pdwCount
,BOOL bOrder
,HANDLE hHeap
,DWORD dwFlags
)
2856 DWORD WINAPI
GetIcmpStatisticsEx(PMIB_ICMP_EX pStats
,DWORD dwFamily
)
2861 return ERROR_INVALID_PARAMETER
;
2863 if (dwFamily
!= AF_INET
&& dwFamily
!= AF_INET6
)
2864 return ERROR_INVALID_PARAMETER
;
2870 SetIpForwardEntryToStack(PMIB_IPFORWARDROW pRoute
)
2872 FIXME("SetIpForwardEntryToStack() stub\n");
2876 DWORD
GetInterfaceNameInternal(_In_
const GUID
* pInterfaceGUID
,
2877 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
2878 _Inout_ PULONG pOutBufLen
)
2880 UNICODE_STRING GuidString
;
2882 WCHAR szKeyName
[2*MAX_PATH
];
2886 if (pInterfaceGUID
== NULL
|| pOutBufLen
== NULL
)
2887 return ERROR_INVALID_PARAMETER
;
2889 result
= RtlStringFromGUID(pInterfaceGUID
, &GuidString
);
2891 if (!NT_SUCCESS(result
))
2893 // failed to convert guid to string
2894 return RtlNtStatusToDosError(result
);
2897 hr
= StringCbPrintfW(szKeyName
, sizeof(szKeyName
), L
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", GuidString
.Buffer
);
2898 RtlFreeUnicodeString(&GuidString
);
2902 // key name is too long
2903 return ERROR_BUFFER_OVERFLOW
;
2906 result
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szKeyName
, 0, KEY_READ
, &hKey
);
2908 if (result
!= ERROR_SUCCESS
)
2910 // failed to find adapter entry
2911 return ERROR_NOT_FOUND
;
2914 result
= RegQueryValueExW(hKey
, L
"Name", NULL
, &type
, (PVOID
)pInterfaceName
, pOutBufLen
);
2918 if (result
== ERROR_MORE_DATA
)
2920 *pOutBufLen
= MAX_INTERFACE_NAME_LEN
* 2;
2921 return ERROR_INSUFFICIENT_BUFFER
;
2924 if (result
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
2926 // failed to read adapter name
2927 return ERROR_NO_DATA
;
2929 return ERROR_SUCCESS
;
2936 NhGetInterfaceNameFromDeviceGuid(_In_
const GUID
* pInterfaceGUID
,
2937 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
2938 _Inout_ PULONG pOutBufLen
,
2942 SetLastError(ERROR_SUCCESS
);
2944 if (pInterfaceName
== NULL
)
2945 return ERROR_INVALID_PARAMETER
;
2947 return GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
2954 NhGetInterfaceNameFromGuid(_In_
const GUID
* pInterfaceGUID
,
2955 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
2956 _Inout_ PULONG pOutBufLen
,
2962 result
= GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
2964 if (result
== ERROR_NOT_FOUND
)
2965 SetLastError(ERROR_PATH_NOT_FOUND
);