2 * iphlpapi dll implementation
4 * Copyright (C) 2003,2006 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 static int resolver_initialised;
55 /* call res_init() just once because of a bug in Mac OS X 10.4 */
56 static void initialise_resolver(void)
58 if (!resolver_initialised)
61 resolver_initialised = 1;
65 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
68 case DLL_PROCESS_ATTACH:
69 DisableThreadLibraryCalls( hinstDLL );
72 case DLL_PROCESS_DETACH:
78 /******************************************************************
79 * AddIPAddress (IPHLPAPI.@)
81 * Add an IP address to an adapter.
84 * Address [In] IP address to add to the adapter
85 * IpMask [In] subnet mask for the IP address
86 * IfIndex [In] adapter index to add the address
87 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
88 * NTEInstance [Out] NTE instance for the IP address
92 * Failure: error code from winerror.h
95 * Stub. Currently returns ERROR_NOT_SUPPORTED.
97 DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
100 return ERROR_NOT_SUPPORTED;
104 /******************************************************************
105 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
107 * Get table of local interfaces.
108 * Like GetIfTable(), but allocate the returned table from heap.
111 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
112 * allocated and returned.
113 * bOrder [In] whether to sort the table
114 * heap [In] heap from which the table is allocated
115 * flags [In] flags to HeapAlloc
118 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
119 * GetIfTable() returns otherwise.
121 DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
122 BOOL bOrder, HANDLE heap, DWORD flags)
126 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable,
127 bOrder, heap, flags);
129 ret = ERROR_INVALID_PARAMETER;
133 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
134 if (ret == ERROR_INSUFFICIENT_BUFFER) {
135 *ppIfTable = HeapAlloc(heap, flags, dwSize);
136 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
139 TRACE("returning %d\n", ret);
144 static int IpAddrTableSorter(const void *a, const void *b)
149 ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
156 /******************************************************************
157 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
159 * Get interface-to-IP address mapping table.
160 * Like GetIpAddrTable(), but allocate the returned table from heap.
163 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
164 * allocated and returned.
165 * bOrder [In] whether to sort the table
166 * heap [In] heap from which the table is allocated
167 * flags [In] flags to HeapAlloc
170 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
171 * failure, NO_ERROR on success.
173 DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
174 BOOL bOrder, HANDLE heap, DWORD flags)
178 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
179 ppIpAddrTable, bOrder, heap, flags);
180 ret = getIPAddrTable(ppIpAddrTable, heap, flags);
182 qsort((*ppIpAddrTable)->table, (*ppIpAddrTable)->dwNumEntries,
183 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
184 TRACE("returning %d\n", ret);
189 static int IpForwardTableSorter(const void *a, const void *b)
194 const MIB_IPFORWARDROW* rowA = (const MIB_IPFORWARDROW*)a;
195 const MIB_IPFORWARDROW* rowB = (const MIB_IPFORWARDROW*)b;
197 ret = rowA->dwForwardDest - rowB->dwForwardDest;
199 ret = rowA->dwForwardProto - rowB->dwForwardProto;
201 ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy;
203 ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop;
213 /******************************************************************
214 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
216 * Get the route table.
217 * Like GetIpForwardTable(), but allocate the returned table from heap.
220 * ppIpForwardTable [Out] pointer into which the MIB_IPFORWARDTABLE is
221 * allocated and returned.
222 * bOrder [In] whether to sort the table
223 * heap [In] heap from which the table is allocated
224 * flags [In] flags to HeapAlloc
227 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, other error codes
228 * on failure, NO_ERROR on success.
230 DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
231 ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags)
235 TRACE("ppIpForwardTable %p, bOrder %d, heap %p, flags 0x%08x\n",
236 ppIpForwardTable, bOrder, heap, flags);
237 ret = getRouteTable(ppIpForwardTable, heap, flags);
239 qsort((*ppIpForwardTable)->table, (*ppIpForwardTable)->dwNumEntries,
240 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
241 TRACE("returning %d\n", ret);
246 static int IpNetTableSorter(const void *a, const void *b)
251 ret = ((const MIB_IPNETROW*)a)->dwAddr - ((const MIB_IPNETROW*)b)->dwAddr;
258 /******************************************************************
259 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
261 * Get the IP-to-physical address mapping table.
262 * Like GetIpNetTable(), but allocate the returned table from heap.
265 * ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE is
266 * allocated and returned.
267 * bOrder [In] whether to sort the table
268 * heap [In] heap from which the table is allocated
269 * flags [In] flags to HeapAlloc
272 * ERROR_INVALID_PARAMETER if ppIpNetTable is NULL, other error codes
273 * on failure, NO_ERROR on success.
275 DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable,
276 BOOL bOrder, HANDLE heap, DWORD flags)
280 TRACE("ppIpNetTable %p, bOrder %d, heap %p, flags 0x%08x\n",
281 ppIpNetTable, bOrder, heap, flags);
282 ret = getArpTable(ppIpNetTable, heap, flags);
284 qsort((*ppIpNetTable)->table, (*ppIpNetTable)->dwNumEntries,
285 sizeof(MIB_IPADDRROW), IpNetTableSorter);
286 TRACE("returning %d\n", ret);
291 static int TcpTableSorter(const void *a, const void *b)
296 const MIB_TCPROW* rowA = a;
297 const MIB_TCPROW* rowB = b;
299 ret = ntohl (rowA->dwLocalAddr) - ntohl (rowB->dwLocalAddr);
301 ret = ntohs ((unsigned short)rowA->dwLocalPort) -
302 ntohs ((unsigned short)rowB->dwLocalPort);
304 ret = ntohl (rowA->dwRemoteAddr) - ntohl (rowB->dwRemoteAddr);
306 ret = ntohs ((unsigned short)rowA->dwRemotePort) -
307 ntohs ((unsigned short)rowB->dwRemotePort);
317 /******************************************************************
318 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
320 * Get the TCP connection table.
321 * Like GetTcpTable(), but allocate the returned table from heap.
324 * ppTcpTable [Out] pointer into which the MIB_TCPTABLE is
325 * allocated and returned.
326 * bOrder [In] whether to sort the table
327 * heap [In] heap from which the table is allocated
328 * flags [In] flags to HeapAlloc
331 * ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable()
334 DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
335 BOOL bOrder, HANDLE heap, DWORD flags)
339 TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
340 ppTcpTable, bOrder, heap, flags);
343 ret = getTcpTable(ppTcpTable, 0, heap, flags);
345 qsort((*ppTcpTable)->table, (*ppTcpTable)->dwNumEntries,
346 sizeof(MIB_TCPROW), TcpTableSorter);
347 TRACE("returning %d\n", ret);
352 static int UdpTableSorter(const void *a, const void *b)
357 const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
358 const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;
360 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
362 ret = rowA->dwLocalPort - rowB->dwLocalPort;
370 /******************************************************************
371 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
373 * Get the UDP listener table.
374 * Like GetUdpTable(), but allocate the returned table from heap.
377 * ppUdpTable [Out] pointer into which the MIB_UDPTABLE is
378 * allocated and returned.
379 * bOrder [In] whether to sort the table
380 * heap [In] heap from which the table is allocated
381 * flags [In] flags to HeapAlloc
384 * ERROR_INVALID_PARAMETER if ppUdpTable is NULL, whatever GetUdpTable()
387 DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
388 BOOL bOrder, HANDLE heap, DWORD flags)
392 TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
393 ppUdpTable, bOrder, heap, flags);
394 ret = getUdpTable(ppUdpTable, heap, flags);
396 qsort((*ppUdpTable)->table, (*ppUdpTable)->dwNumEntries,
397 sizeof(MIB_UDPROW), UdpTableSorter);
398 TRACE("returning %d\n", ret);
403 /******************************************************************
404 * CreateIpForwardEntry (IPHLPAPI.@)
406 * Create a route in the local computer's IP table.
409 * pRoute [In] new route information
413 * Failure: error code from winerror.h
416 * Stub, always returns NO_ERROR.
418 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
420 FIXME("(pRoute %p): stub\n", pRoute);
421 /* could use SIOCADDRT, not sure I want to */
426 /******************************************************************
427 * CreateIpNetEntry (IPHLPAPI.@)
429 * Create entry in the ARP table.
432 * pArpEntry [In] new ARP entry
436 * Failure: error code from winerror.h
439 * Stub, always returns NO_ERROR.
441 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
443 FIXME("(pArpEntry %p)\n", pArpEntry);
444 /* could use SIOCSARP on systems that support it, not sure I want to */
449 /******************************************************************
450 * CreateProxyArpEntry (IPHLPAPI.@)
452 * Create a Proxy ARP (PARP) entry for an IP address.
455 * dwAddress [In] IP address for which this computer acts as a proxy.
456 * dwMask [In] subnet mask for dwAddress
457 * dwIfIndex [In] interface index
461 * Failure: error code from winerror.h
464 * Stub, returns ERROR_NOT_SUPPORTED.
466 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
468 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
469 dwAddress, dwMask, dwIfIndex);
470 return ERROR_NOT_SUPPORTED;
474 /******************************************************************
475 * DeleteIPAddress (IPHLPAPI.@)
477 * Delete an IP address added with AddIPAddress().
480 * NTEContext [In] NTE context from AddIPAddress();
484 * Failure: error code from winerror.h
487 * Stub, returns ERROR_NOT_SUPPORTED.
489 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
491 FIXME("(NTEContext %d): stub\n", NTEContext);
492 return ERROR_NOT_SUPPORTED;
496 /******************************************************************
497 * DeleteIpForwardEntry (IPHLPAPI.@)
502 * pRoute [In] route to delete
506 * Failure: error code from winerror.h
509 * Stub, returns NO_ERROR.
511 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
513 FIXME("(pRoute %p): stub\n", pRoute);
514 /* could use SIOCDELRT, not sure I want to */
519 /******************************************************************
520 * DeleteIpNetEntry (IPHLPAPI.@)
522 * Delete an ARP entry.
525 * pArpEntry [In] ARP entry to delete
529 * Failure: error code from winerror.h
532 * Stub, returns NO_ERROR.
534 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
536 FIXME("(pArpEntry %p): stub\n", pArpEntry);
537 /* could use SIOCDARP on systems that support it, not sure I want to */
542 /******************************************************************
543 * DeleteProxyArpEntry (IPHLPAPI.@)
545 * Delete a Proxy ARP entry.
548 * dwAddress [In] IP address for which this computer acts as a proxy.
549 * dwMask [In] subnet mask for dwAddress
550 * dwIfIndex [In] interface index
554 * Failure: error code from winerror.h
557 * Stub, returns ERROR_NOT_SUPPORTED.
559 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
561 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
562 dwAddress, dwMask, dwIfIndex);
563 return ERROR_NOT_SUPPORTED;
567 /******************************************************************
568 * EnableRouter (IPHLPAPI.@)
570 * Turn on ip forwarding.
574 * pOverlapped [In/Out] hEvent member should contain a valid handle.
577 * Success: ERROR_IO_PENDING
578 * Failure: error code from winerror.h
581 * Stub, returns ERROR_NOT_SUPPORTED.
583 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
585 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle, pOverlapped);
586 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
587 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
589 return ERROR_NOT_SUPPORTED;
593 /******************************************************************
594 * FlushIpNetTable (IPHLPAPI.@)
596 * Delete all ARP entries of an interface
599 * dwIfIndex [In] interface index
603 * Failure: error code from winerror.h
606 * Stub, returns ERROR_NOT_SUPPORTED.
608 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
610 FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex);
611 /* this flushes the arp cache of the given index */
612 return ERROR_NOT_SUPPORTED;
616 /******************************************************************
617 * GetAdapterIndex (IPHLPAPI.@)
619 * Get interface index from its name.
622 * AdapterName [In] unicode string with the adapter name
623 * IfIndex [Out] returns found interface index
627 * Failure: error code from winerror.h
629 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
631 char adapterName[MAX_ADAPTER_NAME];
635 TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName, IfIndex);
636 /* The adapter name is guaranteed not to have any unicode characters, so
637 * this translation is never lossy */
638 for (i = 0; i < sizeof(adapterName) - 1 && AdapterName[i]; i++)
639 adapterName[i] = (char)AdapterName[i];
640 adapterName[i] = '\0';
641 ret = getInterfaceIndexByName(adapterName, IfIndex);
642 TRACE("returning %d\n", ret);
647 /******************************************************************
648 * GetAdaptersInfo (IPHLPAPI.@)
650 * Get information about adapters.
653 * pAdapterInfo [Out] buffer for adapter infos
654 * pOutBufLen [In] length of output buffer
658 * Failure: error code from winerror.h
660 DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
664 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
666 ret = ERROR_INVALID_PARAMETER;
668 DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
670 if (numNonLoopbackInterfaces > 0) {
671 DWORD numIPAddresses = getNumIPAddresses();
674 /* This may slightly overestimate the amount of space needed, because
675 * the IP addresses include the loopback address, but it's easier
676 * to make sure there's more than enough space than to make sure there's
677 * precisely enough space.
679 size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
680 size += numIPAddresses * sizeof(IP_ADDR_STRING);
681 if (!pAdapterInfo || *pOutBufLen < size) {
683 ret = ERROR_BUFFER_OVERFLOW;
686 InterfaceIndexTable *table = NULL;
687 PMIB_IPADDRTABLE ipAddrTable = NULL;
688 PMIB_IPFORWARDTABLE routeTable = NULL;
690 ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
692 ret = getRouteTable(&routeTable, GetProcessHeap(), 0);
694 table = getNonLoopbackInterfaceIndexTable();
696 size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
697 size += ipAddrTable->dwNumEntries * sizeof(IP_ADDR_STRING);
698 if (*pOutBufLen < size) {
700 ret = ERROR_INSUFFICIENT_BUFFER;
705 BOOL winsEnabled = FALSE;
706 IP_ADDRESS_STRING primaryWINS, secondaryWINS;
707 PIP_ADDR_STRING nextIPAddr = (PIP_ADDR_STRING)((LPBYTE)pAdapterInfo
708 + numNonLoopbackInterfaces * sizeof(IP_ADAPTER_INFO));
710 memset(pAdapterInfo, 0, size);
711 /* @@ Wine registry key: HKCU\Software\Wine\Network */
712 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network",
713 &hKey) == ERROR_SUCCESS) {
714 DWORD size = sizeof(primaryWINS.String);
717 RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
718 (LPBYTE)primaryWINS.String, &size);
719 addr = inet_addr(primaryWINS.String);
720 if (addr != INADDR_NONE && addr != INADDR_ANY)
722 size = sizeof(secondaryWINS.String);
723 RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
724 (LPBYTE)secondaryWINS.String, &size);
725 addr = inet_addr(secondaryWINS.String);
726 if (addr != INADDR_NONE && addr != INADDR_ANY)
730 for (ndx = 0; ndx < table->numIndexes; ndx++) {
731 PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
733 PIP_ADDR_STRING currentIPAddr = &ptr->IpAddressList;
734 BOOL firstIPAddr = TRUE;
736 /* on Win98 this is left empty, but whatever */
737 getInterfaceNameByIndex(table->indexes[ndx], ptr->AdapterName);
738 getInterfacePhysicalByIndex(table->indexes[ndx],
739 &ptr->AddressLength, ptr->Address, &ptr->Type);
740 ptr->Index = table->indexes[ndx];
741 for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
742 if (ipAddrTable->table[i].dwIndex == ptr->Index) {
744 toIPAddressString(ipAddrTable->table[i].dwAddr,
745 ptr->IpAddressList.IpAddress.String);
746 toIPAddressString(ipAddrTable->table[i].dwMask,
747 ptr->IpAddressList.IpMask.String);
751 currentIPAddr->Next = nextIPAddr;
752 currentIPAddr = nextIPAddr;
753 toIPAddressString(ipAddrTable->table[i].dwAddr,
754 currentIPAddr->IpAddress.String);
755 toIPAddressString(ipAddrTable->table[i].dwMask,
756 currentIPAddr->IpMask.String);
761 /* Find first router through this interface, which we'll assume
762 * is the default gateway for this adapter */
763 for (i = 0; i < routeTable->dwNumEntries; i++)
764 if (routeTable->table[i].dwForwardIfIndex == ptr->Index
765 && routeTable->table[i].dwForwardType ==
766 MIB_IPROUTE_TYPE_INDIRECT)
767 toIPAddressString(routeTable->table[i].dwForwardNextHop,
768 ptr->GatewayList.IpAddress.String);
770 ptr->HaveWins = TRUE;
771 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
772 primaryWINS.String, sizeof(primaryWINS.String));
773 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
774 secondaryWINS.String, sizeof(secondaryWINS.String));
776 if (ndx < table->numIndexes - 1)
777 ptr->Next = &pAdapterInfo[ndx + 1];
783 HeapFree(GetProcessHeap(), 0, table);
786 ret = ERROR_OUTOFMEMORY;
787 HeapFree(GetProcessHeap(), 0, routeTable);
788 HeapFree(GetProcessHeap(), 0, ipAddrTable);
794 TRACE("returning %d\n", ret);
799 /******************************************************************
800 * GetBestInterface (IPHLPAPI.@)
802 * Get the interface, with the best route for the given IP address.
805 * dwDestAddr [In] IP address to search the interface for
806 * pdwBestIfIndex [Out] found best interface
810 * Failure: error code from winerror.h
812 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
816 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex);
818 ret = ERROR_INVALID_PARAMETER;
820 MIB_IPFORWARDROW ipRow;
822 ret = GetBestRoute(dwDestAddr, 0, &ipRow);
823 if (ret == ERROR_SUCCESS)
824 *pdwBestIfIndex = ipRow.dwForwardIfIndex;
826 TRACE("returning %d\n", ret);
831 /******************************************************************
832 * GetBestRoute (IPHLPAPI.@)
834 * Get the best route for the given IP address.
837 * dwDestAddr [In] IP address to search the best route for
838 * dwSourceAddr [In] optional source IP address
839 * pBestRoute [Out] found best route
843 * Failure: error code from winerror.h
845 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
847 PMIB_IPFORWARDTABLE table;
850 TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr,
851 dwSourceAddr, pBestRoute);
853 return ERROR_INVALID_PARAMETER;
855 ret = AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
857 DWORD ndx, matchedBits, matchedNdx = table->dwNumEntries;
859 for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
860 if (table->table[ndx].dwForwardType != MIB_IPROUTE_TYPE_INVALID &&
861 (dwDestAddr & table->table[ndx].dwForwardMask) ==
862 (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
863 DWORD numShifts, mask;
865 for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
866 mask && !(mask & 1); mask >>= 1, numShifts++)
868 if (numShifts > matchedBits) {
869 matchedBits = numShifts;
874 if (matchedNdx < table->dwNumEntries) {
875 memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
879 /* No route matches, which can happen if there's no default route. */
880 ret = ERROR_HOST_UNREACHABLE;
882 HeapFree(GetProcessHeap(), 0, table);
885 ret = ERROR_OUTOFMEMORY;
886 TRACE("returning %d\n", ret);
891 /******************************************************************
892 * GetFriendlyIfIndex (IPHLPAPI.@)
894 * Get a "friendly" version of IfIndex, which is one that doesn't
895 * have the top byte set. Doesn't validate whether IfIndex is a valid
899 * IfIndex [In] interface index to get the friendly one for
902 * A friendly version of IfIndex.
904 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
906 /* windows doesn't validate these, either, just makes sure the top byte is
907 cleared. I assume my ifenum module never gives an index with the top
909 TRACE("returning %d\n", IfIndex);
914 /******************************************************************
915 * GetIcmpStatistics (IPHLPAPI.@)
917 * Get the ICMP statistics for the local computer.
920 * pStats [Out] buffer for ICMP statistics
924 * Failure: error code from winerror.h
926 DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
930 TRACE("pStats %p\n", pStats);
931 ret = getICMPStats(pStats);
932 TRACE("returning %d\n", ret);
937 /******************************************************************
938 * GetIfEntry (IPHLPAPI.@)
940 * Get information about an interface.
943 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
944 * Out: interface information
948 * Failure: error code from winerror.h
950 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
953 char nameBuf[MAX_ADAPTER_NAME];
956 TRACE("pIfRow %p\n", pIfRow);
958 return ERROR_INVALID_PARAMETER;
960 name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf);
962 ret = getInterfaceEntryByName(name, pIfRow);
964 ret = getInterfaceStatsByName(name, pIfRow);
967 ret = ERROR_INVALID_DATA;
968 TRACE("returning %d\n", ret);
973 static int IfTableSorter(const void *a, const void *b)
978 ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
985 /******************************************************************
986 * GetIfTable (IPHLPAPI.@)
988 * Get a table of local interfaces.
991 * pIfTable [Out] buffer for local interfaces table
992 * pdwSize [In/Out] length of output buffer
993 * bOrder [In] whether to sort the table
997 * Failure: error code from winerror.h
1000 * If pdwSize is less than required, the function will return
1001 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1003 * If bOrder is true, the returned table will be sorted by interface index.
1005 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
1009 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize, pdwSize,
1012 ret = ERROR_INVALID_PARAMETER;
1014 DWORD numInterfaces = getNumInterfaces();
1015 ULONG size = sizeof(MIB_IFTABLE) + (numInterfaces - 1) * sizeof(MIB_IFROW);
1017 if (!pIfTable || *pdwSize < size) {
1019 ret = ERROR_INSUFFICIENT_BUFFER;
1022 InterfaceIndexTable *table = getInterfaceIndexTable();
1025 size = sizeof(MIB_IFTABLE) + (table->numIndexes - 1) *
1027 if (*pdwSize < size) {
1029 ret = ERROR_INSUFFICIENT_BUFFER;
1035 pIfTable->dwNumEntries = 0;
1036 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1037 pIfTable->table[ndx].dwIndex = table->indexes[ndx];
1038 GetIfEntry(&pIfTable->table[ndx]);
1039 pIfTable->dwNumEntries++;
1042 qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
1046 HeapFree(GetProcessHeap(), 0, table);
1049 ret = ERROR_OUTOFMEMORY;
1052 TRACE("returning %d\n", ret);
1057 /******************************************************************
1058 * GetInterfaceInfo (IPHLPAPI.@)
1060 * Get a list of network interface adapters.
1063 * pIfTable [Out] buffer for interface adapters
1064 * dwOutBufLen [Out] if buffer is too small, returns required size
1068 * Failure: error code from winerror.h
1071 * MSDN states this should return non-loopback interfaces only.
1073 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
1077 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1079 ret = ERROR_INVALID_PARAMETER;
1081 DWORD numInterfaces = getNumInterfaces();
1082 ULONG size = sizeof(IP_INTERFACE_INFO) + (numInterfaces - 1) *
1083 sizeof(IP_ADAPTER_INDEX_MAP);
1085 if (!pIfTable || *dwOutBufLen < size) {
1086 *dwOutBufLen = size;
1087 ret = ERROR_INSUFFICIENT_BUFFER;
1090 InterfaceIndexTable *table = getInterfaceIndexTable();
1093 size = sizeof(IP_INTERFACE_INFO) + (table->numIndexes - 1) *
1094 sizeof(IP_ADAPTER_INDEX_MAP);
1095 if (*dwOutBufLen < size) {
1096 *dwOutBufLen = size;
1097 ret = ERROR_INSUFFICIENT_BUFFER;
1101 char nameBuf[MAX_ADAPTER_NAME];
1103 *dwOutBufLen = size;
1104 pIfTable->NumAdapters = 0;
1105 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1106 const char *walker, *name;
1109 pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1110 name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
1111 for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
1112 walker && *walker &&
1113 assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
1114 walker++, assigner++)
1115 *assigner = *walker;
1117 pIfTable->NumAdapters++;
1121 HeapFree(GetProcessHeap(), 0, table);
1124 ret = ERROR_OUTOFMEMORY;
1127 TRACE("returning %d\n", ret);
1132 /******************************************************************
1133 * GetIpAddrTable (IPHLPAPI.@)
1135 * Get interface-to-IP address mapping table.
1138 * pIpAddrTable [Out] buffer for mapping table
1139 * pdwSize [In/Out] length of output buffer
1140 * bOrder [In] whether to sort the table
1144 * Failure: error code from winerror.h
1147 * If pdwSize is less than required, the function will return
1148 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1150 * If bOrder is true, the returned table will be sorted by the next hop and
1151 * an assortment of arbitrary parameters.
1153 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1157 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable, pdwSize,
1160 ret = ERROR_INVALID_PARAMETER;
1162 PMIB_IPADDRTABLE table;
1164 ret = getIPAddrTable(&table, GetProcessHeap(), 0);
1165 if (ret == NO_ERROR)
1167 ULONG size = sizeof(MIB_IPADDRTABLE) + (table->dwNumEntries - 1) *
1168 sizeof(MIB_IPADDRROW);
1170 if (!pIpAddrTable || *pdwSize < size) {
1172 ret = ERROR_INSUFFICIENT_BUFFER;
1176 memcpy(pIpAddrTable, table, sizeof(MIB_IPADDRTABLE) +
1177 (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW));
1179 qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1180 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1183 HeapFree(GetProcessHeap(), 0, table);
1186 TRACE("returning %d\n", ret);
1191 /******************************************************************
1192 * GetIpForwardTable (IPHLPAPI.@)
1194 * Get the route table.
1197 * pIpForwardTable [Out] buffer for route table
1198 * pdwSize [In/Out] length of output buffer
1199 * bOrder [In] whether to sort the table
1203 * Failure: error code from winerror.h
1206 * If pdwSize is less than required, the function will return
1207 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1209 * If bOrder is true, the returned table will be sorted by the next hop and
1210 * an assortment of arbitrary parameters.
1212 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1216 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable,
1217 pdwSize, (DWORD)bOrder);
1219 ret = ERROR_INVALID_PARAMETER;
1221 DWORD numRoutes = getNumRoutes();
1222 ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) *
1223 sizeof(MIB_IPFORWARDROW);
1225 if (!pIpForwardTable || *pdwSize < sizeNeeded) {
1226 *pdwSize = sizeNeeded;
1227 ret = ERROR_INSUFFICIENT_BUFFER;
1230 PMIB_IPFORWARDTABLE table;
1232 ret = getRouteTable(&table, GetProcessHeap(), 0);
1234 sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (table->dwNumEntries - 1) *
1235 sizeof(MIB_IPFORWARDROW);
1236 if (*pdwSize < sizeNeeded) {
1237 *pdwSize = sizeNeeded;
1238 ret = ERROR_INSUFFICIENT_BUFFER;
1241 *pdwSize = sizeNeeded;
1242 memcpy(pIpForwardTable, table, sizeNeeded);
1244 qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
1245 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1248 HeapFree(GetProcessHeap(), 0, table);
1252 TRACE("returning %d\n", ret);
1257 /******************************************************************
1258 * GetIpNetTable (IPHLPAPI.@)
1260 * Get the IP-to-physical address mapping table.
1263 * pIpNetTable [Out] buffer for mapping table
1264 * pdwSize [In/Out] length of output buffer
1265 * bOrder [In] whether to sort the table
1269 * Failure: error code from winerror.h
1272 * If pdwSize is less than required, the function will return
1273 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1275 * If bOrder is true, the returned table will be sorted by IP address.
1277 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1281 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable, pdwSize,
1284 ret = ERROR_INVALID_PARAMETER;
1286 DWORD numEntries = getNumArpEntries();
1287 ULONG size = sizeof(MIB_IPNETTABLE) + (numEntries - 1) *
1288 sizeof(MIB_IPNETROW);
1290 if (!pIpNetTable || *pdwSize < size) {
1292 ret = ERROR_INSUFFICIENT_BUFFER;
1295 PMIB_IPNETTABLE table;
1297 ret = getArpTable(&table, GetProcessHeap(), 0);
1299 size = sizeof(MIB_IPNETTABLE) + (table->dwNumEntries - 1) *
1300 sizeof(MIB_IPNETROW);
1301 if (*pdwSize < size) {
1303 ret = ERROR_INSUFFICIENT_BUFFER;
1307 memcpy(pIpNetTable, table, size);
1309 qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
1310 sizeof(MIB_IPNETROW), IpNetTableSorter);
1313 HeapFree(GetProcessHeap(), 0, table);
1317 TRACE("returning %d\n", ret);
1322 /******************************************************************
1323 * GetIpStatistics (IPHLPAPI.@)
1325 * Get the IP statistics for the local computer.
1328 * pStats [Out] buffer for IP statistics
1332 * Failure: error code from winerror.h
1334 DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
1338 TRACE("pStats %p\n", pStats);
1339 ret = getIPStats(pStats);
1340 TRACE("returning %d\n", ret);
1345 /******************************************************************
1346 * GetNetworkParams (IPHLPAPI.@)
1348 * Get the network parameters for the local computer.
1351 * pFixedInfo [Out] buffer for network parameters
1352 * pOutBufLen [In/Out] length of output buffer
1356 * Failure: error code from winerror.h
1359 * If pOutBufLen is less than required, the function will return
1360 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1363 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1369 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1371 return ERROR_INVALID_PARAMETER;
1373 initialise_resolver();
1374 size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount - 1) *
1375 sizeof(IP_ADDR_STRING) : 0);
1376 if (!pFixedInfo || *pOutBufLen < size) {
1378 return ERROR_BUFFER_OVERFLOW;
1381 memset(pFixedInfo, 0, size);
1382 size = sizeof(pFixedInfo->HostName);
1383 GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1384 size = sizeof(pFixedInfo->DomainName);
1385 GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1386 if (_res.nscount > 0) {
1387 PIP_ADDR_STRING ptr;
1390 for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1391 i++, ptr = ptr->Next) {
1392 toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
1393 ptr->IpAddress.String);
1394 if (i == _res.nscount - 1)
1397 ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
1399 ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1402 pFixedInfo->NodeType = HYBRID_NODETYPE;
1403 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1404 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1405 if (regReturn != ERROR_SUCCESS)
1406 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1407 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1409 if (regReturn == ERROR_SUCCESS)
1411 DWORD size = sizeof(pFixedInfo->ScopeId);
1413 RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1417 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1418 I suppose could also check for a listener on port 53 to set EnableDns */
1420 TRACE("returning %d\n", ret);
1425 /******************************************************************
1426 * GetNumberOfInterfaces (IPHLPAPI.@)
1428 * Get the number of interfaces.
1431 * pdwNumIf [Out] number of interfaces
1434 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1436 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
1440 TRACE("pdwNumIf %p\n", pdwNumIf);
1442 ret = ERROR_INVALID_PARAMETER;
1444 *pdwNumIf = getNumInterfaces();
1447 TRACE("returning %d\n", ret);
1452 /******************************************************************
1453 * GetPerAdapterInfo (IPHLPAPI.@)
1455 * Get information about an adapter corresponding to an interface.
1458 * IfIndex [In] interface info
1459 * pPerAdapterInfo [Out] buffer for per adapter info
1460 * pOutBufLen [In/Out] length of output buffer
1464 * Failure: error code from winerror.h
1467 * Stub, returns empty IP_PER_ADAPTER_INFO in every case.
1469 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
1471 ULONG bytesNeeded = sizeof(IP_PER_ADAPTER_INFO);
1474 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex,
1475 pPerAdapterInfo, pOutBufLen);
1477 ret = ERROR_INVALID_PARAMETER;
1478 else if (!pPerAdapterInfo)
1480 *pOutBufLen = bytesNeeded;
1483 else if (*pOutBufLen < bytesNeeded)
1485 *pOutBufLen = bytesNeeded;
1486 ret = ERROR_BUFFER_OVERFLOW;
1490 memset(pPerAdapterInfo, 0, bytesNeeded);
1497 /******************************************************************
1498 * GetRTTAndHopCount (IPHLPAPI.@)
1500 * Get round-trip time (RTT) and hop count.
1504 * DestIpAddress [In] destination address to get the info for
1505 * HopCount [Out] retrieved hop count
1506 * MaxHops [In] maximum hops to search for the destination
1507 * RTT [Out] RTT in milliseconds
1514 * Stub, returns FALSE.
1516 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
1518 FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %d, RTT %p): stub\n",
1519 DestIpAddress, HopCount, MaxHops, RTT);
1524 /******************************************************************
1525 * GetTcpStatistics (IPHLPAPI.@)
1527 * Get the TCP statistics for the local computer.
1530 * pStats [Out] buffer for TCP statistics
1534 * Failure: error code from winerror.h
1536 DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
1540 TRACE("pStats %p\n", pStats);
1541 ret = getTCPStats(pStats);
1542 TRACE("returning %d\n", ret);
1547 /******************************************************************
1548 * GetTcpTable (IPHLPAPI.@)
1550 * Get the table of active TCP connections.
1553 * pTcpTable [Out] buffer for TCP connections table
1554 * pdwSize [In/Out] length of output buffer
1555 * bOrder [In] whether to order the table
1559 * Failure: error code from winerror.h
1562 * If pdwSize is less than required, the function will return
1563 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1564 * the required byte size.
1565 * If bOrder is true, the returned table will be sorted, first by
1566 * local address and port number, then by remote address and port
1569 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
1573 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize,
1576 ret = ERROR_INVALID_PARAMETER;
1578 DWORD numEntries = getNumTcpEntries();
1579 DWORD size = sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW);
1581 if (!pTcpTable || *pdwSize < size) {
1583 ret = ERROR_INSUFFICIENT_BUFFER;
1586 ret = getTcpTable(&pTcpTable, numEntries, 0, 0);
1588 size = sizeof(MIB_TCPTABLE) + (pTcpTable->dwNumEntries - 1) *
1593 qsort(pTcpTable->table, pTcpTable->dwNumEntries,
1594 sizeof(MIB_TCPROW), TcpTableSorter);
1598 ret = ERROR_OUTOFMEMORY;
1601 TRACE("returning %d\n", ret);
1606 /******************************************************************
1607 * GetUdpStatistics (IPHLPAPI.@)
1609 * Get the UDP statistics for the local computer.
1612 * pStats [Out] buffer for UDP statistics
1616 * Failure: error code from winerror.h
1618 DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
1622 TRACE("pStats %p\n", pStats);
1623 ret = getUDPStats(pStats);
1624 TRACE("returning %d\n", ret);
1629 /******************************************************************
1630 * GetUdpTable (IPHLPAPI.@)
1632 * Get a table of active UDP connections.
1635 * pUdpTable [Out] buffer for UDP connections table
1636 * pdwSize [In/Out] length of output buffer
1637 * bOrder [In] whether to order the table
1641 * Failure: error code from winerror.h
1644 * If pdwSize is less than required, the function will return
1645 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1646 * required byte size.
1647 * If bOrder is true, the returned table will be sorted, first by
1648 * local address, then by local port number.
1650 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
1654 TRACE("pUdpTable %p, pdwSize %p, bOrder %d\n", pUdpTable, pdwSize,
1657 ret = ERROR_INVALID_PARAMETER;
1659 DWORD numEntries = getNumUdpEntries();
1660 DWORD size = sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW);
1662 if (!pUdpTable || *pdwSize < size) {
1664 ret = ERROR_INSUFFICIENT_BUFFER;
1667 PMIB_UDPTABLE table;
1669 ret = getUdpTable(&table, GetProcessHeap(), 0);
1671 size = sizeof(MIB_UDPTABLE) + (table->dwNumEntries - 1) *
1673 if (*pdwSize < size) {
1675 ret = ERROR_INSUFFICIENT_BUFFER;
1679 memcpy(pUdpTable, table, size);
1681 qsort(pUdpTable->table, pUdpTable->dwNumEntries,
1682 sizeof(MIB_UDPROW), UdpTableSorter);
1685 HeapFree(GetProcessHeap(), 0, table);
1688 ret = ERROR_OUTOFMEMORY;
1691 TRACE("returning %d\n", ret);
1696 /******************************************************************
1697 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1699 * This is a Win98-only function to get information on "unidirectional"
1700 * adapters. Since this is pretty nonsensical in other contexts, it
1701 * never returns anything.
1704 * pIPIfInfo [Out] buffer for adapter infos
1705 * dwOutBufLen [Out] length of the output buffer
1709 * Failure: error code from winerror.h
1712 * Stub, returns ERROR_NOT_SUPPORTED.
1714 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
1716 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1717 /* a unidirectional adapter?? not bloody likely! */
1718 return ERROR_NOT_SUPPORTED;
1722 /******************************************************************
1723 * IpReleaseAddress (IPHLPAPI.@)
1725 * Release an IP optained through DHCP,
1728 * AdapterInfo [In] adapter to release IP address
1732 * Failure: error code from winerror.h
1735 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1736 * this function does nothing.
1739 * Stub, returns ERROR_NOT_SUPPORTED.
1741 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1743 TRACE("AdapterInfo %p\n", AdapterInfo);
1744 /* not a stub, never going to support this (and I never mark an adapter as
1745 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1746 return ERROR_NOT_SUPPORTED;
1750 /******************************************************************
1751 * IpRenewAddress (IPHLPAPI.@)
1753 * Renew an IP optained through DHCP.
1756 * AdapterInfo [In] adapter to renew IP address
1760 * Failure: error code from winerror.h
1763 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1764 * this function does nothing.
1767 * Stub, returns ERROR_NOT_SUPPORTED.
1769 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1771 TRACE("AdapterInfo %p\n", AdapterInfo);
1772 /* not a stub, never going to support this (and I never mark an adapter as
1773 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1774 return ERROR_NOT_SUPPORTED;
1778 /******************************************************************
1779 * NotifyAddrChange (IPHLPAPI.@)
1781 * Notify caller whenever the ip-interface map is changed.
1784 * Handle [Out] handle useable in asynchronus notification
1785 * overlapped [In] overlapped structure that notifies the caller
1789 * Failure: error code from winerror.h
1792 * Stub, returns ERROR_NOT_SUPPORTED.
1794 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1796 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1797 return ERROR_NOT_SUPPORTED;
1801 /******************************************************************
1802 * NotifyRouteChange (IPHLPAPI.@)
1804 * Notify caller whenever the ip routing table is changed.
1807 * Handle [Out] handle useable in asynchronus notification
1808 * overlapped [In] overlapped structure that notifies the caller
1812 * Failure: error code from winerror.h
1815 * Stub, returns ERROR_NOT_SUPPORTED.
1817 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1819 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1820 return ERROR_NOT_SUPPORTED;
1824 /******************************************************************
1825 * SendARP (IPHLPAPI.@)
1827 * Send an ARP request.
1830 * DestIP [In] attempt to obtain this IP
1831 * SrcIP [In] optional sender IP address
1832 * pMacAddr [Out] buffer for the mac address
1833 * PhyAddrLen [In/Out] length of the output buffer
1837 * Failure: error code from winerror.h
1840 * Stub, returns ERROR_NOT_SUPPORTED.
1842 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
1844 FIXME("(DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p): stub\n",
1845 DestIP, SrcIP, pMacAddr, PhyAddrLen);
1846 return ERROR_NOT_SUPPORTED;
1850 /******************************************************************
1851 * SetIfEntry (IPHLPAPI.@)
1853 * Set the administrative status of an interface.
1856 * pIfRow [In] dwAdminStatus member specifies the new status.
1860 * Failure: error code from winerror.h
1863 * Stub, returns ERROR_NOT_SUPPORTED.
1865 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
1867 FIXME("(pIfRow %p): stub\n", pIfRow);
1868 /* this is supposed to set an interface administratively up or down.
1869 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1870 this sort of down is indistinguishable from other sorts of down (e.g. no
1872 return ERROR_NOT_SUPPORTED;
1876 /******************************************************************
1877 * SetIpForwardEntry (IPHLPAPI.@)
1879 * Modify an existing route.
1882 * pRoute [In] route with the new information
1886 * Failure: error code from winerror.h
1889 * Stub, returns NO_ERROR.
1891 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
1893 FIXME("(pRoute %p): stub\n", pRoute);
1894 /* this is to add a route entry, how's it distinguishable from
1895 CreateIpForwardEntry?
1896 could use SIOCADDRT, not sure I want to */
1901 /******************************************************************
1902 * SetIpNetEntry (IPHLPAPI.@)
1904 * Modify an existing ARP entry.
1907 * pArpEntry [In] ARP entry with the new information
1911 * Failure: error code from winerror.h
1914 * Stub, returns NO_ERROR.
1916 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
1918 FIXME("(pArpEntry %p): stub\n", pArpEntry);
1919 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1924 /******************************************************************
1925 * SetIpStatistics (IPHLPAPI.@)
1927 * Toggle IP forwarding and det the default TTL value.
1930 * pIpStats [In] IP statistics with the new information
1934 * Failure: error code from winerror.h
1937 * Stub, returns NO_ERROR.
1939 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
1941 FIXME("(pIpStats %p): stub\n", pIpStats);
1946 /******************************************************************
1947 * SetIpTTL (IPHLPAPI.@)
1949 * Set the default TTL value.
1952 * nTTL [In] new TTL value
1956 * Failure: error code from winerror.h
1959 * Stub, returns NO_ERROR.
1961 DWORD WINAPI SetIpTTL(UINT nTTL)
1963 FIXME("(nTTL %d): stub\n", nTTL);
1964 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1965 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1970 /******************************************************************
1971 * SetTcpEntry (IPHLPAPI.@)
1973 * Set the state of a TCP connection.
1976 * pTcpRow [In] specifies connection with new state
1980 * Failure: error code from winerror.h
1983 * Stub, returns NO_ERROR.
1985 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
1987 FIXME("(pTcpRow %p): stub\n", pTcpRow);
1992 /******************************************************************
1993 * UnenableRouter (IPHLPAPI.@)
1995 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
1996 * if it reaches zero.
1999 * pOverlapped [In/Out] should be the same as in EnableRouter()
2000 * lpdwEnableCount [Out] optional, receives reference count
2004 * Failure: error code from winerror.h
2007 * Stub, returns ERROR_NOT_SUPPORTED.
2009 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
2011 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
2013 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
2014 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
2016 return ERROR_NOT_SUPPORTED;