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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "iphlpapi_private.h"
26 #include <sys/types.h>
27 #ifdef HAVE_NETINET_IN_H
28 # include <netinet/in.h>
30 #ifdef HAVE_ARPA_INET_H
31 # include <arpa/inet.h>
33 #ifdef HAVE_ARPA_NAMESER_H
34 # include <arpa/nameser.h>
50 #include "wine/debug.h"
52 #include "dhcp/rosdhcp_public.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
56 typedef struct _NAME_SERVER_LIST_CONTEXT
{
59 PIP_PER_ADAPTER_INFO pData
;
61 IP_ADDR_STRING
*pLastAddr
;
62 } NAME_SERVER_LIST_CONTEXT
, *PNAME_SERVER_LIST_CONTEXT
;
64 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
67 case DLL_PROCESS_ATTACH
:
68 DisableThreadLibraryCalls( hinstDLL
);
72 case DLL_PROCESS_DETACH
:
79 /******************************************************************
80 * AddIPAddress (IPHLPAPI.@)
89 * NTEInstance [In/Out]
96 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask Netmask
, DWORD IfIndex
, PULONG NteContext
, PULONG NteInstance
)
98 return RtlNtStatusToDosError(addIPAddress(Address
, Netmask
, IfIndex
, NteContext
, NteInstance
));
101 DWORD
getInterfaceGatewayByIndex(DWORD index
)
103 DWORD ndx
, retVal
= 0, numRoutes
= getNumRoutes();
104 RouteTable
*table
= getRouteTable();
105 if (!table
) return 0;
107 for (ndx
= 0; ndx
< numRoutes
; ndx
++)
109 if ((table
->routes
[ndx
].ifIndex
== (index
)) && (table
->routes
[ndx
].dest
== 0))
110 retVal
= table
->routes
[ndx
].gateway
;
112 HeapFree(GetProcessHeap(), 0, table
);
116 /******************************************************************
117 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
122 * ppIfTable [Out] -- pointer into which the MIB_IFTABLE is
123 * allocated and returned.
124 * bOrder [In] -- passed to GetIfTable to order the table
125 * heap [In] -- heap from which the table is allocated
126 * flags [In] -- flags to HeapAlloc
128 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
129 * GetIfTable returns otherwise
132 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
133 BOOL bOrder
, HANDLE heap
, DWORD flags
)
137 TRACE("ppIfTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n", ppIfTable
,
138 (DWORD
)bOrder
, (DWORD
)heap
, flags
);
140 ret
= ERROR_INVALID_PARAMETER
;
144 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
145 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
146 *ppIfTable
= (PMIB_IFTABLE
)HeapAlloc(heap
, flags
, dwSize
);
147 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
150 TRACE("returning %ld\n", ret
);
155 /******************************************************************
156 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
161 * ppIpAddrTable [Out]
162 * bOrder [In] -- passed to GetIpAddrTable to order the table
163 * heap [In] -- heap from which the table is allocated
164 * flags [In] -- flags to HeapAlloc
171 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
172 BOOL bOrder
, HANDLE heap
, DWORD flags
)
176 TRACE("ppIpAddrTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
177 ppIpAddrTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
179 ret
= ERROR_INVALID_PARAMETER
;
183 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
184 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
185 *ppIpAddrTable
= (PMIB_IPADDRTABLE
)HeapAlloc(heap
, flags
, dwSize
);
186 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
189 TRACE("returning %ld\n", ret
);
194 /******************************************************************
195 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
198 * ppIpForwardTable [Out] -- pointer into which the MIB_IPFORWARDTABLE is
199 * allocated and returned.
200 * bOrder [In] -- passed to GetIfTable to order the table
201 * heap [In] -- heap from which the table is allocated
202 * flags [In] -- flags to HeapAlloc
204 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
205 * GetIpForwardTable returns otherwise
208 DWORD WINAPI
AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE
*
209 ppIpForwardTable
, BOOL bOrder
, HANDLE heap
, DWORD flags
)
213 TRACE("ppIpForwardTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
214 ppIpForwardTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
215 if (!ppIpForwardTable
)
216 ret
= ERROR_INVALID_PARAMETER
;
220 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
221 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
222 *ppIpForwardTable
= (PMIB_IPFORWARDTABLE
)HeapAlloc(heap
, flags
, dwSize
);
223 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
226 TRACE("returning %ld\n", ret
);
231 /******************************************************************
232 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
238 * bOrder [In] -- passed to GetIpNetTable to order the table
239 * heap [In] -- heap from which the table is allocated
240 * flags [In] -- flags to HeapAlloc
247 DWORD WINAPI
AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE
*ppIpNetTable
,
248 BOOL bOrder
, HANDLE heap
, DWORD flags
)
252 TRACE("ppIpNetTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
253 ppIpNetTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
255 ret
= ERROR_INVALID_PARAMETER
;
259 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
260 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
261 *ppIpNetTable
= (PMIB_IPNETTABLE
)HeapAlloc(heap
, flags
, dwSize
);
262 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
265 TRACE("returning %ld\n", ret
);
270 /******************************************************************
271 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
277 * bOrder [In] -- passed to GetTcpTable to order the table
278 * heap [In] -- heap from which the table is allocated
279 * flags [In] -- flags to HeapAlloc
286 DWORD WINAPI
AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE
*ppTcpTable
,
287 BOOL bOrder
, HANDLE heap
, DWORD flags
)
291 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
292 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
294 ret
= ERROR_INVALID_PARAMETER
;
298 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
299 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
300 *ppTcpTable
= (PMIB_TCPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
301 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
304 TRACE("returning %ld\n", ret
);
309 /******************************************************************
310 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
316 * bOrder [In] -- passed to GetUdpTable to order the table
317 * heap [In] -- heap from which the table is allocated
318 * flags [In] -- flags to HeapAlloc
325 DWORD WINAPI
AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE
*ppUdpTable
,
326 BOOL bOrder
, HANDLE heap
, DWORD flags
)
330 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
331 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
333 ret
= ERROR_INVALID_PARAMETER
;
337 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
338 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
339 *ppUdpTable
= (PMIB_UDPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
340 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
343 TRACE("returning %ld\n", ret
);
348 /******************************************************************
349 * CreateIpForwardEntry (IPHLPAPI.@)
361 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
363 return createIpForwardEntry( pRoute
);
367 /******************************************************************
368 * CreateIpNetEntry (IPHLPAPI.@)
380 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
382 TRACE("pArpEntry %p\n", pArpEntry
);
383 /* could use SIOCSARP on systems that support it, not sure I want to */
389 /******************************************************************
390 * CreateProxyArpEntry (IPHLPAPI.@)
404 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
406 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
409 /* marking Win2K+ functions not supported */
410 return ERROR_NOT_SUPPORTED
;
414 /******************************************************************
415 * DeleteIPAddress (IPHLPAPI.@)
427 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
429 TRACE("NTEContext %ld\n", NTEContext
);
430 return RtlNtStatusToDosError(deleteIpAddress(NTEContext
));
434 /******************************************************************
435 * DeleteIpForwardEntry (IPHLPAPI.@)
447 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
449 return deleteIpForwardEntry( pRoute
);
453 /******************************************************************
454 * DeleteIpNetEntry (IPHLPAPI.@)
466 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
468 TRACE("pArpEntry %p\n", pArpEntry
);
469 /* could use SIOCDARP on systems that support it, not sure I want to */
475 /******************************************************************
476 * DeleteProxyArpEntry (IPHLPAPI.@)
490 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
492 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
495 /* marking Win2K+ functions not supported */
496 return ERROR_NOT_SUPPORTED
;
499 /******************************************************************
500 * EnableRouter (IPHLPAPI.@)
506 * pOverlapped [In/Out]
513 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
515 TRACE("pHandle %p, pOverlapped %p\n", pHandle
, pOverlapped
);
517 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
518 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
519 marking Win2K+ functions not supported */
520 return ERROR_NOT_SUPPORTED
;
524 /******************************************************************
525 * FlushIpNetTable (IPHLPAPI.@)
537 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
539 TRACE("dwIfIndex 0x%08lx\n", dwIfIndex
);
541 /* this flushes the arp cache of the given index
542 marking Win2K+ functions not supported */
543 return ERROR_NOT_SUPPORTED
;
547 /******************************************************************
548 * GetAdapterIndex (IPHLPAPI.@)
553 * AdapterName [In/Out]
561 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
563 TRACE("AdapterName %p, IfIndex %p\n", AdapterName
, IfIndex
);
565 /* marking Win2K+ functions not supported */
566 return ERROR_NOT_SUPPORTED
;
570 /******************************************************************
571 * GetAdaptersInfo (IPHLPAPI.@)
576 * pAdapterInfo [In/Out]
577 * pOutBufLen [In/Out]
584 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
590 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
592 ret
= ERROR_INVALID_PARAMETER
;
594 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
596 if (numNonLoopbackInterfaces
> 0) {
597 /* this calculation assumes only one address in the IP_ADDR_STRING lists.
598 that's okay, because:
599 - we don't get multiple addresses per adapter anyway
600 - we don't know about per-adapter gateways
601 - DHCP and WINS servers can have max one entry per list */
602 ULONG size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
604 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
606 ret
= ERROR_BUFFER_OVERFLOW
;
609 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
612 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
613 if (*pOutBufLen
< size
) {
615 ret
= ERROR_INSUFFICIENT_BUFFER
;
620 BOOL winsEnabled
= FALSE
;
621 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
623 memset(pAdapterInfo
, 0, size
);
624 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
625 "Software\\Wine\\Wine\\Config\\Network", 0, KEY_READ
,
626 &hKey
) == ERROR_SUCCESS
) {
627 DWORD size
= sizeof(primaryWINS
.String
);
630 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
631 (PBYTE
)primaryWINS
.String
, &size
);
632 addr
= inet_addr(primaryWINS
.String
);
633 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
635 size
= sizeof(secondaryWINS
.String
);
636 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
637 (PBYTE
)secondaryWINS
.String
, &size
);
638 addr
= inet_addr(secondaryWINS
.String
);
639 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
643 TRACE("num of index is %lu\n", table
->numIndexes
);
644 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
645 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
646 DWORD addrLen
= sizeof(ptr
->Address
), type
;
648 getInterfaceNameByIndex(table
->indexes
[ndx
]);
650 ret
= ERROR_OUTOFMEMORY
;
654 /* on Win98 this is left empty, but whatever */
655 strncpy(ptr
->AdapterName
,ifname
,sizeof(ptr
->AdapterName
));
656 consumeInterfaceName(ifname
);
657 ptr
->AdapterName
[MAX_ADAPTER_NAME_LENGTH
] = '\0';
658 getInterfacePhysicalByIndex(table
->indexes
[ndx
], &addrLen
,
659 ptr
->Address
, &type
);
660 /* MS defines address length and type as UINT in some places and
661 DWORD in others, **sigh**. Don't want to assume that PUINT and
662 PDWORD are equiv (64-bit?) */
663 ptr
->AddressLength
= addrLen
;
665 ptr
->Index
= table
->indexes
[ndx
];
666 toIPAddressString(getInterfaceIPAddrByIndex(table
->indexes
[ndx
]),
667 ptr
->IpAddressList
.IpAddress
.String
);
668 toIPAddressString(getInterfaceMaskByIndex(table
->indexes
[ndx
]),
669 ptr
->IpAddressList
.IpMask
.String
);
670 toIPAddressString(getInterfaceGatewayByIndex(table
->indexes
[ndx
]),
671 ptr
->GatewayList
.IpAddress
.String
);
672 getDhcpInfoForAdapter(table
->indexes
[ndx
], &dhcpEnabled
,
673 &dhcpServer
, &ptr
->LeaseObtained
,
675 ptr
->DhcpEnabled
= (DWORD
) dhcpEnabled
;
676 toIPAddressString(dhcpServer
,
677 ptr
->DhcpServer
.IpAddress
.String
);
679 ptr
->HaveWins
= TRUE
;
680 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
681 primaryWINS
.String
, sizeof(primaryWINS
.String
));
682 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
683 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
685 if (ndx
< table
->numIndexes
- 1)
686 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
695 ret
= ERROR_OUTOFMEMORY
;
701 TRACE("returning %ld\n", ret
);
706 /******************************************************************
707 * GetBestInterface (IPHLPAPI.@)
713 * pdwBestIfIndex [In/Out]
720 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
724 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr
, pdwBestIfIndex
);
726 ret
= ERROR_INVALID_PARAMETER
;
728 MIB_IPFORWARDROW ipRow
;
730 ret
= GetBestRoute(dwDestAddr
, 0, &ipRow
);
731 if (ret
== ERROR_SUCCESS
)
732 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
734 TRACE("returning %ld\n", ret
);
739 /******************************************************************
740 * GetBestRoute (IPHLPAPI.@)
754 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
756 PMIB_IPFORWARDTABLE table
;
759 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr
,
760 dwSourceAddr
, pBestRoute
);
762 return ERROR_INVALID_PARAMETER
;
764 AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
766 DWORD ndx
, matchedBits
, matchedNdx
= 0;
768 for (ndx
= 0, matchedBits
= 0; ndx
< table
->dwNumEntries
; ndx
++) {
769 if ((dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
770 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
771 DWORD numShifts
, mask
;
773 for (numShifts
= 0, mask
= table
->table
[ndx
].dwForwardMask
;
774 mask
&& !(mask
& 1); mask
>>= 1, numShifts
++)
776 if (numShifts
> matchedBits
) {
777 matchedBits
= numShifts
;
782 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
783 HeapFree(GetProcessHeap(), 0, table
);
787 ret
= ERROR_OUTOFMEMORY
;
788 TRACE("returning %ld\n", ret
);
793 /******************************************************************
794 * GetFriendlyIfIndex (IPHLPAPI.@)
806 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
808 /* windows doesn't validate these, either, just makes sure the top byte is
809 cleared. I assume my ifenum module never gives an index with the top
811 TRACE("returning %ld\n", IfIndex
);
816 /******************************************************************
817 * GetIcmpStatistics (IPHLPAPI.@)
829 DWORD WINAPI
GetIcmpStatistics(PMIB_ICMP pStats
)
833 TRACE("pStats %p\n", pStats
);
834 ret
= getICMPStats(pStats
);
835 TRACE("returning %ld\n", ret
);
840 /******************************************************************
841 * GetIfEntry (IPHLPAPI.@)
853 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
858 TRACE("pIfRow %p\n", pIfRow
);
860 return ERROR_INVALID_PARAMETER
;
862 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
);
864 ret
= getInterfaceEntryByIndex(pIfRow
->dwIndex
, pIfRow
);
866 ret
= getInterfaceStatsByName(name
, pIfRow
);
867 consumeInterfaceName(name
);
870 ret
= ERROR_INVALID_DATA
;
871 TRACE("returning %ld\n", ret
);
876 static int IfTableSorter(const void *a
, const void *b
)
881 ret
= ((PMIB_IFROW
)a
)->dwIndex
- ((PMIB_IFROW
)b
)->dwIndex
;
888 /******************************************************************
889 * GetIfTable (IPHLPAPI.@)
903 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
907 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize
, pdwSize
,
910 ret
= ERROR_INVALID_PARAMETER
;
912 DWORD numInterfaces
= getNumInterfaces();
914 TRACE("GetIfTable: numInterfaces = %d\n", (int)numInterfaces
);
915 size
= sizeof(MIB_IFTABLE
) + (numInterfaces
- 1) * sizeof(MIB_IFROW
);
917 if (!pIfTable
|| *pdwSize
< size
) {
919 ret
= ERROR_INSUFFICIENT_BUFFER
;
922 InterfaceIndexTable
*table
= getInterfaceIndexTable();
925 size
= sizeof(MIB_IFTABLE
) + (table
->numIndexes
- 1) *
927 if (*pdwSize
< size
) {
929 ret
= ERROR_INSUFFICIENT_BUFFER
;
934 pIfTable
->dwNumEntries
= 0;
935 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
936 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
937 GetIfEntry(&pIfTable
->table
[ndx
]);
938 pIfTable
->dwNumEntries
++;
941 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
948 ret
= ERROR_OUTOFMEMORY
;
951 TRACE("returning %ld\n", ret
);
956 /******************************************************************
957 * GetInterfaceInfo (IPHLPAPI.@)
963 * dwOutBufLen [In/Out]
970 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
974 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
976 ret
= ERROR_INVALID_PARAMETER
;
978 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
980 TRACE("numNonLoopbackInterfaces == 0x%x\n", numNonLoopbackInterfaces
);
981 size
= sizeof(IP_INTERFACE_INFO
) + (numNonLoopbackInterfaces
) *
982 sizeof(IP_ADAPTER_INDEX_MAP
);
984 if (!pIfTable
|| *dwOutBufLen
< size
) {
986 ret
= ERROR_INSUFFICIENT_BUFFER
;
989 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
992 TRACE("table->numIndexes == 0x%x\n", table
->numIndexes
);
993 size
= sizeof(IP_INTERFACE_INFO
) + (table
->numIndexes
) *
994 sizeof(IP_ADAPTER_INDEX_MAP
);
995 if (*dwOutBufLen
< size
) {
997 ret
= ERROR_INSUFFICIENT_BUFFER
;
1002 pIfTable
->NumAdapters
= 0;
1003 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1004 const char *walker
, *name
;
1007 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1008 name
= getInterfaceNameByIndex(table
->indexes
[ndx
]);
1009 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1010 walker
&& *walker
&&
1011 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1012 walker
++, assigner
++)
1013 *assigner
= *walker
;
1015 consumeInterfaceName(name
);
1016 pIfTable
->NumAdapters
++;
1023 ret
= ERROR_OUTOFMEMORY
;
1026 TRACE("returning %ld\n", ret
);
1031 static int IpAddrTableSorter(const void *a
, const void *b
)
1036 ret
= ((PMIB_IPADDRROW
)a
)->dwAddr
- ((PMIB_IPADDRROW
)b
)->dwAddr
;
1043 /******************************************************************
1044 * GetIpAddrTable (IPHLPAPI.@)
1049 * pIpAddrTable [In/Out]
1058 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1062 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable
, pdwSize
,
1065 ret
= ERROR_INVALID_PARAMETER
;
1067 DWORD numInterfaces
= getNumInterfaces();
1068 ULONG size
= sizeof(MIB_IPADDRTABLE
) + (numInterfaces
- 1) *
1069 sizeof(MIB_IPADDRROW
);
1071 if (!pIpAddrTable
|| *pdwSize
< size
) {
1073 ret
= ERROR_INSUFFICIENT_BUFFER
;
1076 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1079 size
= sizeof(MIB_IPADDRTABLE
) + (table
->numIndexes
- 1) *
1080 sizeof(MIB_IPADDRROW
);
1081 if (*pdwSize
< size
) {
1083 ret
= ERROR_INSUFFICIENT_BUFFER
;
1088 pIpAddrTable
->dwNumEntries
= 0;
1089 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1090 pIpAddrTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1091 pIpAddrTable
->table
[ndx
].dwAddr
=
1092 getInterfaceIPAddrByIndex(table
->indexes
[ndx
]);
1093 pIpAddrTable
->table
[ndx
].dwMask
=
1094 getInterfaceMaskByIndex(table
->indexes
[ndx
]);
1095 /* the dwBCastAddr member isn't the broadcast address, it indicates
1096 * whether the interface uses the 1's broadcast address (1) or the
1097 * 0's broadcast address (0).
1099 bcast
= getInterfaceBCastAddrByIndex(table
->indexes
[ndx
]);
1100 pIpAddrTable
->table
[ndx
].dwBCastAddr
=
1101 (bcast
& pIpAddrTable
->table
[ndx
].dwMask
) ? 1 : 0;
1102 /* FIXME: hardcoded reasm size, not sure where to get it */
1103 pIpAddrTable
->table
[ndx
].dwReasmSize
= 65535;
1104 pIpAddrTable
->table
[ndx
].unused1
= 0;
1105 pIpAddrTable
->table
[ndx
].wType
= 0; /* aka unused2 */
1106 pIpAddrTable
->dwNumEntries
++;
1109 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1110 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1116 ret
= ERROR_OUTOFMEMORY
;
1119 TRACE("returning %ld\n", ret
);
1124 static int IpForwardTableSorter(const void *a
, const void *b
)
1129 PMIB_IPFORWARDROW rowA
= (PMIB_IPFORWARDROW
)a
, rowB
= (PMIB_IPFORWARDROW
)b
;
1131 ret
= rowA
->dwForwardDest
- rowB
->dwForwardDest
;
1133 ret
= rowA
->dwForwardProto
- rowB
->dwForwardProto
;
1135 ret
= rowA
->dwForwardPolicy
- rowB
->dwForwardPolicy
;
1137 ret
= rowA
->dwForwardNextHop
- rowB
->dwForwardNextHop
;
1147 /******************************************************************
1148 * GetIpForwardTable (IPHLPAPI.@)
1153 * pIpForwardTable [In/Out]
1162 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1166 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable
,
1167 pdwSize
, (DWORD
)bOrder
);
1169 ret
= ERROR_INVALID_PARAMETER
;
1171 DWORD numRoutes
= getNumRoutes();
1172 ULONG sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (numRoutes
- 1) *
1173 sizeof(MIB_IPFORWARDROW
);
1175 if (!pIpForwardTable
|| *pdwSize
< sizeNeeded
) {
1176 *pdwSize
= sizeNeeded
;
1177 ret
= ERROR_INSUFFICIENT_BUFFER
;
1180 RouteTable
*table
= getRouteTable();
1182 sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (table
->numRoutes
- 1) *
1183 sizeof(MIB_IPFORWARDROW
);
1184 if (*pdwSize
< sizeNeeded
) {
1185 *pdwSize
= sizeNeeded
;
1186 ret
= ERROR_INSUFFICIENT_BUFFER
;
1191 pIpForwardTable
->dwNumEntries
= table
->numRoutes
;
1192 for (ndx
= 0; ndx
< numRoutes
; ndx
++) {
1193 pIpForwardTable
->table
[ndx
].dwForwardIfIndex
=
1194 table
->routes
[ndx
].ifIndex
+ 1;
1195 pIpForwardTable
->table
[ndx
].dwForwardDest
=
1196 table
->routes
[ndx
].dest
;
1197 pIpForwardTable
->table
[ndx
].dwForwardMask
=
1198 table
->routes
[ndx
].mask
;
1199 pIpForwardTable
->table
[ndx
].dwForwardPolicy
= 0;
1200 pIpForwardTable
->table
[ndx
].dwForwardNextHop
=
1201 table
->routes
[ndx
].gateway
;
1202 /* FIXME: this type is appropriate for local interfaces; may not
1203 always be appropriate */
1204 pIpForwardTable
->table
[ndx
].dwForwardType
= MIB_IPROUTE_TYPE_DIRECT
;
1205 /* FIXME: other protos might be appropriate, e.g. the default route
1206 is typically set with MIB_IPPROTO_NETMGMT instead */
1207 pIpForwardTable
->table
[ndx
].dwForwardProto
= MIB_IPPROTO_LOCAL
;
1208 /* punt on age and AS */
1209 pIpForwardTable
->table
[ndx
].dwForwardAge
= 0;
1210 pIpForwardTable
->table
[ndx
].dwForwardNextHopAS
= 0;
1211 pIpForwardTable
->table
[ndx
].dwForwardMetric1
=
1212 table
->routes
[ndx
].metric
;
1213 /* rest of the metrics are 0.. */
1214 pIpForwardTable
->table
[ndx
].dwForwardMetric2
= 0;
1215 pIpForwardTable
->table
[ndx
].dwForwardMetric3
= 0;
1216 pIpForwardTable
->table
[ndx
].dwForwardMetric4
= 0;
1217 pIpForwardTable
->table
[ndx
].dwForwardMetric5
= 0;
1220 qsort(pIpForwardTable
->table
, pIpForwardTable
->dwNumEntries
,
1221 sizeof(MIB_IPFORWARDROW
), IpForwardTableSorter
);
1224 HeapFree(GetProcessHeap(), 0, table
);
1227 ret
= ERROR_OUTOFMEMORY
;
1230 TRACE("returning %ld\n", ret
);
1235 static int IpNetTableSorter(const void *a
, const void *b
)
1240 ret
= ((PMIB_IPNETROW
)a
)->dwAddr
- ((PMIB_IPNETROW
)b
)->dwAddr
;
1247 /******************************************************************
1248 * GetIpNetTable (IPHLPAPI.@)
1253 * pIpNetTable [In/Out]
1262 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
1264 DWORD ret
= NO_ERROR
;
1266 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
,
1269 ret
= ERROR_INVALID_PARAMETER
;
1271 DWORD numEntries
= getNumArpEntries();
1272 ULONG size
= sizeof(MIB_IPNETTABLE
);
1275 size
+= (numEntries
- 1) * sizeof(MIB_IPNETROW
);
1276 if (!pIpNetTable
|| *pdwSize
< size
) {
1278 ret
= ERROR_INSUFFICIENT_BUFFER
;
1281 PMIB_IPNETTABLE table
= getArpTable();
1283 size
= sizeof(MIB_IPNETTABLE
);
1284 if (table
->dwNumEntries
> 1)
1285 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPNETROW
);
1286 if (*pdwSize
< size
) {
1288 ret
= ERROR_INSUFFICIENT_BUFFER
;
1292 memcpy(pIpNetTable
, table
, size
);
1294 qsort(pIpNetTable
->table
, pIpNetTable
->dwNumEntries
,
1295 sizeof(MIB_IPNETROW
), IpNetTableSorter
);
1298 HeapFree(GetProcessHeap(), 0, table
);
1302 TRACE("returning %d\n", ret
);
1307 /******************************************************************
1308 * GetIpStatistics (IPHLPAPI.@)
1320 DWORD WINAPI
GetIpStatistics(PMIB_IPSTATS pStats
)
1322 return GetIpStatisticsEx(pStats
, PF_INET
);
1325 /******************************************************************
1326 * GetIpStatisticsEx (IPHLPAPI.@)
1339 DWORD WINAPI
GetIpStatisticsEx(PMIB_IPSTATS pStats
, DWORD dwFamily
)
1343 TRACE("pStats %p\n", pStats
);
1344 ret
= getIPStats(pStats
, dwFamily
);
1345 TRACE("returning %ld\n", ret
);
1349 /******************************************************************
1350 * GetNetworkParams (IPHLPAPI.@)
1355 * pFixedInfo [In/Out]
1356 * pOutBufLen [In/Out]
1363 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
1368 PIPHLP_RES_INFO resInfo
;
1370 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
1372 return ERROR_INVALID_PARAMETER
;
1374 resInfo
= getResInfo();
1376 return ERROR_OUTOFMEMORY
;
1378 size
= sizeof(FIXED_INFO
) + (resInfo
->riCount
> 1 ? (resInfo
->riCount
-1) *
1379 sizeof(IP_ADDR_STRING
) : 0);
1380 if (!pFixedInfo
|| *pOutBufLen
< size
) {
1382 disposeResInfo( resInfo
);
1383 return ERROR_BUFFER_OVERFLOW
;
1386 memset(pFixedInfo
, 0, size
);
1387 size
= sizeof(pFixedInfo
->HostName
);
1388 GetComputerNameExA(ComputerNameDnsHostname
, pFixedInfo
->HostName
, &size
);
1389 size
= sizeof(pFixedInfo
->DomainName
);
1390 GetComputerNameExA(ComputerNameDnsDomain
, pFixedInfo
->DomainName
, &size
);
1392 TRACE("GetComputerNameExA: %s\n", pFixedInfo
->DomainName
);
1394 if (resInfo
->riCount
> 0)
1396 CopyMemory(&pFixedInfo
->DnsServerList
, resInfo
->DnsList
, sizeof(IP_ADDR_STRING
));
1397 if (resInfo
->riCount
> 1)
1399 IP_ADDR_STRING
*pSrc
= resInfo
->DnsList
->Next
;
1400 IP_ADDR_STRING
*pTarget
= (struct _IP_ADDR_STRING
*)((char*)pFixedInfo
+ sizeof(FIXED_INFO
));
1402 pFixedInfo
->DnsServerList
.Next
= pTarget
;
1406 CopyMemory(pTarget
, pSrc
, sizeof(IP_ADDR_STRING
));
1408 if (resInfo
->riCount
> 1)
1410 pTarget
->Next
= (IP_ADDR_STRING
*)((char*)pTarget
+ sizeof(IP_ADDR_STRING
));
1411 pTarget
= pTarget
->Next
;
1416 pTarget
->Next
= NULL
;
1424 pFixedInfo
->DnsServerList
.Next
= NULL
;
1428 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
1429 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1430 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
1431 if (regReturn
!= ERROR_SUCCESS
)
1432 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1433 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
1435 if (regReturn
== ERROR_SUCCESS
)
1437 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
1439 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (PBYTE
)pFixedInfo
->ScopeId
, &size
);
1443 disposeResInfo( resInfo
);
1444 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1445 I suppose could also check for a listener on port 53 to set EnableDns */
1447 TRACE("returning %ld\n", ret
);
1453 /******************************************************************
1454 * GetNumberOfInterfaces (IPHLPAPI.@)
1466 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
1470 TRACE("pdwNumIf %p\n", pdwNumIf
);
1472 ret
= ERROR_INVALID_PARAMETER
;
1474 *pdwNumIf
= getNumInterfaces();
1477 TRACE("returning %ld\n", ret
);
1482 /******************************************************************
1483 * GetPerAdapterInfo (IPHLPAPI.@)
1489 * pPerAdapterInfo [In/Out]
1490 * pOutBufLen [In/Out]
1497 static void CreateNameServerListEnumNamesFunc( PWCHAR Interface
, PWCHAR Server
, PVOID Data
)
1499 IP_ADDR_STRING
*pNext
;
1500 PNAME_SERVER_LIST_CONTEXT Context
= (PNAME_SERVER_LIST_CONTEXT
)Data
;
1502 if (!Context
->NumServers
)
1504 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
1506 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, Context
->pData
->DnsServerList
.IpAddress
.String
, 16, NULL
, NULL
);
1507 Context
->pData
->DnsServerList
.IpAddress
.String
[15] = '\0';
1508 Context
->pLastAddr
= &Context
->pData
->DnsServerList
;
1513 Context
->uSizeRequired
+= sizeof(IP_ADDR_STRING
);
1514 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
1516 pNext
= (IP_ADDR_STRING
*)(((char*)Context
->pLastAddr
) + sizeof(IP_ADDR_STRING
));
1517 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, pNext
->IpAddress
.String
, 16, NULL
, NULL
);
1518 pNext
->IpAddress
.String
[15] = '\0';
1519 Context
->pLastAddr
->Next
= pNext
;
1520 Context
->pLastAddr
= pNext
;
1524 Context
->NumServers
++;
1527 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
1532 NAME_SERVER_LIST_CONTEXT Context
;
1533 WCHAR keyname
[200] = L
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
1536 return ERROR_INVALID_PARAMETER
;
1538 if (!pPerAdapterInfo
|| *pOutBufLen
< sizeof(IP_PER_ADAPTER_INFO
))
1540 *pOutBufLen
= sizeof(IP_PER_ADAPTER_INFO
);
1541 return ERROR_BUFFER_OVERFLOW
;
1544 ifName
= getInterfaceNameByIndex(IfIndex
);
1546 return ERROR_INVALID_PARAMETER
;
1548 MultiByteToWideChar(CP_ACP
, 0, ifName
, -1, &keyname
[62], sizeof(keyname
)/sizeof(WCHAR
) - 63);
1549 HeapFree(GetProcessHeap(), 0, (LPVOID
)ifName
);
1551 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keyname
, 0, KEY_READ
, &hkey
) != ERROR_SUCCESS
)
1553 return ERROR_NOT_SUPPORTED
;
1555 Context
.NumServers
= 0;
1556 Context
.uSizeAvailable
= *pOutBufLen
;
1557 Context
.uSizeRequired
= sizeof(IP_PER_ADAPTER_INFO
);
1558 Context
.pData
= pPerAdapterInfo
;
1560 if (*pOutBufLen
>= sizeof(IP_PER_ADAPTER_INFO
))
1561 ZeroMemory(pPerAdapterInfo
, sizeof(IP_PER_ADAPTER_INFO
));
1563 EnumNameServers(hkey
, &keyname
[62], &Context
, CreateNameServerListEnumNamesFunc
);
1565 if (Context
.uSizeRequired
> Context
.uSizeAvailable
)
1567 *pOutBufLen
= Context
.uSizeRequired
;
1569 return ERROR_BUFFER_OVERFLOW
;
1572 if(RegQueryValueExW(hkey
, L
"DHCPNameServer", NULL
, NULL
, NULL
, &dwSize
) == ERROR_SUCCESS
)
1574 pPerAdapterInfo
->AutoconfigActive
= TRUE
;
1582 /******************************************************************
1583 * GetRTTAndHopCount (IPHLPAPI.@)
1588 * DestIpAddress [In]
1598 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
1600 TRACE("DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p\n",
1601 DestIpAddress
, HopCount
, MaxHops
, RTT
);
1607 /******************************************************************
1608 * GetTcpStatisticsEx (IPHLPAPI.@)
1621 DWORD WINAPI
GetTcpStatisticsEx(PMIB_TCPSTATS pStats
, DWORD dwFamily
)
1625 TRACE("pStats %p\n", pStats
);
1626 ret
= getTCPStats(pStats
, dwFamily
);
1627 TRACE("returning %ld\n", ret
);
1631 /******************************************************************
1632 * GetTcpStatistics (IPHLPAPI.@)
1644 DWORD WINAPI
GetTcpStatistics(PMIB_TCPSTATS pStats
)
1646 return GetTcpStatisticsEx(pStats
, PF_INET
);
1650 static int TcpTableSorter(const void *a
, const void *b
)
1655 PMIB_TCPROW rowA
= (PMIB_TCPROW
)a
, rowB
= (PMIB_TCPROW
)b
;
1657 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1659 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1661 ret
= rowA
->dwRemoteAddr
- rowB
->dwRemoteAddr
;
1663 ret
= rowA
->dwRemotePort
- rowB
->dwRemotePort
;
1673 /******************************************************************
1674 * GetTcpTable (IPHLPAPI.@)
1676 * Get the table of active TCP connections.
1679 * pTcpTable [Out] buffer for TCP connections table
1680 * pdwSize [In/Out] length of output buffer
1681 * bOrder [In] whether to order the table
1685 * Failure: error code from winerror.h
1688 * If pdwSize is less than required, the function will return
1689 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1690 * the required byte size.
1691 * If bOrder is true, the returned table will be sorted, first by
1692 * local address and port number, then by remote address and port
1695 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
1697 DWORD ret
= NO_ERROR
;
1699 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable
, pdwSize
,
1702 ret
= ERROR_INVALID_PARAMETER
;
1704 DWORD numEntries
= getNumTcpEntries();
1705 DWORD size
= sizeof(MIB_TCPTABLE
);
1708 size
+= (numEntries
- 1) * sizeof(MIB_TCPROW
);
1709 if (!pTcpTable
|| *pdwSize
< size
) {
1711 ret
= ERROR_INSUFFICIENT_BUFFER
;
1714 PMIB_TCPTABLE pTcpTable
= getTcpTable();
1717 size
= sizeof(MIB_TCPTABLE
);
1718 if (pTcpTable
->dwNumEntries
> 1)
1719 size
+= (pTcpTable
->dwNumEntries
- 1) * sizeof(MIB_TCPROW
);
1723 qsort(pTcpTable
->table
, pTcpTable
->dwNumEntries
,
1724 sizeof(MIB_TCPROW
), TcpTableSorter
);
1729 TRACE("returning %d\n", ret
);
1734 /******************************************************************
1735 * GetUdpStatisticsEx (IPHLPAPI.@)
1748 DWORD WINAPI
GetUdpStatisticsEx(PMIB_UDPSTATS pStats
, DWORD dwFamily
)
1752 TRACE("pStats %p\n", pStats
);
1753 ret
= getUDPStats(pStats
, dwFamily
);
1754 TRACE("returning %ld\n", ret
);
1758 /******************************************************************
1759 * GetUdpStatistics (IPHLPAPI.@)
1771 DWORD WINAPI
GetUdpStatistics(PMIB_UDPSTATS pStats
)
1773 return GetUdpStatisticsEx(pStats
, PF_INET
);
1777 static int UdpTableSorter(const void *a
, const void *b
)
1782 PMIB_UDPROW rowA
= (PMIB_UDPROW
)a
, rowB
= (PMIB_UDPROW
)b
;
1784 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1786 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1794 /******************************************************************
1795 * GetUdpTable (IPHLPAPI.@)
1800 * pUdpTable [In/Out]
1809 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
1813 TRACE("pUdpTable %p, pdwSize %p, bOrder %ld\n", pUdpTable
, pdwSize
,
1816 ret
= ERROR_INVALID_PARAMETER
;
1818 DWORD numEntries
= getNumUdpEntries();
1819 ULONG size
= sizeof(MIB_UDPTABLE
) + (numEntries
- 1) * sizeof(MIB_UDPROW
);
1821 if (!pUdpTable
|| *pdwSize
< size
) {
1823 ret
= ERROR_INSUFFICIENT_BUFFER
;
1826 PMIB_UDPTABLE table
= getUdpTable();
1829 size
= sizeof(MIB_UDPTABLE
) + (table
->dwNumEntries
- 1) *
1831 if (*pdwSize
< size
) {
1833 ret
= ERROR_INSUFFICIENT_BUFFER
;
1836 memcpy(pUdpTable
, table
, size
);
1838 qsort(pUdpTable
->table
, pUdpTable
->dwNumEntries
,
1839 sizeof(MIB_UDPROW
), UdpTableSorter
);
1845 ret
= ERROR_OUTOFMEMORY
;
1848 TRACE("returning %ld\n", ret
);
1853 /******************************************************************
1854 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1856 * This is a Win98-only function to get information on "unidirectional"
1857 * adapters. Since this is pretty nonsensical in other contexts, it
1858 * never returns anything.
1861 * pIPIfInfo [Out] buffer for adapter infos
1862 * dwOutBufLen [Out] length of the output buffer
1866 * Failure: error code from winerror.h
1869 * Stub, returns ERROR_NOT_SUPPORTED.
1871 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
1873 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
1874 /* a unidirectional adapter?? not bloody likely! */
1875 return ERROR_NOT_SUPPORTED
;
1879 /******************************************************************
1880 * IpReleaseAddress (IPHLPAPI.@)
1882 * Release an IP obtained through DHCP,
1885 * AdapterInfo [In] adapter to release IP address
1889 * Failure: error code from winerror.h
1892 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1894 COMM_DHCP_REPLY Reply
;
1895 COMM_DHCP_REQ Request
;
1898 Request
.AdapterIndex
= AdapterInfo
->Index
;
1899 Request
.Type
= DhcpReqReleaseIpAddress
;
1901 TRACE("AdapterInfo %p\n", AdapterInfo
);
1903 if (CallNamedPipe(DHCP_PIPE_NAME
,
1909 NMPWAIT_USE_DEFAULT_WAIT
))
1914 return ERROR_INVALID_PARAMETER
;
1917 return ERROR_PROC_NOT_FOUND
;
1921 /******************************************************************
1922 * IpRenewAddress (IPHLPAPI.@)
1924 * Renew an IP obtained through DHCP.
1927 * AdapterInfo [In] adapter to renew IP address
1931 * Failure: error code from winerror.h
1933 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1935 COMM_DHCP_REPLY Reply
;
1936 COMM_DHCP_REQ Request
;
1939 Request
.AdapterIndex
= AdapterInfo
->Index
;
1940 Request
.Type
= DhcpReqRenewIpAddress
;
1942 TRACE("AdapterInfo %p\n", AdapterInfo
);
1944 if (CallNamedPipe(DHCP_PIPE_NAME
,
1950 NMPWAIT_USE_DEFAULT_WAIT
))
1955 return ERROR_INVALID_PARAMETER
;
1958 return ERROR_PROC_NOT_FOUND
;
1962 /******************************************************************
1963 * NotifyAddrChange (IPHLPAPI.@)
1965 * Notify caller whenever the ip-interface map is changed.
1968 * Handle [Out] handle usable in asynchronous notification
1969 * overlapped [In] overlapped structure that notifies the caller
1973 * Failure: error code from winerror.h
1976 * Stub, returns ERROR_NOT_SUPPORTED.
1978 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
1980 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
1981 return ERROR_NOT_SUPPORTED
;
1985 /******************************************************************
1986 * NotifyRouteChange (IPHLPAPI.@)
1988 * Notify caller whenever the ip routing table is changed.
1991 * Handle [Out] handle usable in asynchronous notification
1992 * overlapped [In] overlapped structure that notifies the caller
1996 * Failure: error code from winerror.h
1999 * Stub, returns ERROR_NOT_SUPPORTED.
2001 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2003 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2004 return ERROR_NOT_SUPPORTED
;
2008 /******************************************************************
2009 * SendARP (IPHLPAPI.@)
2011 * Send an ARP request.
2014 * DestIP [In] attempt to obtain this IP
2015 * SrcIP [In] optional sender IP address
2016 * pMacAddr [Out] buffer for the mac address
2017 * PhyAddrLen [In/Out] length of the output buffer
2021 * Failure: error code from winerror.h
2024 * Stub, returns ERROR_NOT_SUPPORTED.
2026 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
2028 FIXME("(DestIP 0x%08x, SrcIP 0x%08x, pMacAddr %p, PhyAddrLen %p): stub\n",
2029 DestIP
, SrcIP
, pMacAddr
, PhyAddrLen
);
2030 return ERROR_NOT_SUPPORTED
;
2034 /******************************************************************
2035 * SetIfEntry (IPHLPAPI.@)
2037 * Set the administrative status of an interface.
2040 * pIfRow [In] dwAdminStatus member specifies the new status.
2044 * Failure: error code from winerror.h
2047 * Stub, returns ERROR_NOT_SUPPORTED.
2049 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
2051 FIXME("(pIfRow %p): stub\n", pIfRow
);
2052 /* this is supposed to set an interface administratively up or down.
2053 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2054 this sort of down is indistinguishable from other sorts of down (e.g. no
2056 return ERROR_NOT_SUPPORTED
;
2060 /******************************************************************
2061 * SetIpForwardEntry (IPHLPAPI.@)
2063 * Modify an existing route.
2066 * pRoute [In] route with the new information
2070 * Failure: error code from winerror.h
2073 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
2075 return setIpForwardEntry( pRoute
);
2079 /******************************************************************
2080 * SetIpNetEntry (IPHLPAPI.@)
2082 * Modify an existing ARP entry.
2085 * pArpEntry [In] ARP entry with the new information
2089 * Failure: error code from winerror.h
2091 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
2095 TCP_REQUEST_SET_INFORMATION_EX_ARP_ENTRY req
=
2096 TCP_REQUEST_SET_INFORMATION_INIT
;
2099 PMIB_IPNETROW arpBuff
;
2102 return ERROR_INVALID_PARAMETER
;
2104 if (!NT_SUCCESS(openTcpFile( &tcpFile
)))
2105 return ERROR_NOT_SUPPORTED
;
2107 if (!NT_SUCCESS(getNthIpEntity( tcpFile
, pArpEntry
->dwIndex
, &id
)))
2109 closeTcpFile(tcpFile
);
2110 return ERROR_INVALID_PARAMETER
;
2113 req
.Req
.ID
.toi_class
= INFO_CLASS_PROTOCOL
;
2114 req
.Req
.ID
.toi_type
= INFO_TYPE_PROVIDER
;
2115 req
.Req
.ID
.toi_id
= IP_MIB_ARPTABLE_ENTRY_ID
;
2116 req
.Req
.ID
.toi_entity
.tei_instance
= id
.tei_instance
;
2117 req
.Req
.ID
.toi_entity
.tei_entity
= AT_ENTITY
;
2118 req
.Req
.BufferSize
= sizeof(MIB_IPNETROW
);
2119 arpBuff
= (PMIB_IPNETROW
)&req
.Req
.Buffer
[0];
2121 RtlCopyMemory(arpBuff
, pArpEntry
, sizeof(MIB_IPNETROW
));
2123 status
= DeviceIoControl( tcpFile
,
2124 IOCTL_TCP_SET_INFORMATION_EX
,
2132 closeTcpFile(tcpFile
);
2137 return ERROR_INVALID_PARAMETER
;
2141 /******************************************************************
2142 * SetIpStatistics (IPHLPAPI.@)
2144 * Toggle IP forwarding and det the default TTL value.
2147 * pIpStats [In] IP statistics with the new information
2151 * Failure: error code from winerror.h
2154 * Stub, returns NO_ERROR.
2156 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
2158 FIXME("(pIpStats %p): stub\n", pIpStats
);
2163 /******************************************************************
2164 * SetIpTTL (IPHLPAPI.@)
2166 * Set the default TTL value.
2169 * nTTL [In] new TTL value
2173 * Failure: error code from winerror.h
2176 * Stub, returns NO_ERROR.
2178 DWORD WINAPI
SetIpTTL(UINT nTTL
)
2180 FIXME("(nTTL %d): stub\n", nTTL
);
2185 /******************************************************************
2186 * SetTcpEntry (IPHLPAPI.@)
2188 * Set the state of a TCP connection.
2191 * pTcpRow [In] specifies connection with new state
2195 * Failure: error code from winerror.h
2198 * Stub, returns NO_ERROR.
2200 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
2202 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
2207 /******************************************************************
2208 * UnenableRouter (IPHLPAPI.@)
2210 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2211 * if it reaches zero.
2214 * pOverlapped [In/Out] should be the same as in EnableRouter()
2215 * lpdwEnableCount [Out] optional, receives reference count
2219 * Failure: error code from winerror.h
2222 * Stub, returns ERROR_NOT_SUPPORTED.
2224 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
2226 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
2228 return ERROR_NOT_SUPPORTED
;
2234 DWORD WINAPI
GetIpErrorString(IP_STATUS ErrorCode
,PWCHAR Buffer
,PDWORD Size
)
2244 PIP_ADAPTER_ORDER_MAP WINAPI
GetAdapterOrderMap(VOID
)
2253 DWORD WINAPI
GetAdaptersAddresses(ULONG Family
,ULONG Flags
,PVOID Reserved
,PIP_ADAPTER_ADDRESSES pAdapterAddresses
,PULONG pOutBufLen
)
2255 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
2256 if (!pAdapterAddresses
|| *pOutBufLen
== 0)
2257 return ERROR_BUFFER_OVERFLOW
;
2258 if (Reserved
) return ERROR_INVALID_PARAMETER
;
2261 return ERROR_NO_DATA
;
2267 BOOL WINAPI
CancelIPChangeNotify(LPOVERLAPPED notifyOverlapped
)
2276 DWORD WINAPI
GetBestInterfaceEx(struct sockaddr
*pDestAddr
,PDWORD pdwBestIfIndex
)
2285 DWORD WINAPI
NhpAllocateAndGetInterfaceInfoFromStack(IP_INTERFACE_NAME_INFO
**ppTable
,PDWORD pdwCount
,BOOL bOrder
,HANDLE hHeap
,DWORD dwFlags
)
2294 DWORD WINAPI
GetIcmpStatisticsEx(PMIB_ICMP_EX pStats
,DWORD dwFamily
)
2300 /******************************************************************
2301 * GetIfTable2 (IPHLPAPI.@)
2307 NETIOAPI_API WINAPI
GetIfTable2(PMIB_IF_TABLE2
*pIfTable
)
2310 return ERROR_NOT_SUPPORTED
;
2313 /******************************************************************
2314 * GetIfEntry2 (IPHLPAPI.@)
2319 NETIOAPI_API WINAPI
GetIfEntry2(IN OUT PMIB_IF_ROW2 pIfRow
)
2321 TRACE("pIfRow %p\n", pIfRow
);
2323 return ERROR_INVALID_PARAMETER
;
2326 return ERROR_NOT_SUPPORTED
;
2330 SetIpForwardEntryToStack(PMIB_IPFORWARDROW pRoute
)
2332 FIXME("SetIpForwardEntryToStack() stub\n");
2337 NhGetInterfaceNameFromDeviceGuid(DWORD dwUnknown1
,
2343 FIXME("NhGetInterfaceNameFromDeviceGuid() stub\n");