2 * iphlpapi dll implementation
4 * Copyright (C) 2003,2006 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <sys/types.h>
26 #ifdef HAVE_NETINET_IN_H
27 # include <netinet/in.h>
29 #ifdef HAVE_ARPA_INET_H
30 # include <arpa/inet.h>
32 #ifdef HAVE_ARPA_NAMESER_H
33 # include <arpa/nameser.h>
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
50 #define INADDR_NONE ~0UL
53 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
56 case DLL_PROCESS_ATTACH:
57 DisableThreadLibraryCalls( hinstDLL );
60 case DLL_PROCESS_DETACH:
66 /******************************************************************
67 * AddIPAddress (IPHLPAPI.@)
69 * Add an IP address to an adapter.
72 * Address [In] IP address to add to the adapter
73 * IpMask [In] subnet mask for the IP address
74 * IfIndex [In] adapter index to add the address
75 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
76 * NTEInstance [Out] NTE instance for the IP address
80 * Failure: error code from winerror.h
83 * Stub. Currently returns ERROR_NOT_SUPPORTED.
85 DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
88 return ERROR_NOT_SUPPORTED;
92 /******************************************************************
93 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
95 * Get table of local interfaces.
96 * Like GetIfTable(), but allocate the returned table from heap.
99 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
100 * allocated and returned.
101 * bOrder [In] whether to sort the table
102 * heap [In] heap from which the table is allocated
103 * flags [In] flags to HeapAlloc
106 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
107 * GetIfTable() returns otherwise.
109 DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
110 BOOL bOrder, HANDLE heap, DWORD flags)
114 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08lx\n", ppIfTable,
115 bOrder, heap, flags);
117 ret = ERROR_INVALID_PARAMETER;
121 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
122 if (ret == ERROR_INSUFFICIENT_BUFFER) {
123 *ppIfTable = HeapAlloc(heap, flags, dwSize);
124 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
127 TRACE("returning %ld\n", ret);
132 static int IpAddrTableSorter(const void *a, const void *b)
137 ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
144 /******************************************************************
145 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
147 * Get interface-to-IP address mapping table.
148 * Like GetIpAddrTable(), but allocate the returned table from heap.
151 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
152 * allocated and returned.
153 * bOrder [In] whether to sort the table
154 * heap [In] heap from which the table is allocated
155 * flags [In] flags to HeapAlloc
158 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
159 * failure, NO_ERROR on success.
161 DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
162 BOOL bOrder, HANDLE heap, DWORD flags)
166 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
167 ppIpAddrTable, bOrder, heap, flags);
168 ret = getIPAddrTable(ppIpAddrTable, heap, flags);
170 qsort((*ppIpAddrTable)->table, (*ppIpAddrTable)->dwNumEntries,
171 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
172 TRACE("returning %ld\n", ret);
177 static int IpForwardTableSorter(const void *a, const void *b)
182 const MIB_IPFORWARDROW* rowA = (const MIB_IPFORWARDROW*)a;
183 const MIB_IPFORWARDROW* rowB = (const MIB_IPFORWARDROW*)b;
185 ret = rowA->dwForwardDest - rowB->dwForwardDest;
187 ret = rowA->dwForwardProto - rowB->dwForwardProto;
189 ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy;
191 ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop;
201 /******************************************************************
202 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
204 * Get the route table.
205 * Like GetIpForwardTable(), but allocate the returned table from heap.
208 * ppIpForwardTable [Out] pointer into which the MIB_IPFORWARDTABLE is
209 * allocated and returned.
210 * bOrder [In] whether to sort the table
211 * heap [In] heap from which the table is allocated
212 * flags [In] flags to HeapAlloc
215 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, other error codes
216 * on failure, NO_ERROR on success.
218 DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
219 ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags)
223 TRACE("ppIpForwardTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
224 ppIpForwardTable, bOrder, heap, flags);
225 ret = getRouteTable(ppIpForwardTable, heap, flags);
227 qsort((*ppIpForwardTable)->table, (*ppIpForwardTable)->dwNumEntries,
228 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
229 TRACE("returning %ld\n", ret);
234 static int IpNetTableSorter(const void *a, const void *b)
239 ret = ((const MIB_IPNETROW*)a)->dwAddr - ((const MIB_IPNETROW*)b)->dwAddr;
246 /******************************************************************
247 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
249 * Get the IP-to-physical address mapping table.
250 * Like GetIpNetTable(), but allocate the returned table from heap.
253 * ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE is
254 * allocated and returned.
255 * bOrder [In] whether to sort the table
256 * heap [In] heap from which the table is allocated
257 * flags [In] flags to HeapAlloc
260 * ERROR_INVALID_PARAMETER if ppIpNetTable is NULL, other error codes
261 * on failure, NO_ERROR on success.
263 DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable,
264 BOOL bOrder, HANDLE heap, DWORD flags)
268 TRACE("ppIpNetTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
269 ppIpNetTable, bOrder, heap, flags);
270 ret = getArpTable(ppIpNetTable, heap, flags);
272 qsort((*ppIpNetTable)->table, (*ppIpNetTable)->dwNumEntries,
273 sizeof(MIB_IPADDRROW), IpNetTableSorter);
274 TRACE("returning %ld\n", ret);
279 static int TcpTableSorter(const void *a, const void *b)
284 const MIB_TCPROW* rowA = a;
285 const MIB_TCPROW* rowB = b;
287 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
289 ret = rowA->dwLocalPort - rowB->dwLocalPort;
291 ret = rowA->dwRemoteAddr - rowB->dwRemoteAddr;
293 ret = rowA->dwRemotePort - rowB->dwRemotePort;
303 /******************************************************************
304 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
306 * Get the TCP connection table.
307 * Like GetTcpTable(), but allocate the returned table from heap.
310 * ppTcpTable [Out] pointer into which the MIB_TCPTABLE is
311 * allocated and returned.
312 * bOrder [In] whether to sort the table
313 * heap [In] heap from which the table is allocated
314 * flags [In] flags to HeapAlloc
317 * ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable()
320 DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
321 BOOL bOrder, HANDLE heap, DWORD flags)
325 TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
326 ppTcpTable, bOrder, heap, flags);
327 ret = getTcpTable(ppTcpTable, heap, flags);
329 qsort((*ppTcpTable)->table, (*ppTcpTable)->dwNumEntries,
330 sizeof(MIB_TCPROW), TcpTableSorter);
331 TRACE("returning %ld\n", ret);
336 static int UdpTableSorter(const void *a, const void *b)
341 const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
342 const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;
344 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
346 ret = rowA->dwLocalPort - rowB->dwLocalPort;
354 /******************************************************************
355 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
357 * Get the UDP listener table.
358 * Like GetUdpTable(), but allocate the returned table from heap.
361 * ppUdpTable [Out] pointer into which the MIB_UDPTABLE is
362 * allocated and returned.
363 * bOrder [In] whether to sort the table
364 * heap [In] heap from which the table is allocated
365 * flags [In] flags to HeapAlloc
368 * ERROR_INVALID_PARAMETER if ppUdpTable is NULL, whatever GetUdpTable()
371 DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
372 BOOL bOrder, HANDLE heap, DWORD flags)
376 TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
377 ppUdpTable, bOrder, heap, flags);
378 ret = getUdpTable(ppUdpTable, heap, flags);
380 qsort((*ppUdpTable)->table, (*ppUdpTable)->dwNumEntries,
381 sizeof(MIB_UDPROW), UdpTableSorter);
382 TRACE("returning %ld\n", ret);
387 /******************************************************************
388 * CreateIpForwardEntry (IPHLPAPI.@)
390 * Create a route in the local computer's IP table.
393 * pRoute [In] new route information
397 * Failure: error code from winerror.h
400 * Stub, always returns NO_ERROR.
402 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
404 FIXME("(pRoute %p): stub\n", pRoute);
405 /* could use SIOCADDRT, not sure I want to */
410 /******************************************************************
411 * CreateIpNetEntry (IPHLPAPI.@)
413 * Create entry in the ARP table.
416 * pArpEntry [In] new ARP entry
420 * Failure: error code from winerror.h
423 * Stub, always returns NO_ERROR.
425 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
427 FIXME("(pArpEntry %p)\n", pArpEntry);
428 /* could use SIOCSARP on systems that support it, not sure I want to */
433 /******************************************************************
434 * CreateProxyArpEntry (IPHLPAPI.@)
436 * Create a Proxy ARP (PARP) entry for an IP address.
439 * dwAddress [In] IP address for which this computer acts as a proxy.
440 * dwMask [In] subnet mask for dwAddress
441 * dwIfIndex [In] interface index
445 * Failure: error code from winerror.h
448 * Stub, returns ERROR_NOT_SUPPORTED.
450 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
452 FIXME("(dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx): stub\n",
453 dwAddress, dwMask, dwIfIndex);
454 return ERROR_NOT_SUPPORTED;
458 /******************************************************************
459 * DeleteIPAddress (IPHLPAPI.@)
461 * Delete an IP address added with AddIPAddress().
464 * NTEContext [In] NTE context from AddIPAddress();
468 * Failure: error code from winerror.h
471 * Stub, returns ERROR_NOT_SUPPORTED.
473 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
475 FIXME("(NTEContext %ld): stub\n", NTEContext);
476 return ERROR_NOT_SUPPORTED;
480 /******************************************************************
481 * DeleteIpForwardEntry (IPHLPAPI.@)
486 * pRoute [In] route to delete
490 * Failure: error code from winerror.h
493 * Stub, returns NO_ERROR.
495 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
497 FIXME("(pRoute %p): stub\n", pRoute);
498 /* could use SIOCDELRT, not sure I want to */
503 /******************************************************************
504 * DeleteIpNetEntry (IPHLPAPI.@)
506 * Delete an ARP entry.
509 * pArpEntry [In] ARP entry to delete
513 * Failure: error code from winerror.h
516 * Stub, returns NO_ERROR.
518 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
520 FIXME("(pArpEntry %p): stub\n", pArpEntry);
521 /* could use SIOCDARP on systems that support it, not sure I want to */
526 /******************************************************************
527 * DeleteProxyArpEntry (IPHLPAPI.@)
529 * Delete a Proxy ARP entry.
532 * dwAddress [In] IP address for which this computer acts as a proxy.
533 * dwMask [In] subnet mask for dwAddress
534 * dwIfIndex [In] interface index
538 * Failure: error code from winerror.h
541 * Stub, returns ERROR_NOT_SUPPORTED.
543 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
545 FIXME("(dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx): stub\n",
546 dwAddress, dwMask, dwIfIndex);
547 return ERROR_NOT_SUPPORTED;
551 /******************************************************************
552 * EnableRouter (IPHLPAPI.@)
554 * Turn on ip forwarding.
558 * pOverlapped [In/Out] hEvent member should contain a valid handle.
561 * Success: ERROR_IO_PENDING
562 * Failure: error code from winerror.h
565 * Stub, returns ERROR_NOT_SUPPORTED.
567 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
569 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle, pOverlapped);
570 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
571 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
573 return ERROR_NOT_SUPPORTED;
577 /******************************************************************
578 * FlushIpNetTable (IPHLPAPI.@)
580 * Delete all ARP entries of an interface
583 * dwIfIndex [In] interface index
587 * Failure: error code from winerror.h
590 * Stub, returns ERROR_NOT_SUPPORTED.
592 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
594 FIXME("(dwIfIndex 0x%08lx): stub\n", dwIfIndex);
595 /* this flushes the arp cache of the given index */
596 return ERROR_NOT_SUPPORTED;
600 /******************************************************************
601 * GetAdapterIndex (IPHLPAPI.@)
603 * Get interface index from its name.
606 * AdapterName [In] unicode string with the adapter name
607 * IfIndex [Out] returns found interface index
611 * Failure: error code from winerror.h
614 * Stub, returns ERROR_NOT_SUPPORTED.
616 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
618 FIXME("(AdapterName %p, IfIndex %p): stub\n", AdapterName, IfIndex);
619 /* FIXME: implement using getInterfaceIndexByName */
620 return ERROR_NOT_SUPPORTED;
624 /******************************************************************
625 * GetAdaptersInfo (IPHLPAPI.@)
627 * Get information about adapters.
630 * pAdapterInfo [Out] buffer for adapter infos
631 * pOutBufLen [In] length of output buffer
635 * Failure: error code from winerror.h
637 DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
641 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
643 ret = ERROR_INVALID_PARAMETER;
645 DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
647 if (numNonLoopbackInterfaces > 0) {
648 DWORD numIPAddresses = getNumIPAddresses();
651 /* This may slightly overestimate the amount of space needed, because
652 * the IP addresses include the loopback address, but it's easier
653 * to make sure there's more than enough space than to make sure there's
654 * precisely enough space.
656 size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
657 if (numIPAddresses > numNonLoopbackInterfaces)
658 size += (numIPAddresses - numNonLoopbackInterfaces) *
659 sizeof(IP_ADDR_STRING);
660 if (!pAdapterInfo || *pOutBufLen < size) {
662 ret = ERROR_BUFFER_OVERFLOW;
665 InterfaceIndexTable *table = NULL;
666 PMIB_IPADDRTABLE ipAddrTable = NULL;
668 ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
670 table = getNonLoopbackInterfaceIndexTable();
672 size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
673 if (ipAddrTable->dwNumEntries > numNonLoopbackInterfaces)
674 size += (ipAddrTable->dwNumEntries - numNonLoopbackInterfaces) *
675 sizeof(IP_ADDR_STRING);
676 if (*pOutBufLen < size) {
678 ret = ERROR_INSUFFICIENT_BUFFER;
683 BOOL winsEnabled = FALSE;
684 IP_ADDRESS_STRING primaryWINS, secondaryWINS;
685 PIP_ADDR_STRING nextIPAddr = (PIP_ADDR_STRING)((LPBYTE)pAdapterInfo
686 + numNonLoopbackInterfaces * sizeof(IP_ADAPTER_INFO));
688 memset(pAdapterInfo, 0, size);
689 /* @@ Wine registry key: HKCU\Software\Wine\Network */
690 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network",
691 &hKey) == ERROR_SUCCESS) {
692 DWORD size = sizeof(primaryWINS.String);
695 RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
696 (LPBYTE)primaryWINS.String, &size);
697 addr = inet_addr(primaryWINS.String);
698 if (addr != INADDR_NONE && addr != INADDR_ANY)
700 size = sizeof(secondaryWINS.String);
701 RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
702 (LPBYTE)secondaryWINS.String, &size);
703 addr = inet_addr(secondaryWINS.String);
704 if (addr != INADDR_NONE && addr != INADDR_ANY)
708 for (ndx = 0; ndx < table->numIndexes; ndx++) {
709 PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
710 DWORD addrLen = sizeof(ptr->Address), type, i;
711 PIP_ADDR_STRING currentIPAddr = &ptr->IpAddressList;
712 BOOL firstIPAddr = TRUE;
714 /* on Win98 this is left empty, but whatever */
715 getInterfaceNameByIndex(table->indexes[ndx], ptr->AdapterName);
716 getInterfacePhysicalByIndex(table->indexes[ndx], &addrLen,
717 ptr->Address, &type);
718 /* MS defines address length and type as UINT in some places and
719 DWORD in others, **sigh**. Don't want to assume that PUINT and
720 PDWORD are equiv (64-bit?) */
721 ptr->AddressLength = addrLen;
723 ptr->Index = table->indexes[ndx];
724 for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
725 if (ipAddrTable->table[i].dwIndex == ptr->Index) {
727 toIPAddressString(ipAddrTable->table[i].dwAddr,
728 ptr->IpAddressList.IpAddress.String);
729 toIPAddressString(ipAddrTable->table[i].dwBCastAddr,
730 ptr->IpAddressList.IpMask.String);
734 currentIPAddr->Next = nextIPAddr;
735 currentIPAddr = nextIPAddr;
736 toIPAddressString(ipAddrTable->table[i].dwAddr,
737 currentIPAddr->IpAddress.String);
738 toIPAddressString(ipAddrTable->table[i].dwBCastAddr,
739 currentIPAddr->IpMask.String);
745 ptr->HaveWins = TRUE;
746 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
747 primaryWINS.String, sizeof(primaryWINS.String));
748 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
749 secondaryWINS.String, sizeof(secondaryWINS.String));
751 if (ndx < table->numIndexes - 1)
752 ptr->Next = &pAdapterInfo[ndx + 1];
758 HeapFree(GetProcessHeap(), 0, table);
761 ret = ERROR_OUTOFMEMORY;
763 HeapFree(GetProcessHeap(), 0, ipAddrTable);
769 TRACE("returning %ld\n", ret);
774 /******************************************************************
775 * GetBestInterface (IPHLPAPI.@)
777 * Get the interface, with the best route for the given IP address.
780 * dwDestAddr [In] IP address to search the interface for
781 * pdwBestIfIndex [Out] found best interface
785 * Failure: error code from winerror.h
787 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
791 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex);
793 ret = ERROR_INVALID_PARAMETER;
795 MIB_IPFORWARDROW ipRow;
797 ret = GetBestRoute(dwDestAddr, 0, &ipRow);
798 if (ret == ERROR_SUCCESS)
799 *pdwBestIfIndex = ipRow.dwForwardIfIndex;
801 TRACE("returning %ld\n", ret);
806 /******************************************************************
807 * GetBestRoute (IPHLPAPI.@)
809 * Get the best route for the given IP address.
812 * dwDestAddr [In] IP address to search the best route for
813 * dwSourceAddr [In] optional source IP address
814 * pBestRoute [Out] found best route
818 * Failure: error code from winerror.h
820 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
822 PMIB_IPFORWARDTABLE table;
825 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr,
826 dwSourceAddr, pBestRoute);
828 return ERROR_INVALID_PARAMETER;
830 AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
832 DWORD ndx, matchedBits, matchedNdx = 0;
834 for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
835 if (table->table[ndx].dwForwardType != MIB_IPROUTE_TYPE_INVALID &&
836 (dwDestAddr & table->table[ndx].dwForwardMask) ==
837 (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
838 DWORD numShifts, mask;
840 for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
841 mask && !(mask & 1); mask >>= 1, numShifts++)
843 if (numShifts > matchedBits) {
844 matchedBits = numShifts;
849 if (matchedNdx < table->dwNumEntries) {
850 memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
854 /* No route matches, which can happen if there's no default route. */
855 ret = ERROR_HOST_UNREACHABLE;
857 HeapFree(GetProcessHeap(), 0, table);
860 ret = ERROR_OUTOFMEMORY;
861 TRACE("returning %ld\n", ret);
866 /******************************************************************
867 * GetFriendlyIfIndex (IPHLPAPI.@)
869 * Get a "friendly" version of IfIndex, which is one that doesn't
870 * have the top byte set. Doesn't validate whether IfIndex is a valid
874 * IfIndex [In] interface index to get the friendly one for
877 * A friendly version of IfIndex.
879 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
881 /* windows doesn't validate these, either, just makes sure the top byte is
882 cleared. I assume my ifenum module never gives an index with the top
884 TRACE("returning %ld\n", IfIndex);
889 /******************************************************************
890 * GetIcmpStatistics (IPHLPAPI.@)
892 * Get the ICMP statistics for the local computer.
895 * pStats [Out] buffer for ICMP statistics
899 * Failure: error code from winerror.h
901 DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
905 TRACE("pStats %p\n", pStats);
906 ret = getICMPStats(pStats);
907 TRACE("returning %ld\n", ret);
912 /******************************************************************
913 * GetIfEntry (IPHLPAPI.@)
915 * Get information about an interface.
918 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
919 * Out: interface information
923 * Failure: error code from winerror.h
925 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
928 char nameBuf[MAX_ADAPTER_NAME];
931 TRACE("pIfRow %p\n", pIfRow);
933 return ERROR_INVALID_PARAMETER;
935 name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf);
937 ret = getInterfaceEntryByName(name, pIfRow);
939 ret = getInterfaceStatsByName(name, pIfRow);
942 ret = ERROR_INVALID_DATA;
943 TRACE("returning %ld\n", ret);
948 static int IfTableSorter(const void *a, const void *b)
953 ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
960 /******************************************************************
961 * GetIfTable (IPHLPAPI.@)
963 * Get a table of local interfaces.
966 * pIfTable [Out] buffer for local interfaces table
967 * pdwSize [In/Out] length of output buffer
968 * bOrder [In] whether to sort the table
972 * Failure: error code from winerror.h
975 * If pdwSize is less than required, the function will return
976 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
978 * If bOrder is true, the returned table will be sorted by interface index.
980 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
984 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize, pdwSize,
987 ret = ERROR_INVALID_PARAMETER;
989 DWORD numInterfaces = getNumInterfaces();
990 ULONG size = sizeof(MIB_IFTABLE) + (numInterfaces - 1) * sizeof(MIB_IFROW);
992 if (!pIfTable || *pdwSize < size) {
994 ret = ERROR_INSUFFICIENT_BUFFER;
997 InterfaceIndexTable *table = getInterfaceIndexTable();
1000 size = sizeof(MIB_IFTABLE) + (table->numIndexes - 1) *
1002 if (*pdwSize < size) {
1004 ret = ERROR_INSUFFICIENT_BUFFER;
1010 pIfTable->dwNumEntries = 0;
1011 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1012 pIfTable->table[ndx].dwIndex = table->indexes[ndx];
1013 GetIfEntry(&pIfTable->table[ndx]);
1014 pIfTable->dwNumEntries++;
1017 qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
1021 HeapFree(GetProcessHeap(), 0, table);
1024 ret = ERROR_OUTOFMEMORY;
1027 TRACE("returning %ld\n", ret);
1032 /******************************************************************
1033 * GetInterfaceInfo (IPHLPAPI.@)
1035 * Get a list of network interface adapters.
1038 * pIfTable [Out] buffer for interface adapters
1039 * dwOutBufLen [Out] if buffer is too small, returns required size
1043 * Failure: error code from winerror.h
1046 * MSDN states this should return non-loopback interfaces only.
1048 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
1052 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1054 ret = ERROR_INVALID_PARAMETER;
1056 DWORD numInterfaces = getNumInterfaces();
1057 ULONG size = sizeof(IP_INTERFACE_INFO) + (numInterfaces - 1) *
1058 sizeof(IP_ADAPTER_INDEX_MAP);
1060 if (!pIfTable || *dwOutBufLen < size) {
1061 *dwOutBufLen = size;
1062 ret = ERROR_INSUFFICIENT_BUFFER;
1065 InterfaceIndexTable *table = getInterfaceIndexTable();
1068 size = sizeof(IP_INTERFACE_INFO) + (table->numIndexes - 1) *
1069 sizeof(IP_ADAPTER_INDEX_MAP);
1070 if (*dwOutBufLen < size) {
1071 *dwOutBufLen = size;
1072 ret = ERROR_INSUFFICIENT_BUFFER;
1076 char nameBuf[MAX_ADAPTER_NAME];
1078 *dwOutBufLen = size;
1079 pIfTable->NumAdapters = 0;
1080 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1081 const char *walker, *name;
1084 pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1085 name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
1086 for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
1087 walker && *walker &&
1088 assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
1089 walker++, assigner++)
1090 *assigner = *walker;
1092 pIfTable->NumAdapters++;
1096 HeapFree(GetProcessHeap(), 0, table);
1099 ret = ERROR_OUTOFMEMORY;
1102 TRACE("returning %ld\n", ret);
1107 /******************************************************************
1108 * GetIpAddrTable (IPHLPAPI.@)
1110 * Get interface-to-IP address mapping table.
1113 * pIpAddrTable [Out] buffer for mapping table
1114 * pdwSize [In/Out] length of output buffer
1115 * bOrder [In] whether to sort the table
1119 * Failure: error code from winerror.h
1122 * If pdwSize is less than required, the function will return
1123 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1125 * If bOrder is true, the returned table will be sorted by the next hop and
1126 * an assortment of arbitrary parameters.
1128 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1132 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable, pdwSize,
1135 ret = ERROR_INVALID_PARAMETER;
1137 PMIB_IPADDRTABLE table;
1139 ret = getIPAddrTable(&table, GetProcessHeap(), 0);
1140 if (ret == NO_ERROR)
1142 ULONG size = sizeof(MIB_IPADDRTABLE) + (table->dwNumEntries - 1) *
1143 sizeof(MIB_IPADDRROW);
1145 if (!pIpAddrTable || *pdwSize < size) {
1147 ret = ERROR_INSUFFICIENT_BUFFER;
1151 memcpy(pIpAddrTable, table, sizeof(MIB_IPADDRTABLE) +
1152 (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW));
1154 qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1155 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1158 HeapFree(GetProcessHeap(), 0, table);
1161 TRACE("returning %ld\n", ret);
1166 /******************************************************************
1167 * GetIpForwardTable (IPHLPAPI.@)
1169 * Get the route table.
1172 * pIpForwardTable [Out] buffer for route table
1173 * pdwSize [In/Out] length of output buffer
1174 * bOrder [In] whether to sort the table
1178 * Failure: error code from winerror.h
1181 * If pdwSize is less than required, the function will return
1182 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1184 * If bOrder is true, the returned table will be sorted by the next hop and
1185 * an assortment of arbitrary parameters.
1187 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1191 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable,
1192 pdwSize, (DWORD)bOrder);
1194 ret = ERROR_INVALID_PARAMETER;
1196 DWORD numRoutes = getNumRoutes();
1197 ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) *
1198 sizeof(MIB_IPFORWARDROW);
1200 if (!pIpForwardTable || *pdwSize < sizeNeeded) {
1201 *pdwSize = sizeNeeded;
1202 ret = ERROR_INSUFFICIENT_BUFFER;
1205 PMIB_IPFORWARDTABLE table;
1207 ret = getRouteTable(&table, GetProcessHeap(), 0);
1209 sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (table->dwNumEntries - 1) *
1210 sizeof(MIB_IPFORWARDROW);
1211 if (*pdwSize < sizeNeeded) {
1212 *pdwSize = sizeNeeded;
1213 ret = ERROR_INSUFFICIENT_BUFFER;
1216 *pdwSize = sizeNeeded;
1217 memcpy(pIpForwardTable, table, sizeNeeded);
1219 qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
1220 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1223 HeapFree(GetProcessHeap(), 0, table);
1227 TRACE("returning %ld\n", ret);
1232 /******************************************************************
1233 * GetIpNetTable (IPHLPAPI.@)
1235 * Get the IP-to-physical address mapping table.
1238 * pIpNetTable [Out] buffer for mapping table
1239 * pdwSize [In/Out] length of output buffer
1240 * bOrder [In] whether to sort the table
1244 * Failure: error code from winerror.h
1247 * If pdwSize is less than required, the function will return
1248 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1250 * If bOrder is true, the returned table will be sorted by IP address.
1252 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1256 TRACE("pIpNetTable %p, pdwSize %p, bOrder %ld\n", pIpNetTable, pdwSize,
1259 ret = ERROR_INVALID_PARAMETER;
1261 DWORD numEntries = getNumArpEntries();
1262 ULONG size = sizeof(MIB_IPNETTABLE) + (numEntries - 1) *
1263 sizeof(MIB_IPNETROW);
1265 if (!pIpNetTable || *pdwSize < size) {
1267 ret = ERROR_INSUFFICIENT_BUFFER;
1270 PMIB_IPNETTABLE table;
1272 ret = getArpTable(&table, GetProcessHeap(), 0);
1274 size = sizeof(MIB_IPNETTABLE) + (table->dwNumEntries - 1) *
1275 sizeof(MIB_IPNETROW);
1276 if (*pdwSize < size) {
1278 ret = ERROR_INSUFFICIENT_BUFFER;
1282 memcpy(pIpNetTable, table, size);
1284 qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
1285 sizeof(MIB_IPNETROW), IpNetTableSorter);
1288 HeapFree(GetProcessHeap(), 0, table);
1292 TRACE("returning %ld\n", ret);
1297 /******************************************************************
1298 * GetIpStatistics (IPHLPAPI.@)
1300 * Get the IP statistics for the local computer.
1303 * pStats [Out] buffer for IP statistics
1307 * Failure: error code from winerror.h
1309 DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
1313 TRACE("pStats %p\n", pStats);
1314 ret = getIPStats(pStats);
1315 TRACE("returning %ld\n", ret);
1320 /******************************************************************
1321 * GetNetworkParams (IPHLPAPI.@)
1323 * Get the network parameters for the local computer.
1326 * pFixedInfo [Out] buffer for network parameters
1327 * pOutBufLen [In/Out] length of output buffer
1331 * Failure: error code from winerror.h
1334 * If pOutBufLen is less than required, the function will return
1335 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1338 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1344 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1346 return ERROR_INVALID_PARAMETER;
1349 size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount - 1) *
1350 sizeof(IP_ADDR_STRING) : 0);
1351 if (!pFixedInfo || *pOutBufLen < size) {
1353 return ERROR_BUFFER_OVERFLOW;
1356 memset(pFixedInfo, 0, size);
1357 size = sizeof(pFixedInfo->HostName);
1358 GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1359 size = sizeof(pFixedInfo->DomainName);
1360 GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1361 if (_res.nscount > 0) {
1362 PIP_ADDR_STRING ptr;
1365 for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1366 i++, ptr = ptr->Next) {
1367 toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
1368 ptr->IpAddress.String);
1369 if (i == _res.nscount - 1)
1372 ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
1374 ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1377 pFixedInfo->NodeType = HYBRID_NODETYPE;
1378 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1379 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1380 if (regReturn != ERROR_SUCCESS)
1381 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1382 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1384 if (regReturn == ERROR_SUCCESS)
1386 DWORD size = sizeof(pFixedInfo->ScopeId);
1388 RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1392 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1393 I suppose could also check for a listener on port 53 to set EnableDns */
1395 TRACE("returning %ld\n", ret);
1400 /******************************************************************
1401 * GetNumberOfInterfaces (IPHLPAPI.@)
1403 * Get the number of interfaces.
1406 * pdwNumIf [Out] number of interfaces
1409 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1411 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
1415 TRACE("pdwNumIf %p\n", pdwNumIf);
1417 ret = ERROR_INVALID_PARAMETER;
1419 *pdwNumIf = getNumInterfaces();
1422 TRACE("returning %ld\n", ret);
1427 /******************************************************************
1428 * GetPerAdapterInfo (IPHLPAPI.@)
1430 * Get information about an adapter corresponding to an interface.
1433 * IfIndex [In] interface info
1434 * pPerAdapterInfo [Out] buffer for per adapter info
1435 * pOutBufLen [In/Out] length of output buffer
1439 * Failure: error code from winerror.h
1442 * Stub, returns ERROR_NOT_SUPPORTED.
1444 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
1446 TRACE("(IfIndex %ld, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex,
1447 pPerAdapterInfo, pOutBufLen);
1448 return ERROR_NOT_SUPPORTED;
1452 /******************************************************************
1453 * GetRTTAndHopCount (IPHLPAPI.@)
1455 * Get round-trip time (RTT) and hop count.
1459 * DestIpAddress [In] destination address to get the info for
1460 * HopCount [Out] retrieved hop count
1461 * MaxHops [In] maximum hops to search for the destination
1462 * RTT [Out] RTT in milliseconds
1469 * Stub, returns FALSE.
1471 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
1473 FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p): stub\n",
1474 DestIpAddress, HopCount, MaxHops, RTT);
1479 /******************************************************************
1480 * GetTcpStatistics (IPHLPAPI.@)
1482 * Get the TCP statistics for the local computer.
1485 * pStats [Out] buffer for TCP statistics
1489 * Failure: error code from winerror.h
1491 DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
1495 TRACE("pStats %p\n", pStats);
1496 ret = getTCPStats(pStats);
1497 TRACE("returning %ld\n", ret);
1502 /******************************************************************
1503 * GetTcpTable (IPHLPAPI.@)
1505 * Get the table of active TCP connections.
1508 * pTcpTable [Out] buffer for TCP connections table
1509 * pdwSize [In/Out] length of output buffer
1510 * bOrder [In] whether to order the table
1514 * Failure: error code from winerror.h
1517 * If pdwSize is less than required, the function will return
1518 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1519 * the required byte size.
1520 * If bOrder is true, the returned table will be sorted, first by
1521 * local address and port number, then by remote address and port
1524 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
1528 TRACE("pTcpTable %p, pdwSize %p, bOrder %ld\n", pTcpTable, pdwSize,
1531 ret = ERROR_INVALID_PARAMETER;
1533 DWORD numEntries = getNumTcpEntries();
1534 DWORD size = sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW);
1536 if (!pTcpTable || *pdwSize < size) {
1538 ret = ERROR_INSUFFICIENT_BUFFER;
1541 PMIB_TCPTABLE table;
1543 ret = getTcpTable(&table, GetProcessHeap(), 0);
1545 size = sizeof(MIB_TCPTABLE) + (table->dwNumEntries - 1) *
1547 if (*pdwSize < size) {
1549 ret = ERROR_INSUFFICIENT_BUFFER;
1553 memcpy(pTcpTable, table, size);
1555 qsort(pTcpTable->table, pTcpTable->dwNumEntries,
1556 sizeof(MIB_TCPROW), TcpTableSorter);
1559 HeapFree(GetProcessHeap(), 0, table);
1562 ret = ERROR_OUTOFMEMORY;
1565 TRACE("returning %ld\n", ret);
1570 /******************************************************************
1571 * GetUdpStatistics (IPHLPAPI.@)
1573 * Get the UDP statistics for the local computer.
1576 * pStats [Out] buffer for UDP statistics
1580 * Failure: error code from winerror.h
1582 DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
1586 TRACE("pStats %p\n", pStats);
1587 ret = getUDPStats(pStats);
1588 TRACE("returning %ld\n", ret);
1593 /******************************************************************
1594 * GetUdpTable (IPHLPAPI.@)
1596 * Get a table of active UDP connections.
1599 * pUdpTable [Out] buffer for UDP connections table
1600 * pdwSize [In/Out] length of output buffer
1601 * bOrder [In] whether to order the table
1605 * Failure: error code from winerror.h
1608 * If pdwSize is less than required, the function will return
1609 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1610 * required byte size.
1611 * If bOrder is true, the returned table will be sorted, first by
1612 * local address, then by local port number.
1614 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
1618 TRACE("pUdpTable %p, pdwSize %p, bOrder %ld\n", pUdpTable, pdwSize,
1621 ret = ERROR_INVALID_PARAMETER;
1623 DWORD numEntries = getNumUdpEntries();
1624 DWORD size = sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW);
1626 if (!pUdpTable || *pdwSize < size) {
1628 ret = ERROR_INSUFFICIENT_BUFFER;
1631 PMIB_UDPTABLE table;
1633 ret = getUdpTable(&table, GetProcessHeap(), 0);
1635 size = sizeof(MIB_UDPTABLE) + (table->dwNumEntries - 1) *
1637 if (*pdwSize < size) {
1639 ret = ERROR_INSUFFICIENT_BUFFER;
1643 memcpy(pUdpTable, table, size);
1645 qsort(pUdpTable->table, pUdpTable->dwNumEntries,
1646 sizeof(MIB_UDPROW), UdpTableSorter);
1649 HeapFree(GetProcessHeap(), 0, table);
1652 ret = ERROR_OUTOFMEMORY;
1655 TRACE("returning %ld\n", ret);
1660 /******************************************************************
1661 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1663 * This is a Win98-only function to get information on "unidirectional"
1664 * adapters. Since this is pretty nonsensical in other contexts, it
1665 * never returns anything.
1668 * pIPIfInfo [Out] buffer for adapter infos
1669 * dwOutBufLen [Out] length of the output buffer
1673 * Failure: error code from winerror.h
1676 * Stub, returns ERROR_NOT_SUPPORTED.
1678 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
1680 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1681 /* a unidirectional adapter?? not bloody likely! */
1682 return ERROR_NOT_SUPPORTED;
1686 /******************************************************************
1687 * IpReleaseAddress (IPHLPAPI.@)
1689 * Release an IP optained through DHCP,
1692 * AdapterInfo [In] adapter to release IP address
1696 * Failure: error code from winerror.h
1699 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1700 * this function does nothing.
1703 * Stub, returns ERROR_NOT_SUPPORTED.
1705 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1707 TRACE("AdapterInfo %p\n", AdapterInfo);
1708 /* not a stub, never going to support this (and I never mark an adapter as
1709 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1710 return ERROR_NOT_SUPPORTED;
1714 /******************************************************************
1715 * IpRenewAddress (IPHLPAPI.@)
1717 * Renew an IP optained through DHCP.
1720 * AdapterInfo [In] adapter to renew IP address
1724 * Failure: error code from winerror.h
1727 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1728 * this function does nothing.
1731 * Stub, returns ERROR_NOT_SUPPORTED.
1733 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1735 TRACE("AdapterInfo %p\n", AdapterInfo);
1736 /* not a stub, never going to support this (and I never mark an adapter as
1737 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1738 return ERROR_NOT_SUPPORTED;
1742 /******************************************************************
1743 * NotifyAddrChange (IPHLPAPI.@)
1745 * Notify caller whenever the ip-interface map is changed.
1748 * Handle [Out] handle useable in asynchronus notification
1749 * overlapped [In] overlapped structure that notifies the caller
1753 * Failure: error code from winerror.h
1756 * Stub, returns ERROR_NOT_SUPPORTED.
1758 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1760 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1761 return ERROR_NOT_SUPPORTED;
1765 /******************************************************************
1766 * NotifyRouteChange (IPHLPAPI.@)
1768 * Notify caller whenever the ip routing table is changed.
1771 * Handle [Out] handle useable in asynchronus notification
1772 * overlapped [In] overlapped structure that notifies the caller
1776 * Failure: error code from winerror.h
1779 * Stub, returns ERROR_NOT_SUPPORTED.
1781 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1783 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1784 return ERROR_NOT_SUPPORTED;
1788 /******************************************************************
1789 * SendARP (IPHLPAPI.@)
1791 * Send an ARP request.
1794 * DestIP [In] attempt to obtain this IP
1795 * SrcIP [In] optional sender IP address
1796 * pMacAddr [Out] buffer for the mac address
1797 * PhyAddrLen [In/Out] length of the output buffer
1801 * Failure: error code from winerror.h
1804 * Stub, returns ERROR_NOT_SUPPORTED.
1806 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
1808 FIXME("(DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p): stub\n",
1809 DestIP, SrcIP, pMacAddr, PhyAddrLen);
1810 return ERROR_NOT_SUPPORTED;
1814 /******************************************************************
1815 * SetIfEntry (IPHLPAPI.@)
1817 * Set the administrative status of an interface.
1820 * pIfRow [In] dwAdminStatus member specifies the new status.
1824 * Failure: error code from winerror.h
1827 * Stub, returns ERROR_NOT_SUPPORTED.
1829 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
1831 FIXME("(pIfRow %p): stub\n", pIfRow);
1832 /* this is supposed to set an interface administratively up or down.
1833 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1834 this sort of down is indistinguishable from other sorts of down (e.g. no
1836 return ERROR_NOT_SUPPORTED;
1840 /******************************************************************
1841 * SetIpForwardEntry (IPHLPAPI.@)
1843 * Modify an existing route.
1846 * pRoute [In] route with the new information
1850 * Failure: error code from winerror.h
1853 * Stub, returns NO_ERROR.
1855 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
1857 FIXME("(pRoute %p): stub\n", pRoute);
1858 /* this is to add a route entry, how's it distinguishable from
1859 CreateIpForwardEntry?
1860 could use SIOCADDRT, not sure I want to */
1865 /******************************************************************
1866 * SetIpNetEntry (IPHLPAPI.@)
1868 * Modify an existing ARP entry.
1871 * pArpEntry [In] ARP entry with the new information
1875 * Failure: error code from winerror.h
1878 * Stub, returns NO_ERROR.
1880 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
1882 FIXME("(pArpEntry %p): stub\n", pArpEntry);
1883 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1888 /******************************************************************
1889 * SetIpStatistics (IPHLPAPI.@)
1891 * Toggle IP forwarding and det the default TTL value.
1894 * pIpStats [In] IP statistics with the new information
1898 * Failure: error code from winerror.h
1901 * Stub, returns NO_ERROR.
1903 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
1905 FIXME("(pIpStats %p): stub\n", pIpStats);
1910 /******************************************************************
1911 * SetIpTTL (IPHLPAPI.@)
1913 * Set the default TTL value.
1916 * nTTL [In] new TTL value
1920 * Failure: error code from winerror.h
1923 * Stub, returns NO_ERROR.
1925 DWORD WINAPI SetIpTTL(UINT nTTL)
1927 FIXME("(nTTL %d): stub\n", nTTL);
1928 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1929 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1934 /******************************************************************
1935 * SetTcpEntry (IPHLPAPI.@)
1937 * Set the state of a TCP connection.
1940 * pTcpRow [In] specifies connection with new state
1944 * Failure: error code from winerror.h
1947 * Stub, returns NO_ERROR.
1949 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
1951 FIXME("(pTcpRow %p): stub\n", pTcpRow);
1956 /******************************************************************
1957 * UnenableRouter (IPHLPAPI.@)
1959 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
1960 * if it reaches zero.
1963 * pOverlapped [In/Out] should be the same as in EnableRouter()
1964 * lpdwEnableCount [Out] optional, receives reference count
1968 * Failure: error code from winerror.h
1971 * Stub, returns ERROR_NOT_SUPPORTED.
1973 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
1975 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
1977 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
1978 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
1980 return ERROR_NOT_SUPPORTED;