2 * iphlpapi dll implementation
4 * Copyright (C) 2003,2006 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <sys/types.h>
26 #ifdef HAVE_NETINET_IN_H
27 # include <netinet/in.h>
29 #ifdef HAVE_ARPA_INET_H
30 # include <arpa/inet.h>
32 #ifdef HAVE_ARPA_NAMESER_H
33 # include <arpa/nameser.h>
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
50 #define INADDR_NONE ~0UL
53 static int resolver_initialised;
55 /* call res_init() just once because of a bug in Mac OS X 10.4 */
56 static void initialise_resolver(void)
58 if (!resolver_initialised)
61 resolver_initialised = 1;
65 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
68 case DLL_PROCESS_ATTACH:
69 DisableThreadLibraryCalls( hinstDLL );
72 case DLL_PROCESS_DETACH:
78 /******************************************************************
79 * AddIPAddress (IPHLPAPI.@)
81 * Add an IP address to an adapter.
84 * Address [In] IP address to add to the adapter
85 * IpMask [In] subnet mask for the IP address
86 * IfIndex [In] adapter index to add the address
87 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
88 * NTEInstance [Out] NTE instance for the IP address
92 * Failure: error code from winerror.h
95 * Stub. Currently returns ERROR_NOT_SUPPORTED.
97 DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
100 return ERROR_NOT_SUPPORTED;
104 /******************************************************************
105 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
107 * Get table of local interfaces.
108 * Like GetIfTable(), but allocate the returned table from heap.
111 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
112 * allocated and returned.
113 * bOrder [In] whether to sort the table
114 * heap [In] heap from which the table is allocated
115 * flags [In] flags to HeapAlloc
118 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
119 * GetIfTable() returns otherwise.
121 DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
122 BOOL bOrder, HANDLE heap, DWORD flags)
126 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable,
127 bOrder, heap, flags);
129 ret = ERROR_INVALID_PARAMETER;
133 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
134 if (ret == ERROR_INSUFFICIENT_BUFFER) {
135 *ppIfTable = HeapAlloc(heap, flags, dwSize);
136 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
139 TRACE("returning %d\n", ret);
144 static int IpAddrTableSorter(const void *a, const void *b)
149 ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
156 /******************************************************************
157 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
159 * Get interface-to-IP address mapping table.
160 * Like GetIpAddrTable(), but allocate the returned table from heap.
163 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
164 * allocated and returned.
165 * bOrder [In] whether to sort the table
166 * heap [In] heap from which the table is allocated
167 * flags [In] flags to HeapAlloc
170 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
171 * failure, NO_ERROR on success.
173 DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
174 BOOL bOrder, HANDLE heap, DWORD flags)
178 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
179 ppIpAddrTable, bOrder, heap, flags);
180 ret = getIPAddrTable(ppIpAddrTable, heap, flags);
182 qsort((*ppIpAddrTable)->table, (*ppIpAddrTable)->dwNumEntries,
183 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
184 TRACE("returning %d\n", ret);
189 static int IpForwardTableSorter(const void *a, const void *b)
194 const MIB_IPFORWARDROW* rowA = (const MIB_IPFORWARDROW*)a;
195 const MIB_IPFORWARDROW* rowB = (const MIB_IPFORWARDROW*)b;
197 ret = rowA->dwForwardDest - rowB->dwForwardDest;
199 ret = rowA->dwForwardProto - rowB->dwForwardProto;
201 ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy;
203 ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop;
213 /******************************************************************
214 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
216 * Get the route table.
217 * Like GetIpForwardTable(), but allocate the returned table from heap.
220 * ppIpForwardTable [Out] pointer into which the MIB_IPFORWARDTABLE is
221 * allocated and returned.
222 * bOrder [In] whether to sort the table
223 * heap [In] heap from which the table is allocated
224 * flags [In] flags to HeapAlloc
227 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, other error codes
228 * on failure, NO_ERROR on success.
230 DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
231 ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags)
235 TRACE("ppIpForwardTable %p, bOrder %d, heap %p, flags 0x%08x\n",
236 ppIpForwardTable, bOrder, heap, flags);
237 ret = getRouteTable(ppIpForwardTable, heap, flags);
239 qsort((*ppIpForwardTable)->table, (*ppIpForwardTable)->dwNumEntries,
240 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
241 TRACE("returning %d\n", ret);
246 static int IpNetTableSorter(const void *a, const void *b)
251 ret = ((const MIB_IPNETROW*)a)->dwAddr - ((const MIB_IPNETROW*)b)->dwAddr;
258 /******************************************************************
259 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
261 * Get the IP-to-physical address mapping table.
262 * Like GetIpNetTable(), but allocate the returned table from heap.
265 * ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE is
266 * allocated and returned.
267 * bOrder [In] whether to sort the table
268 * heap [In] heap from which the table is allocated
269 * flags [In] flags to HeapAlloc
272 * ERROR_INVALID_PARAMETER if ppIpNetTable is NULL, other error codes
273 * on failure, NO_ERROR on success.
275 DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable,
276 BOOL bOrder, HANDLE heap, DWORD flags)
280 TRACE("ppIpNetTable %p, bOrder %d, heap %p, flags 0x%08x\n",
281 ppIpNetTable, bOrder, heap, flags);
282 ret = getArpTable(ppIpNetTable, heap, flags);
284 qsort((*ppIpNetTable)->table, (*ppIpNetTable)->dwNumEntries,
285 sizeof(MIB_IPADDRROW), IpNetTableSorter);
286 TRACE("returning %d\n", ret);
291 static int TcpTableSorter(const void *a, const void *b)
296 const MIB_TCPROW* rowA = a;
297 const MIB_TCPROW* rowB = b;
299 ret = ntohl (rowA->dwLocalAddr) - ntohl (rowB->dwLocalAddr);
301 ret = ntohs ((unsigned short)rowA->dwLocalPort) -
302 ntohs ((unsigned short)rowB->dwLocalPort);
304 ret = ntohl (rowA->dwRemoteAddr) - ntohl (rowB->dwRemoteAddr);
306 ret = ntohs ((unsigned short)rowA->dwRemotePort) -
307 ntohs ((unsigned short)rowB->dwRemotePort);
317 /******************************************************************
318 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
320 * Get the TCP connection table.
321 * Like GetTcpTable(), but allocate the returned table from heap.
324 * ppTcpTable [Out] pointer into which the MIB_TCPTABLE is
325 * allocated and returned.
326 * bOrder [In] whether to sort the table
327 * heap [In] heap from which the table is allocated
328 * flags [In] flags to HeapAlloc
331 * ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable()
334 DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
335 BOOL bOrder, HANDLE heap, DWORD flags)
339 TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
340 ppTcpTable, bOrder, heap, flags);
343 ret = getTcpTable(ppTcpTable, 0, heap, flags);
345 qsort((*ppTcpTable)->table, (*ppTcpTable)->dwNumEntries,
346 sizeof(MIB_TCPROW), TcpTableSorter);
347 TRACE("returning %d\n", ret);
352 static int UdpTableSorter(const void *a, const void *b)
357 const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
358 const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;
360 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
362 ret = rowA->dwLocalPort - rowB->dwLocalPort;
370 /******************************************************************
371 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
373 * Get the UDP listener table.
374 * Like GetUdpTable(), but allocate the returned table from heap.
377 * ppUdpTable [Out] pointer into which the MIB_UDPTABLE is
378 * allocated and returned.
379 * bOrder [In] whether to sort the table
380 * heap [In] heap from which the table is allocated
381 * flags [In] flags to HeapAlloc
384 * ERROR_INVALID_PARAMETER if ppUdpTable is NULL, whatever GetUdpTable()
387 DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
388 BOOL bOrder, HANDLE heap, DWORD flags)
392 TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
393 ppUdpTable, bOrder, heap, flags);
394 ret = getUdpTable(ppUdpTable, heap, flags);
396 qsort((*ppUdpTable)->table, (*ppUdpTable)->dwNumEntries,
397 sizeof(MIB_UDPROW), UdpTableSorter);
398 TRACE("returning %d\n", ret);
403 /******************************************************************
404 * CreateIpForwardEntry (IPHLPAPI.@)
406 * Create a route in the local computer's IP table.
409 * pRoute [In] new route information
413 * Failure: error code from winerror.h
416 * Stub, always returns NO_ERROR.
418 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
420 FIXME("(pRoute %p): stub\n", pRoute);
421 /* could use SIOCADDRT, not sure I want to */
426 /******************************************************************
427 * CreateIpNetEntry (IPHLPAPI.@)
429 * Create entry in the ARP table.
432 * pArpEntry [In] new ARP entry
436 * Failure: error code from winerror.h
439 * Stub, always returns NO_ERROR.
441 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
443 FIXME("(pArpEntry %p)\n", pArpEntry);
444 /* could use SIOCSARP on systems that support it, not sure I want to */
449 /******************************************************************
450 * CreateProxyArpEntry (IPHLPAPI.@)
452 * Create a Proxy ARP (PARP) entry for an IP address.
455 * dwAddress [In] IP address for which this computer acts as a proxy.
456 * dwMask [In] subnet mask for dwAddress
457 * dwIfIndex [In] interface index
461 * Failure: error code from winerror.h
464 * Stub, returns ERROR_NOT_SUPPORTED.
466 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
468 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
469 dwAddress, dwMask, dwIfIndex);
470 return ERROR_NOT_SUPPORTED;
474 /******************************************************************
475 * DeleteIPAddress (IPHLPAPI.@)
477 * Delete an IP address added with AddIPAddress().
480 * NTEContext [In] NTE context from AddIPAddress();
484 * Failure: error code from winerror.h
487 * Stub, returns ERROR_NOT_SUPPORTED.
489 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
491 FIXME("(NTEContext %d): stub\n", NTEContext);
492 return ERROR_NOT_SUPPORTED;
496 /******************************************************************
497 * DeleteIpForwardEntry (IPHLPAPI.@)
502 * pRoute [In] route to delete
506 * Failure: error code from winerror.h
509 * Stub, returns NO_ERROR.
511 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
513 FIXME("(pRoute %p): stub\n", pRoute);
514 /* could use SIOCDELRT, not sure I want to */
519 /******************************************************************
520 * DeleteIpNetEntry (IPHLPAPI.@)
522 * Delete an ARP entry.
525 * pArpEntry [In] ARP entry to delete
529 * Failure: error code from winerror.h
532 * Stub, returns NO_ERROR.
534 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
536 FIXME("(pArpEntry %p): stub\n", pArpEntry);
537 /* could use SIOCDARP on systems that support it, not sure I want to */
542 /******************************************************************
543 * DeleteProxyArpEntry (IPHLPAPI.@)
545 * Delete a Proxy ARP entry.
548 * dwAddress [In] IP address for which this computer acts as a proxy.
549 * dwMask [In] subnet mask for dwAddress
550 * dwIfIndex [In] interface index
554 * Failure: error code from winerror.h
557 * Stub, returns ERROR_NOT_SUPPORTED.
559 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
561 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
562 dwAddress, dwMask, dwIfIndex);
563 return ERROR_NOT_SUPPORTED;
567 /******************************************************************
568 * EnableRouter (IPHLPAPI.@)
570 * Turn on ip forwarding.
574 * pOverlapped [In/Out] hEvent member should contain a valid handle.
577 * Success: ERROR_IO_PENDING
578 * Failure: error code from winerror.h
581 * Stub, returns ERROR_NOT_SUPPORTED.
583 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
585 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle, pOverlapped);
586 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
587 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
589 return ERROR_NOT_SUPPORTED;
593 /******************************************************************
594 * FlushIpNetTable (IPHLPAPI.@)
596 * Delete all ARP entries of an interface
599 * dwIfIndex [In] interface index
603 * Failure: error code from winerror.h
606 * Stub, returns ERROR_NOT_SUPPORTED.
608 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
610 FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex);
611 /* this flushes the arp cache of the given index */
612 return ERROR_NOT_SUPPORTED;
616 /******************************************************************
617 * GetAdapterIndex (IPHLPAPI.@)
619 * Get interface index from its name.
622 * AdapterName [In] unicode string with the adapter name
623 * IfIndex [Out] returns found interface index
627 * Failure: error code from winerror.h
630 * Stub, returns ERROR_NOT_SUPPORTED.
632 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
634 FIXME("(AdapterName %p, IfIndex %p): stub\n", AdapterName, IfIndex);
635 /* FIXME: implement using getInterfaceIndexByName */
636 return ERROR_NOT_SUPPORTED;
640 /******************************************************************
641 * GetAdaptersInfo (IPHLPAPI.@)
643 * Get information about adapters.
646 * pAdapterInfo [Out] buffer for adapter infos
647 * pOutBufLen [In] length of output buffer
651 * Failure: error code from winerror.h
653 DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
657 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
659 ret = ERROR_INVALID_PARAMETER;
661 DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
663 if (numNonLoopbackInterfaces > 0) {
664 DWORD numIPAddresses = getNumIPAddresses();
667 /* This may slightly overestimate the amount of space needed, because
668 * the IP addresses include the loopback address, but it's easier
669 * to make sure there's more than enough space than to make sure there's
670 * precisely enough space.
672 size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
673 size += numIPAddresses * sizeof(IP_ADDR_STRING);
674 if (!pAdapterInfo || *pOutBufLen < size) {
676 ret = ERROR_BUFFER_OVERFLOW;
679 InterfaceIndexTable *table = NULL;
680 PMIB_IPADDRTABLE ipAddrTable = NULL;
682 ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
684 table = getNonLoopbackInterfaceIndexTable();
686 size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
687 size += ipAddrTable->dwNumEntries * sizeof(IP_ADDR_STRING);
688 if (*pOutBufLen < size) {
690 ret = ERROR_INSUFFICIENT_BUFFER;
695 BOOL winsEnabled = FALSE;
696 IP_ADDRESS_STRING primaryWINS, secondaryWINS;
697 PIP_ADDR_STRING nextIPAddr = (PIP_ADDR_STRING)((LPBYTE)pAdapterInfo
698 + numNonLoopbackInterfaces * sizeof(IP_ADAPTER_INFO));
700 memset(pAdapterInfo, 0, size);
701 /* @@ Wine registry key: HKCU\Software\Wine\Network */
702 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network",
703 &hKey) == ERROR_SUCCESS) {
704 DWORD size = sizeof(primaryWINS.String);
707 RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
708 (LPBYTE)primaryWINS.String, &size);
709 addr = inet_addr(primaryWINS.String);
710 if (addr != INADDR_NONE && addr != INADDR_ANY)
712 size = sizeof(secondaryWINS.String);
713 RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
714 (LPBYTE)secondaryWINS.String, &size);
715 addr = inet_addr(secondaryWINS.String);
716 if (addr != INADDR_NONE && addr != INADDR_ANY)
720 for (ndx = 0; ndx < table->numIndexes; ndx++) {
721 PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
722 DWORD addrLen = sizeof(ptr->Address), type, i;
723 PIP_ADDR_STRING currentIPAddr = &ptr->IpAddressList;
724 BOOL firstIPAddr = TRUE;
726 /* on Win98 this is left empty, but whatever */
727 getInterfaceNameByIndex(table->indexes[ndx], ptr->AdapterName);
728 getInterfacePhysicalByIndex(table->indexes[ndx], &addrLen,
729 ptr->Address, &type);
730 /* MS defines address length and type as UINT in some places and
731 DWORD in others, **sigh**. Don't want to assume that PUINT and
732 PDWORD are equiv (64-bit?) */
733 ptr->AddressLength = addrLen;
735 ptr->Index = table->indexes[ndx];
736 for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
737 if (ipAddrTable->table[i].dwIndex == ptr->Index) {
739 toIPAddressString(ipAddrTable->table[i].dwAddr,
740 ptr->IpAddressList.IpAddress.String);
741 toIPAddressString(ipAddrTable->table[i].dwMask,
742 ptr->IpAddressList.IpMask.String);
746 currentIPAddr->Next = nextIPAddr;
747 currentIPAddr = nextIPAddr;
748 toIPAddressString(ipAddrTable->table[i].dwAddr,
749 currentIPAddr->IpAddress.String);
750 toIPAddressString(ipAddrTable->table[i].dwMask,
751 currentIPAddr->IpMask.String);
757 ptr->HaveWins = TRUE;
758 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
759 primaryWINS.String, sizeof(primaryWINS.String));
760 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
761 secondaryWINS.String, sizeof(secondaryWINS.String));
763 if (ndx < table->numIndexes - 1)
764 ptr->Next = &pAdapterInfo[ndx + 1];
770 HeapFree(GetProcessHeap(), 0, table);
773 ret = ERROR_OUTOFMEMORY;
774 HeapFree(GetProcessHeap(), 0, ipAddrTable);
780 TRACE("returning %d\n", ret);
785 /******************************************************************
786 * GetBestInterface (IPHLPAPI.@)
788 * Get the interface, with the best route for the given IP address.
791 * dwDestAddr [In] IP address to search the interface for
792 * pdwBestIfIndex [Out] found best interface
796 * Failure: error code from winerror.h
798 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
802 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex);
804 ret = ERROR_INVALID_PARAMETER;
806 MIB_IPFORWARDROW ipRow;
808 ret = GetBestRoute(dwDestAddr, 0, &ipRow);
809 if (ret == ERROR_SUCCESS)
810 *pdwBestIfIndex = ipRow.dwForwardIfIndex;
812 TRACE("returning %d\n", ret);
817 /******************************************************************
818 * GetBestRoute (IPHLPAPI.@)
820 * Get the best route for the given IP address.
823 * dwDestAddr [In] IP address to search the best route for
824 * dwSourceAddr [In] optional source IP address
825 * pBestRoute [Out] found best route
829 * Failure: error code from winerror.h
831 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
833 PMIB_IPFORWARDTABLE table;
836 TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr,
837 dwSourceAddr, pBestRoute);
839 return ERROR_INVALID_PARAMETER;
841 AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
843 DWORD ndx, matchedBits, matchedNdx = 0;
845 for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
846 if (table->table[ndx].dwForwardType != MIB_IPROUTE_TYPE_INVALID &&
847 (dwDestAddr & table->table[ndx].dwForwardMask) ==
848 (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
849 DWORD numShifts, mask;
851 for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
852 mask && !(mask & 1); mask >>= 1, numShifts++)
854 if (numShifts > matchedBits) {
855 matchedBits = numShifts;
860 if (matchedNdx < table->dwNumEntries) {
861 memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
865 /* No route matches, which can happen if there's no default route. */
866 ret = ERROR_HOST_UNREACHABLE;
868 HeapFree(GetProcessHeap(), 0, table);
871 ret = ERROR_OUTOFMEMORY;
872 TRACE("returning %d\n", ret);
877 /******************************************************************
878 * GetFriendlyIfIndex (IPHLPAPI.@)
880 * Get a "friendly" version of IfIndex, which is one that doesn't
881 * have the top byte set. Doesn't validate whether IfIndex is a valid
885 * IfIndex [In] interface index to get the friendly one for
888 * A friendly version of IfIndex.
890 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
892 /* windows doesn't validate these, either, just makes sure the top byte is
893 cleared. I assume my ifenum module never gives an index with the top
895 TRACE("returning %d\n", IfIndex);
900 /******************************************************************
901 * GetIcmpStatistics (IPHLPAPI.@)
903 * Get the ICMP statistics for the local computer.
906 * pStats [Out] buffer for ICMP statistics
910 * Failure: error code from winerror.h
912 DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
916 TRACE("pStats %p\n", pStats);
917 ret = getICMPStats(pStats);
918 TRACE("returning %d\n", ret);
923 /******************************************************************
924 * GetIfEntry (IPHLPAPI.@)
926 * Get information about an interface.
929 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
930 * Out: interface information
934 * Failure: error code from winerror.h
936 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
939 char nameBuf[MAX_ADAPTER_NAME];
942 TRACE("pIfRow %p\n", pIfRow);
944 return ERROR_INVALID_PARAMETER;
946 name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf);
948 ret = getInterfaceEntryByName(name, pIfRow);
950 ret = getInterfaceStatsByName(name, pIfRow);
953 ret = ERROR_INVALID_DATA;
954 TRACE("returning %d\n", ret);
959 static int IfTableSorter(const void *a, const void *b)
964 ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
971 /******************************************************************
972 * GetIfTable (IPHLPAPI.@)
974 * Get a table of local interfaces.
977 * pIfTable [Out] buffer for local interfaces table
978 * pdwSize [In/Out] length of output buffer
979 * bOrder [In] whether to sort the table
983 * Failure: error code from winerror.h
986 * If pdwSize is less than required, the function will return
987 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
989 * If bOrder is true, the returned table will be sorted by interface index.
991 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
995 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize, pdwSize,
998 ret = ERROR_INVALID_PARAMETER;
1000 DWORD numInterfaces = getNumInterfaces();
1001 ULONG size = sizeof(MIB_IFTABLE) + (numInterfaces - 1) * sizeof(MIB_IFROW);
1003 if (!pIfTable || *pdwSize < size) {
1005 ret = ERROR_INSUFFICIENT_BUFFER;
1008 InterfaceIndexTable *table = getInterfaceIndexTable();
1011 size = sizeof(MIB_IFTABLE) + (table->numIndexes - 1) *
1013 if (*pdwSize < size) {
1015 ret = ERROR_INSUFFICIENT_BUFFER;
1021 pIfTable->dwNumEntries = 0;
1022 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1023 pIfTable->table[ndx].dwIndex = table->indexes[ndx];
1024 GetIfEntry(&pIfTable->table[ndx]);
1025 pIfTable->dwNumEntries++;
1028 qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
1032 HeapFree(GetProcessHeap(), 0, table);
1035 ret = ERROR_OUTOFMEMORY;
1038 TRACE("returning %d\n", ret);
1043 /******************************************************************
1044 * GetInterfaceInfo (IPHLPAPI.@)
1046 * Get a list of network interface adapters.
1049 * pIfTable [Out] buffer for interface adapters
1050 * dwOutBufLen [Out] if buffer is too small, returns required size
1054 * Failure: error code from winerror.h
1057 * MSDN states this should return non-loopback interfaces only.
1059 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
1063 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1065 ret = ERROR_INVALID_PARAMETER;
1067 DWORD numInterfaces = getNumInterfaces();
1068 ULONG size = sizeof(IP_INTERFACE_INFO) + (numInterfaces - 1) *
1069 sizeof(IP_ADAPTER_INDEX_MAP);
1071 if (!pIfTable || *dwOutBufLen < size) {
1072 *dwOutBufLen = size;
1073 ret = ERROR_INSUFFICIENT_BUFFER;
1076 InterfaceIndexTable *table = getInterfaceIndexTable();
1079 size = sizeof(IP_INTERFACE_INFO) + (table->numIndexes - 1) *
1080 sizeof(IP_ADAPTER_INDEX_MAP);
1081 if (*dwOutBufLen < size) {
1082 *dwOutBufLen = size;
1083 ret = ERROR_INSUFFICIENT_BUFFER;
1087 char nameBuf[MAX_ADAPTER_NAME];
1089 *dwOutBufLen = size;
1090 pIfTable->NumAdapters = 0;
1091 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1092 const char *walker, *name;
1095 pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1096 name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
1097 for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
1098 walker && *walker &&
1099 assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
1100 walker++, assigner++)
1101 *assigner = *walker;
1103 pIfTable->NumAdapters++;
1107 HeapFree(GetProcessHeap(), 0, table);
1110 ret = ERROR_OUTOFMEMORY;
1113 TRACE("returning %d\n", ret);
1118 /******************************************************************
1119 * GetIpAddrTable (IPHLPAPI.@)
1121 * Get interface-to-IP address mapping table.
1124 * pIpAddrTable [Out] buffer for mapping table
1125 * pdwSize [In/Out] length of output buffer
1126 * bOrder [In] whether to sort the table
1130 * Failure: error code from winerror.h
1133 * If pdwSize is less than required, the function will return
1134 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1136 * If bOrder is true, the returned table will be sorted by the next hop and
1137 * an assortment of arbitrary parameters.
1139 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1143 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable, pdwSize,
1146 ret = ERROR_INVALID_PARAMETER;
1148 PMIB_IPADDRTABLE table;
1150 ret = getIPAddrTable(&table, GetProcessHeap(), 0);
1151 if (ret == NO_ERROR)
1153 ULONG size = sizeof(MIB_IPADDRTABLE) + (table->dwNumEntries - 1) *
1154 sizeof(MIB_IPADDRROW);
1156 if (!pIpAddrTable || *pdwSize < size) {
1158 ret = ERROR_INSUFFICIENT_BUFFER;
1162 memcpy(pIpAddrTable, table, sizeof(MIB_IPADDRTABLE) +
1163 (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW));
1165 qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1166 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1169 HeapFree(GetProcessHeap(), 0, table);
1172 TRACE("returning %d\n", ret);
1177 /******************************************************************
1178 * GetIpForwardTable (IPHLPAPI.@)
1180 * Get the route table.
1183 * pIpForwardTable [Out] buffer for route table
1184 * pdwSize [In/Out] length of output buffer
1185 * bOrder [In] whether to sort the table
1189 * Failure: error code from winerror.h
1192 * If pdwSize is less than required, the function will return
1193 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1195 * If bOrder is true, the returned table will be sorted by the next hop and
1196 * an assortment of arbitrary parameters.
1198 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1202 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable,
1203 pdwSize, (DWORD)bOrder);
1205 ret = ERROR_INVALID_PARAMETER;
1207 DWORD numRoutes = getNumRoutes();
1208 ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) *
1209 sizeof(MIB_IPFORWARDROW);
1211 if (!pIpForwardTable || *pdwSize < sizeNeeded) {
1212 *pdwSize = sizeNeeded;
1213 ret = ERROR_INSUFFICIENT_BUFFER;
1216 PMIB_IPFORWARDTABLE table;
1218 ret = getRouteTable(&table, GetProcessHeap(), 0);
1220 sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (table->dwNumEntries - 1) *
1221 sizeof(MIB_IPFORWARDROW);
1222 if (*pdwSize < sizeNeeded) {
1223 *pdwSize = sizeNeeded;
1224 ret = ERROR_INSUFFICIENT_BUFFER;
1227 *pdwSize = sizeNeeded;
1228 memcpy(pIpForwardTable, table, sizeNeeded);
1230 qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
1231 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1234 HeapFree(GetProcessHeap(), 0, table);
1238 TRACE("returning %d\n", ret);
1243 /******************************************************************
1244 * GetIpNetTable (IPHLPAPI.@)
1246 * Get the IP-to-physical address mapping table.
1249 * pIpNetTable [Out] buffer for mapping table
1250 * pdwSize [In/Out] length of output buffer
1251 * bOrder [In] whether to sort the table
1255 * Failure: error code from winerror.h
1258 * If pdwSize is less than required, the function will return
1259 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1261 * If bOrder is true, the returned table will be sorted by IP address.
1263 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1267 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable, pdwSize,
1270 ret = ERROR_INVALID_PARAMETER;
1272 DWORD numEntries = getNumArpEntries();
1273 ULONG size = sizeof(MIB_IPNETTABLE) + (numEntries - 1) *
1274 sizeof(MIB_IPNETROW);
1276 if (!pIpNetTable || *pdwSize < size) {
1278 ret = ERROR_INSUFFICIENT_BUFFER;
1281 PMIB_IPNETTABLE table;
1283 ret = getArpTable(&table, GetProcessHeap(), 0);
1285 size = sizeof(MIB_IPNETTABLE) + (table->dwNumEntries - 1) *
1286 sizeof(MIB_IPNETROW);
1287 if (*pdwSize < size) {
1289 ret = ERROR_INSUFFICIENT_BUFFER;
1293 memcpy(pIpNetTable, table, size);
1295 qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
1296 sizeof(MIB_IPNETROW), IpNetTableSorter);
1299 HeapFree(GetProcessHeap(), 0, table);
1303 TRACE("returning %d\n", ret);
1308 /******************************************************************
1309 * GetIpStatistics (IPHLPAPI.@)
1311 * Get the IP statistics for the local computer.
1314 * pStats [Out] buffer for IP statistics
1318 * Failure: error code from winerror.h
1320 DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
1324 TRACE("pStats %p\n", pStats);
1325 ret = getIPStats(pStats);
1326 TRACE("returning %d\n", ret);
1331 /******************************************************************
1332 * GetNetworkParams (IPHLPAPI.@)
1334 * Get the network parameters for the local computer.
1337 * pFixedInfo [Out] buffer for network parameters
1338 * pOutBufLen [In/Out] length of output buffer
1342 * Failure: error code from winerror.h
1345 * If pOutBufLen is less than required, the function will return
1346 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1349 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1355 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1357 return ERROR_INVALID_PARAMETER;
1359 initialise_resolver();
1360 size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount - 1) *
1361 sizeof(IP_ADDR_STRING) : 0);
1362 if (!pFixedInfo || *pOutBufLen < size) {
1364 return ERROR_BUFFER_OVERFLOW;
1367 memset(pFixedInfo, 0, size);
1368 size = sizeof(pFixedInfo->HostName);
1369 GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1370 size = sizeof(pFixedInfo->DomainName);
1371 GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1372 if (_res.nscount > 0) {
1373 PIP_ADDR_STRING ptr;
1376 for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1377 i++, ptr = ptr->Next) {
1378 toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
1379 ptr->IpAddress.String);
1380 if (i == _res.nscount - 1)
1383 ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
1385 ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1388 pFixedInfo->NodeType = HYBRID_NODETYPE;
1389 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1390 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1391 if (regReturn != ERROR_SUCCESS)
1392 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1393 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1395 if (regReturn == ERROR_SUCCESS)
1397 DWORD size = sizeof(pFixedInfo->ScopeId);
1399 RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1403 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1404 I suppose could also check for a listener on port 53 to set EnableDns */
1406 TRACE("returning %d\n", ret);
1411 /******************************************************************
1412 * GetNumberOfInterfaces (IPHLPAPI.@)
1414 * Get the number of interfaces.
1417 * pdwNumIf [Out] number of interfaces
1420 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1422 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
1426 TRACE("pdwNumIf %p\n", pdwNumIf);
1428 ret = ERROR_INVALID_PARAMETER;
1430 *pdwNumIf = getNumInterfaces();
1433 TRACE("returning %d\n", ret);
1438 /******************************************************************
1439 * GetPerAdapterInfo (IPHLPAPI.@)
1441 * Get information about an adapter corresponding to an interface.
1444 * IfIndex [In] interface info
1445 * pPerAdapterInfo [Out] buffer for per adapter info
1446 * pOutBufLen [In/Out] length of output buffer
1450 * Failure: error code from winerror.h
1453 * Stub, returns ERROR_NOT_SUPPORTED.
1455 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
1457 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex,
1458 pPerAdapterInfo, pOutBufLen);
1459 return ERROR_NOT_SUPPORTED;
1463 /******************************************************************
1464 * GetRTTAndHopCount (IPHLPAPI.@)
1466 * Get round-trip time (RTT) and hop count.
1470 * DestIpAddress [In] destination address to get the info for
1471 * HopCount [Out] retrieved hop count
1472 * MaxHops [In] maximum hops to search for the destination
1473 * RTT [Out] RTT in milliseconds
1480 * Stub, returns FALSE.
1482 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
1484 FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %d, RTT %p): stub\n",
1485 DestIpAddress, HopCount, MaxHops, RTT);
1490 /******************************************************************
1491 * GetTcpStatistics (IPHLPAPI.@)
1493 * Get the TCP statistics for the local computer.
1496 * pStats [Out] buffer for TCP statistics
1500 * Failure: error code from winerror.h
1502 DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
1506 TRACE("pStats %p\n", pStats);
1507 ret = getTCPStats(pStats);
1508 TRACE("returning %d\n", ret);
1513 /******************************************************************
1514 * GetTcpTable (IPHLPAPI.@)
1516 * Get the table of active TCP connections.
1519 * pTcpTable [Out] buffer for TCP connections table
1520 * pdwSize [In/Out] length of output buffer
1521 * bOrder [In] whether to order the table
1525 * Failure: error code from winerror.h
1528 * If pdwSize is less than required, the function will return
1529 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1530 * the required byte size.
1531 * If bOrder is true, the returned table will be sorted, first by
1532 * local address and port number, then by remote address and port
1535 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
1539 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize,
1542 ret = ERROR_INVALID_PARAMETER;
1544 DWORD numEntries = getNumTcpEntries();
1545 DWORD size = sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW);
1547 if (!pTcpTable || *pdwSize < size) {
1549 ret = ERROR_INSUFFICIENT_BUFFER;
1552 ret = getTcpTable(&pTcpTable, numEntries, 0, 0);
1554 size = sizeof(MIB_TCPTABLE) + (pTcpTable->dwNumEntries - 1) *
1559 qsort(pTcpTable->table, pTcpTable->dwNumEntries,
1560 sizeof(MIB_TCPROW), TcpTableSorter);
1564 ret = ERROR_OUTOFMEMORY;
1567 TRACE("returning %d\n", ret);
1572 /******************************************************************
1573 * GetUdpStatistics (IPHLPAPI.@)
1575 * Get the UDP statistics for the local computer.
1578 * pStats [Out] buffer for UDP statistics
1582 * Failure: error code from winerror.h
1584 DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
1588 TRACE("pStats %p\n", pStats);
1589 ret = getUDPStats(pStats);
1590 TRACE("returning %d\n", ret);
1595 /******************************************************************
1596 * GetUdpTable (IPHLPAPI.@)
1598 * Get a table of active UDP connections.
1601 * pUdpTable [Out] buffer for UDP connections table
1602 * pdwSize [In/Out] length of output buffer
1603 * bOrder [In] whether to order the table
1607 * Failure: error code from winerror.h
1610 * If pdwSize is less than required, the function will return
1611 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1612 * required byte size.
1613 * If bOrder is true, the returned table will be sorted, first by
1614 * local address, then by local port number.
1616 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
1620 TRACE("pUdpTable %p, pdwSize %p, bOrder %d\n", pUdpTable, pdwSize,
1623 ret = ERROR_INVALID_PARAMETER;
1625 DWORD numEntries = getNumUdpEntries();
1626 DWORD size = sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW);
1628 if (!pUdpTable || *pdwSize < size) {
1630 ret = ERROR_INSUFFICIENT_BUFFER;
1633 PMIB_UDPTABLE table;
1635 ret = getUdpTable(&table, GetProcessHeap(), 0);
1637 size = sizeof(MIB_UDPTABLE) + (table->dwNumEntries - 1) *
1639 if (*pdwSize < size) {
1641 ret = ERROR_INSUFFICIENT_BUFFER;
1645 memcpy(pUdpTable, table, size);
1647 qsort(pUdpTable->table, pUdpTable->dwNumEntries,
1648 sizeof(MIB_UDPROW), UdpTableSorter);
1651 HeapFree(GetProcessHeap(), 0, table);
1654 ret = ERROR_OUTOFMEMORY;
1657 TRACE("returning %d\n", ret);
1662 /******************************************************************
1663 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1665 * This is a Win98-only function to get information on "unidirectional"
1666 * adapters. Since this is pretty nonsensical in other contexts, it
1667 * never returns anything.
1670 * pIPIfInfo [Out] buffer for adapter infos
1671 * dwOutBufLen [Out] length of the output buffer
1675 * Failure: error code from winerror.h
1678 * Stub, returns ERROR_NOT_SUPPORTED.
1680 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
1682 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1683 /* a unidirectional adapter?? not bloody likely! */
1684 return ERROR_NOT_SUPPORTED;
1688 /******************************************************************
1689 * IpReleaseAddress (IPHLPAPI.@)
1691 * Release an IP optained through DHCP,
1694 * AdapterInfo [In] adapter to release IP address
1698 * Failure: error code from winerror.h
1701 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1702 * this function does nothing.
1705 * Stub, returns ERROR_NOT_SUPPORTED.
1707 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1709 TRACE("AdapterInfo %p\n", AdapterInfo);
1710 /* not a stub, never going to support this (and I never mark an adapter as
1711 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1712 return ERROR_NOT_SUPPORTED;
1716 /******************************************************************
1717 * IpRenewAddress (IPHLPAPI.@)
1719 * Renew an IP optained through DHCP.
1722 * AdapterInfo [In] adapter to renew IP address
1726 * Failure: error code from winerror.h
1729 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1730 * this function does nothing.
1733 * Stub, returns ERROR_NOT_SUPPORTED.
1735 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1737 TRACE("AdapterInfo %p\n", AdapterInfo);
1738 /* not a stub, never going to support this (and I never mark an adapter as
1739 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1740 return ERROR_NOT_SUPPORTED;
1744 /******************************************************************
1745 * NotifyAddrChange (IPHLPAPI.@)
1747 * Notify caller whenever the ip-interface map is changed.
1750 * Handle [Out] handle useable in asynchronus notification
1751 * overlapped [In] overlapped structure that notifies the caller
1755 * Failure: error code from winerror.h
1758 * Stub, returns ERROR_NOT_SUPPORTED.
1760 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1762 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1763 return ERROR_NOT_SUPPORTED;
1767 /******************************************************************
1768 * NotifyRouteChange (IPHLPAPI.@)
1770 * Notify caller whenever the ip routing table is changed.
1773 * Handle [Out] handle useable in asynchronus notification
1774 * overlapped [In] overlapped structure that notifies the caller
1778 * Failure: error code from winerror.h
1781 * Stub, returns ERROR_NOT_SUPPORTED.
1783 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1785 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1786 return ERROR_NOT_SUPPORTED;
1790 /******************************************************************
1791 * SendARP (IPHLPAPI.@)
1793 * Send an ARP request.
1796 * DestIP [In] attempt to obtain this IP
1797 * SrcIP [In] optional sender IP address
1798 * pMacAddr [Out] buffer for the mac address
1799 * PhyAddrLen [In/Out] length of the output buffer
1803 * Failure: error code from winerror.h
1806 * Stub, returns ERROR_NOT_SUPPORTED.
1808 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
1810 FIXME("(DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p): stub\n",
1811 DestIP, SrcIP, pMacAddr, PhyAddrLen);
1812 return ERROR_NOT_SUPPORTED;
1816 /******************************************************************
1817 * SetIfEntry (IPHLPAPI.@)
1819 * Set the administrative status of an interface.
1822 * pIfRow [In] dwAdminStatus member specifies the new status.
1826 * Failure: error code from winerror.h
1829 * Stub, returns ERROR_NOT_SUPPORTED.
1831 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
1833 FIXME("(pIfRow %p): stub\n", pIfRow);
1834 /* this is supposed to set an interface administratively up or down.
1835 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1836 this sort of down is indistinguishable from other sorts of down (e.g. no
1838 return ERROR_NOT_SUPPORTED;
1842 /******************************************************************
1843 * SetIpForwardEntry (IPHLPAPI.@)
1845 * Modify an existing route.
1848 * pRoute [In] route with the new information
1852 * Failure: error code from winerror.h
1855 * Stub, returns NO_ERROR.
1857 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
1859 FIXME("(pRoute %p): stub\n", pRoute);
1860 /* this is to add a route entry, how's it distinguishable from
1861 CreateIpForwardEntry?
1862 could use SIOCADDRT, not sure I want to */
1867 /******************************************************************
1868 * SetIpNetEntry (IPHLPAPI.@)
1870 * Modify an existing ARP entry.
1873 * pArpEntry [In] ARP entry with the new information
1877 * Failure: error code from winerror.h
1880 * Stub, returns NO_ERROR.
1882 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
1884 FIXME("(pArpEntry %p): stub\n", pArpEntry);
1885 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1890 /******************************************************************
1891 * SetIpStatistics (IPHLPAPI.@)
1893 * Toggle IP forwarding and det the default TTL value.
1896 * pIpStats [In] IP statistics with the new information
1900 * Failure: error code from winerror.h
1903 * Stub, returns NO_ERROR.
1905 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
1907 FIXME("(pIpStats %p): stub\n", pIpStats);
1912 /******************************************************************
1913 * SetIpTTL (IPHLPAPI.@)
1915 * Set the default TTL value.
1918 * nTTL [In] new TTL value
1922 * Failure: error code from winerror.h
1925 * Stub, returns NO_ERROR.
1927 DWORD WINAPI SetIpTTL(UINT nTTL)
1929 FIXME("(nTTL %d): stub\n", nTTL);
1930 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1931 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1936 /******************************************************************
1937 * SetTcpEntry (IPHLPAPI.@)
1939 * Set the state of a TCP connection.
1942 * pTcpRow [In] specifies connection with new state
1946 * Failure: error code from winerror.h
1949 * Stub, returns NO_ERROR.
1951 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
1953 FIXME("(pTcpRow %p): stub\n", pTcpRow);
1958 /******************************************************************
1959 * UnenableRouter (IPHLPAPI.@)
1961 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
1962 * if it reaches zero.
1965 * pOverlapped [In/Out] should be the same as in EnableRouter()
1966 * lpdwEnableCount [Out] optional, receives reference count
1970 * Failure: error code from winerror.h
1973 * Stub, returns ERROR_NOT_SUPPORTED.
1975 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
1977 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
1979 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
1980 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
1982 return ERROR_NOT_SUPPORTED;