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 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
54 typedef struct _NAME_SERVER_LIST_CONTEXT
{
57 PIP_PER_ADAPTER_INFO pData
;
59 IP_ADDR_STRING
*pLastAddr
;
60 } NAME_SERVER_LIST_CONTEXT
, *PNAME_SERVER_LIST_CONTEXT
;
62 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
65 case DLL_PROCESS_ATTACH
:
66 DisableThreadLibraryCalls( hinstDLL
);
70 case DLL_PROCESS_DETACH
:
77 /******************************************************************
78 * AddIPAddress (IPHLPAPI.@)
87 * NTEInstance [In/Out]
94 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask Netmask
, DWORD IfIndex
, PULONG NteContext
, PULONG NteInstance
)
96 return RtlNtStatusToDosError(addIPAddress(Address
, Netmask
, IfIndex
, NteContext
, NteInstance
));
99 DWORD
getInterfaceGatewayByIndex(DWORD index
)
101 DWORD ndx
, retVal
= 0, numRoutes
= getNumRoutes();
102 RouteTable
*table
= getRouteTable();
104 for (ndx
= 0; ndx
< numRoutes
; ndx
++)
106 if ((table
->routes
[ndx
].ifIndex
== (index
- 1)) && (table
->routes
[ndx
].dest
== 0))
107 retVal
= table
->routes
[ndx
].gateway
;
109 HeapFree(GetProcessHeap(), 0, table
);
113 /******************************************************************
114 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
119 * ppIfTable [Out] -- pointer into which the MIB_IFTABLE is
120 * allocated and returned.
121 * bOrder [In] -- passed to GetIfTable to order the table
122 * heap [In] -- heap from which the table is allocated
123 * flags [In] -- flags to HeapAlloc
125 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
126 * GetIfTable returns otherwise
129 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
130 BOOL bOrder
, HANDLE heap
, DWORD flags
)
134 TRACE("ppIfTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n", ppIfTable
,
135 (DWORD
)bOrder
, (DWORD
)heap
, flags
);
137 ret
= ERROR_INVALID_PARAMETER
;
141 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
142 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
143 *ppIfTable
= (PMIB_IFTABLE
)HeapAlloc(heap
, flags
, dwSize
);
144 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
147 TRACE("returning %ld\n", ret
);
152 /******************************************************************
153 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
158 * ppIpAddrTable [Out]
159 * bOrder [In] -- passed to GetIpAddrTable to order the table
160 * heap [In] -- heap from which the table is allocated
161 * flags [In] -- flags to HeapAlloc
168 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
169 BOOL bOrder
, HANDLE heap
, DWORD flags
)
173 TRACE("ppIpAddrTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
174 ppIpAddrTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
176 ret
= ERROR_INVALID_PARAMETER
;
180 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
181 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
182 *ppIpAddrTable
= (PMIB_IPADDRTABLE
)HeapAlloc(heap
, flags
, dwSize
);
183 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
186 TRACE("returning %ld\n", ret
);
191 /******************************************************************
192 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
195 * ppIpForwardTable [Out] -- pointer into which the MIB_IPFORWARDTABLE is
196 * allocated and returned.
197 * bOrder [In] -- passed to GetIfTable to order the table
198 * heap [In] -- heap from which the table is allocated
199 * flags [In] -- flags to HeapAlloc
201 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
202 * GetIpForwardTable returns otherwise
205 DWORD WINAPI
AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE
*
206 ppIpForwardTable
, BOOL bOrder
, HANDLE heap
, DWORD flags
)
210 TRACE("ppIpForwardTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
211 ppIpForwardTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
212 if (!ppIpForwardTable
)
213 ret
= ERROR_INVALID_PARAMETER
;
217 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
218 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
219 *ppIpForwardTable
= (PMIB_IPFORWARDTABLE
)HeapAlloc(heap
, flags
, dwSize
);
220 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
223 TRACE("returning %ld\n", ret
);
228 /******************************************************************
229 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
235 * bOrder [In] -- passed to GetIpNetTable to order the table
236 * heap [In] -- heap from which the table is allocated
237 * flags [In] -- flags to HeapAlloc
244 DWORD WINAPI
AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE
*ppIpNetTable
,
245 BOOL bOrder
, HANDLE heap
, DWORD flags
)
249 TRACE("ppIpNetTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
250 ppIpNetTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
252 ret
= ERROR_INVALID_PARAMETER
;
256 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
257 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
258 *ppIpNetTable
= (PMIB_IPNETTABLE
)HeapAlloc(heap
, flags
, dwSize
);
259 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
262 TRACE("returning %ld\n", ret
);
267 /******************************************************************
268 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
274 * bOrder [In] -- passed to GetTcpTable to order the table
275 * heap [In] -- heap from which the table is allocated
276 * flags [In] -- flags to HeapAlloc
283 DWORD WINAPI
AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE
*ppTcpTable
,
284 BOOL bOrder
, HANDLE heap
, DWORD flags
)
288 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
289 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
291 ret
= ERROR_INVALID_PARAMETER
;
295 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
296 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
297 *ppTcpTable
= (PMIB_TCPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
298 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
301 TRACE("returning %ld\n", ret
);
306 /******************************************************************
307 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
313 * bOrder [In] -- passed to GetUdpTable to order the table
314 * heap [In] -- heap from which the table is allocated
315 * flags [In] -- flags to HeapAlloc
322 DWORD WINAPI
AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE
*ppUdpTable
,
323 BOOL bOrder
, HANDLE heap
, DWORD flags
)
327 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
328 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
330 ret
= ERROR_INVALID_PARAMETER
;
334 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
335 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
336 *ppUdpTable
= (PMIB_UDPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
337 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
340 TRACE("returning %ld\n", ret
);
345 /******************************************************************
346 * CreateIpForwardEntry (IPHLPAPI.@)
358 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
360 return createIpForwardEntry( pRoute
);
364 /******************************************************************
365 * CreateIpNetEntry (IPHLPAPI.@)
377 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
379 TRACE("pArpEntry %p\n", pArpEntry
);
380 /* could use SIOCSARP on systems that support it, not sure I want to */
386 /******************************************************************
387 * CreateProxyArpEntry (IPHLPAPI.@)
401 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
403 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
406 /* marking Win2K+ functions not supported */
407 return ERROR_NOT_SUPPORTED
;
411 /******************************************************************
412 * DeleteIPAddress (IPHLPAPI.@)
424 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
426 TRACE("NTEContext %ld\n", NTEContext
);
427 return RtlNtStatusToDosError(deleteIpAddress(NTEContext
));
431 /******************************************************************
432 * DeleteIpForwardEntry (IPHLPAPI.@)
444 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
446 return deleteIpForwardEntry( pRoute
);
450 /******************************************************************
451 * DeleteIpNetEntry (IPHLPAPI.@)
463 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
465 TRACE("pArpEntry %p\n", pArpEntry
);
466 /* could use SIOCDARP on systems that support it, not sure I want to */
472 /******************************************************************
473 * DeleteProxyArpEntry (IPHLPAPI.@)
487 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
489 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
492 /* marking Win2K+ functions not supported */
493 return ERROR_NOT_SUPPORTED
;
496 /******************************************************************
497 * EnableRouter (IPHLPAPI.@)
503 * pOverlapped [In/Out]
510 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
512 TRACE("pHandle %p, pOverlapped %p\n", pHandle
, pOverlapped
);
514 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
515 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
516 marking Win2K+ functions not supported */
517 return ERROR_NOT_SUPPORTED
;
521 /******************************************************************
522 * FlushIpNetTable (IPHLPAPI.@)
534 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
536 TRACE("dwIfIndex 0x%08lx\n", dwIfIndex
);
538 /* this flushes the arp cache of the given index
539 marking Win2K+ functions not supported */
540 return ERROR_NOT_SUPPORTED
;
544 /******************************************************************
545 * GetAdapterIndex (IPHLPAPI.@)
550 * AdapterName [In/Out]
558 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
560 TRACE("AdapterName %p, IfIndex %p\n", AdapterName
, IfIndex
);
562 /* marking Win2K+ functions not supported */
563 return ERROR_NOT_SUPPORTED
;
567 /******************************************************************
568 * GetAdaptersInfo (IPHLPAPI.@)
573 * pAdapterInfo [In/Out]
574 * pOutBufLen [In/Out]
581 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
587 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
589 ret
= ERROR_INVALID_PARAMETER
;
591 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
593 if (numNonLoopbackInterfaces
> 0) {
594 /* this calculation assumes only one address in the IP_ADDR_STRING lists.
595 that's okay, because:
596 - we don't get multiple addresses per adapter anyway
597 - we don't know about per-adapter gateways
598 - DHCP and WINS servers can have max one entry per list */
599 ULONG size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
601 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
603 ret
= ERROR_BUFFER_OVERFLOW
;
606 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
609 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
610 if (*pOutBufLen
< size
) {
612 ret
= ERROR_INSUFFICIENT_BUFFER
;
617 BOOL winsEnabled
= FALSE
;
618 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
620 memset(pAdapterInfo
, 0, size
);
621 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
622 "Software\\Wine\\Wine\\Config\\Network", 0, KEY_READ
,
623 &hKey
) == ERROR_SUCCESS
) {
624 DWORD size
= sizeof(primaryWINS
.String
);
627 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
628 (PBYTE
)primaryWINS
.String
, &size
);
629 addr
= inet_addr(primaryWINS
.String
);
630 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
632 size
= sizeof(secondaryWINS
.String
);
633 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
634 (PBYTE
)secondaryWINS
.String
, &size
);
635 addr
= inet_addr(secondaryWINS
.String
);
636 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
640 TRACE("num of index is %lu\n", table
->numIndexes
);
641 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
642 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
643 DWORD addrLen
= sizeof(ptr
->Address
), type
;
645 getInterfaceNameByIndex(table
->indexes
[ndx
]);
647 /* on Win98 this is left empty, but whatever */
649 strncpy(ptr
->AdapterName
,ifname
,sizeof(ptr
->AdapterName
));
650 consumeInterfaceName(ifname
);
651 ptr
->AdapterName
[MAX_ADAPTER_NAME_LENGTH
] = '\0';
652 getInterfacePhysicalByIndex(table
->indexes
[ndx
], &addrLen
,
653 ptr
->Address
, &type
);
654 /* MS defines address length and type as UINT in some places and
655 DWORD in others, **sigh**. Don't want to assume that PUINT and
656 PDWORD are equiv (64-bit?) */
657 ptr
->AddressLength
= addrLen
;
659 ptr
->Index
= table
->indexes
[ndx
];
660 toIPAddressString(getInterfaceIPAddrByIndex(table
->indexes
[ndx
]),
661 ptr
->IpAddressList
.IpAddress
.String
);
662 toIPAddressString(getInterfaceMaskByIndex(table
->indexes
[ndx
]),
663 ptr
->IpAddressList
.IpMask
.String
);
664 toIPAddressString(getInterfaceGatewayByIndex(table
->indexes
[ndx
]),
665 ptr
->GatewayList
.IpAddress
.String
);
666 getDhcpInfoForAdapter(table
->indexes
[ndx
], &dhcpEnabled
,
667 &dhcpServer
, &ptr
->LeaseObtained
,
669 ptr
->DhcpEnabled
= (DWORD
) dhcpEnabled
;
670 toIPAddressString(dhcpServer
,
671 ptr
->DhcpServer
.IpAddress
.String
);
673 ptr
->HaveWins
= TRUE
;
674 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
675 primaryWINS
.String
, sizeof(primaryWINS
.String
));
676 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
677 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
679 if (ndx
< table
->numIndexes
- 1)
680 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
689 ret
= ERROR_OUTOFMEMORY
;
695 TRACE("returning %ld\n", ret
);
700 /******************************************************************
701 * GetBestInterface (IPHLPAPI.@)
707 * pdwBestIfIndex [In/Out]
714 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
718 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr
, pdwBestIfIndex
);
720 ret
= ERROR_INVALID_PARAMETER
;
722 MIB_IPFORWARDROW ipRow
;
724 ret
= GetBestRoute(dwDestAddr
, 0, &ipRow
);
725 if (ret
== ERROR_SUCCESS
)
726 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
728 TRACE("returning %ld\n", ret
);
733 /******************************************************************
734 * GetBestRoute (IPHLPAPI.@)
748 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
750 PMIB_IPFORWARDTABLE table
;
753 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr
,
754 dwSourceAddr
, pBestRoute
);
756 return ERROR_INVALID_PARAMETER
;
758 AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
760 DWORD ndx
, matchedBits
, matchedNdx
= 0;
762 for (ndx
= 0, matchedBits
= 0; ndx
< table
->dwNumEntries
; ndx
++) {
763 if ((dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
764 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
765 DWORD numShifts
, mask
;
767 for (numShifts
= 0, mask
= table
->table
[ndx
].dwForwardMask
;
768 mask
&& !(mask
& 1); mask
>>= 1, numShifts
++)
770 if (numShifts
> matchedBits
) {
771 matchedBits
= numShifts
;
776 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
777 HeapFree(GetProcessHeap(), 0, table
);
781 ret
= ERROR_OUTOFMEMORY
;
782 TRACE("returning %ld\n", ret
);
787 /******************************************************************
788 * GetFriendlyIfIndex (IPHLPAPI.@)
800 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
802 /* windows doesn't validate these, either, just makes sure the top byte is
803 cleared. I assume my ifenum module never gives an index with the top
805 TRACE("returning %ld\n", IfIndex
);
810 /******************************************************************
811 * GetIcmpStatistics (IPHLPAPI.@)
823 DWORD WINAPI
GetIcmpStatistics(PMIB_ICMP pStats
)
827 TRACE("pStats %p\n", pStats
);
828 ret
= getICMPStats(pStats
);
829 TRACE("returning %ld\n", ret
);
834 /******************************************************************
835 * GetIfEntry (IPHLPAPI.@)
847 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
852 TRACE("pIfRow %p\n", pIfRow
);
854 return ERROR_INVALID_PARAMETER
;
856 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
);
858 ret
= getInterfaceEntryByIndex(pIfRow
->dwIndex
, pIfRow
);
860 ret
= getInterfaceStatsByName(name
, pIfRow
);
861 consumeInterfaceName(name
);
864 ret
= ERROR_INVALID_DATA
;
865 TRACE("returning %ld\n", ret
);
870 static int IfTableSorter(const void *a
, const void *b
)
875 ret
= ((PMIB_IFROW
)a
)->dwIndex
- ((PMIB_IFROW
)b
)->dwIndex
;
882 /******************************************************************
883 * GetIfTable (IPHLPAPI.@)
897 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
901 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize
, pdwSize
,
904 ret
= ERROR_INVALID_PARAMETER
;
906 DWORD numInterfaces
= getNumInterfaces();
907 TRACE("GetIfTable: numInterfaces = %d\n", (int)numInterfaces
);
908 ULONG size
= sizeof(MIB_IFTABLE
) + (numInterfaces
- 1) * sizeof(MIB_IFROW
);
910 if (!pIfTable
|| *pdwSize
< size
) {
912 ret
= ERROR_INSUFFICIENT_BUFFER
;
915 InterfaceIndexTable
*table
= getInterfaceIndexTable();
918 size
= sizeof(MIB_IFTABLE
) + (table
->numIndexes
- 1) *
920 if (*pdwSize
< size
) {
922 ret
= ERROR_INSUFFICIENT_BUFFER
;
927 pIfTable
->dwNumEntries
= 0;
928 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
929 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
930 GetIfEntry(&pIfTable
->table
[ndx
]);
931 pIfTable
->dwNumEntries
++;
934 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
941 ret
= ERROR_OUTOFMEMORY
;
944 TRACE("returning %ld\n", ret
);
949 /******************************************************************
950 * GetInterfaceInfo (IPHLPAPI.@)
956 * dwOutBufLen [In/Out]
963 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
967 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
969 ret
= ERROR_INVALID_PARAMETER
;
971 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
972 TRACE("numNonLoopbackInterfaces == 0x%x\n", numNonLoopbackInterfaces
);
973 ULONG size
= sizeof(IP_INTERFACE_INFO
) + (numNonLoopbackInterfaces
) *
974 sizeof(IP_ADAPTER_INDEX_MAP
);
976 if (!pIfTable
|| *dwOutBufLen
< size
) {
978 ret
= ERROR_INSUFFICIENT_BUFFER
;
981 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
982 TRACE("table->numIndexes == 0x%x\n", table
->numIndexes
);
985 size
= sizeof(IP_INTERFACE_INFO
) + (table
->numIndexes
) *
986 sizeof(IP_ADAPTER_INDEX_MAP
);
987 if (*dwOutBufLen
< size
) {
989 ret
= ERROR_INSUFFICIENT_BUFFER
;
994 pIfTable
->NumAdapters
= 0;
995 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
996 const char *walker
, *name
;
999 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1000 name
= getInterfaceNameByIndex(table
->indexes
[ndx
]);
1001 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1002 walker
&& *walker
&&
1003 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1004 walker
++, assigner
++)
1005 *assigner
= *walker
;
1007 consumeInterfaceName(name
);
1008 pIfTable
->NumAdapters
++;
1015 ret
= ERROR_OUTOFMEMORY
;
1018 TRACE("returning %ld\n", ret
);
1023 static int IpAddrTableSorter(const void *a
, const void *b
)
1028 ret
= ((PMIB_IPADDRROW
)a
)->dwAddr
- ((PMIB_IPADDRROW
)b
)->dwAddr
;
1035 /******************************************************************
1036 * GetIpAddrTable (IPHLPAPI.@)
1041 * pIpAddrTable [In/Out]
1050 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1054 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable
, pdwSize
,
1057 ret
= ERROR_INVALID_PARAMETER
;
1059 DWORD numInterfaces
= getNumInterfaces();
1060 ULONG size
= sizeof(MIB_IPADDRTABLE
) + (numInterfaces
- 1) *
1061 sizeof(MIB_IPADDRROW
);
1063 if (!pIpAddrTable
|| *pdwSize
< size
) {
1065 ret
= ERROR_INSUFFICIENT_BUFFER
;
1068 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1071 size
= sizeof(MIB_IPADDRTABLE
) + (table
->numIndexes
- 1) *
1072 sizeof(MIB_IPADDRROW
);
1073 if (*pdwSize
< size
) {
1075 ret
= ERROR_INSUFFICIENT_BUFFER
;
1080 pIpAddrTable
->dwNumEntries
= 0;
1081 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1082 pIpAddrTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1083 pIpAddrTable
->table
[ndx
].dwAddr
=
1084 getInterfaceIPAddrByIndex(table
->indexes
[ndx
]);
1085 pIpAddrTable
->table
[ndx
].dwMask
=
1086 getInterfaceMaskByIndex(table
->indexes
[ndx
]);
1087 /* the dwBCastAddr member isn't the broadcast address, it indicates
1088 * whether the interface uses the 1's broadcast address (1) or the
1089 * 0's broadcast address (0).
1091 bcast
= getInterfaceBCastAddrByIndex(table
->indexes
[ndx
]);
1092 pIpAddrTable
->table
[ndx
].dwBCastAddr
=
1093 (bcast
& pIpAddrTable
->table
[ndx
].dwMask
) ? 1 : 0;
1094 /* FIXME: hardcoded reasm size, not sure where to get it */
1095 pIpAddrTable
->table
[ndx
].dwReasmSize
= 65535;
1096 pIpAddrTable
->table
[ndx
].unused1
= 0;
1097 pIpAddrTable
->table
[ndx
].wType
= 0; /* aka unused2 */
1098 pIpAddrTable
->dwNumEntries
++;
1101 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1102 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1108 ret
= ERROR_OUTOFMEMORY
;
1111 TRACE("returning %ld\n", ret
);
1116 static int IpForwardTableSorter(const void *a
, const void *b
)
1121 PMIB_IPFORWARDROW rowA
= (PMIB_IPFORWARDROW
)a
, rowB
= (PMIB_IPFORWARDROW
)b
;
1123 ret
= rowA
->dwForwardDest
- rowB
->dwForwardDest
;
1125 ret
= rowA
->dwForwardProto
- rowB
->dwForwardProto
;
1127 ret
= rowA
->dwForwardPolicy
- rowB
->dwForwardPolicy
;
1129 ret
= rowA
->dwForwardNextHop
- rowB
->dwForwardNextHop
;
1139 /******************************************************************
1140 * GetIpForwardTable (IPHLPAPI.@)
1145 * pIpForwardTable [In/Out]
1154 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1158 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable
,
1159 pdwSize
, (DWORD
)bOrder
);
1161 ret
= ERROR_INVALID_PARAMETER
;
1163 DWORD numRoutes
= getNumRoutes();
1164 ULONG sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (numRoutes
- 1) *
1165 sizeof(MIB_IPFORWARDROW
);
1167 if (!pIpForwardTable
|| *pdwSize
< sizeNeeded
) {
1168 *pdwSize
= sizeNeeded
;
1169 ret
= ERROR_INSUFFICIENT_BUFFER
;
1172 RouteTable
*table
= getRouteTable();
1174 sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (table
->numRoutes
- 1) *
1175 sizeof(MIB_IPFORWARDROW
);
1176 if (*pdwSize
< sizeNeeded
) {
1177 *pdwSize
= sizeNeeded
;
1178 ret
= ERROR_INSUFFICIENT_BUFFER
;
1183 pIpForwardTable
->dwNumEntries
= table
->numRoutes
;
1184 for (ndx
= 0; ndx
< numRoutes
; ndx
++) {
1185 pIpForwardTable
->table
[ndx
].dwForwardIfIndex
=
1186 table
->routes
[ndx
].ifIndex
+ 1;
1187 pIpForwardTable
->table
[ndx
].dwForwardDest
=
1188 table
->routes
[ndx
].dest
;
1189 pIpForwardTable
->table
[ndx
].dwForwardMask
=
1190 table
->routes
[ndx
].mask
;
1191 pIpForwardTable
->table
[ndx
].dwForwardPolicy
= 0;
1192 pIpForwardTable
->table
[ndx
].dwForwardNextHop
=
1193 table
->routes
[ndx
].gateway
;
1194 /* FIXME: this type is appropriate for local interfaces; may not
1195 always be appropriate */
1196 pIpForwardTable
->table
[ndx
].dwForwardType
= MIB_IPROUTE_TYPE_DIRECT
;
1197 /* FIXME: other protos might be appropriate, e.g. the default route
1198 is typically set with MIB_IPPROTO_NETMGMT instead */
1199 pIpForwardTable
->table
[ndx
].dwForwardProto
= MIB_IPPROTO_LOCAL
;
1200 /* punt on age and AS */
1201 pIpForwardTable
->table
[ndx
].dwForwardAge
= 0;
1202 pIpForwardTable
->table
[ndx
].dwForwardNextHopAS
= 0;
1203 pIpForwardTable
->table
[ndx
].dwForwardMetric1
=
1204 table
->routes
[ndx
].metric
;
1205 /* rest of the metrics are 0.. */
1206 pIpForwardTable
->table
[ndx
].dwForwardMetric2
= 0;
1207 pIpForwardTable
->table
[ndx
].dwForwardMetric3
= 0;
1208 pIpForwardTable
->table
[ndx
].dwForwardMetric4
= 0;
1209 pIpForwardTable
->table
[ndx
].dwForwardMetric5
= 0;
1212 qsort(pIpForwardTable
->table
, pIpForwardTable
->dwNumEntries
,
1213 sizeof(MIB_IPFORWARDROW
), IpForwardTableSorter
);
1216 HeapFree(GetProcessHeap(), 0, table
);
1219 ret
= ERROR_OUTOFMEMORY
;
1222 TRACE("returning %ld\n", ret
);
1227 static int IpNetTableSorter(const void *a
, const void *b
)
1232 ret
= ((PMIB_IPNETROW
)a
)->dwAddr
- ((PMIB_IPNETROW
)b
)->dwAddr
;
1239 /******************************************************************
1240 * GetIpNetTable (IPHLPAPI.@)
1245 * pIpNetTable [In/Out]
1254 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
1258 TRACE("pIpNetTable %p, pdwSize %p, bOrder %ld\n", pIpNetTable
, pdwSize
,
1261 ret
= ERROR_INVALID_PARAMETER
;
1263 DWORD numEntries
= getNumArpEntries();
1264 ULONG size
= sizeof(MIB_IPNETTABLE
) + (numEntries
- 1) *
1265 sizeof(MIB_IPNETROW
);
1267 if (!pIpNetTable
|| *pdwSize
< size
) {
1269 ret
= ERROR_INSUFFICIENT_BUFFER
;
1272 PMIB_IPNETTABLE table
= getArpTable();
1275 size
= sizeof(MIB_IPNETTABLE
) + (table
->dwNumEntries
- 1) *
1276 sizeof(MIB_IPNETROW
);
1277 if (*pdwSize
< size
) {
1279 ret
= ERROR_INSUFFICIENT_BUFFER
;
1282 memcpy(pIpNetTable
, table
, size
);
1284 qsort(pIpNetTable
->table
, pIpNetTable
->dwNumEntries
,
1285 sizeof(MIB_IPNETROW
), IpNetTableSorter
);
1291 ret
= ERROR_OUTOFMEMORY
;
1294 TRACE("returning %ld\n", ret
);
1299 /******************************************************************
1300 * GetIpStatistics (IPHLPAPI.@)
1312 DWORD WINAPI
GetIpStatistics(PMIB_IPSTATS pStats
)
1314 return GetIpStatisticsEx(pStats
, PF_INET
);
1317 /******************************************************************
1318 * GetIpStatisticsEx (IPHLPAPI.@)
1331 DWORD WINAPI
GetIpStatisticsEx(PMIB_IPSTATS pStats
, DWORD dwFamily
)
1335 TRACE("pStats %p\n", pStats
);
1336 ret
= getIPStats(pStats
, dwFamily
);
1337 TRACE("returning %ld\n", ret
);
1341 /******************************************************************
1342 * GetNetworkParams (IPHLPAPI.@)
1347 * pFixedInfo [In/Out]
1348 * pOutBufLen [In/Out]
1355 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
1360 PIPHLP_RES_INFO resInfo
;
1362 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
1364 return ERROR_INVALID_PARAMETER
;
1366 resInfo
= getResInfo();
1368 return ERROR_OUTOFMEMORY
;
1370 size
= sizeof(FIXED_INFO
) + (resInfo
->riCount
> 0 ? (resInfo
->riCount
- 1) *
1371 sizeof(IP_ADDR_STRING
) : 0);
1372 if (!pFixedInfo
|| *pOutBufLen
< size
) {
1374 disposeResInfo( resInfo
);
1375 return ERROR_BUFFER_OVERFLOW
;
1378 memset(pFixedInfo
, 0, size
);
1379 size
= sizeof(pFixedInfo
->HostName
);
1380 GetComputerNameExA(ComputerNameDnsHostname
, pFixedInfo
->HostName
, &size
);
1381 size
= sizeof(pFixedInfo
->DomainName
);
1382 GetComputerNameExA(ComputerNameDnsDomain
, pFixedInfo
->DomainName
, &size
);
1384 TRACE("GetComputerNameExA: %s\n", pFixedInfo
->DomainName
);
1386 if (resInfo
->riCount
> 0) {
1387 PIP_ADDR_STRING ptr
;
1390 for (i
= 0, ptr
= &pFixedInfo
->DnsServerList
; i
< resInfo
->riCount
&& ptr
;
1391 i
++, ptr
= ptr
->Next
) {
1392 struct sockaddr_in
*addr_v4
=
1393 (struct sockaddr_in
*)&resInfo
->riAddressList
[i
];
1395 (addr_v4
->sin_addr
.s_addr
,
1396 ptr
->IpAddress
.String
);
1397 if (i
== resInfo
->riCount
- 1)
1400 ptr
->Next
= (PIP_ADDR_STRING
)((LPBYTE
)pFixedInfo
+ sizeof(FIXED_INFO
));
1402 ptr
->Next
= (PIP_ADDR_STRING
)((PBYTE
)ptr
+ sizeof(IP_ADDR_STRING
));
1405 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
1406 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1407 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
1408 if (regReturn
!= ERROR_SUCCESS
)
1409 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1410 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
1412 if (regReturn
== ERROR_SUCCESS
)
1414 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
1416 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (PBYTE
)pFixedInfo
->ScopeId
, &size
);
1420 disposeResInfo( resInfo
);
1421 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1422 I suppose could also check for a listener on port 53 to set EnableDns */
1424 TRACE("returning %ld\n", ret
);
1430 /******************************************************************
1431 * GetNumberOfInterfaces (IPHLPAPI.@)
1443 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
1447 TRACE("pdwNumIf %p\n", pdwNumIf
);
1449 ret
= ERROR_INVALID_PARAMETER
;
1451 *pdwNumIf
= getNumInterfaces();
1454 TRACE("returning %ld\n", ret
);
1459 /******************************************************************
1460 * GetPerAdapterInfo (IPHLPAPI.@)
1466 * pPerAdapterInfo [In/Out]
1467 * pOutBufLen [In/Out]
1474 static void CreateNameServerListEnumNamesFunc( PWCHAR Interface
, PWCHAR Server
, PVOID Data
)
1476 IP_ADDR_STRING
*pNext
;
1477 PNAME_SERVER_LIST_CONTEXT Context
= (PNAME_SERVER_LIST_CONTEXT
)Data
;
1479 if (!Context
->NumServers
)
1481 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
1483 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, Context
->pData
->DnsServerList
.IpAddress
.String
, 16, NULL
, NULL
);
1484 Context
->pData
->DnsServerList
.IpAddress
.String
[15] = '\0';
1485 Context
->pLastAddr
= &Context
->pData
->DnsServerList
;
1490 Context
->uSizeRequired
+= sizeof(IP_ADDR_STRING
);
1491 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
1493 pNext
= ((char*)Context
->pLastAddr
) + sizeof(IP_ADDR_STRING
);
1494 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, pNext
->IpAddress
.String
, 16, NULL
, NULL
);
1495 pNext
->IpAddress
.String
[15] = '\0';
1496 Context
->pLastAddr
->Next
= pNext
;
1497 Context
->pLastAddr
= pNext
;
1501 Context
->NumServers
++;
1504 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
1509 NAME_SERVER_LIST_CONTEXT Context
;
1510 WCHAR keyname
[200] = L
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
1513 return ERROR_INVALID_PARAMETER
;
1515 ifName
= getInterfaceNameByIndex(IfIndex
);
1517 return ERROR_INVALID_PARAMETER
;
1519 MultiByteToWideChar(CP_ACP
, 0, ifName
, -1, &keyname
[62], sizeof(keyname
)/sizeof(WCHAR
) - 63);
1520 HeapFree(GetProcessHeap(), 0, (LPVOID
)ifName
);
1522 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keyname
, 0, KEY_READ
, &hkey
) != ERROR_SUCCESS
)
1524 return ERROR_NOT_SUPPORTED
;
1526 Context
.NumServers
= 0;
1527 Context
.uSizeAvailable
= *pOutBufLen
;
1528 Context
.uSizeRequired
= sizeof(IP_PER_ADAPTER_INFO
);
1529 Context
.pData
= pPerAdapterInfo
;
1531 if (*pOutBufLen
>= sizeof(IP_PER_ADAPTER_INFO
))
1532 ZeroMemory(pPerAdapterInfo
, sizeof(IP_PER_ADAPTER_INFO
));
1534 EnumNameServers(hkey
, &keyname
[62], &Context
, CreateNameServerListEnumNamesFunc
);
1536 if (Context
.uSizeRequired
> Context
.uSizeAvailable
)
1538 *pOutBufLen
= Context
.uSizeRequired
;
1540 return ERROR_BUFFER_OVERFLOW
;
1543 if(RegQueryValueExW(hkey
, L
"DHCPNameServer", NULL
, NULL
, NULL
, &dwSize
) == ERROR_SUCCESS
)
1545 pPerAdapterInfo
->AutoconfigActive
= TRUE
;
1553 /******************************************************************
1554 * GetRTTAndHopCount (IPHLPAPI.@)
1559 * DestIpAddress [In]
1569 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
1571 TRACE("DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p\n",
1572 DestIpAddress
, HopCount
, MaxHops
, RTT
);
1578 /******************************************************************
1579 * GetTcpStatisticsEx (IPHLPAPI.@)
1592 DWORD WINAPI
GetTcpStatisticsEx(PMIB_TCPSTATS pStats
, DWORD dwFamily
)
1596 TRACE("pStats %p\n", pStats
);
1597 ret
= getTCPStats(pStats
, dwFamily
);
1598 TRACE("returning %ld\n", ret
);
1602 /******************************************************************
1603 * GetTcpStatistics (IPHLPAPI.@)
1615 DWORD WINAPI
GetTcpStatistics(PMIB_TCPSTATS pStats
)
1617 return GetTcpStatisticsEx(pStats
, PF_INET
);
1621 static int TcpTableSorter(const void *a
, const void *b
)
1626 PMIB_TCPROW rowA
= (PMIB_TCPROW
)a
, rowB
= (PMIB_TCPROW
)b
;
1628 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1630 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1632 ret
= rowA
->dwRemoteAddr
- rowB
->dwRemoteAddr
;
1634 ret
= rowA
->dwRemotePort
- rowB
->dwRemotePort
;
1644 /******************************************************************
1645 * GetTcpTable (IPHLPAPI.@)
1650 * pTcpTable [In/Out]
1659 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
1663 TRACE("pTcpTable %p, pdwSize %p, bOrder %ld\n", pTcpTable
, pdwSize
,
1666 ret
= ERROR_INVALID_PARAMETER
;
1668 DWORD numEntries
= getNumTcpEntries();
1669 ULONG size
= sizeof(MIB_TCPTABLE
) + (numEntries
- 1) * sizeof(MIB_TCPROW
);
1671 if (!pTcpTable
|| *pdwSize
< size
) {
1673 ret
= ERROR_INSUFFICIENT_BUFFER
;
1676 PMIB_TCPTABLE table
= getTcpTable();
1679 size
= sizeof(MIB_TCPTABLE
) + (table
->dwNumEntries
- 1) *
1681 if (*pdwSize
< size
) {
1683 ret
= ERROR_INSUFFICIENT_BUFFER
;
1686 memcpy(pTcpTable
, table
, size
);
1688 qsort(pTcpTable
->table
, pTcpTable
->dwNumEntries
,
1689 sizeof(MIB_TCPROW
), TcpTableSorter
);
1695 ret
= ERROR_OUTOFMEMORY
;
1698 TRACE("returning %ld\n", ret
);
1703 /******************************************************************
1704 * GetUdpStatisticsEx (IPHLPAPI.@)
1717 DWORD WINAPI
GetUdpStatisticsEx(PMIB_UDPSTATS pStats
, DWORD dwFamily
)
1721 TRACE("pStats %p\n", pStats
);
1722 ret
= getUDPStats(pStats
, dwFamily
);
1723 TRACE("returning %ld\n", ret
);
1727 /******************************************************************
1728 * GetUdpStatistics (IPHLPAPI.@)
1740 DWORD WINAPI
GetUdpStatistics(PMIB_UDPSTATS pStats
)
1742 return GetUdpStatisticsEx(pStats
, PF_INET
);
1746 static int UdpTableSorter(const void *a
, const void *b
)
1751 PMIB_UDPROW rowA
= (PMIB_UDPROW
)a
, rowB
= (PMIB_UDPROW
)b
;
1753 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1755 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1763 /******************************************************************
1764 * GetUdpTable (IPHLPAPI.@)
1769 * pUdpTable [In/Out]
1778 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
1782 TRACE("pUdpTable %p, pdwSize %p, bOrder %ld\n", pUdpTable
, pdwSize
,
1785 ret
= ERROR_INVALID_PARAMETER
;
1787 DWORD numEntries
= getNumUdpEntries();
1788 ULONG size
= sizeof(MIB_UDPTABLE
) + (numEntries
- 1) * sizeof(MIB_UDPROW
);
1790 if (!pUdpTable
|| *pdwSize
< size
) {
1792 ret
= ERROR_INSUFFICIENT_BUFFER
;
1795 PMIB_UDPTABLE table
= getUdpTable();
1798 size
= sizeof(MIB_UDPTABLE
) + (table
->dwNumEntries
- 1) *
1800 if (*pdwSize
< size
) {
1802 ret
= ERROR_INSUFFICIENT_BUFFER
;
1805 memcpy(pUdpTable
, table
, size
);
1807 qsort(pUdpTable
->table
, pUdpTable
->dwNumEntries
,
1808 sizeof(MIB_UDPROW
), UdpTableSorter
);
1814 ret
= ERROR_OUTOFMEMORY
;
1817 TRACE("returning %ld\n", ret
);
1822 /******************************************************************
1823 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1828 * pIPIfInfo [In/Out]
1829 * dwOutBufLen [In/Out]
1836 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
1838 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
1839 /* a unidirectional adapter?? not bloody likely! */
1840 return ERROR_NOT_SUPPORTED
;
1844 /******************************************************************
1845 * IpReleaseAddress (IPHLPAPI.@)
1850 * AdapterInfo [In/Out]
1857 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1859 TRACE("AdapterInfo %p\n", AdapterInfo
);
1860 /* not a stub, never going to support this (and I never mark an adapter as
1861 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1862 return ERROR_NOT_SUPPORTED
;
1866 /******************************************************************
1867 * IpRenewAddress (IPHLPAPI.@)
1872 * AdapterInfo [In/Out]
1879 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1881 TRACE("AdapterInfo %p\n", AdapterInfo
);
1882 /* not a stub, never going to support this (and I never mark an adapter as
1883 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1884 return ERROR_NOT_SUPPORTED
;
1888 /******************************************************************
1889 * NotifyAddrChange (IPHLPAPI.@)
1895 * overlapped [In/Out]
1902 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
1904 TRACE("Handle %p, overlapped %p\n", Handle
, overlapped
);
1906 /* marking Win2K+ functions not supported */
1907 return ERROR_NOT_SUPPORTED
;
1911 /******************************************************************
1912 * NotifyRouteChange (IPHLPAPI.@)
1918 * overlapped [In/Out]
1925 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
1927 TRACE("Handle %p, overlapped %p\n", Handle
, overlapped
);
1929 /* marking Win2K+ functions not supported */
1930 return ERROR_NOT_SUPPORTED
;
1934 /******************************************************************
1935 * SendARP (IPHLPAPI.@)
1943 * PhyAddrLen [In/Out]
1950 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
1952 TRACE("DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p\n", DestIP
,
1953 SrcIP
, pMacAddr
, PhyAddrLen
);
1955 /* marking Win2K+ functions not supported */
1956 return ERROR_NOT_SUPPORTED
;
1960 /******************************************************************
1961 * SetIfEntry (IPHLPAPI.@)
1973 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
1975 TRACE("pIfRow %p\n", pIfRow
);
1976 /* this is supposed to set an administratively interface up or down.
1977 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1978 this sort of down is indistinguishable from other sorts of down (e.g. no
1981 return ERROR_NOT_SUPPORTED
;
1985 /******************************************************************
1986 * SetIpForwardEntry (IPHLPAPI.@)
1998 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
2000 return setIpForwardEntry( pRoute
);
2004 /******************************************************************
2005 * SetIpNetEntry (IPHLPAPI.@)
2010 * pArpEntry [In/Out]
2017 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
2019 TRACE("pArpEntry %p\n", pArpEntry
);
2020 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
2026 /******************************************************************
2027 * SetIpStatistics (IPHLPAPI.@)
2039 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
2041 TRACE("pIpStats %p\n", pIpStats
);
2047 /******************************************************************
2048 * SetIpTTL (IPHLPAPI.@)
2060 DWORD WINAPI
SetIpTTL(UINT nTTL
)
2062 TRACE("nTTL %d\n", nTTL
);
2063 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
2064 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
2070 /******************************************************************
2071 * SetTcpEntry (IPHLPAPI.@)
2083 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
2085 TRACE("pTcpRow %p\n", pTcpRow
);
2091 /******************************************************************
2092 * UnenableRouter (IPHLPAPI.@)
2097 * pOverlapped [In/Out]
2098 * lpdwEnableCount [In/Out]
2105 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
2107 TRACE("pOverlapped %p, lpdwEnableCount %p\n", pOverlapped
, lpdwEnableCount
);
2109 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
2110 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
2111 marking Win2K+ functions not supported */
2112 return ERROR_NOT_SUPPORTED
;
2118 DWORD WINAPI
GetIpErrorString(IP_STATUS ErrorCode
,PWCHAR Buffer
,PDWORD Size
)
2128 PIP_ADAPTER_ORDER_MAP WINAPI
GetAdapterOrderMap(VOID
)
2137 DWORD WINAPI
GetAdaptersAddresses(ULONG Family
,DWORD Flags
,PVOID Reserved
,PIP_ADAPTER_ADDRESSES pAdapterAddresses
,PULONG pOutBufLen
)
2146 BOOL WINAPI
CancelIPChangeNotify(LPOVERLAPPED notifyOverlapped
)
2155 DWORD WINAPI
GetBestInterfaceEx(struct sockaddr
*pDestAddr
,PDWORD pdwBestIfIndex
)
2164 DWORD WINAPI
NhpAllocateAndGetInterfaceInfoFromStack(IP_INTERFACE_NAME_INFO
**ppTable
,PDWORD pdwCount
,BOOL bOrder
,HANDLE hHeap
,DWORD dwFlags
)
2173 DWORD WINAPI
GetIcmpStatisticsEx(PMIB_ICMP_EX pStats
,DWORD dwFamily
)