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>
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
53 #define INADDR_NONE ~0UL
56 static int resolver_initialised;
58 /* call res_init() just once because of a bug in Mac OS X 10.4 */
59 static void initialise_resolver(void)
61 if (!resolver_initialised)
64 resolver_initialised = 1;
68 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
71 case DLL_PROCESS_ATTACH:
72 DisableThreadLibraryCalls( hinstDLL );
75 case DLL_PROCESS_DETACH:
81 /******************************************************************
82 * AddIPAddress (IPHLPAPI.@)
84 * Add an IP address to an adapter.
87 * Address [In] IP address to add to the adapter
88 * IpMask [In] subnet mask for the IP address
89 * IfIndex [In] adapter index to add the address
90 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
91 * NTEInstance [Out] NTE instance for the IP address
95 * Failure: error code from winerror.h
98 * Stub. Currently returns ERROR_NOT_SUPPORTED.
100 DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
103 return ERROR_NOT_SUPPORTED;
107 /******************************************************************
108 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
110 * Get table of local interfaces.
111 * Like GetIfTable(), but allocate the returned table from heap.
114 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
115 * allocated and returned.
116 * bOrder [In] whether to sort the table
117 * heap [In] heap from which the table is allocated
118 * flags [In] flags to HeapAlloc
121 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
122 * GetIfTable() returns otherwise.
124 DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
125 BOOL bOrder, HANDLE heap, DWORD flags)
129 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable,
130 bOrder, heap, flags);
132 ret = ERROR_INVALID_PARAMETER;
136 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
137 if (ret == ERROR_INSUFFICIENT_BUFFER) {
138 *ppIfTable = HeapAlloc(heap, flags, dwSize);
139 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
142 TRACE("returning %d\n", ret);
147 static int IpAddrTableSorter(const void *a, const void *b)
152 ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
159 /******************************************************************
160 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
162 * Get interface-to-IP address mapping table.
163 * Like GetIpAddrTable(), but allocate the returned table from heap.
166 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
167 * allocated and returned.
168 * bOrder [In] whether to sort the table
169 * heap [In] heap from which the table is allocated
170 * flags [In] flags to HeapAlloc
173 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
174 * failure, NO_ERROR on success.
176 DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
177 BOOL bOrder, HANDLE heap, DWORD flags)
181 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
182 ppIpAddrTable, bOrder, heap, flags);
183 ret = getIPAddrTable(ppIpAddrTable, heap, flags);
185 qsort((*ppIpAddrTable)->table, (*ppIpAddrTable)->dwNumEntries,
186 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
187 TRACE("returning %d\n", ret);
192 static int IpForwardTableSorter(const void *a, const void *b)
197 const MIB_IPFORWARDROW* rowA = (const MIB_IPFORWARDROW*)a;
198 const MIB_IPFORWARDROW* rowB = (const MIB_IPFORWARDROW*)b;
200 ret = rowA->dwForwardDest - rowB->dwForwardDest;
202 ret = rowA->dwForwardProto - rowB->dwForwardProto;
204 ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy;
206 ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop;
216 /******************************************************************
217 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
219 * Get the route table.
220 * Like GetIpForwardTable(), but allocate the returned table from heap.
223 * ppIpForwardTable [Out] pointer into which the MIB_IPFORWARDTABLE is
224 * allocated and returned.
225 * bOrder [In] whether to sort the table
226 * heap [In] heap from which the table is allocated
227 * flags [In] flags to HeapAlloc
230 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, other error codes
231 * on failure, NO_ERROR on success.
233 DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
234 ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags)
238 TRACE("ppIpForwardTable %p, bOrder %d, heap %p, flags 0x%08x\n",
239 ppIpForwardTable, bOrder, heap, flags);
240 ret = getRouteTable(ppIpForwardTable, heap, flags);
242 qsort((*ppIpForwardTable)->table, (*ppIpForwardTable)->dwNumEntries,
243 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
244 TRACE("returning %d\n", ret);
249 static int IpNetTableSorter(const void *a, const void *b)
254 ret = ((const MIB_IPNETROW*)a)->dwAddr - ((const MIB_IPNETROW*)b)->dwAddr;
261 /******************************************************************
262 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
264 * Get the IP-to-physical address mapping table.
265 * Like GetIpNetTable(), but allocate the returned table from heap.
268 * ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE is
269 * allocated and returned.
270 * bOrder [In] whether to sort the table
271 * heap [In] heap from which the table is allocated
272 * flags [In] flags to HeapAlloc
275 * ERROR_INVALID_PARAMETER if ppIpNetTable is NULL, other error codes
276 * on failure, NO_ERROR on success.
278 DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable,
279 BOOL bOrder, HANDLE heap, DWORD flags)
283 TRACE("ppIpNetTable %p, bOrder %d, heap %p, flags 0x%08x\n",
284 ppIpNetTable, bOrder, heap, flags);
285 ret = getArpTable(ppIpNetTable, heap, flags);
287 qsort((*ppIpNetTable)->table, (*ppIpNetTable)->dwNumEntries,
288 sizeof(MIB_IPADDRROW), IpNetTableSorter);
289 TRACE("returning %d\n", ret);
294 static int TcpTableSorter(const void *a, const void *b)
299 const MIB_TCPROW* rowA = a;
300 const MIB_TCPROW* rowB = b;
302 ret = ntohl (rowA->dwLocalAddr) - ntohl (rowB->dwLocalAddr);
304 ret = ntohs ((unsigned short)rowA->dwLocalPort) -
305 ntohs ((unsigned short)rowB->dwLocalPort);
307 ret = ntohl (rowA->dwRemoteAddr) - ntohl (rowB->dwRemoteAddr);
309 ret = ntohs ((unsigned short)rowA->dwRemotePort) -
310 ntohs ((unsigned short)rowB->dwRemotePort);
320 /******************************************************************
321 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
323 * Get the TCP connection table.
324 * Like GetTcpTable(), but allocate the returned table from heap.
327 * ppTcpTable [Out] pointer into which the MIB_TCPTABLE is
328 * allocated and returned.
329 * bOrder [In] whether to sort the table
330 * heap [In] heap from which the table is allocated
331 * flags [In] flags to HeapAlloc
334 * ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable()
337 DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
338 BOOL bOrder, HANDLE heap, DWORD flags)
342 TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
343 ppTcpTable, bOrder, heap, flags);
346 ret = getTcpTable(ppTcpTable, 0, heap, flags);
348 qsort((*ppTcpTable)->table, (*ppTcpTable)->dwNumEntries,
349 sizeof(MIB_TCPROW), TcpTableSorter);
350 TRACE("returning %d\n", ret);
355 static int UdpTableSorter(const void *a, const void *b)
360 const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
361 const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;
363 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
365 ret = rowA->dwLocalPort - rowB->dwLocalPort;
373 /******************************************************************
374 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
376 * Get the UDP listener table.
377 * Like GetUdpTable(), but allocate the returned table from heap.
380 * ppUdpTable [Out] pointer into which the MIB_UDPTABLE is
381 * allocated and returned.
382 * bOrder [In] whether to sort the table
383 * heap [In] heap from which the table is allocated
384 * flags [In] flags to HeapAlloc
387 * ERROR_INVALID_PARAMETER if ppUdpTable is NULL, whatever GetUdpTable()
390 DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
391 BOOL bOrder, HANDLE heap, DWORD flags)
395 TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
396 ppUdpTable, bOrder, heap, flags);
397 ret = getUdpTable(ppUdpTable, heap, flags);
399 qsort((*ppUdpTable)->table, (*ppUdpTable)->dwNumEntries,
400 sizeof(MIB_UDPROW), UdpTableSorter);
401 TRACE("returning %d\n", ret);
406 /******************************************************************
407 * CreateIpForwardEntry (IPHLPAPI.@)
409 * Create a route in the local computer's IP table.
412 * pRoute [In] new route information
416 * Failure: error code from winerror.h
419 * Stub, always returns NO_ERROR.
421 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
423 FIXME("(pRoute %p): stub\n", pRoute);
424 /* could use SIOCADDRT, not sure I want to */
429 /******************************************************************
430 * CreateIpNetEntry (IPHLPAPI.@)
432 * Create entry in the ARP table.
435 * pArpEntry [In] new ARP entry
439 * Failure: error code from winerror.h
442 * Stub, always returns NO_ERROR.
444 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
446 FIXME("(pArpEntry %p)\n", pArpEntry);
447 /* could use SIOCSARP on systems that support it, not sure I want to */
452 /******************************************************************
453 * CreateProxyArpEntry (IPHLPAPI.@)
455 * Create a Proxy ARP (PARP) entry for an IP address.
458 * dwAddress [In] IP address for which this computer acts as a proxy.
459 * dwMask [In] subnet mask for dwAddress
460 * dwIfIndex [In] interface index
464 * Failure: error code from winerror.h
467 * Stub, returns ERROR_NOT_SUPPORTED.
469 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
471 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
472 dwAddress, dwMask, dwIfIndex);
473 return ERROR_NOT_SUPPORTED;
477 /******************************************************************
478 * DeleteIPAddress (IPHLPAPI.@)
480 * Delete an IP address added with AddIPAddress().
483 * NTEContext [In] NTE context from AddIPAddress();
487 * Failure: error code from winerror.h
490 * Stub, returns ERROR_NOT_SUPPORTED.
492 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
494 FIXME("(NTEContext %d): stub\n", NTEContext);
495 return ERROR_NOT_SUPPORTED;
499 /******************************************************************
500 * DeleteIpForwardEntry (IPHLPAPI.@)
505 * pRoute [In] route to delete
509 * Failure: error code from winerror.h
512 * Stub, returns NO_ERROR.
514 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
516 FIXME("(pRoute %p): stub\n", pRoute);
517 /* could use SIOCDELRT, not sure I want to */
522 /******************************************************************
523 * DeleteIpNetEntry (IPHLPAPI.@)
525 * Delete an ARP entry.
528 * pArpEntry [In] ARP entry to delete
532 * Failure: error code from winerror.h
535 * Stub, returns NO_ERROR.
537 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
539 FIXME("(pArpEntry %p): stub\n", pArpEntry);
540 /* could use SIOCDARP on systems that support it, not sure I want to */
545 /******************************************************************
546 * DeleteProxyArpEntry (IPHLPAPI.@)
548 * Delete a Proxy ARP entry.
551 * dwAddress [In] IP address for which this computer acts as a proxy.
552 * dwMask [In] subnet mask for dwAddress
553 * dwIfIndex [In] interface index
557 * Failure: error code from winerror.h
560 * Stub, returns ERROR_NOT_SUPPORTED.
562 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
564 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
565 dwAddress, dwMask, dwIfIndex);
566 return ERROR_NOT_SUPPORTED;
570 /******************************************************************
571 * EnableRouter (IPHLPAPI.@)
573 * Turn on ip forwarding.
577 * pOverlapped [In/Out] hEvent member should contain a valid handle.
580 * Success: ERROR_IO_PENDING
581 * Failure: error code from winerror.h
584 * Stub, returns ERROR_NOT_SUPPORTED.
586 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
588 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle, pOverlapped);
589 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
590 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
592 return ERROR_NOT_SUPPORTED;
596 /******************************************************************
597 * FlushIpNetTable (IPHLPAPI.@)
599 * Delete all ARP entries of an interface
602 * dwIfIndex [In] interface index
606 * Failure: error code from winerror.h
609 * Stub, returns ERROR_NOT_SUPPORTED.
611 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
613 FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex);
614 /* this flushes the arp cache of the given index */
615 return ERROR_NOT_SUPPORTED;
619 /******************************************************************
620 * GetAdapterIndex (IPHLPAPI.@)
622 * Get interface index from its name.
625 * AdapterName [In] unicode string with the adapter name
626 * IfIndex [Out] returns found interface index
630 * Failure: error code from winerror.h
632 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
634 char adapterName[MAX_ADAPTER_NAME];
638 TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName, IfIndex);
639 /* The adapter name is guaranteed not to have any unicode characters, so
640 * this translation is never lossy */
641 for (i = 0; i < sizeof(adapterName) - 1 && AdapterName[i]; i++)
642 adapterName[i] = (char)AdapterName[i];
643 adapterName[i] = '\0';
644 ret = getInterfaceIndexByName(adapterName, IfIndex);
645 TRACE("returning %d\n", ret);
650 /******************************************************************
651 * GetAdaptersInfo (IPHLPAPI.@)
653 * Get information about adapters.
656 * pAdapterInfo [Out] buffer for adapter infos
657 * pOutBufLen [In] length of output buffer
661 * Failure: error code from winerror.h
663 DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
667 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
669 ret = ERROR_INVALID_PARAMETER;
671 DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
673 if (numNonLoopbackInterfaces > 0) {
674 DWORD numIPAddresses = getNumIPAddresses();
677 /* This may slightly overestimate the amount of space needed, because
678 * the IP addresses include the loopback address, but it's easier
679 * to make sure there's more than enough space than to make sure there's
680 * precisely enough space.
682 size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
683 size += numIPAddresses * sizeof(IP_ADDR_STRING);
684 if (!pAdapterInfo || *pOutBufLen < size) {
686 ret = ERROR_BUFFER_OVERFLOW;
689 InterfaceIndexTable *table = NULL;
690 PMIB_IPADDRTABLE ipAddrTable = NULL;
691 PMIB_IPFORWARDTABLE routeTable = NULL;
693 ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
695 ret = getRouteTable(&routeTable, GetProcessHeap(), 0);
697 table = getNonLoopbackInterfaceIndexTable();
699 size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
700 size += ipAddrTable->dwNumEntries * sizeof(IP_ADDR_STRING);
701 if (*pOutBufLen < size) {
703 ret = ERROR_INSUFFICIENT_BUFFER;
708 BOOL winsEnabled = FALSE;
709 IP_ADDRESS_STRING primaryWINS, secondaryWINS;
710 PIP_ADDR_STRING nextIPAddr = (PIP_ADDR_STRING)((LPBYTE)pAdapterInfo
711 + numNonLoopbackInterfaces * sizeof(IP_ADAPTER_INFO));
713 memset(pAdapterInfo, 0, size);
714 /* @@ Wine registry key: HKCU\Software\Wine\Network */
715 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network",
716 &hKey) == ERROR_SUCCESS) {
717 DWORD size = sizeof(primaryWINS.String);
720 RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
721 (LPBYTE)primaryWINS.String, &size);
722 addr = inet_addr(primaryWINS.String);
723 if (addr != INADDR_NONE && addr != INADDR_ANY)
725 size = sizeof(secondaryWINS.String);
726 RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
727 (LPBYTE)secondaryWINS.String, &size);
728 addr = inet_addr(secondaryWINS.String);
729 if (addr != INADDR_NONE && addr != INADDR_ANY)
733 for (ndx = 0; ndx < table->numIndexes; ndx++) {
734 PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
736 PIP_ADDR_STRING currentIPAddr = &ptr->IpAddressList;
737 BOOL firstIPAddr = TRUE;
739 /* on Win98 this is left empty, but whatever */
740 getInterfaceNameByIndex(table->indexes[ndx], ptr->AdapterName);
741 getInterfaceNameByIndex(table->indexes[ndx], ptr->Description);
742 ptr->AddressLength = sizeof(ptr->Address);
743 getInterfacePhysicalByIndex(table->indexes[ndx],
744 &ptr->AddressLength, ptr->Address, &ptr->Type);
745 ptr->Index = table->indexes[ndx];
746 for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
747 if (ipAddrTable->table[i].dwIndex == ptr->Index) {
749 toIPAddressString(ipAddrTable->table[i].dwAddr,
750 ptr->IpAddressList.IpAddress.String);
751 toIPAddressString(ipAddrTable->table[i].dwMask,
752 ptr->IpAddressList.IpMask.String);
756 currentIPAddr->Next = nextIPAddr;
757 currentIPAddr = nextIPAddr;
758 toIPAddressString(ipAddrTable->table[i].dwAddr,
759 currentIPAddr->IpAddress.String);
760 toIPAddressString(ipAddrTable->table[i].dwMask,
761 currentIPAddr->IpMask.String);
766 /* Find first router through this interface, which we'll assume
767 * is the default gateway for this adapter */
768 for (i = 0; i < routeTable->dwNumEntries; i++)
769 if (routeTable->table[i].dwForwardIfIndex == ptr->Index
770 && routeTable->table[i].dwForwardType ==
771 MIB_IPROUTE_TYPE_INDIRECT)
772 toIPAddressString(routeTable->table[i].dwForwardNextHop,
773 ptr->GatewayList.IpAddress.String);
775 ptr->HaveWins = TRUE;
776 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
777 primaryWINS.String, sizeof(primaryWINS.String));
778 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
779 secondaryWINS.String, sizeof(secondaryWINS.String));
781 if (ndx < table->numIndexes - 1)
782 ptr->Next = &pAdapterInfo[ndx + 1];
788 HeapFree(GetProcessHeap(), 0, table);
791 ret = ERROR_OUTOFMEMORY;
792 HeapFree(GetProcessHeap(), 0, routeTable);
793 HeapFree(GetProcessHeap(), 0, ipAddrTable);
799 TRACE("returning %d\n", ret);
804 /******************************************************************
805 * GetBestInterface (IPHLPAPI.@)
807 * Get the interface, with the best route for the given IP address.
810 * dwDestAddr [In] IP address to search the interface for
811 * pdwBestIfIndex [Out] found best interface
815 * Failure: error code from winerror.h
817 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
819 struct WS_sockaddr_in sa_in;
820 memset(&sa_in, 0, sizeof(sa_in));
821 sa_in.sin_family = AF_INET;
822 sa_in.sin_addr.S_un.S_addr = dwDestAddr;
823 return GetBestInterfaceEx((struct WS_sockaddr *)&sa_in, pdwBestIfIndex);
826 /******************************************************************
827 * GetBestInterfaceEx (IPHLPAPI.@)
829 * Get the interface, with the best route for the given IP address.
832 * dwDestAddr [In] IP address to search the interface for
833 * pdwBestIfIndex [Out] found best interface
837 * Failure: error code from winerror.h
839 DWORD WINAPI GetBestInterfaceEx(struct WS_sockaddr *pDestAddr, PDWORD pdwBestIfIndex)
843 TRACE("pDestAddr %p, pdwBestIfIndex %p\n", pDestAddr, pdwBestIfIndex);
844 if (!pDestAddr || !pdwBestIfIndex)
845 ret = ERROR_INVALID_PARAMETER;
847 MIB_IPFORWARDROW ipRow;
849 if (pDestAddr->sa_family == AF_INET) {
850 ret = GetBestRoute(((struct WS_sockaddr_in *)pDestAddr)->sin_addr.S_un.S_addr, 0, &ipRow);
851 if (ret == ERROR_SUCCESS)
852 *pdwBestIfIndex = ipRow.dwForwardIfIndex;
854 FIXME("address family %d not supported\n", pDestAddr->sa_family);
855 ret = ERROR_NOT_SUPPORTED;
858 TRACE("returning %d\n", ret);
863 /******************************************************************
864 * GetBestRoute (IPHLPAPI.@)
866 * Get the best route for the given IP address.
869 * dwDestAddr [In] IP address to search the best route for
870 * dwSourceAddr [In] optional source IP address
871 * pBestRoute [Out] found best route
875 * Failure: error code from winerror.h
877 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
879 PMIB_IPFORWARDTABLE table;
882 TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr,
883 dwSourceAddr, pBestRoute);
885 return ERROR_INVALID_PARAMETER;
887 ret = AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
889 DWORD ndx, matchedBits, matchedNdx = table->dwNumEntries;
891 for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
892 if (table->table[ndx].dwForwardType != MIB_IPROUTE_TYPE_INVALID &&
893 (dwDestAddr & table->table[ndx].dwForwardMask) ==
894 (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
895 DWORD numShifts, mask;
897 for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
898 mask && !(mask & 1); mask >>= 1, numShifts++)
900 if (numShifts > matchedBits) {
901 matchedBits = numShifts;
904 else if (!matchedBits && table->table[ndx].dwForwardType ==
905 MIB_IPROUTE_TYPE_INDIRECT) {
906 /* default to a default gateway */
911 if (matchedNdx < table->dwNumEntries) {
912 memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
916 /* No route matches, which can happen if there's no default route. */
917 ret = ERROR_HOST_UNREACHABLE;
919 HeapFree(GetProcessHeap(), 0, table);
921 TRACE("returning %d\n", ret);
926 /******************************************************************
927 * GetFriendlyIfIndex (IPHLPAPI.@)
929 * Get a "friendly" version of IfIndex, which is one that doesn't
930 * have the top byte set. Doesn't validate whether IfIndex is a valid
934 * IfIndex [In] interface index to get the friendly one for
937 * A friendly version of IfIndex.
939 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
941 /* windows doesn't validate these, either, just makes sure the top byte is
942 cleared. I assume my ifenum module never gives an index with the top
944 TRACE("returning %d\n", IfIndex);
949 /******************************************************************
950 * GetIcmpStatistics (IPHLPAPI.@)
952 * Get the ICMP statistics for the local computer.
955 * pStats [Out] buffer for ICMP statistics
959 * Failure: error code from winerror.h
961 DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
965 TRACE("pStats %p\n", pStats);
966 ret = getICMPStats(pStats);
967 TRACE("returning %d\n", ret);
972 /******************************************************************
973 * GetIfEntry (IPHLPAPI.@)
975 * Get information about an interface.
978 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
979 * Out: interface information
983 * Failure: error code from winerror.h
985 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
988 char nameBuf[MAX_ADAPTER_NAME];
991 TRACE("pIfRow %p\n", pIfRow);
993 return ERROR_INVALID_PARAMETER;
995 name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf);
997 ret = getInterfaceEntryByName(name, pIfRow);
999 ret = getInterfaceStatsByName(name, pIfRow);
1002 ret = ERROR_INVALID_DATA;
1003 TRACE("returning %d\n", ret);
1008 static int IfTableSorter(const void *a, const void *b)
1013 ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
1020 /******************************************************************
1021 * GetIfTable (IPHLPAPI.@)
1023 * Get a table of local interfaces.
1026 * pIfTable [Out] buffer for local interfaces table
1027 * pdwSize [In/Out] length of output buffer
1028 * bOrder [In] whether to sort the table
1032 * Failure: error code from winerror.h
1035 * If pdwSize is less than required, the function will return
1036 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1038 * If bOrder is true, the returned table will be sorted by interface index.
1040 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
1044 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize, pdwSize,
1047 ret = ERROR_INVALID_PARAMETER;
1049 DWORD numInterfaces = getNumInterfaces();
1050 ULONG size = sizeof(MIB_IFTABLE);
1052 if (numInterfaces > 1)
1053 size += (numInterfaces - 1) * sizeof(MIB_IFROW);
1054 if (!pIfTable || *pdwSize < size) {
1056 ret = ERROR_INSUFFICIENT_BUFFER;
1059 InterfaceIndexTable *table = getInterfaceIndexTable();
1062 size = sizeof(MIB_IFTABLE);
1063 if (table->numIndexes > 1)
1064 size += (table->numIndexes - 1) * sizeof(MIB_IFROW);
1065 if (*pdwSize < size) {
1067 ret = ERROR_INSUFFICIENT_BUFFER;
1073 pIfTable->dwNumEntries = 0;
1074 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1075 pIfTable->table[ndx].dwIndex = table->indexes[ndx];
1076 GetIfEntry(&pIfTable->table[ndx]);
1077 pIfTable->dwNumEntries++;
1080 qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
1084 HeapFree(GetProcessHeap(), 0, table);
1087 ret = ERROR_OUTOFMEMORY;
1090 TRACE("returning %d\n", ret);
1095 /******************************************************************
1096 * GetInterfaceInfo (IPHLPAPI.@)
1098 * Get a list of network interface adapters.
1101 * pIfTable [Out] buffer for interface adapters
1102 * dwOutBufLen [Out] if buffer is too small, returns required size
1106 * Failure: error code from winerror.h
1109 * MSDN states this should return non-loopback interfaces only.
1111 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
1115 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1117 ret = ERROR_INVALID_PARAMETER;
1119 DWORD numInterfaces = getNumInterfaces();
1120 ULONG size = sizeof(IP_INTERFACE_INFO);
1122 if (numInterfaces > 1)
1123 size += (numInterfaces - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
1124 if (!pIfTable || *dwOutBufLen < size) {
1125 *dwOutBufLen = size;
1126 ret = ERROR_INSUFFICIENT_BUFFER;
1129 InterfaceIndexTable *table = getInterfaceIndexTable();
1132 size = sizeof(IP_INTERFACE_INFO);
1133 if (table->numIndexes > 1)
1134 size += (table->numIndexes - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
1135 if (*dwOutBufLen < size) {
1136 *dwOutBufLen = size;
1137 ret = ERROR_INSUFFICIENT_BUFFER;
1141 char nameBuf[MAX_ADAPTER_NAME];
1143 *dwOutBufLen = size;
1144 pIfTable->NumAdapters = 0;
1145 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1146 const char *walker, *name;
1149 pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1150 name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
1151 for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
1152 walker && *walker &&
1153 assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
1154 walker++, assigner++)
1155 *assigner = *walker;
1157 pIfTable->NumAdapters++;
1161 HeapFree(GetProcessHeap(), 0, table);
1164 ret = ERROR_OUTOFMEMORY;
1167 TRACE("returning %d\n", ret);
1172 /******************************************************************
1173 * GetIpAddrTable (IPHLPAPI.@)
1175 * Get interface-to-IP address mapping table.
1178 * pIpAddrTable [Out] buffer for mapping table
1179 * pdwSize [In/Out] length of output buffer
1180 * bOrder [In] whether to sort the table
1184 * Failure: error code from winerror.h
1187 * If pdwSize is less than required, the function will return
1188 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1190 * If bOrder is true, the returned table will be sorted by the next hop and
1191 * an assortment of arbitrary parameters.
1193 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1197 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable, pdwSize,
1200 ret = ERROR_INVALID_PARAMETER;
1202 PMIB_IPADDRTABLE table;
1204 ret = getIPAddrTable(&table, GetProcessHeap(), 0);
1205 if (ret == NO_ERROR)
1207 ULONG size = sizeof(MIB_IPADDRTABLE);
1209 if (table->dwNumEntries > 1)
1210 size += (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW);
1211 if (!pIpAddrTable || *pdwSize < size) {
1213 ret = ERROR_INSUFFICIENT_BUFFER;
1217 memcpy(pIpAddrTable, table, size);
1219 qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1220 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1223 HeapFree(GetProcessHeap(), 0, table);
1226 TRACE("returning %d\n", ret);
1231 /******************************************************************
1232 * GetIpForwardTable (IPHLPAPI.@)
1234 * Get the route table.
1237 * pIpForwardTable [Out] buffer for route table
1238 * pdwSize [In/Out] length of output buffer
1239 * bOrder [In] whether to sort the table
1243 * Failure: error code from winerror.h
1246 * If pdwSize is less than required, the function will return
1247 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1249 * If bOrder is true, the returned table will be sorted by the next hop and
1250 * an assortment of arbitrary parameters.
1252 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1256 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable,
1257 pdwSize, (DWORD)bOrder);
1259 ret = ERROR_INVALID_PARAMETER;
1261 DWORD numRoutes = getNumRoutes();
1262 ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE);
1265 sizeNeeded += (numRoutes - 1) * sizeof(MIB_IPFORWARDROW);
1266 if (!pIpForwardTable || *pdwSize < sizeNeeded) {
1267 *pdwSize = sizeNeeded;
1268 ret = ERROR_INSUFFICIENT_BUFFER;
1271 PMIB_IPFORWARDTABLE table;
1273 ret = getRouteTable(&table, GetProcessHeap(), 0);
1275 sizeNeeded = sizeof(MIB_IPFORWARDTABLE);
1276 if (table->dwNumEntries > 1)
1277 sizeNeeded += (table->dwNumEntries - 1) * sizeof(MIB_IPFORWARDROW);
1278 if (*pdwSize < sizeNeeded) {
1279 *pdwSize = sizeNeeded;
1280 ret = ERROR_INSUFFICIENT_BUFFER;
1283 *pdwSize = sizeNeeded;
1284 memcpy(pIpForwardTable, table, sizeNeeded);
1286 qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
1287 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1290 HeapFree(GetProcessHeap(), 0, table);
1294 TRACE("returning %d\n", ret);
1299 /******************************************************************
1300 * GetIpNetTable (IPHLPAPI.@)
1302 * Get the IP-to-physical address mapping table.
1305 * pIpNetTable [Out] buffer for mapping table
1306 * pdwSize [In/Out] length of output buffer
1307 * bOrder [In] whether to sort the table
1311 * Failure: error code from winerror.h
1314 * If pdwSize is less than required, the function will return
1315 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1317 * If bOrder is true, the returned table will be sorted by IP address.
1319 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1323 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable, pdwSize,
1326 ret = ERROR_INVALID_PARAMETER;
1328 DWORD numEntries = getNumArpEntries();
1329 ULONG size = sizeof(MIB_IPNETTABLE);
1332 size += (numEntries - 1) * sizeof(MIB_IPNETROW);
1333 if (!pIpNetTable || *pdwSize < size) {
1335 ret = ERROR_INSUFFICIENT_BUFFER;
1338 PMIB_IPNETTABLE table;
1340 ret = getArpTable(&table, GetProcessHeap(), 0);
1342 size = sizeof(MIB_IPNETTABLE);
1343 if (table->dwNumEntries > 1)
1344 size += (table->dwNumEntries - 1) * sizeof(MIB_IPNETROW);
1345 if (*pdwSize < size) {
1347 ret = ERROR_INSUFFICIENT_BUFFER;
1351 memcpy(pIpNetTable, table, size);
1353 qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
1354 sizeof(MIB_IPNETROW), IpNetTableSorter);
1357 HeapFree(GetProcessHeap(), 0, table);
1361 TRACE("returning %d\n", ret);
1366 /******************************************************************
1367 * GetIpStatistics (IPHLPAPI.@)
1369 * Get the IP statistics for the local computer.
1372 * pStats [Out] buffer for IP statistics
1376 * Failure: error code from winerror.h
1378 DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
1382 TRACE("pStats %p\n", pStats);
1383 ret = getIPStats(pStats);
1384 TRACE("returning %d\n", ret);
1389 /******************************************************************
1390 * GetNetworkParams (IPHLPAPI.@)
1392 * Get the network parameters for the local computer.
1395 * pFixedInfo [Out] buffer for network parameters
1396 * pOutBufLen [In/Out] length of output buffer
1400 * Failure: error code from winerror.h
1403 * If pOutBufLen is less than required, the function will return
1404 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1407 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1413 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1415 return ERROR_INVALID_PARAMETER;
1417 initialise_resolver();
1418 size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount - 1) *
1419 sizeof(IP_ADDR_STRING) : 0);
1420 if (!pFixedInfo || *pOutBufLen < size) {
1422 return ERROR_BUFFER_OVERFLOW;
1425 memset(pFixedInfo, 0, size);
1426 size = sizeof(pFixedInfo->HostName);
1427 GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1428 size = sizeof(pFixedInfo->DomainName);
1429 GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1430 if (_res.nscount > 0) {
1431 PIP_ADDR_STRING ptr;
1434 for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1435 i++, ptr = ptr->Next) {
1436 toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
1437 ptr->IpAddress.String);
1438 if (i == _res.nscount - 1)
1441 ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
1443 ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1446 pFixedInfo->NodeType = HYBRID_NODETYPE;
1447 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1448 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1449 if (regReturn != ERROR_SUCCESS)
1450 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1451 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1453 if (regReturn == ERROR_SUCCESS)
1455 DWORD size = sizeof(pFixedInfo->ScopeId);
1457 RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1461 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1462 I suppose could also check for a listener on port 53 to set EnableDns */
1464 TRACE("returning %d\n", ret);
1469 /******************************************************************
1470 * GetNumberOfInterfaces (IPHLPAPI.@)
1472 * Get the number of interfaces.
1475 * pdwNumIf [Out] number of interfaces
1478 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1480 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
1484 TRACE("pdwNumIf %p\n", pdwNumIf);
1486 ret = ERROR_INVALID_PARAMETER;
1488 *pdwNumIf = getNumInterfaces();
1491 TRACE("returning %d\n", ret);
1496 /******************************************************************
1497 * GetPerAdapterInfo (IPHLPAPI.@)
1499 * Get information about an adapter corresponding to an interface.
1502 * IfIndex [In] interface info
1503 * pPerAdapterInfo [Out] buffer for per adapter info
1504 * pOutBufLen [In/Out] length of output buffer
1508 * Failure: error code from winerror.h
1511 * Stub, returns empty IP_PER_ADAPTER_INFO in every case.
1513 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
1515 ULONG bytesNeeded = sizeof(IP_PER_ADAPTER_INFO);
1517 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex, pPerAdapterInfo, pOutBufLen);
1519 if (!pOutBufLen) return ERROR_INVALID_PARAMETER;
1521 if (!pPerAdapterInfo || *pOutBufLen < bytesNeeded)
1523 *pOutBufLen = bytesNeeded;
1524 return ERROR_BUFFER_OVERFLOW;
1527 memset(pPerAdapterInfo, 0, bytesNeeded);
1532 /******************************************************************
1533 * GetRTTAndHopCount (IPHLPAPI.@)
1535 * Get round-trip time (RTT) and hop count.
1539 * DestIpAddress [In] destination address to get the info for
1540 * HopCount [Out] retrieved hop count
1541 * MaxHops [In] maximum hops to search for the destination
1542 * RTT [Out] RTT in milliseconds
1549 * Stub, returns FALSE.
1551 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
1553 FIXME("(DestIpAddress 0x%08x, HopCount %p, MaxHops %d, RTT %p): stub\n",
1554 DestIpAddress, HopCount, MaxHops, RTT);
1559 /******************************************************************
1560 * GetTcpStatistics (IPHLPAPI.@)
1562 * Get the TCP statistics for the local computer.
1565 * pStats [Out] buffer for TCP statistics
1569 * Failure: error code from winerror.h
1571 DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
1575 TRACE("pStats %p\n", pStats);
1576 ret = getTCPStats(pStats);
1577 TRACE("returning %d\n", ret);
1582 /******************************************************************
1583 * GetTcpTable (IPHLPAPI.@)
1585 * Get the table of active TCP connections.
1588 * pTcpTable [Out] buffer for TCP connections table
1589 * pdwSize [In/Out] length of output buffer
1590 * bOrder [In] whether to order the table
1594 * Failure: error code from winerror.h
1597 * If pdwSize is less than required, the function will return
1598 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1599 * the required byte size.
1600 * If bOrder is true, the returned table will be sorted, first by
1601 * local address and port number, then by remote address and port
1604 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
1608 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize,
1611 ret = ERROR_INVALID_PARAMETER;
1613 DWORD numEntries = getNumTcpEntries();
1614 DWORD size = sizeof(MIB_TCPTABLE);
1617 size += (numEntries - 1) * sizeof(MIB_TCPROW);
1618 if (!pTcpTable || *pdwSize < size) {
1620 ret = ERROR_INSUFFICIENT_BUFFER;
1623 ret = getTcpTable(&pTcpTable, numEntries, 0, 0);
1625 size = sizeof(MIB_TCPTABLE);
1626 if (pTcpTable->dwNumEntries > 1)
1627 size += (pTcpTable->dwNumEntries - 1) * sizeof(MIB_TCPROW);
1631 qsort(pTcpTable->table, pTcpTable->dwNumEntries,
1632 sizeof(MIB_TCPROW), TcpTableSorter);
1637 TRACE("returning %d\n", ret);
1642 /******************************************************************
1643 * GetUdpStatistics (IPHLPAPI.@)
1645 * Get the UDP statistics for the local computer.
1648 * pStats [Out] buffer for UDP statistics
1652 * Failure: error code from winerror.h
1654 DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
1658 TRACE("pStats %p\n", pStats);
1659 ret = getUDPStats(pStats);
1660 TRACE("returning %d\n", ret);
1665 /******************************************************************
1666 * GetUdpTable (IPHLPAPI.@)
1668 * Get a table of active UDP connections.
1671 * pUdpTable [Out] buffer for UDP connections table
1672 * pdwSize [In/Out] length of output buffer
1673 * bOrder [In] whether to order the table
1677 * Failure: error code from winerror.h
1680 * If pdwSize is less than required, the function will return
1681 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1682 * required byte size.
1683 * If bOrder is true, the returned table will be sorted, first by
1684 * local address, then by local port number.
1686 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
1690 TRACE("pUdpTable %p, pdwSize %p, bOrder %d\n", pUdpTable, pdwSize,
1693 ret = ERROR_INVALID_PARAMETER;
1695 DWORD numEntries = getNumUdpEntries();
1696 DWORD size = sizeof(MIB_UDPTABLE);
1699 size += (numEntries - 1) * sizeof(MIB_UDPROW);
1700 if (!pUdpTable || *pdwSize < size) {
1702 ret = ERROR_INSUFFICIENT_BUFFER;
1705 PMIB_UDPTABLE table;
1707 ret = getUdpTable(&table, GetProcessHeap(), 0);
1709 size = sizeof(MIB_UDPTABLE);
1710 if (table->dwNumEntries > 1)
1711 size += (table->dwNumEntries - 1) * sizeof(MIB_UDPROW);
1712 if (*pdwSize < size) {
1714 ret = ERROR_INSUFFICIENT_BUFFER;
1718 memcpy(pUdpTable, table, size);
1720 qsort(pUdpTable->table, pUdpTable->dwNumEntries,
1721 sizeof(MIB_UDPROW), UdpTableSorter);
1724 HeapFree(GetProcessHeap(), 0, table);
1727 ret = ERROR_OUTOFMEMORY;
1730 TRACE("returning %d\n", ret);
1735 /******************************************************************
1736 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1738 * This is a Win98-only function to get information on "unidirectional"
1739 * adapters. Since this is pretty nonsensical in other contexts, it
1740 * never returns anything.
1743 * pIPIfInfo [Out] buffer for adapter infos
1744 * dwOutBufLen [Out] length of the output buffer
1748 * Failure: error code from winerror.h
1751 * Stub, returns ERROR_NOT_SUPPORTED.
1753 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
1755 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1756 /* a unidirectional adapter?? not bloody likely! */
1757 return ERROR_NOT_SUPPORTED;
1761 /******************************************************************
1762 * IpReleaseAddress (IPHLPAPI.@)
1764 * Release an IP obtained through DHCP,
1767 * AdapterInfo [In] adapter to release IP address
1771 * Failure: error code from winerror.h
1774 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1775 * this function does nothing.
1778 * Stub, returns ERROR_NOT_SUPPORTED.
1780 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1782 TRACE("AdapterInfo %p\n", AdapterInfo);
1783 /* not a stub, never going to support this (and I never mark an adapter as
1784 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1785 return ERROR_NOT_SUPPORTED;
1789 /******************************************************************
1790 * IpRenewAddress (IPHLPAPI.@)
1792 * Renew an IP obtained through DHCP.
1795 * AdapterInfo [In] adapter to renew IP address
1799 * Failure: error code from winerror.h
1802 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1803 * this function does nothing.
1806 * Stub, returns ERROR_NOT_SUPPORTED.
1808 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1810 TRACE("AdapterInfo %p\n", AdapterInfo);
1811 /* not a stub, never going to support this (and I never mark an adapter as
1812 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1813 return ERROR_NOT_SUPPORTED;
1817 /******************************************************************
1818 * NotifyAddrChange (IPHLPAPI.@)
1820 * Notify caller whenever the ip-interface map is changed.
1823 * Handle [Out] handle usable in asynchronous notification
1824 * overlapped [In] overlapped structure that notifies the caller
1828 * Failure: error code from winerror.h
1831 * Stub, returns ERROR_NOT_SUPPORTED.
1833 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1835 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1836 return ERROR_NOT_SUPPORTED;
1840 /******************************************************************
1841 * NotifyRouteChange (IPHLPAPI.@)
1843 * Notify caller whenever the ip routing table is changed.
1846 * Handle [Out] handle usable in asynchronous notification
1847 * overlapped [In] overlapped structure that notifies the caller
1851 * Failure: error code from winerror.h
1854 * Stub, returns ERROR_NOT_SUPPORTED.
1856 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1858 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1859 return ERROR_NOT_SUPPORTED;
1863 /******************************************************************
1864 * SendARP (IPHLPAPI.@)
1866 * Send an ARP request.
1869 * DestIP [In] attempt to obtain this IP
1870 * SrcIP [In] optional sender IP address
1871 * pMacAddr [Out] buffer for the mac address
1872 * PhyAddrLen [In/Out] length of the output buffer
1876 * Failure: error code from winerror.h
1879 * Stub, returns ERROR_NOT_SUPPORTED.
1881 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
1883 FIXME("(DestIP 0x%08x, SrcIP 0x%08x, pMacAddr %p, PhyAddrLen %p): stub\n",
1884 DestIP, SrcIP, pMacAddr, PhyAddrLen);
1885 return ERROR_NOT_SUPPORTED;
1889 /******************************************************************
1890 * SetIfEntry (IPHLPAPI.@)
1892 * Set the administrative status of an interface.
1895 * pIfRow [In] dwAdminStatus member specifies the new status.
1899 * Failure: error code from winerror.h
1902 * Stub, returns ERROR_NOT_SUPPORTED.
1904 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
1906 FIXME("(pIfRow %p): stub\n", pIfRow);
1907 /* this is supposed to set an interface administratively up or down.
1908 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1909 this sort of down is indistinguishable from other sorts of down (e.g. no
1911 return ERROR_NOT_SUPPORTED;
1915 /******************************************************************
1916 * SetIpForwardEntry (IPHLPAPI.@)
1918 * Modify an existing route.
1921 * pRoute [In] route with the new information
1925 * Failure: error code from winerror.h
1928 * Stub, returns NO_ERROR.
1930 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
1932 FIXME("(pRoute %p): stub\n", pRoute);
1933 /* this is to add a route entry, how's it distinguishable from
1934 CreateIpForwardEntry?
1935 could use SIOCADDRT, not sure I want to */
1940 /******************************************************************
1941 * SetIpNetEntry (IPHLPAPI.@)
1943 * Modify an existing ARP entry.
1946 * pArpEntry [In] ARP entry with the new information
1950 * Failure: error code from winerror.h
1953 * Stub, returns NO_ERROR.
1955 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
1957 FIXME("(pArpEntry %p): stub\n", pArpEntry);
1958 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1963 /******************************************************************
1964 * SetIpStatistics (IPHLPAPI.@)
1966 * Toggle IP forwarding and det the default TTL value.
1969 * pIpStats [In] IP statistics with the new information
1973 * Failure: error code from winerror.h
1976 * Stub, returns NO_ERROR.
1978 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
1980 FIXME("(pIpStats %p): stub\n", pIpStats);
1985 /******************************************************************
1986 * SetIpTTL (IPHLPAPI.@)
1988 * Set the default TTL value.
1991 * nTTL [In] new TTL value
1995 * Failure: error code from winerror.h
1998 * Stub, returns NO_ERROR.
2000 DWORD WINAPI SetIpTTL(UINT nTTL)
2002 FIXME("(nTTL %d): stub\n", nTTL);
2003 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
2004 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
2009 /******************************************************************
2010 * SetTcpEntry (IPHLPAPI.@)
2012 * Set the state of a TCP connection.
2015 * pTcpRow [In] specifies connection with new state
2019 * Failure: error code from winerror.h
2022 * Stub, returns NO_ERROR.
2024 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
2026 FIXME("(pTcpRow %p): stub\n", pTcpRow);
2031 /******************************************************************
2032 * UnenableRouter (IPHLPAPI.@)
2034 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2035 * if it reaches zero.
2038 * pOverlapped [In/Out] should be the same as in EnableRouter()
2039 * lpdwEnableCount [Out] optional, receives reference count
2043 * Failure: error code from winerror.h
2046 * Stub, returns ERROR_NOT_SUPPORTED.
2048 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
2050 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
2052 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
2053 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
2055 return ERROR_NOT_SUPPORTED;