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., 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] whether to sort 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 static int IpAddrTableSorter(const void *a, const void *b)
139 ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
146 /******************************************************************
147 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
149 * Get interface-to-IP address mapping table.
150 * Like GetIpAddrTable(), but allocate the returned table from heap.
153 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
154 * allocated and returned.
155 * bOrder [In] whether to sort the table
156 * heap [In] heap from which the table is allocated
157 * flags [In] flags to HeapAlloc
160 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
161 * failure, NO_ERROR on success.
163 DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
164 BOOL bOrder, HANDLE heap, DWORD flags)
168 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
169 ppIpAddrTable, bOrder, heap, flags);
170 ret = getIPAddrTable(ppIpAddrTable, heap, flags);
172 qsort((*ppIpAddrTable)->table, (*ppIpAddrTable)->dwNumEntries,
173 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
174 TRACE("returning %ld\n", ret);
179 static int IpForwardTableSorter(const void *a, const void *b)
184 const MIB_IPFORWARDROW* rowA = (const MIB_IPFORWARDROW*)a;
185 const MIB_IPFORWARDROW* rowB = (const MIB_IPFORWARDROW*)b;
187 ret = rowA->dwForwardDest - rowB->dwForwardDest;
189 ret = rowA->dwForwardProto - rowB->dwForwardProto;
191 ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy;
193 ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop;
203 /******************************************************************
204 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
206 * Get the route table.
207 * Like GetIpForwardTable(), but allocate the returned table from heap.
210 * ppIpForwardTable [Out] pointer into which the MIB_IPFORWARDTABLE is
211 * allocated and returned.
212 * bOrder [In] whether to sort the table
213 * heap [In] heap from which the table is allocated
214 * flags [In] flags to HeapAlloc
217 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, other error codes
218 * on failure, NO_ERROR on success.
220 DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
221 ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags)
225 TRACE("ppIpForwardTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
226 ppIpForwardTable, bOrder, heap, flags);
227 ret = getRouteTable(ppIpForwardTable, heap, flags);
229 qsort((*ppIpForwardTable)->table, (*ppIpForwardTable)->dwNumEntries,
230 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
231 TRACE("returning %ld\n", ret);
236 static int IpNetTableSorter(const void *a, const void *b)
241 ret = ((const MIB_IPNETROW*)a)->dwAddr - ((const MIB_IPNETROW*)b)->dwAddr;
248 /******************************************************************
249 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
251 * Get the IP-to-physical address mapping table.
252 * Like GetIpNetTable(), but allocate the returned table from heap.
255 * ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE is
256 * allocated and returned.
257 * bOrder [In] whether to sort the table
258 * heap [In] heap from which the table is allocated
259 * flags [In] flags to HeapAlloc
262 * ERROR_INVALID_PARAMETER if ppIpNetTable is NULL, other error codes
263 * on failure, NO_ERROR on success.
265 DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable,
266 BOOL bOrder, HANDLE heap, DWORD flags)
270 TRACE("ppIpNetTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
271 ppIpNetTable, bOrder, heap, flags);
272 ret = getArpTable(ppIpNetTable, heap, flags);
274 qsort((*ppIpNetTable)->table, (*ppIpNetTable)->dwNumEntries,
275 sizeof(MIB_IPADDRROW), IpNetTableSorter);
276 TRACE("returning %ld\n", ret);
281 static int TcpTableSorter(const void *a, const void *b)
286 const MIB_TCPROW* rowA = a;
287 const MIB_TCPROW* rowB = b;
289 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
291 ret = rowA->dwLocalPort - rowB->dwLocalPort;
293 ret = rowA->dwRemoteAddr - rowB->dwRemoteAddr;
295 ret = rowA->dwRemotePort - rowB->dwRemotePort;
305 /******************************************************************
306 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
308 * Get the TCP connection table.
309 * Like GetTcpTable(), but allocate the returned table from heap.
312 * ppTcpTable [Out] pointer into which the MIB_TCPTABLE is
313 * allocated and returned.
314 * bOrder [In] whether to sort the table
315 * heap [In] heap from which the table is allocated
316 * flags [In] flags to HeapAlloc
319 * ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable()
322 DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
323 BOOL bOrder, HANDLE heap, DWORD flags)
327 TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
328 ppTcpTable, bOrder, heap, flags);
329 ret = getTcpTable(ppTcpTable, heap, flags);
331 qsort((*ppTcpTable)->table, (*ppTcpTable)->dwNumEntries,
332 sizeof(MIB_TCPROW), TcpTableSorter);
333 TRACE("returning %ld\n", ret);
338 static int UdpTableSorter(const void *a, const void *b)
343 const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
344 const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;
346 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
348 ret = rowA->dwLocalPort - rowB->dwLocalPort;
356 /******************************************************************
357 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
359 * Get the UDP listener table.
360 * Like GetUdpTable(), but allocate the returned table from heap.
363 * ppUdpTable [Out] pointer into which the MIB_UDPTABLE is
364 * allocated and returned.
365 * bOrder [In] whether to sort the table
366 * heap [In] heap from which the table is allocated
367 * flags [In] flags to HeapAlloc
370 * ERROR_INVALID_PARAMETER if ppUdpTable is NULL, whatever GetUdpTable()
373 DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
374 BOOL bOrder, HANDLE heap, DWORD flags)
378 TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
379 ppUdpTable, bOrder, heap, flags);
380 ret = getUdpTable(ppUdpTable, heap, flags);
382 qsort((*ppUdpTable)->table, (*ppUdpTable)->dwNumEntries,
383 sizeof(MIB_UDPROW), UdpTableSorter);
384 TRACE("returning %ld\n", ret);
389 /******************************************************************
390 * CreateIpForwardEntry (IPHLPAPI.@)
392 * Create a route in the local computer's IP table.
395 * pRoute [In] new route information
399 * Failure: error code from winerror.h
402 * Stub, always returns NO_ERROR.
404 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
406 FIXME("(pRoute %p): stub\n", pRoute);
407 /* could use SIOCADDRT, not sure I want to */
412 /******************************************************************
413 * CreateIpNetEntry (IPHLPAPI.@)
415 * Create entry in the ARP table.
418 * pArpEntry [In] new ARP entry
422 * Failure: error code from winerror.h
425 * Stub, always returns NO_ERROR.
427 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
429 FIXME("(pArpEntry %p)\n", pArpEntry);
430 /* could use SIOCSARP on systems that support it, not sure I want to */
435 /******************************************************************
436 * CreateProxyArpEntry (IPHLPAPI.@)
438 * Create a Proxy ARP (PARP) entry for an IP address.
441 * dwAddress [In] IP address for which this computer acts as a proxy.
442 * dwMask [In] subnet mask for dwAddress
443 * dwIfIndex [In] interface index
447 * Failure: error code from winerror.h
450 * Stub, returns ERROR_NOT_SUPPORTED.
452 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
454 FIXME("(dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx): stub\n",
455 dwAddress, dwMask, dwIfIndex);
456 return ERROR_NOT_SUPPORTED;
460 /******************************************************************
461 * DeleteIPAddress (IPHLPAPI.@)
463 * Delete an IP address added with AddIPAddress().
466 * NTEContext [In] NTE context from AddIPAddress();
470 * Failure: error code from winerror.h
473 * Stub, returns ERROR_NOT_SUPPORTED.
475 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
477 FIXME("(NTEContext %ld): stub\n", NTEContext);
478 return ERROR_NOT_SUPPORTED;
482 /******************************************************************
483 * DeleteIpForwardEntry (IPHLPAPI.@)
488 * pRoute [In] route to delete
492 * Failure: error code from winerror.h
495 * Stub, returns NO_ERROR.
497 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
499 FIXME("(pRoute %p): stub\n", pRoute);
500 /* could use SIOCDELRT, not sure I want to */
505 /******************************************************************
506 * DeleteIpNetEntry (IPHLPAPI.@)
508 * Delete an ARP entry.
511 * pArpEntry [In] ARP entry to delete
515 * Failure: error code from winerror.h
518 * Stub, returns NO_ERROR.
520 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
522 FIXME("(pArpEntry %p): stub\n", pArpEntry);
523 /* could use SIOCDARP on systems that support it, not sure I want to */
528 /******************************************************************
529 * DeleteProxyArpEntry (IPHLPAPI.@)
531 * Delete a Proxy ARP entry.
534 * dwAddress [In] IP address for which this computer acts as a proxy.
535 * dwMask [In] subnet mask for dwAddress
536 * dwIfIndex [In] interface index
540 * Failure: error code from winerror.h
543 * Stub, returns ERROR_NOT_SUPPORTED.
545 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
547 FIXME("(dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx): stub\n",
548 dwAddress, dwMask, dwIfIndex);
549 return ERROR_NOT_SUPPORTED;
553 /******************************************************************
554 * EnableRouter (IPHLPAPI.@)
556 * Turn on ip forwarding.
560 * pOverlapped [In/Out] hEvent member should contain a valid handle.
563 * Success: ERROR_IO_PENDING
564 * Failure: error code from winerror.h
567 * Stub, returns ERROR_NOT_SUPPORTED.
569 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
571 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle, pOverlapped);
572 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
573 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
575 return ERROR_NOT_SUPPORTED;
579 /******************************************************************
580 * FlushIpNetTable (IPHLPAPI.@)
582 * Delete all ARP entries of an interface
585 * dwIfIndex [In] interface index
589 * Failure: error code from winerror.h
592 * Stub, returns ERROR_NOT_SUPPORTED.
594 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
596 FIXME("(dwIfIndex 0x%08lx): stub\n", dwIfIndex);
597 /* this flushes the arp cache of the given index */
598 return ERROR_NOT_SUPPORTED;
602 /******************************************************************
603 * GetAdapterIndex (IPHLPAPI.@)
605 * Get interface index from its name.
608 * AdapterName [In] unicode string with the adapter name
609 * IfIndex [Out] returns found interface index
613 * Failure: error code from winerror.h
616 * Stub, returns ERROR_NOT_SUPPORTED.
618 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
620 FIXME("(AdapterName %p, IfIndex %p): stub\n", AdapterName, IfIndex);
621 /* FIXME: implement using getInterfaceIndexByName */
622 return ERROR_NOT_SUPPORTED;
626 /******************************************************************
627 * GetAdaptersInfo (IPHLPAPI.@)
629 * Get information about adapters.
632 * pAdapterInfo [Out] buffer for adapter infos
633 * pOutBufLen [In] length of output buffer
637 * Failure: error code from winerror.h
639 DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
643 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
645 ret = ERROR_INVALID_PARAMETER;
647 DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
649 if (numNonLoopbackInterfaces > 0) {
650 DWORD numIPAddresses = getNumIPAddresses();
653 /* This may slightly overestimate the amount of space needed, because
654 * the IP addresses include the loopback address, but it's easier
655 * to make sure there's more than enough space than to make sure there's
656 * precisely enough space.
658 size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
659 if (numIPAddresses > numNonLoopbackInterfaces)
660 size += (numIPAddresses - numNonLoopbackInterfaces) *
661 sizeof(IP_ADDR_STRING);
662 if (!pAdapterInfo || *pOutBufLen < size) {
664 ret = ERROR_BUFFER_OVERFLOW;
667 InterfaceIndexTable *table = NULL;
668 PMIB_IPADDRTABLE ipAddrTable = NULL;
670 ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
672 table = getNonLoopbackInterfaceIndexTable();
674 size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
675 if (ipAddrTable->dwNumEntries > numNonLoopbackInterfaces)
676 size += (ipAddrTable->dwNumEntries - numNonLoopbackInterfaces) *
677 sizeof(IP_ADDR_STRING);
678 if (*pOutBufLen < size) {
680 ret = ERROR_INSUFFICIENT_BUFFER;
685 BOOL winsEnabled = FALSE;
686 IP_ADDRESS_STRING primaryWINS, secondaryWINS;
687 PIP_ADDR_STRING nextIPAddr = (PIP_ADDR_STRING)((LPBYTE)pAdapterInfo
688 + numNonLoopbackInterfaces * sizeof(IP_ADAPTER_INFO));
690 memset(pAdapterInfo, 0, size);
691 /* @@ Wine registry key: HKCU\Software\Wine\Network */
692 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network",
693 &hKey) == ERROR_SUCCESS) {
694 DWORD size = sizeof(primaryWINS.String);
697 RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
698 (LPBYTE)primaryWINS.String, &size);
699 addr = inet_addr(primaryWINS.String);
700 if (addr != INADDR_NONE && addr != INADDR_ANY)
702 size = sizeof(secondaryWINS.String);
703 RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
704 (LPBYTE)secondaryWINS.String, &size);
705 addr = inet_addr(secondaryWINS.String);
706 if (addr != INADDR_NONE && addr != INADDR_ANY)
710 for (ndx = 0; ndx < table->numIndexes; ndx++) {
711 PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
712 DWORD addrLen = sizeof(ptr->Address), type, i;
713 PIP_ADDR_STRING currentIPAddr = &ptr->IpAddressList;
714 BOOL firstIPAddr = TRUE;
716 /* on Win98 this is left empty, but whatever */
717 lstrcpynA(ptr->AdapterName,
718 getInterfaceNameByIndex(table->indexes[ndx]),
719 MAX_ADAPTER_NAME_LENGTH+1);
720 getInterfacePhysicalByIndex(table->indexes[ndx], &addrLen,
721 ptr->Address, &type);
722 /* MS defines address length and type as UINT in some places and
723 DWORD in others, **sigh**. Don't want to assume that PUINT and
724 PDWORD are equiv (64-bit?) */
725 ptr->AddressLength = addrLen;
727 ptr->Index = table->indexes[ndx];
728 for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
729 if (ipAddrTable->table[i].dwIndex == ptr->Index) {
731 toIPAddressString(ipAddrTable->table[i].dwAddr,
732 ptr->IpAddressList.IpAddress.String);
733 toIPAddressString(ipAddrTable->table[i].dwBCastAddr,
734 ptr->IpAddressList.IpMask.String);
738 currentIPAddr->Next = nextIPAddr;
739 currentIPAddr = nextIPAddr;
740 toIPAddressString(ipAddrTable->table[i].dwAddr,
741 currentIPAddr->IpAddress.String);
742 toIPAddressString(ipAddrTable->table[i].dwBCastAddr,
743 currentIPAddr->IpMask.String);
749 ptr->HaveWins = TRUE;
750 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
751 primaryWINS.String, sizeof(primaryWINS.String));
752 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
753 secondaryWINS.String, sizeof(secondaryWINS.String));
755 if (ndx < table->numIndexes - 1)
756 ptr->Next = &pAdapterInfo[ndx + 1];
762 HeapFree(GetProcessHeap(), 0, table);
765 ret = ERROR_OUTOFMEMORY;
767 HeapFree(GetProcessHeap(), 0, ipAddrTable);
773 TRACE("returning %ld\n", ret);
778 /******************************************************************
779 * GetBestInterface (IPHLPAPI.@)
781 * Get the interface, with the best route for the given IP address.
784 * dwDestAddr [In] IP address to search the interface for
785 * pdwBestIfIndex [Out] found best interface
789 * Failure: error code from winerror.h
791 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
795 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex);
797 ret = ERROR_INVALID_PARAMETER;
799 MIB_IPFORWARDROW ipRow;
801 ret = GetBestRoute(dwDestAddr, 0, &ipRow);
802 if (ret == ERROR_SUCCESS)
803 *pdwBestIfIndex = ipRow.dwForwardIfIndex;
805 TRACE("returning %ld\n", ret);
810 /******************************************************************
811 * GetBestRoute (IPHLPAPI.@)
813 * Get the best route for the given IP address.
816 * dwDestAddr [In] IP address to search the best route for
817 * dwSourceAddr [In] optional source IP address
818 * pBestRoute [Out] found best route
822 * Failure: error code from winerror.h
824 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
826 PMIB_IPFORWARDTABLE table;
829 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr,
830 dwSourceAddr, pBestRoute);
832 return ERROR_INVALID_PARAMETER;
834 AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
836 DWORD ndx, matchedBits, matchedNdx = 0;
838 for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
839 if (table->table[ndx].dwForwardType != MIB_IPROUTE_TYPE_INVALID &&
840 (dwDestAddr & table->table[ndx].dwForwardMask) ==
841 (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
842 DWORD numShifts, mask;
844 for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
845 mask && !(mask & 1); mask >>= 1, numShifts++)
847 if (numShifts > matchedBits) {
848 matchedBits = numShifts;
853 if (matchedNdx < table->dwNumEntries) {
854 memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
858 /* No route matches, which can happen if there's no default route. */
859 ret = ERROR_HOST_UNREACHABLE;
861 HeapFree(GetProcessHeap(), 0, table);
864 ret = ERROR_OUTOFMEMORY;
865 TRACE("returning %ld\n", ret);
870 /******************************************************************
871 * GetFriendlyIfIndex (IPHLPAPI.@)
873 * Get a "friendly" version of IfIndex, which is one that doesn't
874 * have the top byte set. Doesn't validate whether IfIndex is a valid
878 * IfIndex [In] interface index to get the friendly one for
881 * A friendly version of IfIndex.
883 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
885 /* windows doesn't validate these, either, just makes sure the top byte is
886 cleared. I assume my ifenum module never gives an index with the top
888 TRACE("returning %ld\n", IfIndex);
893 /******************************************************************
894 * GetIcmpStatistics (IPHLPAPI.@)
896 * Get the ICMP statistics for the local computer.
899 * pStats [Out] buffer for ICMP statistics
903 * Failure: error code from winerror.h
905 DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
909 TRACE("pStats %p\n", pStats);
910 ret = getICMPStats(pStats);
911 TRACE("returning %ld\n", ret);
916 /******************************************************************
917 * GetIfEntry (IPHLPAPI.@)
919 * Get information about an interface.
922 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
923 * Out: interface information
927 * Failure: error code from winerror.h
929 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
934 TRACE("pIfRow %p\n", pIfRow);
936 return ERROR_INVALID_PARAMETER;
938 name = getInterfaceNameByIndex(pIfRow->dwIndex);
940 ret = getInterfaceEntryByName(name, pIfRow);
942 ret = getInterfaceStatsByName(name, pIfRow);
945 ret = ERROR_INVALID_DATA;
946 TRACE("returning %ld\n", ret);
951 static int IfTableSorter(const void *a, const void *b)
956 ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
963 /******************************************************************
964 * GetIfTable (IPHLPAPI.@)
966 * Get a table of local interfaces.
969 * pIfTable [Out] buffer for local interfaces table
970 * pdwSize [In/Out] length of output buffer
971 * bOrder [In] whether to sort the table
975 * Failure: error code from winerror.h
978 * If pdwSize is less than required, the function will return
979 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
981 * If bOrder is true, the returned table will be sorted by interface index.
983 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
987 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize, pdwSize,
990 ret = ERROR_INVALID_PARAMETER;
992 DWORD numInterfaces = getNumInterfaces();
993 ULONG size = sizeof(MIB_IFTABLE) + (numInterfaces - 1) * sizeof(MIB_IFROW);
995 if (!pIfTable || *pdwSize < size) {
997 ret = ERROR_INSUFFICIENT_BUFFER;
1000 InterfaceIndexTable *table = getInterfaceIndexTable();
1003 size = sizeof(MIB_IFTABLE) + (table->numIndexes - 1) *
1005 if (*pdwSize < size) {
1007 ret = ERROR_INSUFFICIENT_BUFFER;
1013 pIfTable->dwNumEntries = 0;
1014 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1015 pIfTable->table[ndx].dwIndex = table->indexes[ndx];
1016 GetIfEntry(&pIfTable->table[ndx]);
1017 pIfTable->dwNumEntries++;
1020 qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
1024 HeapFree(GetProcessHeap(), 0, table);
1027 ret = ERROR_OUTOFMEMORY;
1030 TRACE("returning %ld\n", ret);
1035 /******************************************************************
1036 * GetInterfaceInfo (IPHLPAPI.@)
1038 * Get a list of network interface adapters.
1041 * pIfTable [Out] buffer for interface adapters
1042 * dwOutBufLen [Out] if buffer is too small, returns required size
1046 * Failure: error code from winerror.h
1048 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
1052 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1054 ret = ERROR_INVALID_PARAMETER;
1056 DWORD numInterfaces = getNumInterfaces();
1057 ULONG size = sizeof(IP_INTERFACE_INFO) + (numInterfaces - 1) *
1058 sizeof(IP_ADAPTER_INDEX_MAP);
1060 if (!pIfTable || *dwOutBufLen < size) {
1061 *dwOutBufLen = size;
1062 ret = ERROR_INSUFFICIENT_BUFFER;
1065 InterfaceIndexTable *table = getInterfaceIndexTable();
1068 size = sizeof(IP_INTERFACE_INFO) + (table->numIndexes - 1) *
1069 sizeof(IP_ADAPTER_INDEX_MAP);
1070 if (*dwOutBufLen < size) {
1071 *dwOutBufLen = size;
1072 ret = ERROR_INSUFFICIENT_BUFFER;
1077 *dwOutBufLen = size;
1078 pIfTable->NumAdapters = 0;
1079 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1080 const char *walker, *name;
1083 pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1084 name = getInterfaceNameByIndex(table->indexes[ndx]);
1085 for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
1086 walker && *walker &&
1087 assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
1088 walker++, assigner++)
1089 *assigner = *walker;
1091 pIfTable->NumAdapters++;
1095 HeapFree(GetProcessHeap(), 0, table);
1098 ret = ERROR_OUTOFMEMORY;
1101 TRACE("returning %ld\n", ret);
1106 /******************************************************************
1107 * GetIpAddrTable (IPHLPAPI.@)
1109 * Get interface-to-IP address mapping table.
1112 * pIpAddrTable [Out] buffer for mapping table
1113 * pdwSize [In/Out] length of output buffer
1114 * bOrder [In] whether to sort the table
1118 * Failure: error code from winerror.h
1121 * If pdwSize is less than required, the function will return
1122 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1124 * If bOrder is true, the returned table will be sorted by the next hop and
1125 * an assortment of arbitrary parameters.
1127 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1131 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable, pdwSize,
1134 ret = ERROR_INVALID_PARAMETER;
1136 PMIB_IPADDRTABLE table;
1138 ret = getIPAddrTable(&table, GetProcessHeap(), 0);
1139 if (ret == NO_ERROR)
1141 ULONG size = sizeof(MIB_IPADDRTABLE) + (table->dwNumEntries - 1) *
1142 sizeof(MIB_IPADDRROW);
1144 if (!pIpAddrTable || *pdwSize < size) {
1146 ret = ERROR_INSUFFICIENT_BUFFER;
1150 memcpy(pIpAddrTable, table, sizeof(MIB_IPADDRTABLE) +
1151 (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW));
1153 qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1154 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1157 HeapFree(GetProcessHeap(), 0, table);
1160 TRACE("returning %ld\n", ret);
1165 /******************************************************************
1166 * GetIpForwardTable (IPHLPAPI.@)
1168 * Get the route table.
1171 * pIpForwardTable [Out] buffer for route table
1172 * pdwSize [In/Out] length of output buffer
1173 * bOrder [In] whether to sort the table
1177 * Failure: error code from winerror.h
1180 * If pdwSize is less than required, the function will return
1181 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1183 * If bOrder is true, the returned table will be sorted by the next hop and
1184 * an assortment of arbitrary parameters.
1186 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1190 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable,
1191 pdwSize, (DWORD)bOrder);
1193 ret = ERROR_INVALID_PARAMETER;
1195 DWORD numRoutes = getNumRoutes();
1196 ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) *
1197 sizeof(MIB_IPFORWARDROW);
1199 if (!pIpForwardTable || *pdwSize < sizeNeeded) {
1200 *pdwSize = sizeNeeded;
1201 ret = ERROR_INSUFFICIENT_BUFFER;
1204 PMIB_IPFORWARDTABLE table;
1206 ret = getRouteTable(&table, GetProcessHeap(), 0);
1208 sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (table->dwNumEntries - 1) *
1209 sizeof(MIB_IPFORWARDROW);
1210 if (*pdwSize < sizeNeeded) {
1211 *pdwSize = sizeNeeded;
1212 ret = ERROR_INSUFFICIENT_BUFFER;
1215 *pdwSize = sizeNeeded;
1216 memcpy(pIpForwardTable, table, sizeNeeded);
1218 qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
1219 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1222 HeapFree(GetProcessHeap(), 0, table);
1226 TRACE("returning %ld\n", ret);
1231 /******************************************************************
1232 * GetIpNetTable (IPHLPAPI.@)
1234 * Get the IP-to-physical address mapping table.
1237 * pIpNetTable [Out] buffer for mapping table
1238 * pdwSize [In/Out] length of output buffer
1239 * bOrder [In] whether to sort the table
1243 * Failure: error code from winerror.h
1246 * If pdwSize is less than required, the function will return
1247 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1249 * If bOrder is true, the returned table will be sorted by IP address.
1251 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1255 TRACE("pIpNetTable %p, pdwSize %p, bOrder %ld\n", pIpNetTable, pdwSize,
1258 ret = ERROR_INVALID_PARAMETER;
1260 DWORD numEntries = getNumArpEntries();
1261 ULONG size = sizeof(MIB_IPNETTABLE) + (numEntries - 1) *
1262 sizeof(MIB_IPNETROW);
1264 if (!pIpNetTable || *pdwSize < size) {
1266 ret = ERROR_INSUFFICIENT_BUFFER;
1269 PMIB_IPNETTABLE table;
1271 ret = getArpTable(&table, GetProcessHeap(), 0);
1273 size = sizeof(MIB_IPNETTABLE) + (table->dwNumEntries - 1) *
1274 sizeof(MIB_IPNETROW);
1275 if (*pdwSize < size) {
1277 ret = ERROR_INSUFFICIENT_BUFFER;
1281 memcpy(pIpNetTable, table, size);
1283 qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
1284 sizeof(MIB_IPNETROW), IpNetTableSorter);
1287 HeapFree(GetProcessHeap(), 0, table);
1291 TRACE("returning %ld\n", ret);
1296 /******************************************************************
1297 * GetIpStatistics (IPHLPAPI.@)
1299 * Get the IP statistics for the local computer.
1302 * pStats [Out] buffer for IP statistics
1306 * Failure: error code from winerror.h
1308 DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
1312 TRACE("pStats %p\n", pStats);
1313 ret = getIPStats(pStats);
1314 TRACE("returning %ld\n", ret);
1319 /******************************************************************
1320 * GetNetworkParams (IPHLPAPI.@)
1322 * Get the network parameters for the local computer.
1325 * pFixedInfo [Out] buffer for network parameters
1326 * pOutBufLen [In/Out] length of output buffer
1330 * Failure: error code from winerror.h
1333 * If pOutBufLen is less than required, the function will return
1334 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1337 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1343 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1345 return ERROR_INVALID_PARAMETER;
1348 size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount - 1) *
1349 sizeof(IP_ADDR_STRING) : 0);
1350 if (!pFixedInfo || *pOutBufLen < size) {
1352 return ERROR_BUFFER_OVERFLOW;
1355 memset(pFixedInfo, 0, size);
1356 size = sizeof(pFixedInfo->HostName);
1357 GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1358 size = sizeof(pFixedInfo->DomainName);
1359 GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1360 if (_res.nscount > 0) {
1361 PIP_ADDR_STRING ptr;
1364 for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1365 i++, ptr = ptr->Next) {
1366 toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
1367 ptr->IpAddress.String);
1368 if (i == _res.nscount - 1)
1371 ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
1373 ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1376 pFixedInfo->NodeType = HYBRID_NODETYPE;
1377 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1378 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1379 if (regReturn != ERROR_SUCCESS)
1380 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1381 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1383 if (regReturn == ERROR_SUCCESS)
1385 DWORD size = sizeof(pFixedInfo->ScopeId);
1387 RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1391 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1392 I suppose could also check for a listener on port 53 to set EnableDns */
1394 TRACE("returning %ld\n", ret);
1399 /******************************************************************
1400 * GetNumberOfInterfaces (IPHLPAPI.@)
1402 * Get the number of interfaces.
1405 * pdwNumIf [Out] number of interfaces
1408 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1410 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
1414 TRACE("pdwNumIf %p\n", pdwNumIf);
1416 ret = ERROR_INVALID_PARAMETER;
1418 *pdwNumIf = getNumInterfaces();
1421 TRACE("returning %ld\n", ret);
1426 /******************************************************************
1427 * GetPerAdapterInfo (IPHLPAPI.@)
1429 * Get information about an adapter corresponding to an interface.
1432 * IfIndex [In] interface info
1433 * pPerAdapterInfo [Out] buffer for per adapter info
1434 * pOutBufLen [In/Out] length of output buffer
1438 * Failure: error code from winerror.h
1441 * Stub, returns ERROR_NOT_SUPPORTED.
1443 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
1445 TRACE("(IfIndex %ld, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex,
1446 pPerAdapterInfo, pOutBufLen);
1447 return ERROR_NOT_SUPPORTED;
1451 /******************************************************************
1452 * GetRTTAndHopCount (IPHLPAPI.@)
1454 * Get round-trip time (RTT) and hop count.
1458 * DestIpAddress [In] destination address to get the info for
1459 * HopCount [Out] retrieved hop count
1460 * MaxHops [In] maximum hops to search for the destination
1461 * RTT [Out] RTT in milliseconds
1468 * Stub, returns FALSE.
1470 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
1472 FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p): stub\n",
1473 DestIpAddress, HopCount, MaxHops, RTT);
1478 /******************************************************************
1479 * GetTcpStatistics (IPHLPAPI.@)
1481 * Get the TCP statistics for the local computer.
1484 * pStats [Out] buffer for TCP statistics
1488 * Failure: error code from winerror.h
1490 DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
1494 TRACE("pStats %p\n", pStats);
1495 ret = getTCPStats(pStats);
1496 TRACE("returning %ld\n", ret);
1501 /******************************************************************
1502 * GetTcpTable (IPHLPAPI.@)
1504 * Get the table of active TCP connections.
1507 * pTcpTable [Out] buffer for TCP connections table
1508 * pdwSize [In/Out] length of output buffer
1509 * bOrder [In] whether to order the table
1513 * Failure: error code from winerror.h
1516 * If pdwSize is less than required, the function will return
1517 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1518 * the required byte size.
1519 * If bOrder is true, the returned table will be sorted, first by
1520 * local address and port number, then by remote address and port
1523 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
1527 TRACE("pTcpTable %p, pdwSize %p, bOrder %ld\n", pTcpTable, pdwSize,
1530 ret = ERROR_INVALID_PARAMETER;
1532 DWORD numEntries = getNumTcpEntries();
1533 DWORD size = sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW);
1535 if (!pTcpTable || *pdwSize < size) {
1537 ret = ERROR_INSUFFICIENT_BUFFER;
1540 PMIB_TCPTABLE table;
1542 ret = getTcpTable(&table, GetProcessHeap(), 0);
1544 size = sizeof(MIB_TCPTABLE) + (table->dwNumEntries - 1) *
1546 if (*pdwSize < size) {
1548 ret = ERROR_INSUFFICIENT_BUFFER;
1552 memcpy(pTcpTable, table, size);
1554 qsort(pTcpTable->table, pTcpTable->dwNumEntries,
1555 sizeof(MIB_TCPROW), TcpTableSorter);
1558 HeapFree(GetProcessHeap(), 0, table);
1561 ret = ERROR_OUTOFMEMORY;
1564 TRACE("returning %ld\n", ret);
1569 /******************************************************************
1570 * GetUdpStatistics (IPHLPAPI.@)
1572 * Get the UDP statistics for the local computer.
1575 * pStats [Out] buffer for UDP statistics
1579 * Failure: error code from winerror.h
1581 DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
1585 TRACE("pStats %p\n", pStats);
1586 ret = getUDPStats(pStats);
1587 TRACE("returning %ld\n", ret);
1592 /******************************************************************
1593 * GetUdpTable (IPHLPAPI.@)
1595 * Get a table of active UDP connections.
1598 * pUdpTable [Out] buffer for UDP connections table
1599 * pdwSize [In/Out] length of output buffer
1600 * bOrder [In] whether to order the table
1604 * Failure: error code from winerror.h
1607 * If pdwSize is less than required, the function will return
1608 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1609 * required byte size.
1610 * If bOrder is true, the returned table will be sorted, first by
1611 * local address, then by local port number.
1613 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
1617 TRACE("pUdpTable %p, pdwSize %p, bOrder %ld\n", pUdpTable, pdwSize,
1620 ret = ERROR_INVALID_PARAMETER;
1622 DWORD numEntries = getNumUdpEntries();
1623 DWORD size = sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW);
1625 if (!pUdpTable || *pdwSize < size) {
1627 ret = ERROR_INSUFFICIENT_BUFFER;
1630 PMIB_UDPTABLE table;
1632 ret = getUdpTable(&table, GetProcessHeap(), 0);
1634 size = sizeof(MIB_UDPTABLE) + (table->dwNumEntries - 1) *
1636 if (*pdwSize < size) {
1638 ret = ERROR_INSUFFICIENT_BUFFER;
1642 memcpy(pUdpTable, table, size);
1644 qsort(pUdpTable->table, pUdpTable->dwNumEntries,
1645 sizeof(MIB_UDPROW), UdpTableSorter);
1648 HeapFree(GetProcessHeap(), 0, table);
1651 ret = ERROR_OUTOFMEMORY;
1654 TRACE("returning %ld\n", ret);
1659 /******************************************************************
1660 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1662 * This is a Win98-only function to get information on "unidirectional"
1663 * adapters. Since this is pretty nonsensical in other contexts, it
1664 * never returns anything.
1667 * pIPIfInfo [Out] buffer for adapter infos
1668 * dwOutBufLen [Out] length of the output buffer
1672 * Failure: error code from winerror.h
1675 * Stub, returns ERROR_NOT_SUPPORTED.
1677 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
1679 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1680 /* a unidirectional adapter?? not bloody likely! */
1681 return ERROR_NOT_SUPPORTED;
1685 /******************************************************************
1686 * IpReleaseAddress (IPHLPAPI.@)
1688 * Release an IP optained through DHCP,
1691 * AdapterInfo [In] adapter to release IP address
1695 * Failure: error code from winerror.h
1698 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1699 * this function does nothing.
1702 * Stub, returns ERROR_NOT_SUPPORTED.
1704 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1706 TRACE("AdapterInfo %p\n", AdapterInfo);
1707 /* not a stub, never going to support this (and I never mark an adapter as
1708 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1709 return ERROR_NOT_SUPPORTED;
1713 /******************************************************************
1714 * IpRenewAddress (IPHLPAPI.@)
1716 * Renew an IP optained through DHCP.
1719 * AdapterInfo [In] adapter to renew IP address
1723 * Failure: error code from winerror.h
1726 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1727 * this function does nothing.
1730 * Stub, returns ERROR_NOT_SUPPORTED.
1732 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1734 TRACE("AdapterInfo %p\n", AdapterInfo);
1735 /* not a stub, never going to support this (and I never mark an adapter as
1736 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1737 return ERROR_NOT_SUPPORTED;
1741 /******************************************************************
1742 * NotifyAddrChange (IPHLPAPI.@)
1744 * Notify caller whenever the ip-interface map is changed.
1747 * Handle [Out] handle useable in asynchronus notification
1748 * overlapped [In] overlapped structure that notifies the caller
1752 * Failure: error code from winerror.h
1755 * Stub, returns ERROR_NOT_SUPPORTED.
1757 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1759 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1760 return ERROR_NOT_SUPPORTED;
1764 /******************************************************************
1765 * NotifyRouteChange (IPHLPAPI.@)
1767 * Notify caller whenever the ip routing table is changed.
1770 * Handle [Out] handle useable in asynchronus notification
1771 * overlapped [In] overlapped structure that notifies the caller
1775 * Failure: error code from winerror.h
1778 * Stub, returns ERROR_NOT_SUPPORTED.
1780 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1782 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1783 return ERROR_NOT_SUPPORTED;
1787 /******************************************************************
1788 * SendARP (IPHLPAPI.@)
1790 * Send an ARP request.
1793 * DestIP [In] attempt to obtain this IP
1794 * SrcIP [In] optional sender IP address
1795 * pMacAddr [Out] buffer for the mac address
1796 * PhyAddrLen [In/Out] length of the output buffer
1800 * Failure: error code from winerror.h
1803 * Stub, returns ERROR_NOT_SUPPORTED.
1805 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
1807 FIXME("(DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p): stub\n",
1808 DestIP, SrcIP, pMacAddr, PhyAddrLen);
1809 return ERROR_NOT_SUPPORTED;
1813 /******************************************************************
1814 * SetIfEntry (IPHLPAPI.@)
1816 * Set the administrative status of an interface.
1819 * pIfRow [In] dwAdminStatus member specifies the new status.
1823 * Failure: error code from winerror.h
1826 * Stub, returns ERROR_NOT_SUPPORTED.
1828 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
1830 FIXME("(pIfRow %p): stub\n", pIfRow);
1831 /* this is supposed to set an interface administratively up or down.
1832 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1833 this sort of down is indistinguishable from other sorts of down (e.g. no
1835 return ERROR_NOT_SUPPORTED;
1839 /******************************************************************
1840 * SetIpForwardEntry (IPHLPAPI.@)
1842 * Modify an existing route.
1845 * pRoute [In] route with the new information
1849 * Failure: error code from winerror.h
1852 * Stub, returns NO_ERROR.
1854 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
1856 FIXME("(pRoute %p): stub\n", pRoute);
1857 /* this is to add a route entry, how's it distinguishable from
1858 CreateIpForwardEntry?
1859 could use SIOCADDRT, not sure I want to */
1864 /******************************************************************
1865 * SetIpNetEntry (IPHLPAPI.@)
1867 * Modify an existing ARP entry.
1870 * pArpEntry [In] ARP entry with the new information
1874 * Failure: error code from winerror.h
1877 * Stub, returns NO_ERROR.
1879 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
1881 FIXME("(pArpEntry %p): stub\n", pArpEntry);
1882 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1887 /******************************************************************
1888 * SetIpStatistics (IPHLPAPI.@)
1890 * Toggle IP forwarding and det the default TTL value.
1893 * pIpStats [In] IP statistics with the new information
1897 * Failure: error code from winerror.h
1900 * Stub, returns NO_ERROR.
1902 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
1904 FIXME("(pIpStats %p): stub\n", pIpStats);
1909 /******************************************************************
1910 * SetIpTTL (IPHLPAPI.@)
1912 * Set the default TTL value.
1915 * nTTL [In] new TTL value
1919 * Failure: error code from winerror.h
1922 * Stub, returns NO_ERROR.
1924 DWORD WINAPI SetIpTTL(UINT nTTL)
1926 FIXME("(nTTL %d): stub\n", nTTL);
1927 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1928 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1933 /******************************************************************
1934 * SetTcpEntry (IPHLPAPI.@)
1936 * Set the state of a TCP connection.
1939 * pTcpRow [In] specifies connection with new state
1943 * Failure: error code from winerror.h
1946 * Stub, returns NO_ERROR.
1948 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
1950 FIXME("(pTcpRow %p): stub\n", pTcpRow);
1955 /******************************************************************
1956 * UnenableRouter (IPHLPAPI.@)
1958 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
1959 * if it reaches zero.
1962 * pOverlapped [In/Out] should be the same as in EnableRouter()
1963 * lpdwEnableCount [Out] optional, receives reference count
1967 * Failure: error code from winerror.h
1970 * Stub, returns ERROR_NOT_SUPPORTED.
1972 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
1974 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
1976 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
1977 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
1979 return ERROR_NOT_SUPPORTED;