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_SYS_SOCKET_H
27 #include <sys/socket.h>
32 #ifdef HAVE_NETINET_IN_H
33 # include <netinet/in.h>
35 #ifdef HAVE_ARPA_INET_H
36 # include <arpa/inet.h>
38 #ifdef HAVE_ARPA_NAMESER_H
39 # include <arpa/nameser.h>
45 #define NONAMELESSUNION
46 #define NONAMELESSSTRUCT
58 #include "wine/debug.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
63 #define IF_NAMESIZE 16
67 #define INADDR_NONE ~0UL
70 /* call res_init() just once because of a bug in Mac OS X 10.4 */
71 /* Call once per thread on systems that have per-thread _res. */
72 static void initialise_resolver(void)
74 if ((_res.options & RES_INIT) == 0)
78 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
81 case DLL_PROCESS_ATTACH:
82 DisableThreadLibraryCalls( hinstDLL );
85 case DLL_PROCESS_DETACH:
91 /******************************************************************
92 * AddIPAddress (IPHLPAPI.@)
94 * Add an IP address to an adapter.
97 * Address [In] IP address to add to the adapter
98 * IpMask [In] subnet mask for the IP address
99 * IfIndex [In] adapter index to add the address
100 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
101 * NTEInstance [Out] NTE instance for the IP address
105 * Failure: error code from winerror.h
108 * Stub. Currently returns ERROR_NOT_SUPPORTED.
110 DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
113 return ERROR_NOT_SUPPORTED;
117 /******************************************************************
118 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
120 * Get table of local interfaces.
121 * Like GetIfTable(), but allocate the returned table from heap.
124 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
125 * allocated and returned.
126 * bOrder [In] whether to sort the table
127 * heap [In] heap from which the table is allocated
128 * flags [In] flags to HeapAlloc
131 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
132 * GetIfTable() returns otherwise.
134 DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
135 BOOL bOrder, HANDLE heap, DWORD flags)
139 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable,
140 bOrder, heap, flags);
142 ret = ERROR_INVALID_PARAMETER;
146 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
147 if (ret == ERROR_INSUFFICIENT_BUFFER) {
148 *ppIfTable = HeapAlloc(heap, flags, dwSize);
149 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
152 TRACE("returning %d\n", ret);
157 static int IpAddrTableSorter(const void *a, const void *b)
162 ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
169 /******************************************************************
170 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
172 * Get interface-to-IP address mapping table.
173 * Like GetIpAddrTable(), but allocate the returned table from heap.
176 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
177 * allocated and returned.
178 * bOrder [In] whether to sort the table
179 * heap [In] heap from which the table is allocated
180 * flags [In] flags to HeapAlloc
183 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
184 * failure, NO_ERROR on success.
186 DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
187 BOOL bOrder, HANDLE heap, DWORD flags)
191 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
192 ppIpAddrTable, bOrder, heap, flags);
193 ret = getIPAddrTable(ppIpAddrTable, heap, flags);
195 qsort((*ppIpAddrTable)->table, (*ppIpAddrTable)->dwNumEntries,
196 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
197 TRACE("returning %d\n", ret);
202 /******************************************************************
203 * CreateIpForwardEntry (IPHLPAPI.@)
205 * Create a route in the local computer's IP table.
208 * pRoute [In] new route information
212 * Failure: error code from winerror.h
215 * Stub, always returns NO_ERROR.
217 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
219 FIXME("(pRoute %p): stub\n", pRoute);
220 /* could use SIOCADDRT, not sure I want to */
225 /******************************************************************
226 * CreateIpNetEntry (IPHLPAPI.@)
228 * Create entry in the ARP table.
231 * pArpEntry [In] new ARP entry
235 * Failure: error code from winerror.h
238 * Stub, always returns NO_ERROR.
240 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
242 FIXME("(pArpEntry %p)\n", pArpEntry);
243 /* could use SIOCSARP on systems that support it, not sure I want to */
248 /******************************************************************
249 * CreateProxyArpEntry (IPHLPAPI.@)
251 * Create a Proxy ARP (PARP) entry for an IP address.
254 * dwAddress [In] IP address for which this computer acts as a proxy.
255 * dwMask [In] subnet mask for dwAddress
256 * dwIfIndex [In] interface index
260 * Failure: error code from winerror.h
263 * Stub, returns ERROR_NOT_SUPPORTED.
265 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
267 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
268 dwAddress, dwMask, dwIfIndex);
269 return ERROR_NOT_SUPPORTED;
273 /******************************************************************
274 * DeleteIPAddress (IPHLPAPI.@)
276 * Delete an IP address added with AddIPAddress().
279 * NTEContext [In] NTE context from AddIPAddress();
283 * Failure: error code from winerror.h
286 * Stub, returns ERROR_NOT_SUPPORTED.
288 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
290 FIXME("(NTEContext %d): stub\n", NTEContext);
291 return ERROR_NOT_SUPPORTED;
295 /******************************************************************
296 * DeleteIpForwardEntry (IPHLPAPI.@)
301 * pRoute [In] route to delete
305 * Failure: error code from winerror.h
308 * Stub, returns NO_ERROR.
310 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
312 FIXME("(pRoute %p): stub\n", pRoute);
313 /* could use SIOCDELRT, not sure I want to */
318 /******************************************************************
319 * DeleteIpNetEntry (IPHLPAPI.@)
321 * Delete an ARP entry.
324 * pArpEntry [In] ARP entry to delete
328 * Failure: error code from winerror.h
331 * Stub, returns NO_ERROR.
333 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
335 FIXME("(pArpEntry %p): stub\n", pArpEntry);
336 /* could use SIOCDARP on systems that support it, not sure I want to */
341 /******************************************************************
342 * DeleteProxyArpEntry (IPHLPAPI.@)
344 * Delete a Proxy ARP entry.
347 * dwAddress [In] IP address for which this computer acts as a proxy.
348 * dwMask [In] subnet mask for dwAddress
349 * dwIfIndex [In] interface index
353 * Failure: error code from winerror.h
356 * Stub, returns ERROR_NOT_SUPPORTED.
358 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
360 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
361 dwAddress, dwMask, dwIfIndex);
362 return ERROR_NOT_SUPPORTED;
366 /******************************************************************
367 * EnableRouter (IPHLPAPI.@)
369 * Turn on ip forwarding.
373 * pOverlapped [In/Out] hEvent member should contain a valid handle.
376 * Success: ERROR_IO_PENDING
377 * Failure: error code from winerror.h
380 * Stub, returns ERROR_NOT_SUPPORTED.
382 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
384 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle, pOverlapped);
385 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
386 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
388 return ERROR_NOT_SUPPORTED;
392 /******************************************************************
393 * FlushIpNetTable (IPHLPAPI.@)
395 * Delete all ARP entries of an interface
398 * dwIfIndex [In] interface index
402 * Failure: error code from winerror.h
405 * Stub, returns ERROR_NOT_SUPPORTED.
407 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
409 FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex);
410 /* this flushes the arp cache of the given index */
411 return ERROR_NOT_SUPPORTED;
415 /******************************************************************
416 * GetAdapterIndex (IPHLPAPI.@)
418 * Get interface index from its name.
421 * AdapterName [In] unicode string with the adapter name
422 * IfIndex [Out] returns found interface index
426 * Failure: error code from winerror.h
428 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
430 char adapterName[MAX_ADAPTER_NAME];
434 TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName, IfIndex);
435 /* The adapter name is guaranteed not to have any unicode characters, so
436 * this translation is never lossy */
437 for (i = 0; i < sizeof(adapterName) - 1 && AdapterName[i]; i++)
438 adapterName[i] = (char)AdapterName[i];
439 adapterName[i] = '\0';
440 ret = getInterfaceIndexByName(adapterName, IfIndex);
441 TRACE("returning %d\n", ret);
446 /******************************************************************
447 * GetAdaptersInfo (IPHLPAPI.@)
449 * Get information about adapters.
452 * pAdapterInfo [Out] buffer for adapter infos
453 * pOutBufLen [In] length of output buffer
457 * Failure: error code from winerror.h
459 DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
463 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
465 ret = ERROR_INVALID_PARAMETER;
467 DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
469 if (numNonLoopbackInterfaces > 0) {
470 DWORD numIPAddresses = getNumIPAddresses();
473 /* This may slightly overestimate the amount of space needed, because
474 * the IP addresses include the loopback address, but it's easier
475 * to make sure there's more than enough space than to make sure there's
476 * precisely enough space.
478 size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
479 size += numIPAddresses * sizeof(IP_ADDR_STRING);
480 if (!pAdapterInfo || *pOutBufLen < size) {
482 ret = ERROR_BUFFER_OVERFLOW;
485 InterfaceIndexTable *table = NULL;
486 PMIB_IPADDRTABLE ipAddrTable = NULL;
487 PMIB_IPFORWARDTABLE routeTable = NULL;
489 ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
491 ret = AllocateAndGetIpForwardTableFromStack(&routeTable, FALSE, GetProcessHeap(), 0);
493 table = getNonLoopbackInterfaceIndexTable();
495 size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
496 size += ipAddrTable->dwNumEntries * sizeof(IP_ADDR_STRING);
497 if (*pOutBufLen < size) {
499 ret = ERROR_INSUFFICIENT_BUFFER;
504 BOOL winsEnabled = FALSE;
505 IP_ADDRESS_STRING primaryWINS, secondaryWINS;
506 PIP_ADDR_STRING nextIPAddr = (PIP_ADDR_STRING)((LPBYTE)pAdapterInfo
507 + numNonLoopbackInterfaces * sizeof(IP_ADAPTER_INFO));
509 memset(pAdapterInfo, 0, size);
510 /* @@ Wine registry key: HKCU\Software\Wine\Network */
511 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network",
512 &hKey) == ERROR_SUCCESS) {
513 DWORD size = sizeof(primaryWINS.String);
516 RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
517 (LPBYTE)primaryWINS.String, &size);
518 addr = inet_addr(primaryWINS.String);
519 if (addr != INADDR_NONE && addr != INADDR_ANY)
521 size = sizeof(secondaryWINS.String);
522 RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
523 (LPBYTE)secondaryWINS.String, &size);
524 addr = inet_addr(secondaryWINS.String);
525 if (addr != INADDR_NONE && addr != INADDR_ANY)
529 for (ndx = 0; ndx < table->numIndexes; ndx++) {
530 PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
532 PIP_ADDR_STRING currentIPAddr = &ptr->IpAddressList;
533 BOOL firstIPAddr = TRUE;
535 /* on Win98 this is left empty, but whatever */
536 getInterfaceNameByIndex(table->indexes[ndx], ptr->AdapterName);
537 getInterfaceNameByIndex(table->indexes[ndx], ptr->Description);
538 ptr->AddressLength = sizeof(ptr->Address);
539 getInterfacePhysicalByIndex(table->indexes[ndx],
540 &ptr->AddressLength, ptr->Address, &ptr->Type);
541 ptr->Index = table->indexes[ndx];
542 for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
543 if (ipAddrTable->table[i].dwIndex == ptr->Index) {
545 toIPAddressString(ipAddrTable->table[i].dwAddr,
546 ptr->IpAddressList.IpAddress.String);
547 toIPAddressString(ipAddrTable->table[i].dwMask,
548 ptr->IpAddressList.IpMask.String);
552 currentIPAddr->Next = nextIPAddr;
553 currentIPAddr = nextIPAddr;
554 toIPAddressString(ipAddrTable->table[i].dwAddr,
555 currentIPAddr->IpAddress.String);
556 toIPAddressString(ipAddrTable->table[i].dwMask,
557 currentIPAddr->IpMask.String);
562 /* Find first router through this interface, which we'll assume
563 * is the default gateway for this adapter */
564 for (i = 0; i < routeTable->dwNumEntries; i++)
565 if (routeTable->table[i].dwForwardIfIndex == ptr->Index
566 && routeTable->table[i].dwForwardType ==
567 MIB_IPROUTE_TYPE_INDIRECT)
568 toIPAddressString(routeTable->table[i].dwForwardNextHop,
569 ptr->GatewayList.IpAddress.String);
571 ptr->HaveWins = TRUE;
572 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
573 primaryWINS.String, sizeof(primaryWINS.String));
574 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
575 secondaryWINS.String, sizeof(secondaryWINS.String));
577 if (ndx < table->numIndexes - 1)
578 ptr->Next = &pAdapterInfo[ndx + 1];
584 HeapFree(GetProcessHeap(), 0, table);
587 ret = ERROR_OUTOFMEMORY;
588 HeapFree(GetProcessHeap(), 0, routeTable);
589 HeapFree(GetProcessHeap(), 0, ipAddrTable);
595 TRACE("returning %d\n", ret);
599 static DWORD typeFromMibType(DWORD mib_type)
603 case MIB_IF_TYPE_ETHERNET: return IF_TYPE_ETHERNET_CSMACD;
604 case MIB_IF_TYPE_TOKENRING: return IF_TYPE_ISO88025_TOKENRING;
605 case MIB_IF_TYPE_PPP: return IF_TYPE_PPP;
606 case MIB_IF_TYPE_LOOPBACK: return IF_TYPE_SOFTWARE_LOOPBACK;
607 default: return IF_TYPE_OTHER;
611 static DWORD connectionTypeFromMibType(DWORD mib_type)
615 case MIB_IF_TYPE_PPP: return NET_IF_CONNECTION_DEMAND;
616 case MIB_IF_TYPE_SLIP: return NET_IF_CONNECTION_DEMAND;
617 default: return NET_IF_CONNECTION_DEDICATED;
621 static ULONG v4addressesFromIndex(DWORD index, DWORD **addrs, ULONG *num_addrs)
627 if ((ret = getIPAddrTable(&at, GetProcessHeap(), 0))) return ret;
628 for (i = 0; i < at->dwNumEntries; i++)
630 if (at->table[i].dwIndex == index) (*num_addrs)++;
632 if (!(*addrs = HeapAlloc(GetProcessHeap(), 0, *num_addrs * sizeof(DWORD))))
634 HeapFree(GetProcessHeap(), 0, at);
635 return ERROR_OUTOFMEMORY;
637 for (i = 0, j = 0; i < at->dwNumEntries; i++)
639 if (at->table[i].dwIndex == index) (*addrs)[j++] = at->table[i].dwAddr;
641 HeapFree(GetProcessHeap(), 0, at);
642 return ERROR_SUCCESS;
645 static char *debugstr_ipv4(const in_addr_t *in_addr, char *buf)
650 for (addrp = (const BYTE *)in_addr;
651 addrp - (const BYTE *)in_addr < sizeof(*in_addr);
654 if (addrp == (const BYTE *)in_addr + sizeof(*in_addr) - 1)
655 sprintf(p, "%d", *addrp);
660 sprintf(p, "%d.%n", *addrp, &n);
667 static char *debugstr_ipv6(const struct WS_sockaddr_in6 *sin, char *buf)
669 const IN6_ADDR *addr = &sin->sin6_addr;
672 BOOL in_zero = FALSE;
674 for (i = 0; i < 7; i++)
676 if (!addr->u.Word[i])
690 sprintf(p, "%x:%n", ntohs(addr->u.Word[i]), &n);
695 sprintf(p, "%x", ntohs(addr->u.Word[7]));
699 static ULONG adapterAddressesFromIndex(ULONG family, DWORD index, IP_ADAPTER_ADDRESSES *aa, ULONG *size)
701 ULONG ret, i, num_v4addrs = 0, num_v6addrs = 0, total_size;
702 DWORD *v4addrs = NULL;
703 SOCKET_ADDRESS *v6addrs = NULL;
705 if (family == AF_INET)
706 ret = v4addressesFromIndex(index, &v4addrs, &num_v4addrs);
707 else if (family == AF_INET6)
708 ret = v6addressesFromIndex(index, &v6addrs, &num_v6addrs);
709 else if (family == AF_UNSPEC)
711 ret = v4addressesFromIndex(index, &v4addrs, &num_v4addrs);
713 ret = v6addressesFromIndex(index, &v6addrs, &num_v6addrs);
717 FIXME("address family %u unsupported\n", family);
722 total_size = sizeof(IP_ADAPTER_ADDRESSES);
723 total_size += IF_NAMESIZE;
724 total_size += IF_NAMESIZE * sizeof(WCHAR);
725 total_size += sizeof(IP_ADAPTER_UNICAST_ADDRESS) * num_v4addrs;
726 total_size += sizeof(struct sockaddr_in) * num_v4addrs;
727 total_size += sizeof(IP_ADAPTER_UNICAST_ADDRESS) * num_v6addrs;
728 total_size += sizeof(SOCKET_ADDRESS) * num_v6addrs;
729 for (i = 0; i < num_v6addrs; i++)
730 total_size += v6addrs[i].iSockaddrLength;
732 if (aa && *size >= total_size)
734 char name[IF_NAMESIZE], *ptr = (char *)aa + sizeof(IP_ADAPTER_ADDRESSES), *src;
736 DWORD buflen, type, status;
738 memset(aa, 0, sizeof(IP_ADAPTER_ADDRESSES));
739 aa->u.s.Length = sizeof(IP_ADAPTER_ADDRESSES);
740 aa->u.s.IfIndex = index;
742 getInterfaceNameByIndex(index, name);
743 memcpy(ptr, name, IF_NAMESIZE);
744 aa->AdapterName = ptr;
746 aa->FriendlyName = (WCHAR *)ptr;
747 for (src = name, dst = (WCHAR *)ptr; *src; src++, dst++)
752 TRACE("%s: %d IPv4 addresses, %d IPv6 addresses:\n", name, num_v4addrs,
756 IP_ADAPTER_UNICAST_ADDRESS *ua;
757 struct sockaddr_in *sa;
759 aa->Flags |= IP_ADAPTER_IPV4_ENABLED;
760 ua = aa->FirstUnicastAddress = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
761 for (i = 0; i < num_v4addrs; i++)
765 memset(ua, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS));
766 ua->u.s.Length = sizeof(IP_ADAPTER_UNICAST_ADDRESS);
767 ua->Address.iSockaddrLength = sizeof(struct sockaddr_in);
768 ua->Address.lpSockaddr = (SOCKADDR *)((char *)ua + ua->u.s.Length);
770 sa = (struct sockaddr_in *)ua->Address.lpSockaddr;
771 sa->sin_family = AF_INET;
772 sa->sin_addr.s_addr = v4addrs[i];
774 TRACE("IPv4 %d/%d: %s\n", i + 1, num_v4addrs,
775 debugstr_ipv4(&sa->sin_addr.s_addr, addr_buf));
777 ptr += ua->u.s.Length + ua->Address.iSockaddrLength;
778 if (i < num_v4addrs - 1)
780 ua->Next = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
787 IP_ADAPTER_UNICAST_ADDRESS *ua;
788 struct WS_sockaddr_in6 *sa;
790 aa->Flags |= IP_ADAPTER_IPV6_ENABLED;
791 if (aa->FirstUnicastAddress)
793 for (ua = aa->FirstUnicastAddress; ua->Next; ua = ua->Next)
795 ua->Next = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
796 ua = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
799 ua = aa->FirstUnicastAddress = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
800 for (i = 0; i < num_v6addrs; i++)
804 memset(ua, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS));
805 ua->u.s.Length = sizeof(IP_ADAPTER_UNICAST_ADDRESS);
806 ua->Address.iSockaddrLength = v6addrs[i].iSockaddrLength;
807 ua->Address.lpSockaddr = (SOCKADDR *)((char *)ua + ua->u.s.Length);
809 sa = (struct WS_sockaddr_in6 *)ua->Address.lpSockaddr;
810 memcpy(sa, v6addrs[i].lpSockaddr, sizeof(*sa));
811 TRACE("IPv6 %d/%d: %s\n", i + 1, num_v6addrs,
812 debugstr_ipv6(sa, addr_buf));
814 ptr += ua->u.s.Length + ua->Address.iSockaddrLength;
815 if (i < num_v6addrs - 1)
817 ua->Next = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
823 buflen = MAX_INTERFACE_PHYSADDR;
824 getInterfacePhysicalByIndex(index, &buflen, aa->PhysicalAddress, &type);
825 aa->PhysicalAddressLength = buflen;
826 aa->IfType = typeFromMibType(type);
827 aa->ConnectionType = connectionTypeFromMibType(type);
829 getInterfaceMtuByName(name, &aa->Mtu);
831 getInterfaceStatusByName(name, &status);
832 if (status == MIB_IF_OPER_STATUS_OPERATIONAL) aa->OperStatus = IfOperStatusUp;
833 else if (status == MIB_IF_OPER_STATUS_NON_OPERATIONAL) aa->OperStatus = IfOperStatusDown;
834 else aa->OperStatus = IfOperStatusUnknown;
837 HeapFree(GetProcessHeap(), 0, v6addrs);
838 HeapFree(GetProcessHeap(), 0, v4addrs);
839 return ERROR_SUCCESS;
842 ULONG WINAPI GetAdaptersAddresses(ULONG family, ULONG flags, PVOID reserved,
843 PIP_ADAPTER_ADDRESSES aa, PULONG buflen)
845 InterfaceIndexTable *table;
846 ULONG i, size, total_size, ret = ERROR_NO_DATA;
848 if (!buflen) return ERROR_INVALID_PARAMETER;
850 table = getInterfaceIndexTable();
851 if (!table || !table->numIndexes)
853 HeapFree(GetProcessHeap(), 0, table);
854 return ERROR_NO_DATA;
857 for (i = 0; i < table->numIndexes; i++)
860 if ((ret = adapterAddressesFromIndex(family, table->indexes[i], NULL, &size)))
862 HeapFree(GetProcessHeap(), 0, table);
867 if (aa && *buflen >= total_size)
869 ULONG bytes_left = size = total_size;
870 for (i = 0; i < table->numIndexes; i++)
872 if ((ret = adapterAddressesFromIndex(family, table->indexes[i], aa, &size)))
874 HeapFree(GetProcessHeap(), 0, table);
877 if (i < table->numIndexes - 1)
879 aa->Next = (IP_ADAPTER_ADDRESSES *)((char *)aa + size);
881 size = bytes_left -= size;
886 if (*buflen < total_size) ret = ERROR_BUFFER_OVERFLOW;
887 *buflen = total_size;
889 TRACE("num adapters %u\n", table->numIndexes);
890 HeapFree(GetProcessHeap(), 0, table);
894 /******************************************************************
895 * GetBestInterface (IPHLPAPI.@)
897 * Get the interface, with the best route for the given IP address.
900 * dwDestAddr [In] IP address to search the interface for
901 * pdwBestIfIndex [Out] found best interface
905 * Failure: error code from winerror.h
907 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
909 struct WS_sockaddr_in sa_in;
910 memset(&sa_in, 0, sizeof(sa_in));
911 sa_in.sin_family = AF_INET;
912 sa_in.sin_addr.S_un.S_addr = dwDestAddr;
913 return GetBestInterfaceEx((struct WS_sockaddr *)&sa_in, pdwBestIfIndex);
916 /******************************************************************
917 * GetBestInterfaceEx (IPHLPAPI.@)
919 * Get the interface, with the best route for the given IP address.
922 * dwDestAddr [In] IP address to search the interface for
923 * pdwBestIfIndex [Out] found best interface
927 * Failure: error code from winerror.h
929 DWORD WINAPI GetBestInterfaceEx(struct WS_sockaddr *pDestAddr, PDWORD pdwBestIfIndex)
933 TRACE("pDestAddr %p, pdwBestIfIndex %p\n", pDestAddr, pdwBestIfIndex);
934 if (!pDestAddr || !pdwBestIfIndex)
935 ret = ERROR_INVALID_PARAMETER;
937 MIB_IPFORWARDROW ipRow;
939 if (pDestAddr->sa_family == AF_INET) {
940 ret = GetBestRoute(((struct WS_sockaddr_in *)pDestAddr)->sin_addr.S_un.S_addr, 0, &ipRow);
941 if (ret == ERROR_SUCCESS)
942 *pdwBestIfIndex = ipRow.dwForwardIfIndex;
944 FIXME("address family %d not supported\n", pDestAddr->sa_family);
945 ret = ERROR_NOT_SUPPORTED;
948 TRACE("returning %d\n", ret);
953 /******************************************************************
954 * GetBestRoute (IPHLPAPI.@)
956 * Get the best route for the given IP address.
959 * dwDestAddr [In] IP address to search the best route for
960 * dwSourceAddr [In] optional source IP address
961 * pBestRoute [Out] found best route
965 * Failure: error code from winerror.h
967 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
969 PMIB_IPFORWARDTABLE table;
972 TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr,
973 dwSourceAddr, pBestRoute);
975 return ERROR_INVALID_PARAMETER;
977 ret = AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
979 DWORD ndx, matchedBits, matchedNdx = table->dwNumEntries;
981 for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
982 if (table->table[ndx].dwForwardType != MIB_IPROUTE_TYPE_INVALID &&
983 (dwDestAddr & table->table[ndx].dwForwardMask) ==
984 (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
985 DWORD numShifts, mask;
987 for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
988 mask && !(mask & 1); mask >>= 1, numShifts++)
990 if (numShifts > matchedBits) {
991 matchedBits = numShifts;
994 else if (!matchedBits) {
999 if (matchedNdx < table->dwNumEntries) {
1000 memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
1001 ret = ERROR_SUCCESS;
1004 /* No route matches, which can happen if there's no default route. */
1005 ret = ERROR_HOST_UNREACHABLE;
1007 HeapFree(GetProcessHeap(), 0, table);
1009 TRACE("returning %d\n", ret);
1014 /******************************************************************
1015 * GetFriendlyIfIndex (IPHLPAPI.@)
1017 * Get a "friendly" version of IfIndex, which is one that doesn't
1018 * have the top byte set. Doesn't validate whether IfIndex is a valid
1022 * IfIndex [In] interface index to get the friendly one for
1025 * A friendly version of IfIndex.
1027 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
1029 /* windows doesn't validate these, either, just makes sure the top byte is
1030 cleared. I assume my ifenum module never gives an index with the top
1032 TRACE("returning %d\n", IfIndex);
1037 /******************************************************************
1038 * GetIfEntry (IPHLPAPI.@)
1040 * Get information about an interface.
1043 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
1044 * Out: interface information
1048 * Failure: error code from winerror.h
1050 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
1053 char nameBuf[MAX_ADAPTER_NAME];
1056 TRACE("pIfRow %p\n", pIfRow);
1058 return ERROR_INVALID_PARAMETER;
1060 name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf);
1062 ret = getInterfaceEntryByName(name, pIfRow);
1063 if (ret == NO_ERROR)
1064 ret = getInterfaceStatsByName(name, pIfRow);
1067 ret = ERROR_INVALID_DATA;
1068 TRACE("returning %d\n", ret);
1073 static int IfTableSorter(const void *a, const void *b)
1078 ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
1085 /******************************************************************
1086 * GetIfTable (IPHLPAPI.@)
1088 * Get a table of local interfaces.
1091 * pIfTable [Out] buffer for local interfaces table
1092 * pdwSize [In/Out] length of output buffer
1093 * bOrder [In] whether to sort the table
1097 * Failure: error code from winerror.h
1100 * If pdwSize is less than required, the function will return
1101 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1103 * If bOrder is true, the returned table will be sorted by interface index.
1105 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
1109 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize, pdwSize,
1112 ret = ERROR_INVALID_PARAMETER;
1114 DWORD numInterfaces = getNumInterfaces();
1115 ULONG size = sizeof(MIB_IFTABLE);
1117 if (numInterfaces > 1)
1118 size += (numInterfaces - 1) * sizeof(MIB_IFROW);
1119 if (!pIfTable || *pdwSize < size) {
1121 ret = ERROR_INSUFFICIENT_BUFFER;
1124 InterfaceIndexTable *table = getInterfaceIndexTable();
1127 size = sizeof(MIB_IFTABLE);
1128 if (table->numIndexes > 1)
1129 size += (table->numIndexes - 1) * sizeof(MIB_IFROW);
1130 if (*pdwSize < size) {
1132 ret = ERROR_INSUFFICIENT_BUFFER;
1138 pIfTable->dwNumEntries = 0;
1139 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1140 pIfTable->table[ndx].dwIndex = table->indexes[ndx];
1141 GetIfEntry(&pIfTable->table[ndx]);
1142 pIfTable->dwNumEntries++;
1145 qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
1149 HeapFree(GetProcessHeap(), 0, table);
1152 ret = ERROR_OUTOFMEMORY;
1155 TRACE("returning %d\n", ret);
1160 /******************************************************************
1161 * GetInterfaceInfo (IPHLPAPI.@)
1163 * Get a list of network interface adapters.
1166 * pIfTable [Out] buffer for interface adapters
1167 * dwOutBufLen [Out] if buffer is too small, returns required size
1171 * Failure: error code from winerror.h
1174 * MSDN states this should return non-loopback interfaces only.
1176 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
1180 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1182 ret = ERROR_INVALID_PARAMETER;
1184 DWORD numInterfaces = getNumInterfaces();
1185 ULONG size = sizeof(IP_INTERFACE_INFO);
1187 if (numInterfaces > 1)
1188 size += (numInterfaces - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
1189 if (!pIfTable || *dwOutBufLen < size) {
1190 *dwOutBufLen = size;
1191 ret = ERROR_INSUFFICIENT_BUFFER;
1194 InterfaceIndexTable *table = getInterfaceIndexTable();
1197 size = sizeof(IP_INTERFACE_INFO);
1198 if (table->numIndexes > 1)
1199 size += (table->numIndexes - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
1200 if (*dwOutBufLen < size) {
1201 *dwOutBufLen = size;
1202 ret = ERROR_INSUFFICIENT_BUFFER;
1206 char nameBuf[MAX_ADAPTER_NAME];
1208 *dwOutBufLen = size;
1209 pIfTable->NumAdapters = 0;
1210 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1211 const char *walker, *name;
1214 pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1215 name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
1216 for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
1217 walker && *walker &&
1218 assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
1219 walker++, assigner++)
1220 *assigner = *walker;
1222 pIfTable->NumAdapters++;
1226 HeapFree(GetProcessHeap(), 0, table);
1229 ret = ERROR_OUTOFMEMORY;
1232 TRACE("returning %d\n", ret);
1237 /******************************************************************
1238 * GetIpAddrTable (IPHLPAPI.@)
1240 * Get interface-to-IP address mapping table.
1243 * pIpAddrTable [Out] buffer for mapping table
1244 * pdwSize [In/Out] length of output buffer
1245 * bOrder [In] whether to sort the table
1249 * Failure: error code from winerror.h
1252 * If pdwSize is less than required, the function will return
1253 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1255 * If bOrder is true, the returned table will be sorted by the next hop and
1256 * an assortment of arbitrary parameters.
1258 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1262 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable, pdwSize,
1265 ret = ERROR_INVALID_PARAMETER;
1267 PMIB_IPADDRTABLE table;
1269 ret = getIPAddrTable(&table, GetProcessHeap(), 0);
1270 if (ret == NO_ERROR)
1272 ULONG size = sizeof(MIB_IPADDRTABLE);
1274 if (table->dwNumEntries > 1)
1275 size += (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW);
1276 if (!pIpAddrTable || *pdwSize < size) {
1278 ret = ERROR_INSUFFICIENT_BUFFER;
1282 memcpy(pIpAddrTable, table, size);
1284 qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1285 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1288 HeapFree(GetProcessHeap(), 0, table);
1291 TRACE("returning %d\n", ret);
1296 /******************************************************************
1297 * GetIpForwardTable (IPHLPAPI.@)
1299 * Get the route table.
1302 * pIpForwardTable [Out] buffer for route table
1303 * pdwSize [In/Out] length of output buffer
1304 * bOrder [In] whether to sort the table
1308 * Failure: error code from winerror.h
1311 * If pdwSize is less than required, the function will return
1312 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1314 * If bOrder is true, the returned table will be sorted by the next hop and
1315 * an assortment of arbitrary parameters.
1317 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1320 PMIB_IPFORWARDTABLE table;
1322 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable, pdwSize, bOrder);
1324 if (!pdwSize) return ERROR_INVALID_PARAMETER;
1326 ret = AllocateAndGetIpForwardTableFromStack(&table, bOrder, GetProcessHeap(), 0);
1328 DWORD size = FIELD_OFFSET( MIB_IPFORWARDTABLE, table[table->dwNumEntries] );
1329 if (!pIpForwardTable || *pdwSize < size) {
1331 ret = ERROR_INSUFFICIENT_BUFFER;
1335 memcpy(pIpForwardTable, table, size);
1337 HeapFree(GetProcessHeap(), 0, table);
1339 TRACE("returning %d\n", ret);
1344 /******************************************************************
1345 * GetIpNetTable (IPHLPAPI.@)
1347 * Get the IP-to-physical address mapping table.
1350 * pIpNetTable [Out] buffer for mapping table
1351 * pdwSize [In/Out] length of output buffer
1352 * bOrder [In] whether to sort the table
1356 * Failure: error code from winerror.h
1359 * If pdwSize is less than required, the function will return
1360 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1362 * If bOrder is true, the returned table will be sorted by IP address.
1364 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1367 PMIB_IPNETTABLE table;
1369 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable, pdwSize, bOrder);
1371 if (!pdwSize) return ERROR_INVALID_PARAMETER;
1373 ret = AllocateAndGetIpNetTableFromStack( &table, bOrder, GetProcessHeap(), 0 );
1375 DWORD size = FIELD_OFFSET( MIB_IPNETTABLE, table[table->dwNumEntries] );
1376 if (!pIpNetTable || *pdwSize < size) {
1378 ret = ERROR_INSUFFICIENT_BUFFER;
1382 memcpy(pIpNetTable, table, size);
1384 HeapFree(GetProcessHeap(), 0, table);
1386 TRACE("returning %d\n", ret);
1391 /******************************************************************
1392 * GetNetworkParams (IPHLPAPI.@)
1394 * Get the network parameters for the local computer.
1397 * pFixedInfo [Out] buffer for network parameters
1398 * pOutBufLen [In/Out] length of output buffer
1402 * Failure: error code from winerror.h
1405 * If pOutBufLen is less than required, the function will return
1406 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1409 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1415 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1417 return ERROR_INVALID_PARAMETER;
1419 initialise_resolver();
1420 size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount - 1) *
1421 sizeof(IP_ADDR_STRING) : 0);
1422 if (!pFixedInfo || *pOutBufLen < size) {
1424 return ERROR_BUFFER_OVERFLOW;
1427 memset(pFixedInfo, 0, size);
1428 size = sizeof(pFixedInfo->HostName);
1429 GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1430 size = sizeof(pFixedInfo->DomainName);
1431 GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1432 if (_res.nscount > 0) {
1433 PIP_ADDR_STRING ptr;
1436 for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1437 i++, ptr = ptr->Next) {
1438 toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
1439 ptr->IpAddress.String);
1440 if (i == _res.nscount - 1)
1443 ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
1445 ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1448 pFixedInfo->NodeType = HYBRID_NODETYPE;
1449 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1450 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1451 if (regReturn != ERROR_SUCCESS)
1452 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1453 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1455 if (regReturn == ERROR_SUCCESS)
1457 DWORD size = sizeof(pFixedInfo->ScopeId);
1459 RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1463 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1464 I suppose could also check for a listener on port 53 to set EnableDns */
1466 TRACE("returning %d\n", ret);
1471 /******************************************************************
1472 * GetNumberOfInterfaces (IPHLPAPI.@)
1474 * Get the number of interfaces.
1477 * pdwNumIf [Out] number of interfaces
1480 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1482 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
1486 TRACE("pdwNumIf %p\n", pdwNumIf);
1488 ret = ERROR_INVALID_PARAMETER;
1490 *pdwNumIf = getNumInterfaces();
1493 TRACE("returning %d\n", ret);
1498 /******************************************************************
1499 * GetPerAdapterInfo (IPHLPAPI.@)
1501 * Get information about an adapter corresponding to an interface.
1504 * IfIndex [In] interface info
1505 * pPerAdapterInfo [Out] buffer for per adapter info
1506 * pOutBufLen [In/Out] length of output buffer
1510 * Failure: error code from winerror.h
1513 * Stub, returns empty IP_PER_ADAPTER_INFO in every case.
1515 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
1517 ULONG bytesNeeded = sizeof(IP_PER_ADAPTER_INFO);
1519 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex, pPerAdapterInfo, pOutBufLen);
1521 if (!pOutBufLen) return ERROR_INVALID_PARAMETER;
1523 if (!pPerAdapterInfo || *pOutBufLen < bytesNeeded)
1525 *pOutBufLen = bytesNeeded;
1526 return ERROR_BUFFER_OVERFLOW;
1529 memset(pPerAdapterInfo, 0, bytesNeeded);
1534 /******************************************************************
1535 * GetRTTAndHopCount (IPHLPAPI.@)
1537 * Get round-trip time (RTT) and hop count.
1541 * DestIpAddress [In] destination address to get the info for
1542 * HopCount [Out] retrieved hop count
1543 * MaxHops [In] maximum hops to search for the destination
1544 * RTT [Out] RTT in milliseconds
1551 * Stub, returns FALSE.
1553 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
1555 FIXME("(DestIpAddress 0x%08x, HopCount %p, MaxHops %d, RTT %p): stub\n",
1556 DestIpAddress, HopCount, MaxHops, RTT);
1561 /******************************************************************
1562 * GetTcpTable (IPHLPAPI.@)
1564 * Get the table of active TCP connections.
1567 * pTcpTable [Out] buffer for TCP connections table
1568 * pdwSize [In/Out] length of output buffer
1569 * bOrder [In] whether to order the table
1573 * Failure: error code from winerror.h
1576 * If pdwSize is less than required, the function will return
1577 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1578 * the required byte size.
1579 * If bOrder is true, the returned table will be sorted, first by
1580 * local address and port number, then by remote address and port
1583 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
1586 PMIB_TCPTABLE table;
1588 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize, bOrder);
1590 if (!pdwSize) return ERROR_INVALID_PARAMETER;
1592 ret = AllocateAndGetTcpTableFromStack(&table, bOrder, GetProcessHeap(), 0);
1594 DWORD size = FIELD_OFFSET( MIB_TCPTABLE, table[table->dwNumEntries] );
1595 if (!pTcpTable || *pdwSize < size) {
1597 ret = ERROR_INSUFFICIENT_BUFFER;
1601 memcpy(pTcpTable, table, size);
1603 HeapFree(GetProcessHeap(), 0, table);
1605 TRACE("returning %d\n", ret);
1610 /******************************************************************
1611 * GetUdpTable (IPHLPAPI.@)
1613 * Get a table of active UDP connections.
1616 * pUdpTable [Out] buffer for UDP connections table
1617 * pdwSize [In/Out] length of output buffer
1618 * bOrder [In] whether to order the table
1622 * Failure: error code from winerror.h
1625 * If pdwSize is less than required, the function will return
1626 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1627 * required byte size.
1628 * If bOrder is true, the returned table will be sorted, first by
1629 * local address, then by local port number.
1631 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
1634 PMIB_UDPTABLE table;
1636 TRACE("pUdpTable %p, pdwSize %p, bOrder %d\n", pUdpTable, pdwSize, bOrder);
1638 if (!pdwSize) return ERROR_INVALID_PARAMETER;
1640 ret = AllocateAndGetUdpTableFromStack( &table, bOrder, GetProcessHeap(), 0 );
1642 DWORD size = FIELD_OFFSET( MIB_UDPTABLE, table[table->dwNumEntries] );
1643 if (!pUdpTable || *pdwSize < size) {
1645 ret = ERROR_INSUFFICIENT_BUFFER;
1649 memcpy(pUdpTable, table, size);
1651 HeapFree(GetProcessHeap(), 0, table);
1653 TRACE("returning %d\n", ret);
1658 /******************************************************************
1659 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1661 * This is a Win98-only function to get information on "unidirectional"
1662 * adapters. Since this is pretty nonsensical in other contexts, it
1663 * never returns anything.
1666 * pIPIfInfo [Out] buffer for adapter infos
1667 * dwOutBufLen [Out] length of the output buffer
1671 * Failure: error code from winerror.h
1674 * Stub, returns ERROR_NOT_SUPPORTED.
1676 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
1678 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1679 /* a unidirectional adapter?? not bloody likely! */
1680 return ERROR_NOT_SUPPORTED;
1684 /******************************************************************
1685 * IpReleaseAddress (IPHLPAPI.@)
1687 * Release an IP obtained through DHCP,
1690 * AdapterInfo [In] adapter to release IP address
1694 * Failure: error code from winerror.h
1697 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1698 * this function does nothing.
1701 * Stub, returns ERROR_NOT_SUPPORTED.
1703 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1705 TRACE("AdapterInfo %p\n", AdapterInfo);
1706 /* not a stub, never going to support this (and I never mark an adapter as
1707 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1708 return ERROR_NOT_SUPPORTED;
1712 /******************************************************************
1713 * IpRenewAddress (IPHLPAPI.@)
1715 * Renew an IP obtained through DHCP.
1718 * AdapterInfo [In] adapter to renew IP address
1722 * Failure: error code from winerror.h
1725 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1726 * this function does nothing.
1729 * Stub, returns ERROR_NOT_SUPPORTED.
1731 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1733 TRACE("AdapterInfo %p\n", AdapterInfo);
1734 /* not a stub, never going to support this (and I never mark an adapter as
1735 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1736 return ERROR_NOT_SUPPORTED;
1740 /******************************************************************
1741 * NotifyAddrChange (IPHLPAPI.@)
1743 * Notify caller whenever the ip-interface map is changed.
1746 * Handle [Out] handle usable in asynchronous notification
1747 * overlapped [In] overlapped structure that notifies the caller
1751 * Failure: error code from winerror.h
1754 * Stub, returns ERROR_NOT_SUPPORTED.
1756 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1758 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1759 return ERROR_NOT_SUPPORTED;
1763 /******************************************************************
1764 * NotifyRouteChange (IPHLPAPI.@)
1766 * Notify caller whenever the ip routing table is changed.
1769 * Handle [Out] handle usable in asynchronous notification
1770 * overlapped [In] overlapped structure that notifies the caller
1774 * Failure: error code from winerror.h
1777 * Stub, returns ERROR_NOT_SUPPORTED.
1779 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1781 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1782 return ERROR_NOT_SUPPORTED;
1786 /******************************************************************
1787 * SendARP (IPHLPAPI.@)
1789 * Send an ARP request.
1792 * DestIP [In] attempt to obtain this IP
1793 * SrcIP [In] optional sender IP address
1794 * pMacAddr [Out] buffer for the mac address
1795 * PhyAddrLen [In/Out] length of the output buffer
1799 * Failure: error code from winerror.h
1802 * Stub, returns ERROR_NOT_SUPPORTED.
1804 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
1806 FIXME("(DestIP 0x%08x, SrcIP 0x%08x, pMacAddr %p, PhyAddrLen %p): stub\n",
1807 DestIP, SrcIP, pMacAddr, PhyAddrLen);
1808 return ERROR_NOT_SUPPORTED;
1812 /******************************************************************
1813 * SetIfEntry (IPHLPAPI.@)
1815 * Set the administrative status of an interface.
1818 * pIfRow [In] dwAdminStatus member specifies the new status.
1822 * Failure: error code from winerror.h
1825 * Stub, returns ERROR_NOT_SUPPORTED.
1827 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
1829 FIXME("(pIfRow %p): stub\n", pIfRow);
1830 /* this is supposed to set an interface administratively up or down.
1831 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1832 this sort of down is indistinguishable from other sorts of down (e.g. no
1834 return ERROR_NOT_SUPPORTED;
1838 /******************************************************************
1839 * SetIpForwardEntry (IPHLPAPI.@)
1841 * Modify an existing route.
1844 * pRoute [In] route with the new information
1848 * Failure: error code from winerror.h
1851 * Stub, returns NO_ERROR.
1853 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
1855 FIXME("(pRoute %p): stub\n", pRoute);
1856 /* this is to add a route entry, how's it distinguishable from
1857 CreateIpForwardEntry?
1858 could use SIOCADDRT, not sure I want to */
1863 /******************************************************************
1864 * SetIpNetEntry (IPHLPAPI.@)
1866 * Modify an existing ARP entry.
1869 * pArpEntry [In] ARP entry with the new information
1873 * Failure: error code from winerror.h
1876 * Stub, returns NO_ERROR.
1878 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
1880 FIXME("(pArpEntry %p): stub\n", pArpEntry);
1881 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1886 /******************************************************************
1887 * SetIpStatistics (IPHLPAPI.@)
1889 * Toggle IP forwarding and det the default TTL value.
1892 * pIpStats [In] IP statistics with the new information
1896 * Failure: error code from winerror.h
1899 * Stub, returns NO_ERROR.
1901 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
1903 FIXME("(pIpStats %p): stub\n", pIpStats);
1908 /******************************************************************
1909 * SetIpTTL (IPHLPAPI.@)
1911 * Set the default TTL value.
1914 * nTTL [In] new TTL value
1918 * Failure: error code from winerror.h
1921 * Stub, returns NO_ERROR.
1923 DWORD WINAPI SetIpTTL(UINT nTTL)
1925 FIXME("(nTTL %d): stub\n", nTTL);
1926 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1927 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1932 /******************************************************************
1933 * SetTcpEntry (IPHLPAPI.@)
1935 * Set the state of a TCP connection.
1938 * pTcpRow [In] specifies connection with new state
1942 * Failure: error code from winerror.h
1945 * Stub, returns NO_ERROR.
1947 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
1949 FIXME("(pTcpRow %p): stub\n", pTcpRow);
1954 /******************************************************************
1955 * UnenableRouter (IPHLPAPI.@)
1957 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
1958 * if it reaches zero.
1961 * pOverlapped [In/Out] should be the same as in EnableRouter()
1962 * lpdwEnableCount [Out] optional, receives reference count
1966 * Failure: error code from winerror.h
1969 * Stub, returns ERROR_NOT_SUPPORTED.
1971 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
1973 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
1975 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
1976 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
1978 return ERROR_NOT_SUPPORTED;