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
25 #include <sys/types.h>
26 #ifdef HAVE_NETINET_IN_H
27 # include <netinet/in.h>
29 #ifdef HAVE_ARPA_INET_H
30 # include <arpa/inet.h>
32 #ifdef HAVE_ARPA_NAMESER_H
33 # include <arpa/nameser.h>
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
50 #define INADDR_NONE ~0UL
53 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
56 case DLL_PROCESS_ATTACH:
57 DisableThreadLibraryCalls( hinstDLL );
61 case DLL_PROCESS_DETACH:
68 /******************************************************************
69 * AddIPAddress (IPHLPAPI.@)
71 * Add an IP address to an adapter.
74 * Address [In] IP address to add to the adapter
75 * IpMask [In] subnet mask for the IP address
76 * IfIndex [In] adapter index to add the address
77 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
78 * NTEInstance [Out] NTE instance for the IP address
82 * Failure: error code from winerror.h
85 * Stub. Currently returns ERROR_NOT_SUPPORTED.
87 DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
90 return ERROR_NOT_SUPPORTED;
94 /******************************************************************
95 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
97 * Get table of local interfaces.
98 * Like GetIfTable(), but allocate the returned table from heap.
101 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
102 * allocated and returned.
103 * bOrder [In] passed to GetIfTable() to order the table
104 * heap [In] heap from which the table is allocated
105 * flags [In] flags to HeapAlloc
108 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
109 * GetIfTable() returns otherwise.
111 DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
112 BOOL bOrder, HANDLE heap, DWORD flags)
116 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08lx\n", ppIfTable,
117 bOrder, heap, flags);
119 ret = ERROR_INVALID_PARAMETER;
123 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
124 if (ret == ERROR_INSUFFICIENT_BUFFER) {
125 *ppIfTable = HeapAlloc(heap, flags, dwSize);
126 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
129 TRACE("returning %ld\n", ret);
134 /******************************************************************
135 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
137 * Get interface-to-IP address mapping table.
138 * Like GetIpAddrTable(), but allocate the returned table from heap.
141 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
142 * allocated and returned.
143 * bOrder [In] passed to GetIpAddrTable to order the table
144 * heap [In] heap from which the table is allocated
145 * flags [In] flags to HeapAlloc
148 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, whatever GetIpAddrTable()
151 DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
152 BOOL bOrder, HANDLE heap, DWORD flags)
156 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
157 ppIpAddrTable, bOrder, heap, flags);
159 ret = ERROR_INVALID_PARAMETER;
163 ret = GetIpAddrTable(*ppIpAddrTable, &dwSize, bOrder);
164 if (ret == ERROR_INSUFFICIENT_BUFFER) {
165 *ppIpAddrTable = HeapAlloc(heap, flags, dwSize);
166 ret = GetIpAddrTable(*ppIpAddrTable, &dwSize, bOrder);
169 TRACE("returning %ld\n", ret);
174 /******************************************************************
175 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
177 * Get the route table.
178 * Like GetIpForwardTable(), but allocate the returned table from heap.
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
188 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
189 * GetIpForwardTable() returns otherwise.
191 DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
192 ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags)
196 TRACE("ppIpForwardTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
197 ppIpForwardTable, bOrder, heap, flags);
198 if (!ppIpForwardTable)
199 ret = ERROR_INVALID_PARAMETER;
203 ret = GetIpForwardTable(*ppIpForwardTable, &dwSize, bOrder);
204 if (ret == ERROR_INSUFFICIENT_BUFFER) {
205 *ppIpForwardTable = HeapAlloc(heap, flags, dwSize);
206 ret = GetIpForwardTable(*ppIpForwardTable, &dwSize, bOrder);
209 TRACE("returning %ld\n", ret);
214 /******************************************************************
215 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
217 * Get the IP-to-physical address mapping table.
218 * Like GetIpNetTable(), but allocate the returned table from heap.
221 * ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE is
222 * allocated and returned.
223 * bOrder [In] passed to GetIpNetTable to order the table
224 * heap [In] heap from which the table is allocated
225 * flags [In] flags to HeapAlloc
228 * ERROR_INVALID_PARAMETER if ppIpNetTable is NULL, whatever GetIpNetTable()
231 DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable,
232 BOOL bOrder, HANDLE heap, DWORD flags)
236 TRACE("ppIpNetTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
237 ppIpNetTable, bOrder, heap, flags);
239 ret = ERROR_INVALID_PARAMETER;
243 ret = GetIpNetTable(*ppIpNetTable, &dwSize, bOrder);
244 if (ret == ERROR_INSUFFICIENT_BUFFER) {
245 *ppIpNetTable = HeapAlloc(heap, flags, dwSize);
246 ret = GetIpNetTable(*ppIpNetTable, &dwSize, bOrder);
249 TRACE("returning %ld\n", ret);
254 /******************************************************************
255 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
257 * Get the TCP connection table.
258 * Like GetTcpTable(), but allocate the returned table from heap.
261 * ppTcpTable [Out] pointer into which the MIB_TCPTABLE is
262 * allocated and returned.
263 * bOrder [In] passed to GetTcpTable to order the table
264 * heap [In] heap from which the table is allocated
265 * flags [In] flags to HeapAlloc
268 * ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable()
271 DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
272 BOOL bOrder, HANDLE heap, DWORD flags)
276 TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
277 ppTcpTable, bOrder, heap, flags);
279 ret = ERROR_INVALID_PARAMETER;
283 ret = GetTcpTable(*ppTcpTable, &dwSize, bOrder);
284 if (ret == ERROR_INSUFFICIENT_BUFFER) {
285 *ppTcpTable = HeapAlloc(heap, flags, dwSize);
286 ret = GetTcpTable(*ppTcpTable, &dwSize, bOrder);
289 TRACE("returning %ld\n", ret);
294 /******************************************************************
295 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
297 * Get the UDP listener table.
298 * Like GetUdpTable(), but allocate the returned table from heap.
301 * ppUdpTable [Out] pointer into which the MIB_UDPTABLE is
302 * allocated and returned.
303 * bOrder [In] passed to GetUdpTable to order the table
304 * heap [In] heap from which the table is allocated
305 * flags [In] flags to HeapAlloc
308 * ERROR_INVALID_PARAMETER if ppUdpTable is NULL, whatever GetUdpTable()
311 DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
312 BOOL bOrder, HANDLE heap, DWORD flags)
316 TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
317 ppUdpTable, bOrder, heap, flags);
319 ret = ERROR_INVALID_PARAMETER;
323 ret = GetUdpTable(*ppUdpTable, &dwSize, bOrder);
324 if (ret == ERROR_INSUFFICIENT_BUFFER) {
325 *ppUdpTable = HeapAlloc(heap, flags, dwSize);
326 ret = GetUdpTable(*ppUdpTable, &dwSize, bOrder);
329 TRACE("returning %ld\n", ret);
334 /******************************************************************
335 * CreateIpForwardEntry (IPHLPAPI.@)
337 * Create a route in the local computer's IP table.
340 * pRoute [In] new route information
344 * Failure: error code from winerror.h
347 * Stub, always returns NO_ERROR.
349 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
351 FIXME("(pRoute %p): stub\n", pRoute);
352 /* could use SIOCADDRT, not sure I want to */
357 /******************************************************************
358 * CreateIpNetEntry (IPHLPAPI.@)
360 * Create entry in the ARP table.
363 * pArpEntry [In] new ARP entry
367 * Failure: error code from winerror.h
370 * Stub, always returns NO_ERROR.
372 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
374 FIXME("(pArpEntry %p)\n", pArpEntry);
375 /* could use SIOCSARP on systems that support it, not sure I want to */
380 /******************************************************************
381 * CreateProxyArpEntry (IPHLPAPI.@)
383 * Create a Proxy ARP (PARP) entry for an IP address.
386 * dwAddress [In] IP address for which this computer acts as a proxy.
387 * dwMask [In] subnet mask for dwAddress
388 * dwIfIndex [In] interface index
392 * Failure: error code from winerror.h
395 * Stub, returns ERROR_NOT_SUPPORTED.
397 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
399 FIXME("(dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx): stub\n",
400 dwAddress, dwMask, dwIfIndex);
401 return ERROR_NOT_SUPPORTED;
405 /******************************************************************
406 * DeleteIPAddress (IPHLPAPI.@)
408 * Delete an IP address added with AddIPAddress().
411 * NTEContext [In] NTE context from AddIPAddress();
415 * Failure: error code from winerror.h
418 * Stub, returns ERROR_NOT_SUPPORTED.
420 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
422 FIXME("(NTEContext %ld): stub\n", NTEContext);
423 return ERROR_NOT_SUPPORTED;
427 /******************************************************************
428 * DeleteIpForwardEntry (IPHLPAPI.@)
433 * pRoute [In] route to delete
437 * Failure: error code from winerror.h
440 * Stub, returns NO_ERROR.
442 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
444 FIXME("(pRoute %p): stub\n", pRoute);
445 /* could use SIOCDELRT, not sure I want to */
450 /******************************************************************
451 * DeleteIpNetEntry (IPHLPAPI.@)
453 * Delete an ARP entry.
456 * pArpEntry [In] ARP entry to delete
460 * Failure: error code from winerror.h
463 * Stub, returns NO_ERROR.
465 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
467 FIXME("(pArpEntry %p): stub\n", pArpEntry);
468 /* could use SIOCDARP on systems that support it, not sure I want to */
473 /******************************************************************
474 * DeleteProxyArpEntry (IPHLPAPI.@)
476 * Delete a Proxy ARP entry.
479 * dwAddress [In] IP address for which this computer acts as a proxy.
480 * dwMask [In] subnet mask for dwAddress
481 * dwIfIndex [In] interface index
485 * Failure: error code from winerror.h
488 * Stub, returns ERROR_NOT_SUPPORTED.
490 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
492 FIXME("(dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx): stub\n",
493 dwAddress, dwMask, dwIfIndex);
494 return ERROR_NOT_SUPPORTED;
498 /******************************************************************
499 * EnableRouter (IPHLPAPI.@)
501 * Turn on ip forwarding.
505 * pOverlapped [In/Out] hEvent member should contain a valid handle.
508 * Success: ERROR_IO_PENDING
509 * Failure: error code from winerror.h
512 * Stub, returns ERROR_NOT_SUPPORTED.
514 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
516 FIXME("(pHandle %p, pOverlapped %p): stub\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
520 return ERROR_NOT_SUPPORTED;
524 /******************************************************************
525 * FlushIpNetTable (IPHLPAPI.@)
527 * Delete all ARP entries of an interface
530 * dwIfIndex [In] interface index
534 * Failure: error code from winerror.h
537 * Stub, returns ERROR_NOT_SUPPORTED.
539 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
541 FIXME("(dwIfIndex 0x%08lx): stub\n", dwIfIndex);
542 /* this flushes the arp cache of the given index */
543 return ERROR_NOT_SUPPORTED;
547 /******************************************************************
548 * GetAdapterIndex (IPHLPAPI.@)
550 * Get interface index from its name.
553 * AdapterName [In] unicode string with the adapter name
554 * IfIndex [Out] returns found interface index
558 * Failure: error code from winerror.h
561 * Stub, returns ERROR_NOT_SUPPORTED.
563 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
565 FIXME("(AdapterName %p, IfIndex %p): stub\n", AdapterName, IfIndex);
566 return ERROR_NOT_SUPPORTED;
570 /******************************************************************
571 * GetAdaptersInfo (IPHLPAPI.@)
573 * Get information about adapters.
576 * pAdapterInfo [Out] buffer for adapter infos
577 * pOutBufLen [In] length of output buffer
581 * Failure: error code from winerror.h
583 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 /* @@ Wine registry key: HKCU\Software\Wine\Network */
622 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network", &hKey) == ERROR_SUCCESS) {
623 DWORD size = sizeof(primaryWINS.String);
626 RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
627 (LPBYTE)primaryWINS.String, &size);
628 addr = inet_addr(primaryWINS.String);
629 if (addr != INADDR_NONE && addr != INADDR_ANY)
631 size = sizeof(secondaryWINS.String);
632 RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
633 (LPBYTE)secondaryWINS.String, &size);
634 addr = inet_addr(secondaryWINS.String);
635 if (addr != INADDR_NONE && addr != INADDR_ANY)
639 for (ndx = 0; ndx < table->numIndexes; ndx++) {
640 PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
641 DWORD addrLen = sizeof(ptr->Address), type;
643 /* on Win98 this is left empty, but whatever */
644 lstrcpynA(ptr->AdapterName,
645 getInterfaceNameByIndex(table->indexes[ndx]),
646 MAX_ADAPTER_NAME_LENGTH+1);
647 getInterfacePhysicalByIndex(table->indexes[ndx], &addrLen,
648 ptr->Address, &type);
649 /* MS defines address length and type as UINT in some places and
650 DWORD in others, **sigh**. Don't want to assume that PUINT and
651 PDWORD are equiv (64-bit?) */
652 ptr->AddressLength = addrLen;
654 ptr->Index = table->indexes[ndx];
655 toIPAddressString(getInterfaceIPAddrByIndex(table->indexes[ndx]),
656 ptr->IpAddressList.IpAddress.String);
657 toIPAddressString(getInterfaceMaskByIndex(table->indexes[ndx]),
658 ptr->IpAddressList.IpMask.String);
660 ptr->HaveWins = TRUE;
661 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
662 primaryWINS.String, sizeof(primaryWINS.String));
663 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
664 secondaryWINS.String, sizeof(secondaryWINS.String));
666 if (ndx < table->numIndexes - 1)
667 ptr->Next = &pAdapterInfo[ndx + 1];
673 HeapFree(GetProcessHeap(), 0, table);
676 ret = ERROR_OUTOFMEMORY;
682 TRACE("returning %ld\n", ret);
687 /******************************************************************
688 * GetBestInterface (IPHLPAPI.@)
690 * Get the interface, with the best route for the given IP address.
693 * dwDestAddr [In] IP address to search the interface for
694 * pdwBestIfIndex [Out] found best interface
698 * Failure: error code from winerror.h
700 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
704 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex);
706 ret = ERROR_INVALID_PARAMETER;
708 MIB_IPFORWARDROW ipRow;
710 ret = GetBestRoute(dwDestAddr, 0, &ipRow);
711 if (ret == ERROR_SUCCESS)
712 *pdwBestIfIndex = ipRow.dwForwardIfIndex;
714 TRACE("returning %ld\n", ret);
719 /******************************************************************
720 * GetBestRoute (IPHLPAPI.@)
722 * Get the best route for the given IP address.
725 * dwDestAddr [In] IP address to search the best route for
726 * dwSourceAddr [In] optional source IP address
727 * pBestRoute [Out] found best route
731 * Failure: error code from winerror.h
733 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
735 PMIB_IPFORWARDTABLE table;
738 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr,
739 dwSourceAddr, pBestRoute);
741 return ERROR_INVALID_PARAMETER;
743 AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
745 DWORD ndx, matchedBits, matchedNdx = 0;
747 for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
748 if ((dwDestAddr & table->table[ndx].dwForwardMask) ==
749 (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
750 DWORD numShifts, mask;
752 for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
753 mask && !(mask & 1); mask >>= 1, numShifts++)
755 if (numShifts > matchedBits) {
756 matchedBits = numShifts;
761 memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
762 HeapFree(GetProcessHeap(), 0, table);
766 ret = ERROR_OUTOFMEMORY;
767 TRACE("returning %ld\n", ret);
772 /******************************************************************
773 * GetFriendlyIfIndex (IPHLPAPI.@)
775 * Get a "friendly" version of IfIndex, which is one that doesn't
776 * have the top byte set. Doesn't validate whether IfIndex is a valid
780 * IfIndex [In] interface index to get the friendly one for
783 * A friendly version of IfIndex.
785 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
787 /* windows doesn't validate these, either, just makes sure the top byte is
788 cleared. I assume my ifenum module never gives an index with the top
790 TRACE("returning %ld\n", IfIndex);
795 /******************************************************************
796 * GetIcmpStatistics (IPHLPAPI.@)
798 * Get the ICMP statistics for the local computer.
801 * pStats [Out] buffer for ICMP statistics
805 * Failure: error code from winerror.h
807 DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
811 TRACE("pStats %p\n", pStats);
812 ret = getICMPStats(pStats);
813 TRACE("returning %ld\n", ret);
818 /******************************************************************
819 * GetIfEntry (IPHLPAPI.@)
821 * Get information about an interface.
824 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
825 * Out: interface information
829 * Failure: error code from winerror.h
831 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
836 TRACE("pIfRow %p\n", pIfRow);
838 return ERROR_INVALID_PARAMETER;
840 name = getInterfaceNameByIndex(pIfRow->dwIndex);
842 ret = getInterfaceEntryByName(name, pIfRow);
844 ret = getInterfaceStatsByName(name, pIfRow);
847 ret = ERROR_INVALID_DATA;
848 TRACE("returning %ld\n", ret);
853 static int IfTableSorter(const void *a, const void *b)
858 ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
865 /******************************************************************
866 * GetIfTable (IPHLPAPI.@)
868 * Get a table of local interfaces.
871 * pIfTable [Out] buffer for local interfaces table
872 * pdwSize [In/Out] length of output buffer
873 * bOrder [In] whether to sort the table
877 * Failure: error code from winerror.h
880 * If pdwSize is less than required, the function will return
881 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
883 * If bOrder is true, the returned table will be sorted by interface index.
885 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
889 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize, pdwSize,
892 ret = ERROR_INVALID_PARAMETER;
894 DWORD numInterfaces = getNumInterfaces();
895 ULONG size = sizeof(MIB_IFTABLE) + (numInterfaces - 1) * sizeof(MIB_IFROW);
897 if (!pIfTable || *pdwSize < size) {
899 ret = ERROR_INSUFFICIENT_BUFFER;
902 InterfaceIndexTable *table = getInterfaceIndexTable();
905 size = sizeof(MIB_IFTABLE) + (table->numIndexes - 1) *
907 if (*pdwSize < size) {
909 ret = ERROR_INSUFFICIENT_BUFFER;
914 pIfTable->dwNumEntries = 0;
915 for (ndx = 0; ndx < table->numIndexes; ndx++) {
916 pIfTable->table[ndx].dwIndex = table->indexes[ndx];
917 GetIfEntry(&pIfTable->table[ndx]);
918 pIfTable->dwNumEntries++;
921 qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
925 HeapFree(GetProcessHeap(), 0, table);
928 ret = ERROR_OUTOFMEMORY;
931 TRACE("returning %ld\n", ret);
936 /******************************************************************
937 * GetInterfaceInfo (IPHLPAPI.@)
939 * Get a list of network interface adapters.
942 * pIfTable [Out] buffer for interface adapters
943 * dwOutBufLen [Out] if buffer is too small, returns required size
947 * Failure: error code from winerror.h
949 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
953 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
955 ret = ERROR_INVALID_PARAMETER;
957 DWORD numInterfaces = getNumInterfaces();
958 ULONG size = sizeof(IP_INTERFACE_INFO) + (numInterfaces - 1) *
959 sizeof(IP_ADAPTER_INDEX_MAP);
961 if (!pIfTable || *dwOutBufLen < size) {
963 ret = ERROR_INSUFFICIENT_BUFFER;
966 InterfaceIndexTable *table = getInterfaceIndexTable();
969 size = sizeof(IP_INTERFACE_INFO) + (table->numIndexes - 1) *
970 sizeof(IP_ADAPTER_INDEX_MAP);
971 if (*dwOutBufLen < size) {
973 ret = ERROR_INSUFFICIENT_BUFFER;
978 pIfTable->NumAdapters = 0;
979 for (ndx = 0; ndx < table->numIndexes; ndx++) {
980 const char *walker, *name;
983 pIfTable->Adapter[ndx].Index = table->indexes[ndx];
984 name = getInterfaceNameByIndex(table->indexes[ndx]);
985 for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
987 assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
988 walker++, assigner++)
991 pIfTable->NumAdapters++;
995 HeapFree(GetProcessHeap(), 0, table);
998 ret = ERROR_OUTOFMEMORY;
1001 TRACE("returning %ld\n", ret);
1006 static int IpAddrTableSorter(const void *a, const void *b)
1011 ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
1018 /******************************************************************
1019 * GetIpAddrTable (IPHLPAPI.@)
1021 * Get interface-to-IP address mapping table.
1024 * pIpAddrTable [Out] buffer for mapping table
1025 * pdwSize [In/Out] length of output buffer
1026 * bOrder [In] whether to sort the table
1030 * Failure: error code from winerror.h
1033 * If pdwSize is less than required, the function will return
1034 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1036 * If bOrder is true, the returned table will be sorted by the next hop and
1037 * an assortment of arbitrary parameters.
1039 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1043 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable, pdwSize,
1046 ret = ERROR_INVALID_PARAMETER;
1048 DWORD numInterfaces = getNumInterfaces();
1049 ULONG size = sizeof(MIB_IPADDRTABLE) + (numInterfaces - 1) *
1050 sizeof(MIB_IPADDRROW);
1052 if (!pIpAddrTable || *pdwSize < size) {
1054 ret = ERROR_INSUFFICIENT_BUFFER;
1057 InterfaceIndexTable *table = getInterfaceIndexTable();
1060 size = sizeof(MIB_IPADDRTABLE) + (table->numIndexes - 1) *
1061 sizeof(MIB_IPADDRROW);
1062 if (*pdwSize < size) {
1064 ret = ERROR_INSUFFICIENT_BUFFER;
1069 pIpAddrTable->dwNumEntries = 0;
1070 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1071 pIpAddrTable->table[ndx].dwIndex = table->indexes[ndx];
1072 pIpAddrTable->table[ndx].dwAddr =
1073 getInterfaceIPAddrByIndex(table->indexes[ndx]);
1074 pIpAddrTable->table[ndx].dwMask =
1075 getInterfaceMaskByIndex(table->indexes[ndx]);
1076 /* the dwBCastAddr member isn't the broadcast address, it indicates
1077 * whether the interface uses the 1's broadcast address (1) or the
1078 * 0's broadcast address (0).
1080 bcast = getInterfaceBCastAddrByIndex(table->indexes[ndx]);
1081 pIpAddrTable->table[ndx].dwBCastAddr =
1082 (bcast & pIpAddrTable->table[ndx].dwMask) ? 1 : 0;
1083 /* FIXME: hardcoded reasm size, not sure where to get it */
1084 pIpAddrTable->table[ndx].dwReasmSize = 65535;
1085 pIpAddrTable->table[ndx].unused1 = 0;
1086 pIpAddrTable->table[ndx].wType = 0; /* aka unused2 */
1087 pIpAddrTable->dwNumEntries++;
1090 qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1091 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1094 HeapFree(GetProcessHeap(), 0, table);
1097 ret = ERROR_OUTOFMEMORY;
1100 TRACE("returning %ld\n", ret);
1105 static int IpForwardTableSorter(const void *a, const void *b)
1110 const MIB_IPFORWARDROW* rowA = (const MIB_IPFORWARDROW*)a;
1111 const MIB_IPFORWARDROW* rowB = (const MIB_IPFORWARDROW*)b;
1113 ret = rowA->dwForwardDest - rowB->dwForwardDest;
1115 ret = rowA->dwForwardProto - rowB->dwForwardProto;
1117 ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy;
1119 ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop;
1129 /******************************************************************
1130 * GetIpForwardTable (IPHLPAPI.@)
1132 * Get the route table.
1135 * pIpForwardTable [Out] buffer for route table
1136 * pdwSize [In/Out] length of output buffer
1137 * bOrder [In] whether to sort the table
1141 * Failure: error code from winerror.h
1144 * If pdwSize is less than required, the function will return
1145 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1147 * If bOrder is true, the returned table will be sorted by the next hop and
1148 * an assortment of arbitrary parameters.
1150 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1154 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable,
1155 pdwSize, (DWORD)bOrder);
1157 ret = ERROR_INVALID_PARAMETER;
1159 DWORD numRoutes = getNumRoutes();
1160 ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) *
1161 sizeof(MIB_IPFORWARDROW);
1163 if (!pIpForwardTable || *pdwSize < sizeNeeded) {
1164 *pdwSize = sizeNeeded;
1165 ret = ERROR_INSUFFICIENT_BUFFER;
1168 RouteTable *table = getRouteTable();
1170 sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (table->numRoutes - 1) *
1171 sizeof(MIB_IPFORWARDROW);
1172 if (*pdwSize < sizeNeeded) {
1173 *pdwSize = sizeNeeded;
1174 ret = ERROR_INSUFFICIENT_BUFFER;
1179 pIpForwardTable->dwNumEntries = table->numRoutes;
1180 for (ndx = 0; ndx < numRoutes; ndx++) {
1181 pIpForwardTable->table[ndx].dwForwardIfIndex =
1182 table->routes[ndx].ifIndex;
1183 pIpForwardTable->table[ndx].dwForwardDest =
1184 table->routes[ndx].dest;
1185 pIpForwardTable->table[ndx].dwForwardMask =
1186 table->routes[ndx].mask;
1187 pIpForwardTable->table[ndx].dwForwardPolicy = 0;
1188 pIpForwardTable->table[ndx].dwForwardNextHop =
1189 table->routes[ndx].gateway;
1190 /* FIXME: this type is appropriate for local interfaces; may not
1191 always be appropriate */
1192 pIpForwardTable->table[ndx].dwForwardType = MIB_IPROUTE_TYPE_DIRECT;
1193 /* FIXME: other protos might be appropriate, e.g. the default route
1194 is typically set with MIB_IPPROTO_NETMGMT instead */
1195 pIpForwardTable->table[ndx].dwForwardProto = MIB_IPPROTO_LOCAL;
1196 /* punt on age and AS */
1197 pIpForwardTable->table[ndx].dwForwardAge = 0;
1198 pIpForwardTable->table[ndx].dwForwardNextHopAS = 0;
1199 pIpForwardTable->table[ndx].dwForwardMetric1 =
1200 table->routes[ndx].metric;
1201 /* rest of the metrics are 0.. */
1202 pIpForwardTable->table[ndx].dwForwardMetric2 = 0;
1203 pIpForwardTable->table[ndx].dwForwardMetric3 = 0;
1204 pIpForwardTable->table[ndx].dwForwardMetric4 = 0;
1205 pIpForwardTable->table[ndx].dwForwardMetric5 = 0;
1208 qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
1209 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1212 HeapFree(GetProcessHeap(), 0, table);
1215 ret = ERROR_OUTOFMEMORY;
1218 TRACE("returning %ld\n", ret);
1223 static int IpNetTableSorter(const void *a, const void *b)
1228 ret = ((const MIB_IPNETROW*)a)->dwAddr - ((const MIB_IPNETROW*)b)->dwAddr;
1235 /******************************************************************
1236 * GetIpNetTable (IPHLPAPI.@)
1238 * Get the IP-to-physical address mapping table.
1241 * pIpNetTable [Out] buffer for mapping table
1242 * pdwSize [In/Out] length of output buffer
1243 * bOrder [In] whether to sort the table
1247 * Failure: error code from winerror.h
1250 * If pdwSize is less than required, the function will return
1251 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1253 * If bOrder is true, the returned table will be sorted by IP address.
1255 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1259 TRACE("pIpNetTable %p, pdwSize %p, bOrder %ld\n", pIpNetTable, pdwSize,
1262 ret = ERROR_INVALID_PARAMETER;
1264 DWORD numEntries = getNumArpEntries();
1265 ULONG size = sizeof(MIB_IPNETTABLE) + (numEntries - 1) *
1266 sizeof(MIB_IPNETROW);
1268 if (!pIpNetTable || *pdwSize < size) {
1270 ret = ERROR_INSUFFICIENT_BUFFER;
1273 PMIB_IPNETTABLE table = getArpTable();
1276 size = sizeof(MIB_IPNETTABLE) + (table->dwNumEntries - 1) *
1277 sizeof(MIB_IPNETROW);
1278 if (*pdwSize < size) {
1280 ret = ERROR_INSUFFICIENT_BUFFER;
1283 memcpy(pIpNetTable, table, size);
1285 qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
1286 sizeof(MIB_IPNETROW), IpNetTableSorter);
1289 HeapFree(GetProcessHeap(), 0, table);
1292 ret = ERROR_OUTOFMEMORY;
1295 TRACE("returning %ld\n", ret);
1300 /******************************************************************
1301 * GetIpStatistics (IPHLPAPI.@)
1303 * Get the IP statistics for the local computer.
1306 * pStats [Out] buffer for IP statistics
1310 * Failure: error code from winerror.h
1312 DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
1316 TRACE("pStats %p\n", pStats);
1317 ret = getIPStats(pStats);
1318 TRACE("returning %ld\n", ret);
1323 /******************************************************************
1324 * GetNetworkParams (IPHLPAPI.@)
1326 * Get the network parameters for the local computer.
1329 * pFixedInfo [Out] buffer for network parameters
1330 * pOutBufLen [In/Out] length of output buffer
1334 * Failure: error code from winerror.h
1337 * If pOutBufLen is less than required, the function will return
1338 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1341 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1347 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1349 return ERROR_INVALID_PARAMETER;
1352 size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount - 1) *
1353 sizeof(IP_ADDR_STRING) : 0);
1354 if (!pFixedInfo || *pOutBufLen < size) {
1356 return ERROR_BUFFER_OVERFLOW;
1359 memset(pFixedInfo, 0, size);
1360 size = sizeof(pFixedInfo->HostName);
1361 GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1362 size = sizeof(pFixedInfo->DomainName);
1363 GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1364 if (_res.nscount > 0) {
1365 PIP_ADDR_STRING ptr;
1368 for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1369 i++, ptr = ptr->Next) {
1370 toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
1371 ptr->IpAddress.String);
1372 if (i == _res.nscount - 1)
1375 ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
1377 ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1380 pFixedInfo->NodeType = HYBRID_NODETYPE;
1381 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1382 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1383 if (regReturn != ERROR_SUCCESS)
1384 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1385 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1387 if (regReturn == ERROR_SUCCESS)
1389 DWORD size = sizeof(pFixedInfo->ScopeId);
1391 RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1395 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1396 I suppose could also check for a listener on port 53 to set EnableDns */
1398 TRACE("returning %ld\n", ret);
1403 /******************************************************************
1404 * GetNumberOfInterfaces (IPHLPAPI.@)
1406 * Get the number of interfaces.
1409 * pdwNumIf [Out] number of interfaces
1412 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1414 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
1418 TRACE("pdwNumIf %p\n", pdwNumIf);
1420 ret = ERROR_INVALID_PARAMETER;
1422 *pdwNumIf = getNumInterfaces();
1425 TRACE("returning %ld\n", ret);
1430 /******************************************************************
1431 * GetPerAdapterInfo (IPHLPAPI.@)
1433 * Get information about an adapter corresponding to an interface.
1436 * IfIndex [In] interface info
1437 * pPerAdapterInfo [Out] buffer for per adapter info
1438 * pOutBufLen [In/Out] length of output buffer
1442 * Failure: error code from winerror.h
1445 * Stub, returns ERROR_NOT_SUPPORTED.
1447 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
1449 TRACE("(IfIndex %ld, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex,
1450 pPerAdapterInfo, pOutBufLen);
1451 return ERROR_NOT_SUPPORTED;
1455 /******************************************************************
1456 * GetRTTAndHopCount (IPHLPAPI.@)
1458 * Get round-trip time (RTT) and hop count.
1462 * DestIpAddress [In] destination address to get the info for
1463 * HopCount [Out] retrieved hop count
1464 * MaxHops [In] maximum hops to search for the destination
1465 * RTT [Out] RTT in milliseconds
1472 * Stub, returns FALSE.
1474 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
1476 FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p): stub\n",
1477 DestIpAddress, HopCount, MaxHops, RTT);
1482 /******************************************************************
1483 * GetTcpStatistics (IPHLPAPI.@)
1485 * Get the TCP statistics for the local computer.
1488 * pStats [Out] buffer for TCP statistics
1492 * Failure: error code from winerror.h
1494 DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
1498 TRACE("pStats %p\n", pStats);
1499 ret = getTCPStats(pStats);
1500 TRACE("returning %ld\n", ret);
1505 static int TcpTableSorter(const void *a, const void *b)
1510 const MIB_TCPROW* rowA = a;
1511 const MIB_TCPROW* rowB = b;
1513 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
1515 ret = rowA->dwLocalPort - rowB->dwLocalPort;
1517 ret = rowA->dwRemoteAddr - rowB->dwRemoteAddr;
1519 ret = rowA->dwRemotePort - rowB->dwRemotePort;
1529 /******************************************************************
1530 * GetTcpTable (IPHLPAPI.@)
1532 * Get the table of active TCP connections.
1535 * pTcpTable [Out] buffer for TCP connections table
1536 * pdwSize [In/Out] length of output buffer
1537 * bOrder [In] whether to order the table
1541 * Failure: error code from winerror.h
1544 * If pdwSize is less than required, the function will return
1545 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1546 * the required byte size.
1547 * If bOrder is true, the returned table will be sorted, first by
1548 * local address and port number, then by remote address and port
1551 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
1555 TRACE("pTcpTable %p, pdwSize %p, bOrder %ld\n", pTcpTable, pdwSize,
1558 ret = ERROR_INVALID_PARAMETER;
1560 DWORD numEntries = getNumTcpEntries();
1561 ULONG size = sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW);
1563 if (!pTcpTable || *pdwSize < size) {
1565 ret = ERROR_INSUFFICIENT_BUFFER;
1568 PMIB_TCPTABLE table = getTcpTable();
1571 size = sizeof(MIB_TCPTABLE) + (table->dwNumEntries - 1) *
1573 if (*pdwSize < size) {
1575 ret = ERROR_INSUFFICIENT_BUFFER;
1578 memcpy(pTcpTable, table, size);
1580 qsort(pTcpTable->table, pTcpTable->dwNumEntries,
1581 sizeof(MIB_TCPROW), TcpTableSorter);
1584 HeapFree(GetProcessHeap(), 0, table);
1587 ret = ERROR_OUTOFMEMORY;
1590 TRACE("returning %ld\n", ret);
1595 /******************************************************************
1596 * GetUdpStatistics (IPHLPAPI.@)
1598 * Get the UDP statistics for the local computer.
1601 * pStats [Out] buffer for UDP statistics
1605 * Failure: error code from winerror.h
1607 DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
1611 TRACE("pStats %p\n", pStats);
1612 ret = getUDPStats(pStats);
1613 TRACE("returning %ld\n", ret);
1618 static int UdpTableSorter(const void *a, const void *b)
1623 const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
1624 const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;
1626 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
1628 ret = rowA->dwLocalPort - rowB->dwLocalPort;
1636 /******************************************************************
1637 * GetUdpTable (IPHLPAPI.@)
1639 * Get a table of active UDP connections.
1642 * pUdpTable [Out] buffer for UDP connections table
1643 * pdwSize [In/Out] length of output buffer
1644 * bOrder [In] whether to order the table
1648 * Failure: error code from winerror.h
1651 * If pdwSize is less than required, the function will return
1652 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1653 * required byte size.
1654 * If bOrder is true, the returned table will be sorted, first by
1655 * local address, then by local port number.
1657 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
1661 TRACE("pUdpTable %p, pdwSize %p, bOrder %ld\n", pUdpTable, pdwSize,
1664 ret = ERROR_INVALID_PARAMETER;
1666 DWORD numEntries = getNumUdpEntries();
1667 ULONG size = sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW);
1669 if (!pUdpTable || *pdwSize < size) {
1671 ret = ERROR_INSUFFICIENT_BUFFER;
1674 PMIB_UDPTABLE table = getUdpTable();
1677 size = sizeof(MIB_UDPTABLE) + (table->dwNumEntries - 1) *
1679 if (*pdwSize < size) {
1681 ret = ERROR_INSUFFICIENT_BUFFER;
1684 memcpy(pUdpTable, table, size);
1686 qsort(pUdpTable->table, pUdpTable->dwNumEntries,
1687 sizeof(MIB_UDPROW), UdpTableSorter);
1690 HeapFree(GetProcessHeap(), 0, table);
1693 ret = ERROR_OUTOFMEMORY;
1696 TRACE("returning %ld\n", ret);
1701 /******************************************************************
1702 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1704 * This is a Win98-only function to get information on "unidirectional"
1705 * adapters. Since this is pretty nonsensical in other contexts, it
1706 * never returns anything.
1709 * pIPIfInfo [Out] buffer for adapter infos
1710 * dwOutBufLen [Out] length of the output buffer
1714 * Failure: error code from winerror.h
1717 * Stub, returns ERROR_NOT_SUPPORTED.
1719 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
1721 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1722 /* a unidirectional adapter?? not bloody likely! */
1723 return ERROR_NOT_SUPPORTED;
1727 /******************************************************************
1728 * IpReleaseAddress (IPHLPAPI.@)
1730 * Release an IP optained through DHCP,
1733 * AdapterInfo [In] adapter to release IP address
1737 * Failure: error code from winerror.h
1740 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1741 * this function does nothing.
1744 * Stub, returns ERROR_NOT_SUPPORTED.
1746 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1748 TRACE("AdapterInfo %p\n", AdapterInfo);
1749 /* not a stub, never going to support this (and I never mark an adapter as
1750 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1751 return ERROR_NOT_SUPPORTED;
1755 /******************************************************************
1756 * IpRenewAddress (IPHLPAPI.@)
1758 * Renew an IP optained through DHCP.
1761 * AdapterInfo [In] adapter to renew IP address
1765 * Failure: error code from winerror.h
1768 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1769 * this function does nothing.
1772 * Stub, returns ERROR_NOT_SUPPORTED.
1774 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1776 TRACE("AdapterInfo %p\n", AdapterInfo);
1777 /* not a stub, never going to support this (and I never mark an adapter as
1778 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1779 return ERROR_NOT_SUPPORTED;
1783 /******************************************************************
1784 * NotifyAddrChange (IPHLPAPI.@)
1786 * Notify caller whenever the ip-interface map is changed.
1789 * Handle [Out] handle useable in asynchronus notification
1790 * overlapped [In] overlapped structure that notifies the caller
1794 * Failure: error code from winerror.h
1797 * Stub, returns ERROR_NOT_SUPPORTED.
1799 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1801 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1802 return ERROR_NOT_SUPPORTED;
1806 /******************************************************************
1807 * NotifyRouteChange (IPHLPAPI.@)
1809 * Notify caller whenever the ip routing table is changed.
1812 * Handle [Out] handle useable in asynchronus notification
1813 * overlapped [In] overlapped structure that notifies the caller
1817 * Failure: error code from winerror.h
1820 * Stub, returns ERROR_NOT_SUPPORTED.
1822 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1824 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1825 return ERROR_NOT_SUPPORTED;
1829 /******************************************************************
1830 * SendARP (IPHLPAPI.@)
1832 * Send an ARP request.
1835 * DestIP [In] attemp to obtain this IP
1836 * SrcIP [In] optional sender IP address
1837 * pMacAddr [Out] buffer for the mac address
1838 * PhyAddrLen [In/Out] length of the output buffer
1842 * Failure: error code from winerror.h
1845 * Stub, returns ERROR_NOT_SUPPORTED.
1847 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
1849 FIXME("(DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p): stub\n",
1850 DestIP, SrcIP, pMacAddr, PhyAddrLen);
1851 return ERROR_NOT_SUPPORTED;
1855 /******************************************************************
1856 * SetIfEntry (IPHLPAPI.@)
1858 * Set the administrative status of an interface.
1861 * pIfRow [In] dwAdminStatus member specifies the new status.
1865 * Failure: error code from winerror.h
1868 * Stub, returns ERROR_NOT_SUPPORTED.
1870 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
1872 FIXME("(pIfRow %p): stub\n", pIfRow);
1873 /* this is supposed to set an administratively interface up or down.
1874 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1875 this sort of down is indistinguishable from other sorts of down (e.g. no
1877 return ERROR_NOT_SUPPORTED;
1881 /******************************************************************
1882 * SetIpForwardEntry (IPHLPAPI.@)
1884 * Modify an existing route.
1887 * pRoute [In] route with the new information
1891 * Failure: error code from winerror.h
1894 * Stub, returns NO_ERROR.
1896 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
1898 FIXME("(pRoute %p): stub\n", pRoute);
1899 /* this is to add a route entry, how's it distinguishable from
1900 CreateIpForwardEntry?
1901 could use SIOCADDRT, not sure I want to */
1906 /******************************************************************
1907 * SetIpNetEntry (IPHLPAPI.@)
1909 * Modify an existing ARP entry.
1912 * pArpEntry [In] ARP entry with the new information
1916 * Failure: error code from winerror.h
1919 * Stub, returns NO_ERROR.
1921 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
1923 FIXME("(pArpEntry %p): stub\n", pArpEntry);
1924 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1929 /******************************************************************
1930 * SetIpStatistics (IPHLPAPI.@)
1932 * Toggle IP forwarding and det the default TTL value.
1935 * pIpStats [In] IP statistics with the new information
1939 * Failure: error code from winerror.h
1942 * Stub, returns NO_ERROR.
1944 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
1946 FIXME("(pIpStats %p): stub\n", pIpStats);
1951 /******************************************************************
1952 * SetIpTTL (IPHLPAPI.@)
1954 * Set the default TTL value.
1957 * nTTL [In] new TTL value
1961 * Failure: error code from winerror.h
1964 * Stub, returns NO_ERROR.
1966 DWORD WINAPI SetIpTTL(UINT nTTL)
1968 FIXME("(nTTL %d): stub\n", nTTL);
1969 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1970 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1975 /******************************************************************
1976 * SetTcpEntry (IPHLPAPI.@)
1978 * Set the state of a TCP connection.
1981 * pTcpRow [In] specifies connection with new state
1985 * Failure: error code from winerror.h
1988 * Stub, returns NO_ERROR.
1990 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
1992 FIXME("(pTcpRow %p): stub\n", pTcpRow);
1997 /******************************************************************
1998 * UnenableRouter (IPHLPAPI.@)
2000 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2001 * if it reaches zero.
2004 * pOverlapped [In/Out] should be the same as in EnableRouter()
2005 * lpdwEnableCount [Out] optional, receives reference count
2009 * Failure: error code from winerror.h
2012 * Stub, returns ERROR_NOT_SUPPORTED.
2014 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
2016 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
2018 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
2019 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
2021 return ERROR_NOT_SUPPORTED;