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 = rowA->dwLocalAddr - rowB->dwLocalAddr;
301 ret = rowA->dwLocalPort - rowB->dwLocalPort;
303 ret = rowA->dwRemoteAddr - rowB->dwRemoteAddr;
305 ret = rowA->dwRemotePort - rowB->dwRemotePort;
315 /******************************************************************
316 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
318 * Get the TCP connection table.
319 * Like GetTcpTable(), but allocate the returned table from heap.
322 * ppTcpTable [Out] pointer into which the MIB_TCPTABLE is
323 * allocated and returned.
324 * bOrder [In] whether to sort the table
325 * heap [In] heap from which the table is allocated
326 * flags [In] flags to HeapAlloc
329 * ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable()
332 DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
333 BOOL bOrder, HANDLE heap, DWORD flags)
337 TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
338 ppTcpTable, bOrder, heap, flags);
339 ret = getTcpTable(ppTcpTable, heap, flags);
341 qsort((*ppTcpTable)->table, (*ppTcpTable)->dwNumEntries,
342 sizeof(MIB_TCPROW), TcpTableSorter);
343 TRACE("returning %d\n", ret);
348 static int UdpTableSorter(const void *a, const void *b)
353 const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
354 const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;
356 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
358 ret = rowA->dwLocalPort - rowB->dwLocalPort;
366 /******************************************************************
367 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
369 * Get the UDP listener table.
370 * Like GetUdpTable(), but allocate the returned table from heap.
373 * ppUdpTable [Out] pointer into which the MIB_UDPTABLE is
374 * allocated and returned.
375 * bOrder [In] whether to sort the table
376 * heap [In] heap from which the table is allocated
377 * flags [In] flags to HeapAlloc
380 * ERROR_INVALID_PARAMETER if ppUdpTable is NULL, whatever GetUdpTable()
383 DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
384 BOOL bOrder, HANDLE heap, DWORD flags)
388 TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
389 ppUdpTable, bOrder, heap, flags);
390 ret = getUdpTable(ppUdpTable, heap, flags);
392 qsort((*ppUdpTable)->table, (*ppUdpTable)->dwNumEntries,
393 sizeof(MIB_UDPROW), UdpTableSorter);
394 TRACE("returning %d\n", ret);
399 /******************************************************************
400 * CreateIpForwardEntry (IPHLPAPI.@)
402 * Create a route in the local computer's IP table.
405 * pRoute [In] new route information
409 * Failure: error code from winerror.h
412 * Stub, always returns NO_ERROR.
414 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
416 FIXME("(pRoute %p): stub\n", pRoute);
417 /* could use SIOCADDRT, not sure I want to */
422 /******************************************************************
423 * CreateIpNetEntry (IPHLPAPI.@)
425 * Create entry in the ARP table.
428 * pArpEntry [In] new ARP entry
432 * Failure: error code from winerror.h
435 * Stub, always returns NO_ERROR.
437 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
439 FIXME("(pArpEntry %p)\n", pArpEntry);
440 /* could use SIOCSARP on systems that support it, not sure I want to */
445 /******************************************************************
446 * CreateProxyArpEntry (IPHLPAPI.@)
448 * Create a Proxy ARP (PARP) entry for an IP address.
451 * dwAddress [In] IP address for which this computer acts as a proxy.
452 * dwMask [In] subnet mask for dwAddress
453 * dwIfIndex [In] interface index
457 * Failure: error code from winerror.h
460 * Stub, returns ERROR_NOT_SUPPORTED.
462 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
464 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
465 dwAddress, dwMask, dwIfIndex);
466 return ERROR_NOT_SUPPORTED;
470 /******************************************************************
471 * DeleteIPAddress (IPHLPAPI.@)
473 * Delete an IP address added with AddIPAddress().
476 * NTEContext [In] NTE context from AddIPAddress();
480 * Failure: error code from winerror.h
483 * Stub, returns ERROR_NOT_SUPPORTED.
485 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
487 FIXME("(NTEContext %d): stub\n", NTEContext);
488 return ERROR_NOT_SUPPORTED;
492 /******************************************************************
493 * DeleteIpForwardEntry (IPHLPAPI.@)
498 * pRoute [In] route to delete
502 * Failure: error code from winerror.h
505 * Stub, returns NO_ERROR.
507 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
509 FIXME("(pRoute %p): stub\n", pRoute);
510 /* could use SIOCDELRT, not sure I want to */
515 /******************************************************************
516 * DeleteIpNetEntry (IPHLPAPI.@)
518 * Delete an ARP entry.
521 * pArpEntry [In] ARP entry to delete
525 * Failure: error code from winerror.h
528 * Stub, returns NO_ERROR.
530 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
532 FIXME("(pArpEntry %p): stub\n", pArpEntry);
533 /* could use SIOCDARP on systems that support it, not sure I want to */
538 /******************************************************************
539 * DeleteProxyArpEntry (IPHLPAPI.@)
541 * Delete a Proxy ARP entry.
544 * dwAddress [In] IP address for which this computer acts as a proxy.
545 * dwMask [In] subnet mask for dwAddress
546 * dwIfIndex [In] interface index
550 * Failure: error code from winerror.h
553 * Stub, returns ERROR_NOT_SUPPORTED.
555 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
557 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
558 dwAddress, dwMask, dwIfIndex);
559 return ERROR_NOT_SUPPORTED;
563 /******************************************************************
564 * EnableRouter (IPHLPAPI.@)
566 * Turn on ip forwarding.
570 * pOverlapped [In/Out] hEvent member should contain a valid handle.
573 * Success: ERROR_IO_PENDING
574 * Failure: error code from winerror.h
577 * Stub, returns ERROR_NOT_SUPPORTED.
579 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
581 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle, pOverlapped);
582 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
583 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
585 return ERROR_NOT_SUPPORTED;
589 /******************************************************************
590 * FlushIpNetTable (IPHLPAPI.@)
592 * Delete all ARP entries of an interface
595 * dwIfIndex [In] interface index
599 * Failure: error code from winerror.h
602 * Stub, returns ERROR_NOT_SUPPORTED.
604 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
606 FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex);
607 /* this flushes the arp cache of the given index */
608 return ERROR_NOT_SUPPORTED;
612 /******************************************************************
613 * GetAdapterIndex (IPHLPAPI.@)
615 * Get interface index from its name.
618 * AdapterName [In] unicode string with the adapter name
619 * IfIndex [Out] returns found interface index
623 * Failure: error code from winerror.h
626 * Stub, returns ERROR_NOT_SUPPORTED.
628 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
630 FIXME("(AdapterName %p, IfIndex %p): stub\n", AdapterName, IfIndex);
631 /* FIXME: implement using getInterfaceIndexByName */
632 return ERROR_NOT_SUPPORTED;
636 /******************************************************************
637 * GetAdaptersInfo (IPHLPAPI.@)
639 * Get information about adapters.
642 * pAdapterInfo [Out] buffer for adapter infos
643 * pOutBufLen [In] length of output buffer
647 * Failure: error code from winerror.h
649 DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
653 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
655 ret = ERROR_INVALID_PARAMETER;
657 DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
659 if (numNonLoopbackInterfaces > 0) {
660 DWORD numIPAddresses = getNumIPAddresses();
663 /* This may slightly overestimate the amount of space needed, because
664 * the IP addresses include the loopback address, but it's easier
665 * to make sure there's more than enough space than to make sure there's
666 * precisely enough space.
668 size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
669 size += numIPAddresses * sizeof(IP_ADDR_STRING);
670 if (!pAdapterInfo || *pOutBufLen < size) {
672 ret = ERROR_BUFFER_OVERFLOW;
675 InterfaceIndexTable *table = NULL;
676 PMIB_IPADDRTABLE ipAddrTable = NULL;
678 ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
680 table = getNonLoopbackInterfaceIndexTable();
682 size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
683 size += ipAddrTable->dwNumEntries * sizeof(IP_ADDR_STRING);
684 if (*pOutBufLen < size) {
686 ret = ERROR_INSUFFICIENT_BUFFER;
691 BOOL winsEnabled = FALSE;
692 IP_ADDRESS_STRING primaryWINS, secondaryWINS;
693 PIP_ADDR_STRING nextIPAddr = (PIP_ADDR_STRING)((LPBYTE)pAdapterInfo
694 + numNonLoopbackInterfaces * sizeof(IP_ADAPTER_INFO));
696 memset(pAdapterInfo, 0, size);
697 /* @@ Wine registry key: HKCU\Software\Wine\Network */
698 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network",
699 &hKey) == ERROR_SUCCESS) {
700 DWORD size = sizeof(primaryWINS.String);
703 RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
704 (LPBYTE)primaryWINS.String, &size);
705 addr = inet_addr(primaryWINS.String);
706 if (addr != INADDR_NONE && addr != INADDR_ANY)
708 size = sizeof(secondaryWINS.String);
709 RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
710 (LPBYTE)secondaryWINS.String, &size);
711 addr = inet_addr(secondaryWINS.String);
712 if (addr != INADDR_NONE && addr != INADDR_ANY)
716 for (ndx = 0; ndx < table->numIndexes; ndx++) {
717 PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
718 DWORD addrLen = sizeof(ptr->Address), type, i;
719 PIP_ADDR_STRING currentIPAddr = &ptr->IpAddressList;
720 BOOL firstIPAddr = TRUE;
722 /* on Win98 this is left empty, but whatever */
723 getInterfaceNameByIndex(table->indexes[ndx], ptr->AdapterName);
724 getInterfacePhysicalByIndex(table->indexes[ndx], &addrLen,
725 ptr->Address, &type);
726 /* MS defines address length and type as UINT in some places and
727 DWORD in others, **sigh**. Don't want to assume that PUINT and
728 PDWORD are equiv (64-bit?) */
729 ptr->AddressLength = addrLen;
731 ptr->Index = table->indexes[ndx];
732 for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
733 if (ipAddrTable->table[i].dwIndex == ptr->Index) {
735 toIPAddressString(ipAddrTable->table[i].dwAddr,
736 ptr->IpAddressList.IpAddress.String);
737 toIPAddressString(ipAddrTable->table[i].dwMask,
738 ptr->IpAddressList.IpMask.String);
742 currentIPAddr->Next = nextIPAddr;
743 currentIPAddr = nextIPAddr;
744 toIPAddressString(ipAddrTable->table[i].dwAddr,
745 currentIPAddr->IpAddress.String);
746 toIPAddressString(ipAddrTable->table[i].dwMask,
747 currentIPAddr->IpMask.String);
753 ptr->HaveWins = TRUE;
754 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
755 primaryWINS.String, sizeof(primaryWINS.String));
756 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
757 secondaryWINS.String, sizeof(secondaryWINS.String));
759 if (ndx < table->numIndexes - 1)
760 ptr->Next = &pAdapterInfo[ndx + 1];
766 HeapFree(GetProcessHeap(), 0, table);
769 ret = ERROR_OUTOFMEMORY;
770 HeapFree(GetProcessHeap(), 0, ipAddrTable);
776 TRACE("returning %d\n", ret);
781 /******************************************************************
782 * GetBestInterface (IPHLPAPI.@)
784 * Get the interface, with the best route for the given IP address.
787 * dwDestAddr [In] IP address to search the interface for
788 * pdwBestIfIndex [Out] found best interface
792 * Failure: error code from winerror.h
794 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
798 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex);
800 ret = ERROR_INVALID_PARAMETER;
802 MIB_IPFORWARDROW ipRow;
804 ret = GetBestRoute(dwDestAddr, 0, &ipRow);
805 if (ret == ERROR_SUCCESS)
806 *pdwBestIfIndex = ipRow.dwForwardIfIndex;
808 TRACE("returning %d\n", ret);
813 /******************************************************************
814 * GetBestRoute (IPHLPAPI.@)
816 * Get the best route for the given IP address.
819 * dwDestAddr [In] IP address to search the best route for
820 * dwSourceAddr [In] optional source IP address
821 * pBestRoute [Out] found best route
825 * Failure: error code from winerror.h
827 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
829 PMIB_IPFORWARDTABLE table;
832 TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr,
833 dwSourceAddr, pBestRoute);
835 return ERROR_INVALID_PARAMETER;
837 AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
839 DWORD ndx, matchedBits, matchedNdx = 0;
841 for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
842 if (table->table[ndx].dwForwardType != MIB_IPROUTE_TYPE_INVALID &&
843 (dwDestAddr & table->table[ndx].dwForwardMask) ==
844 (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
845 DWORD numShifts, mask;
847 for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
848 mask && !(mask & 1); mask >>= 1, numShifts++)
850 if (numShifts > matchedBits) {
851 matchedBits = numShifts;
856 if (matchedNdx < table->dwNumEntries) {
857 memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
861 /* No route matches, which can happen if there's no default route. */
862 ret = ERROR_HOST_UNREACHABLE;
864 HeapFree(GetProcessHeap(), 0, table);
867 ret = ERROR_OUTOFMEMORY;
868 TRACE("returning %d\n", ret);
873 /******************************************************************
874 * GetFriendlyIfIndex (IPHLPAPI.@)
876 * Get a "friendly" version of IfIndex, which is one that doesn't
877 * have the top byte set. Doesn't validate whether IfIndex is a valid
881 * IfIndex [In] interface index to get the friendly one for
884 * A friendly version of IfIndex.
886 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
888 /* windows doesn't validate these, either, just makes sure the top byte is
889 cleared. I assume my ifenum module never gives an index with the top
891 TRACE("returning %d\n", IfIndex);
896 /******************************************************************
897 * GetIcmpStatistics (IPHLPAPI.@)
899 * Get the ICMP statistics for the local computer.
902 * pStats [Out] buffer for ICMP statistics
906 * Failure: error code from winerror.h
908 DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
912 TRACE("pStats %p\n", pStats);
913 ret = getICMPStats(pStats);
914 TRACE("returning %d\n", ret);
919 /******************************************************************
920 * GetIfEntry (IPHLPAPI.@)
922 * Get information about an interface.
925 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
926 * Out: interface information
930 * Failure: error code from winerror.h
932 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
935 char nameBuf[MAX_ADAPTER_NAME];
938 TRACE("pIfRow %p\n", pIfRow);
940 return ERROR_INVALID_PARAMETER;
942 name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf);
944 ret = getInterfaceEntryByName(name, pIfRow);
946 ret = getInterfaceStatsByName(name, pIfRow);
949 ret = ERROR_INVALID_DATA;
950 TRACE("returning %d\n", ret);
955 static int IfTableSorter(const void *a, const void *b)
960 ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
967 /******************************************************************
968 * GetIfTable (IPHLPAPI.@)
970 * Get a table of local interfaces.
973 * pIfTable [Out] buffer for local interfaces table
974 * pdwSize [In/Out] length of output buffer
975 * bOrder [In] whether to sort the table
979 * Failure: error code from winerror.h
982 * If pdwSize is less than required, the function will return
983 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
985 * If bOrder is true, the returned table will be sorted by interface index.
987 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
991 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize, pdwSize,
994 ret = ERROR_INVALID_PARAMETER;
996 DWORD numInterfaces = getNumInterfaces();
997 ULONG size = sizeof(MIB_IFTABLE) + (numInterfaces - 1) * sizeof(MIB_IFROW);
999 if (!pIfTable || *pdwSize < size) {
1001 ret = ERROR_INSUFFICIENT_BUFFER;
1004 InterfaceIndexTable *table = getInterfaceIndexTable();
1007 size = sizeof(MIB_IFTABLE) + (table->numIndexes - 1) *
1009 if (*pdwSize < size) {
1011 ret = ERROR_INSUFFICIENT_BUFFER;
1017 pIfTable->dwNumEntries = 0;
1018 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1019 pIfTable->table[ndx].dwIndex = table->indexes[ndx];
1020 GetIfEntry(&pIfTable->table[ndx]);
1021 pIfTable->dwNumEntries++;
1024 qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
1028 HeapFree(GetProcessHeap(), 0, table);
1031 ret = ERROR_OUTOFMEMORY;
1034 TRACE("returning %d\n", ret);
1039 /******************************************************************
1040 * GetInterfaceInfo (IPHLPAPI.@)
1042 * Get a list of network interface adapters.
1045 * pIfTable [Out] buffer for interface adapters
1046 * dwOutBufLen [Out] if buffer is too small, returns required size
1050 * Failure: error code from winerror.h
1053 * MSDN states this should return non-loopback interfaces only.
1055 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
1059 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1061 ret = ERROR_INVALID_PARAMETER;
1063 DWORD numInterfaces = getNumInterfaces();
1064 ULONG size = sizeof(IP_INTERFACE_INFO) + (numInterfaces - 1) *
1065 sizeof(IP_ADAPTER_INDEX_MAP);
1067 if (!pIfTable || *dwOutBufLen < size) {
1068 *dwOutBufLen = size;
1069 ret = ERROR_INSUFFICIENT_BUFFER;
1072 InterfaceIndexTable *table = getInterfaceIndexTable();
1075 size = sizeof(IP_INTERFACE_INFO) + (table->numIndexes - 1) *
1076 sizeof(IP_ADAPTER_INDEX_MAP);
1077 if (*dwOutBufLen < size) {
1078 *dwOutBufLen = size;
1079 ret = ERROR_INSUFFICIENT_BUFFER;
1083 char nameBuf[MAX_ADAPTER_NAME];
1085 *dwOutBufLen = size;
1086 pIfTable->NumAdapters = 0;
1087 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1088 const char *walker, *name;
1091 pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1092 name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
1093 for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
1094 walker && *walker &&
1095 assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
1096 walker++, assigner++)
1097 *assigner = *walker;
1099 pIfTable->NumAdapters++;
1103 HeapFree(GetProcessHeap(), 0, table);
1106 ret = ERROR_OUTOFMEMORY;
1109 TRACE("returning %d\n", ret);
1114 /******************************************************************
1115 * GetIpAddrTable (IPHLPAPI.@)
1117 * Get interface-to-IP address mapping table.
1120 * pIpAddrTable [Out] buffer for mapping table
1121 * pdwSize [In/Out] length of output buffer
1122 * bOrder [In] whether to sort the table
1126 * Failure: error code from winerror.h
1129 * If pdwSize is less than required, the function will return
1130 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1132 * If bOrder is true, the returned table will be sorted by the next hop and
1133 * an assortment of arbitrary parameters.
1135 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1139 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable, pdwSize,
1142 ret = ERROR_INVALID_PARAMETER;
1144 PMIB_IPADDRTABLE table;
1146 ret = getIPAddrTable(&table, GetProcessHeap(), 0);
1147 if (ret == NO_ERROR)
1149 ULONG size = sizeof(MIB_IPADDRTABLE) + (table->dwNumEntries - 1) *
1150 sizeof(MIB_IPADDRROW);
1152 if (!pIpAddrTable || *pdwSize < size) {
1154 ret = ERROR_INSUFFICIENT_BUFFER;
1158 memcpy(pIpAddrTable, table, sizeof(MIB_IPADDRTABLE) +
1159 (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW));
1161 qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1162 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1165 HeapFree(GetProcessHeap(), 0, table);
1168 TRACE("returning %d\n", ret);
1173 /******************************************************************
1174 * GetIpForwardTable (IPHLPAPI.@)
1176 * Get the route table.
1179 * pIpForwardTable [Out] buffer for route table
1180 * pdwSize [In/Out] length of output buffer
1181 * bOrder [In] whether to sort the table
1185 * Failure: error code from winerror.h
1188 * If pdwSize is less than required, the function will return
1189 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1191 * If bOrder is true, the returned table will be sorted by the next hop and
1192 * an assortment of arbitrary parameters.
1194 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1198 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable,
1199 pdwSize, (DWORD)bOrder);
1201 ret = ERROR_INVALID_PARAMETER;
1203 DWORD numRoutes = getNumRoutes();
1204 ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) *
1205 sizeof(MIB_IPFORWARDROW);
1207 if (!pIpForwardTable || *pdwSize < sizeNeeded) {
1208 *pdwSize = sizeNeeded;
1209 ret = ERROR_INSUFFICIENT_BUFFER;
1212 PMIB_IPFORWARDTABLE table;
1214 ret = getRouteTable(&table, GetProcessHeap(), 0);
1216 sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (table->dwNumEntries - 1) *
1217 sizeof(MIB_IPFORWARDROW);
1218 if (*pdwSize < sizeNeeded) {
1219 *pdwSize = sizeNeeded;
1220 ret = ERROR_INSUFFICIENT_BUFFER;
1223 *pdwSize = sizeNeeded;
1224 memcpy(pIpForwardTable, table, sizeNeeded);
1226 qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
1227 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1230 HeapFree(GetProcessHeap(), 0, table);
1234 TRACE("returning %d\n", ret);
1239 /******************************************************************
1240 * GetIpNetTable (IPHLPAPI.@)
1242 * Get the IP-to-physical address mapping table.
1245 * pIpNetTable [Out] buffer for mapping table
1246 * pdwSize [In/Out] length of output buffer
1247 * bOrder [In] whether to sort the table
1251 * Failure: error code from winerror.h
1254 * If pdwSize is less than required, the function will return
1255 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1257 * If bOrder is true, the returned table will be sorted by IP address.
1259 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1263 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable, pdwSize,
1266 ret = ERROR_INVALID_PARAMETER;
1268 DWORD numEntries = getNumArpEntries();
1269 ULONG size = sizeof(MIB_IPNETTABLE) + (numEntries - 1) *
1270 sizeof(MIB_IPNETROW);
1272 if (!pIpNetTable || *pdwSize < size) {
1274 ret = ERROR_INSUFFICIENT_BUFFER;
1277 PMIB_IPNETTABLE table;
1279 ret = getArpTable(&table, GetProcessHeap(), 0);
1281 size = sizeof(MIB_IPNETTABLE) + (table->dwNumEntries - 1) *
1282 sizeof(MIB_IPNETROW);
1283 if (*pdwSize < size) {
1285 ret = ERROR_INSUFFICIENT_BUFFER;
1289 memcpy(pIpNetTable, table, size);
1291 qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
1292 sizeof(MIB_IPNETROW), IpNetTableSorter);
1295 HeapFree(GetProcessHeap(), 0, table);
1299 TRACE("returning %d\n", ret);
1304 /******************************************************************
1305 * GetIpStatistics (IPHLPAPI.@)
1307 * Get the IP statistics for the local computer.
1310 * pStats [Out] buffer for IP statistics
1314 * Failure: error code from winerror.h
1316 DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
1320 TRACE("pStats %p\n", pStats);
1321 ret = getIPStats(pStats);
1322 TRACE("returning %d\n", ret);
1327 /******************************************************************
1328 * GetNetworkParams (IPHLPAPI.@)
1330 * Get the network parameters for the local computer.
1333 * pFixedInfo [Out] buffer for network parameters
1334 * pOutBufLen [In/Out] length of output buffer
1338 * Failure: error code from winerror.h
1341 * If pOutBufLen is less than required, the function will return
1342 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1345 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1351 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1353 return ERROR_INVALID_PARAMETER;
1355 initialise_resolver();
1356 size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount - 1) *
1357 sizeof(IP_ADDR_STRING) : 0);
1358 if (!pFixedInfo || *pOutBufLen < size) {
1360 return ERROR_BUFFER_OVERFLOW;
1363 memset(pFixedInfo, 0, size);
1364 size = sizeof(pFixedInfo->HostName);
1365 GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1366 size = sizeof(pFixedInfo->DomainName);
1367 GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1368 if (_res.nscount > 0) {
1369 PIP_ADDR_STRING ptr;
1372 for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1373 i++, ptr = ptr->Next) {
1374 toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
1375 ptr->IpAddress.String);
1376 if (i == _res.nscount - 1)
1379 ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
1381 ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1384 pFixedInfo->NodeType = HYBRID_NODETYPE;
1385 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1386 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1387 if (regReturn != ERROR_SUCCESS)
1388 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1389 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1391 if (regReturn == ERROR_SUCCESS)
1393 DWORD size = sizeof(pFixedInfo->ScopeId);
1395 RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1399 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1400 I suppose could also check for a listener on port 53 to set EnableDns */
1402 TRACE("returning %d\n", ret);
1407 /******************************************************************
1408 * GetNumberOfInterfaces (IPHLPAPI.@)
1410 * Get the number of interfaces.
1413 * pdwNumIf [Out] number of interfaces
1416 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1418 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
1422 TRACE("pdwNumIf %p\n", pdwNumIf);
1424 ret = ERROR_INVALID_PARAMETER;
1426 *pdwNumIf = getNumInterfaces();
1429 TRACE("returning %d\n", ret);
1434 /******************************************************************
1435 * GetPerAdapterInfo (IPHLPAPI.@)
1437 * Get information about an adapter corresponding to an interface.
1440 * IfIndex [In] interface info
1441 * pPerAdapterInfo [Out] buffer for per adapter info
1442 * pOutBufLen [In/Out] length of output buffer
1446 * Failure: error code from winerror.h
1449 * Stub, returns ERROR_NOT_SUPPORTED.
1451 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
1453 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex,
1454 pPerAdapterInfo, pOutBufLen);
1455 return ERROR_NOT_SUPPORTED;
1459 /******************************************************************
1460 * GetRTTAndHopCount (IPHLPAPI.@)
1462 * Get round-trip time (RTT) and hop count.
1466 * DestIpAddress [In] destination address to get the info for
1467 * HopCount [Out] retrieved hop count
1468 * MaxHops [In] maximum hops to search for the destination
1469 * RTT [Out] RTT in milliseconds
1476 * Stub, returns FALSE.
1478 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
1480 FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %d, RTT %p): stub\n",
1481 DestIpAddress, HopCount, MaxHops, RTT);
1486 /******************************************************************
1487 * GetTcpStatistics (IPHLPAPI.@)
1489 * Get the TCP statistics for the local computer.
1492 * pStats [Out] buffer for TCP statistics
1496 * Failure: error code from winerror.h
1498 DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
1502 TRACE("pStats %p\n", pStats);
1503 ret = getTCPStats(pStats);
1504 TRACE("returning %d\n", ret);
1509 /******************************************************************
1510 * GetTcpTable (IPHLPAPI.@)
1512 * Get the table of active TCP connections.
1515 * pTcpTable [Out] buffer for TCP connections table
1516 * pdwSize [In/Out] length of output buffer
1517 * bOrder [In] whether to order the table
1521 * Failure: error code from winerror.h
1524 * If pdwSize is less than required, the function will return
1525 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1526 * the required byte size.
1527 * If bOrder is true, the returned table will be sorted, first by
1528 * local address and port number, then by remote address and port
1531 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
1535 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize,
1538 ret = ERROR_INVALID_PARAMETER;
1540 DWORD numEntries = getNumTcpEntries();
1541 DWORD size = sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW);
1543 if (!pTcpTable || *pdwSize < size) {
1545 ret = ERROR_INSUFFICIENT_BUFFER;
1548 PMIB_TCPTABLE table;
1550 ret = getTcpTable(&table, GetProcessHeap(), 0);
1552 size = sizeof(MIB_TCPTABLE) + (table->dwNumEntries - 1) *
1554 if (*pdwSize < size) {
1556 ret = ERROR_INSUFFICIENT_BUFFER;
1560 memcpy(pTcpTable, table, size);
1562 qsort(pTcpTable->table, pTcpTable->dwNumEntries,
1563 sizeof(MIB_TCPROW), TcpTableSorter);
1566 HeapFree(GetProcessHeap(), 0, table);
1569 ret = ERROR_OUTOFMEMORY;
1572 TRACE("returning %d\n", ret);
1577 /******************************************************************
1578 * GetUdpStatistics (IPHLPAPI.@)
1580 * Get the UDP statistics for the local computer.
1583 * pStats [Out] buffer for UDP statistics
1587 * Failure: error code from winerror.h
1589 DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
1593 TRACE("pStats %p\n", pStats);
1594 ret = getUDPStats(pStats);
1595 TRACE("returning %d\n", ret);
1600 /******************************************************************
1601 * GetUdpTable (IPHLPAPI.@)
1603 * Get a table of active UDP connections.
1606 * pUdpTable [Out] buffer for UDP connections table
1607 * pdwSize [In/Out] length of output buffer
1608 * bOrder [In] whether to order the table
1612 * Failure: error code from winerror.h
1615 * If pdwSize is less than required, the function will return
1616 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1617 * required byte size.
1618 * If bOrder is true, the returned table will be sorted, first by
1619 * local address, then by local port number.
1621 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
1625 TRACE("pUdpTable %p, pdwSize %p, bOrder %d\n", pUdpTable, pdwSize,
1628 ret = ERROR_INVALID_PARAMETER;
1630 DWORD numEntries = getNumUdpEntries();
1631 DWORD size = sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW);
1633 if (!pUdpTable || *pdwSize < size) {
1635 ret = ERROR_INSUFFICIENT_BUFFER;
1638 PMIB_UDPTABLE table;
1640 ret = getUdpTable(&table, GetProcessHeap(), 0);
1642 size = sizeof(MIB_UDPTABLE) + (table->dwNumEntries - 1) *
1644 if (*pdwSize < size) {
1646 ret = ERROR_INSUFFICIENT_BUFFER;
1650 memcpy(pUdpTable, table, size);
1652 qsort(pUdpTable->table, pUdpTable->dwNumEntries,
1653 sizeof(MIB_UDPROW), UdpTableSorter);
1656 HeapFree(GetProcessHeap(), 0, table);
1659 ret = ERROR_OUTOFMEMORY;
1662 TRACE("returning %d\n", ret);
1667 /******************************************************************
1668 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1670 * This is a Win98-only function to get information on "unidirectional"
1671 * adapters. Since this is pretty nonsensical in other contexts, it
1672 * never returns anything.
1675 * pIPIfInfo [Out] buffer for adapter infos
1676 * dwOutBufLen [Out] length of the output buffer
1680 * Failure: error code from winerror.h
1683 * Stub, returns ERROR_NOT_SUPPORTED.
1685 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
1687 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1688 /* a unidirectional adapter?? not bloody likely! */
1689 return ERROR_NOT_SUPPORTED;
1693 /******************************************************************
1694 * IpReleaseAddress (IPHLPAPI.@)
1696 * Release an IP optained through DHCP,
1699 * AdapterInfo [In] adapter to release IP address
1703 * Failure: error code from winerror.h
1706 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1707 * this function does nothing.
1710 * Stub, returns ERROR_NOT_SUPPORTED.
1712 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1714 TRACE("AdapterInfo %p\n", AdapterInfo);
1715 /* not a stub, never going to support this (and I never mark an adapter as
1716 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1717 return ERROR_NOT_SUPPORTED;
1721 /******************************************************************
1722 * IpRenewAddress (IPHLPAPI.@)
1724 * Renew an IP optained through DHCP.
1727 * AdapterInfo [In] adapter to renew IP address
1731 * Failure: error code from winerror.h
1734 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1735 * this function does nothing.
1738 * Stub, returns ERROR_NOT_SUPPORTED.
1740 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1742 TRACE("AdapterInfo %p\n", AdapterInfo);
1743 /* not a stub, never going to support this (and I never mark an adapter as
1744 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1745 return ERROR_NOT_SUPPORTED;
1749 /******************************************************************
1750 * NotifyAddrChange (IPHLPAPI.@)
1752 * Notify caller whenever the ip-interface map is changed.
1755 * Handle [Out] handle useable in asynchronus notification
1756 * overlapped [In] overlapped structure that notifies the caller
1760 * Failure: error code from winerror.h
1763 * Stub, returns ERROR_NOT_SUPPORTED.
1765 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1767 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1768 return ERROR_NOT_SUPPORTED;
1772 /******************************************************************
1773 * NotifyRouteChange (IPHLPAPI.@)
1775 * Notify caller whenever the ip routing table is changed.
1778 * Handle [Out] handle useable in asynchronus notification
1779 * overlapped [In] overlapped structure that notifies the caller
1783 * Failure: error code from winerror.h
1786 * Stub, returns ERROR_NOT_SUPPORTED.
1788 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1790 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1791 return ERROR_NOT_SUPPORTED;
1795 /******************************************************************
1796 * SendARP (IPHLPAPI.@)
1798 * Send an ARP request.
1801 * DestIP [In] attempt to obtain this IP
1802 * SrcIP [In] optional sender IP address
1803 * pMacAddr [Out] buffer for the mac address
1804 * PhyAddrLen [In/Out] length of the output buffer
1808 * Failure: error code from winerror.h
1811 * Stub, returns ERROR_NOT_SUPPORTED.
1813 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
1815 FIXME("(DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p): stub\n",
1816 DestIP, SrcIP, pMacAddr, PhyAddrLen);
1817 return ERROR_NOT_SUPPORTED;
1821 /******************************************************************
1822 * SetIfEntry (IPHLPAPI.@)
1824 * Set the administrative status of an interface.
1827 * pIfRow [In] dwAdminStatus member specifies the new status.
1831 * Failure: error code from winerror.h
1834 * Stub, returns ERROR_NOT_SUPPORTED.
1836 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
1838 FIXME("(pIfRow %p): stub\n", pIfRow);
1839 /* this is supposed to set an interface administratively up or down.
1840 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1841 this sort of down is indistinguishable from other sorts of down (e.g. no
1843 return ERROR_NOT_SUPPORTED;
1847 /******************************************************************
1848 * SetIpForwardEntry (IPHLPAPI.@)
1850 * Modify an existing route.
1853 * pRoute [In] route with the new information
1857 * Failure: error code from winerror.h
1860 * Stub, returns NO_ERROR.
1862 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
1864 FIXME("(pRoute %p): stub\n", pRoute);
1865 /* this is to add a route entry, how's it distinguishable from
1866 CreateIpForwardEntry?
1867 could use SIOCADDRT, not sure I want to */
1872 /******************************************************************
1873 * SetIpNetEntry (IPHLPAPI.@)
1875 * Modify an existing ARP entry.
1878 * pArpEntry [In] ARP entry with the new information
1882 * Failure: error code from winerror.h
1885 * Stub, returns NO_ERROR.
1887 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
1889 FIXME("(pArpEntry %p): stub\n", pArpEntry);
1890 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1895 /******************************************************************
1896 * SetIpStatistics (IPHLPAPI.@)
1898 * Toggle IP forwarding and det the default TTL value.
1901 * pIpStats [In] IP statistics with the new information
1905 * Failure: error code from winerror.h
1908 * Stub, returns NO_ERROR.
1910 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
1912 FIXME("(pIpStats %p): stub\n", pIpStats);
1917 /******************************************************************
1918 * SetIpTTL (IPHLPAPI.@)
1920 * Set the default TTL value.
1923 * nTTL [In] new TTL value
1927 * Failure: error code from winerror.h
1930 * Stub, returns NO_ERROR.
1932 DWORD WINAPI SetIpTTL(UINT nTTL)
1934 FIXME("(nTTL %d): stub\n", nTTL);
1935 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1936 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1941 /******************************************************************
1942 * SetTcpEntry (IPHLPAPI.@)
1944 * Set the state of a TCP connection.
1947 * pTcpRow [In] specifies connection with new state
1951 * Failure: error code from winerror.h
1954 * Stub, returns NO_ERROR.
1956 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
1958 FIXME("(pTcpRow %p): stub\n", pTcpRow);
1963 /******************************************************************
1964 * UnenableRouter (IPHLPAPI.@)
1966 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
1967 * if it reaches zero.
1970 * pOverlapped [In/Out] should be the same as in EnableRouter()
1971 * lpdwEnableCount [Out] optional, receives reference count
1975 * Failure: error code from winerror.h
1978 * Stub, returns ERROR_NOT_SUPPORTED.
1980 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
1982 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
1984 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
1985 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
1987 return ERROR_NOT_SUPPORTED;