imm32: Move thread data from TLSEntry to an internal list.
[wine.git] / dlls / iphlpapi / iphlpapi_main.c
blobd2f36feeaaafb4231c3f2d0b1812c646812af9e7
1 /*
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
21 #include "config.h"
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <sys/types.h>
27 #ifdef HAVE_NETINET_IN_H
28 # include <netinet/in.h>
29 #endif
30 #ifdef HAVE_ARPA_INET_H
31 # include <arpa/inet.h>
32 #endif
33 #ifdef HAVE_ARPA_NAMESER_H
34 # include <arpa/nameser.h>
35 #endif
36 #ifdef HAVE_RESOLV_H
37 # include <resolv.h>
38 #endif
40 #define NONAMELESSUNION
41 #define NONAMELESSSTRUCT
42 #include "windef.h"
43 #include "winbase.h"
44 #include "winreg.h"
45 #define USE_WS_PREFIX
46 #include "winsock2.h"
47 #include "winternl.h"
48 #include "ws2ipdef.h"
49 #include "iphlpapi.h"
50 #include "ifenum.h"
51 #include "ipstats.h"
52 #include "ipifcons.h"
53 #include "fltdefs.h"
55 #include "wine/debug.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
59 #ifndef IF_NAMESIZE
60 #define IF_NAMESIZE 16
61 #endif
63 #ifndef INADDR_NONE
64 #define INADDR_NONE ~0UL
65 #endif
67 /******************************************************************
68 * AddIPAddress (IPHLPAPI.@)
70 * Add an IP address to an adapter.
72 * PARAMS
73 * Address [In] IP address to add to the adapter
74 * IpMask [In] subnet mask for the IP address
75 * IfIndex [In] adapter index to add the address
76 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
77 * NTEInstance [Out] NTE instance for the IP address
79 * RETURNS
80 * Success: NO_ERROR
81 * Failure: error code from winerror.h
83 * FIXME
84 * Stub. Currently returns ERROR_NOT_SUPPORTED.
86 DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
88 FIXME(":stub\n");
89 return ERROR_NOT_SUPPORTED;
93 /******************************************************************
94 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
96 * Get table of local interfaces.
97 * Like GetIfTable(), but allocate the returned table from heap.
99 * PARAMS
100 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
101 * allocated and returned.
102 * bOrder [In] whether to sort the table
103 * heap [In] heap from which the table is allocated
104 * flags [In] flags to HeapAlloc
106 * RETURNS
107 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
108 * GetIfTable() returns otherwise.
110 DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
111 BOOL bOrder, HANDLE heap, DWORD flags)
113 DWORD ret;
115 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable,
116 bOrder, heap, flags);
117 if (!ppIfTable)
118 ret = ERROR_INVALID_PARAMETER;
119 else {
120 DWORD dwSize = 0;
122 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
123 if (ret == ERROR_INSUFFICIENT_BUFFER) {
124 *ppIfTable = HeapAlloc(heap, flags, dwSize);
125 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
128 TRACE("returning %d\n", ret);
129 return ret;
133 static int IpAddrTableSorter(const void *a, const void *b)
135 int ret;
137 if (a && b)
138 ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
139 else
140 ret = 0;
141 return ret;
145 /******************************************************************
146 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
148 * Get interface-to-IP address mapping table.
149 * Like GetIpAddrTable(), but allocate the returned table from heap.
151 * PARAMS
152 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
153 * allocated and returned.
154 * bOrder [In] whether to sort the table
155 * heap [In] heap from which the table is allocated
156 * flags [In] flags to HeapAlloc
158 * RETURNS
159 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
160 * failure, NO_ERROR on success.
162 DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
163 BOOL bOrder, HANDLE heap, DWORD flags)
165 DWORD ret;
167 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
168 ppIpAddrTable, bOrder, heap, flags);
169 ret = getIPAddrTable(ppIpAddrTable, heap, flags);
170 if (!ret && bOrder)
171 qsort((*ppIpAddrTable)->table, (*ppIpAddrTable)->dwNumEntries,
172 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
173 TRACE("returning %d\n", ret);
174 return ret;
178 /******************************************************************
179 * CancelIPChangeNotify (IPHLPAPI.@)
181 * Cancel a previous notification created by NotifyAddrChange or
182 * NotifyRouteChange.
184 * PARAMS
185 * overlapped [In] overlapped structure that notifies the caller
187 * RETURNS
188 * Success: TRUE
189 * Failure: FALSE
191 * FIXME
192 * Stub, returns FALSE.
194 BOOL WINAPI CancelIPChangeNotify(LPOVERLAPPED overlapped)
196 FIXME("(overlapped %p): stub\n", overlapped);
197 return FALSE;
201 /******************************************************************
202 * CancelMibChangeNotify2 (IPHLPAPI.@)
204 DWORD WINAPI CancelMibChangeNotify2(HANDLE handle)
206 FIXME("(handle %p): stub\n", handle);
207 return NO_ERROR;
211 /******************************************************************
212 * CreateIpForwardEntry (IPHLPAPI.@)
214 * Create a route in the local computer's IP table.
216 * PARAMS
217 * pRoute [In] new route information
219 * RETURNS
220 * Success: NO_ERROR
221 * Failure: error code from winerror.h
223 * FIXME
224 * Stub, always returns NO_ERROR.
226 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
228 FIXME("(pRoute %p): stub\n", pRoute);
229 /* could use SIOCADDRT, not sure I want to */
230 return 0;
234 /******************************************************************
235 * CreateIpNetEntry (IPHLPAPI.@)
237 * Create entry in the ARP table.
239 * PARAMS
240 * pArpEntry [In] new ARP entry
242 * RETURNS
243 * Success: NO_ERROR
244 * Failure: error code from winerror.h
246 * FIXME
247 * Stub, always returns NO_ERROR.
249 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
251 FIXME("(pArpEntry %p)\n", pArpEntry);
252 /* could use SIOCSARP on systems that support it, not sure I want to */
253 return 0;
257 /******************************************************************
258 * CreateProxyArpEntry (IPHLPAPI.@)
260 * Create a Proxy ARP (PARP) entry for an IP address.
262 * PARAMS
263 * dwAddress [In] IP address for which this computer acts as a proxy.
264 * dwMask [In] subnet mask for dwAddress
265 * dwIfIndex [In] interface index
267 * RETURNS
268 * Success: NO_ERROR
269 * Failure: error code from winerror.h
271 * FIXME
272 * Stub, returns ERROR_NOT_SUPPORTED.
274 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
276 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
277 dwAddress, dwMask, dwIfIndex);
278 return ERROR_NOT_SUPPORTED;
282 /******************************************************************
283 * CreateSortedAddressPairs (IPHLPAPI.@)
285 DWORD WINAPI CreateSortedAddressPairs(const PSOCKADDR_IN6 source, DWORD sourcecount,
286 const PSOCKADDR_IN6 destination, DWORD destinationcount,
287 DWORD sortoptions,
288 PSOCKADDR_IN6_PAIR *sortedaddr, DWORD *sortedcount)
290 FIXME("(source %p, sourcecount %d, destination %p, destcount %d, sortoptions %x,"
291 " sortedaddr %p, sortedcount %p): stub\n", source, sourcecount, destination,
292 destinationcount, sortoptions, sortedaddr, sortedcount);
294 if (source || sourcecount || !destination || !sortedaddr || !sortedcount || destinationcount > 500)
295 return ERROR_INVALID_PARAMETER;
297 /* Returning not supported tells the client we don't have IPv6 support
298 * so applications can fallback to IPv4.
300 return ERROR_NOT_SUPPORTED;
304 /******************************************************************
305 * DeleteIPAddress (IPHLPAPI.@)
307 * Delete an IP address added with AddIPAddress().
309 * PARAMS
310 * NTEContext [In] NTE context from AddIPAddress();
312 * RETURNS
313 * Success: NO_ERROR
314 * Failure: error code from winerror.h
316 * FIXME
317 * Stub, returns ERROR_NOT_SUPPORTED.
319 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
321 FIXME("(NTEContext %d): stub\n", NTEContext);
322 return ERROR_NOT_SUPPORTED;
326 /******************************************************************
327 * DeleteIpForwardEntry (IPHLPAPI.@)
329 * Delete a route.
331 * PARAMS
332 * pRoute [In] route to delete
334 * RETURNS
335 * Success: NO_ERROR
336 * Failure: error code from winerror.h
338 * FIXME
339 * Stub, returns NO_ERROR.
341 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
343 FIXME("(pRoute %p): stub\n", pRoute);
344 /* could use SIOCDELRT, not sure I want to */
345 return 0;
349 /******************************************************************
350 * DeleteIpNetEntry (IPHLPAPI.@)
352 * Delete an ARP entry.
354 * PARAMS
355 * pArpEntry [In] ARP entry to delete
357 * RETURNS
358 * Success: NO_ERROR
359 * Failure: error code from winerror.h
361 * FIXME
362 * Stub, returns NO_ERROR.
364 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
366 FIXME("(pArpEntry %p): stub\n", pArpEntry);
367 /* could use SIOCDARP on systems that support it, not sure I want to */
368 return 0;
372 /******************************************************************
373 * DeleteProxyArpEntry (IPHLPAPI.@)
375 * Delete a Proxy ARP entry.
377 * PARAMS
378 * dwAddress [In] IP address for which this computer acts as a proxy.
379 * dwMask [In] subnet mask for dwAddress
380 * dwIfIndex [In] interface index
382 * RETURNS
383 * Success: NO_ERROR
384 * Failure: error code from winerror.h
386 * FIXME
387 * Stub, returns ERROR_NOT_SUPPORTED.
389 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
391 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
392 dwAddress, dwMask, dwIfIndex);
393 return ERROR_NOT_SUPPORTED;
397 /******************************************************************
398 * EnableRouter (IPHLPAPI.@)
400 * Turn on ip forwarding.
402 * PARAMS
403 * pHandle [In/Out]
404 * pOverlapped [In/Out] hEvent member should contain a valid handle.
406 * RETURNS
407 * Success: ERROR_IO_PENDING
408 * Failure: error code from winerror.h
410 * FIXME
411 * Stub, returns ERROR_NOT_SUPPORTED.
413 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
415 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle, pOverlapped);
416 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
417 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
419 return ERROR_NOT_SUPPORTED;
423 /******************************************************************
424 * FlushIpNetTable (IPHLPAPI.@)
426 * Delete all ARP entries of an interface
428 * PARAMS
429 * dwIfIndex [In] interface index
431 * RETURNS
432 * Success: NO_ERROR
433 * Failure: error code from winerror.h
435 * FIXME
436 * Stub, returns ERROR_NOT_SUPPORTED.
438 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
440 FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex);
441 /* this flushes the arp cache of the given index */
442 return ERROR_NOT_SUPPORTED;
445 /******************************************************************
446 * FreeMibTable (IPHLPAPI.@)
448 * Free buffer allocated by network functions
450 * PARAMS
451 * ptr [In] pointer to the buffer to free
454 void WINAPI FreeMibTable(void *ptr)
456 TRACE("(%p)\n", ptr);
457 HeapFree(GetProcessHeap(), 0, ptr);
460 /******************************************************************
461 * GetAdapterIndex (IPHLPAPI.@)
463 * Get interface index from its name.
465 * PARAMS
466 * AdapterName [In] unicode string with the adapter name
467 * IfIndex [Out] returns found interface index
469 * RETURNS
470 * Success: NO_ERROR
471 * Failure: error code from winerror.h
473 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
475 char adapterName[MAX_ADAPTER_NAME];
476 unsigned int i;
477 DWORD ret;
479 TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName, IfIndex);
480 /* The adapter name is guaranteed not to have any unicode characters, so
481 * this translation is never lossy */
482 for (i = 0; i < sizeof(adapterName) - 1 && AdapterName[i]; i++)
483 adapterName[i] = (char)AdapterName[i];
484 adapterName[i] = '\0';
485 ret = getInterfaceIndexByName(adapterName, IfIndex);
486 TRACE("returning %d\n", ret);
487 return ret;
491 /******************************************************************
492 * GetAdaptersInfo (IPHLPAPI.@)
494 * Get information about adapters.
496 * PARAMS
497 * pAdapterInfo [Out] buffer for adapter infos
498 * pOutBufLen [In] length of output buffer
500 * RETURNS
501 * Success: NO_ERROR
502 * Failure: error code from winerror.h
504 DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
506 DWORD ret;
508 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
509 if (!pOutBufLen)
510 ret = ERROR_INVALID_PARAMETER;
511 else {
512 DWORD numNonLoopbackInterfaces = get_interface_indices( TRUE, NULL );
514 if (numNonLoopbackInterfaces > 0) {
515 DWORD numIPAddresses = getNumIPAddresses();
516 ULONG size;
518 /* This may slightly overestimate the amount of space needed, because
519 * the IP addresses include the loopback address, but it's easier
520 * to make sure there's more than enough space than to make sure there's
521 * precisely enough space.
523 size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
524 size += numIPAddresses * sizeof(IP_ADDR_STRING);
525 if (!pAdapterInfo || *pOutBufLen < size) {
526 *pOutBufLen = size;
527 ret = ERROR_BUFFER_OVERFLOW;
529 else {
530 InterfaceIndexTable *table = NULL;
531 PMIB_IPADDRTABLE ipAddrTable = NULL;
532 PMIB_IPFORWARDTABLE routeTable = NULL;
534 ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
535 if (!ret)
536 ret = AllocateAndGetIpForwardTableFromStack(&routeTable, FALSE, GetProcessHeap(), 0);
537 if (!ret)
538 get_interface_indices( TRUE, &table );
539 if (table) {
540 size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
541 size += ipAddrTable->dwNumEntries * sizeof(IP_ADDR_STRING);
542 if (*pOutBufLen < size) {
543 *pOutBufLen = size;
544 ret = ERROR_INSUFFICIENT_BUFFER;
546 else {
547 DWORD ndx;
548 HKEY hKey;
549 BOOL winsEnabled = FALSE;
550 IP_ADDRESS_STRING primaryWINS, secondaryWINS;
551 PIP_ADDR_STRING nextIPAddr = (PIP_ADDR_STRING)((LPBYTE)pAdapterInfo
552 + numNonLoopbackInterfaces * sizeof(IP_ADAPTER_INFO));
554 memset(pAdapterInfo, 0, size);
555 /* @@ Wine registry key: HKCU\Software\Wine\Network */
556 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network",
557 &hKey) == ERROR_SUCCESS) {
558 DWORD size = sizeof(primaryWINS.String);
559 unsigned long addr;
561 RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
562 (LPBYTE)primaryWINS.String, &size);
563 addr = inet_addr(primaryWINS.String);
564 if (addr != INADDR_NONE && addr != INADDR_ANY)
565 winsEnabled = TRUE;
566 size = sizeof(secondaryWINS.String);
567 RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
568 (LPBYTE)secondaryWINS.String, &size);
569 addr = inet_addr(secondaryWINS.String);
570 if (addr != INADDR_NONE && addr != INADDR_ANY)
571 winsEnabled = TRUE;
572 RegCloseKey(hKey);
574 for (ndx = 0; ndx < table->numIndexes; ndx++) {
575 PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
576 DWORD i;
577 PIP_ADDR_STRING currentIPAddr = &ptr->IpAddressList;
578 BOOL firstIPAddr = TRUE;
580 /* on Win98 this is left empty, but whatever */
581 getInterfaceNameByIndex(table->indexes[ndx], ptr->AdapterName);
582 getInterfaceNameByIndex(table->indexes[ndx], ptr->Description);
583 ptr->AddressLength = sizeof(ptr->Address);
584 getInterfacePhysicalByIndex(table->indexes[ndx],
585 &ptr->AddressLength, ptr->Address, &ptr->Type);
586 ptr->Index = table->indexes[ndx];
587 for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
588 if (ipAddrTable->table[i].dwIndex == ptr->Index) {
589 if (firstIPAddr) {
590 toIPAddressString(ipAddrTable->table[i].dwAddr,
591 ptr->IpAddressList.IpAddress.String);
592 toIPAddressString(ipAddrTable->table[i].dwMask,
593 ptr->IpAddressList.IpMask.String);
594 firstIPAddr = FALSE;
596 else {
597 currentIPAddr->Next = nextIPAddr;
598 currentIPAddr = nextIPAddr;
599 toIPAddressString(ipAddrTable->table[i].dwAddr,
600 currentIPAddr->IpAddress.String);
601 toIPAddressString(ipAddrTable->table[i].dwMask,
602 currentIPAddr->IpMask.String);
603 nextIPAddr++;
607 /* If no IP was found it probably means that the interface is not
608 * configured. In this case we have to return a zeroed IP and mask. */
609 if (firstIPAddr) {
610 strcpy(ptr->IpAddressList.IpAddress.String, "0.0.0.0");
611 strcpy(ptr->IpAddressList.IpMask.String, "0.0.0.0");
613 /* Find first router through this interface, which we'll assume
614 * is the default gateway for this adapter */
615 for (i = 0; i < routeTable->dwNumEntries; i++)
616 if (routeTable->table[i].dwForwardIfIndex == ptr->Index
617 && routeTable->table[i].u1.ForwardType ==
618 MIB_IPROUTE_TYPE_INDIRECT)
620 toIPAddressString(routeTable->table[i].dwForwardNextHop,
621 ptr->GatewayList.IpAddress.String);
622 toIPAddressString(routeTable->table[i].dwForwardMask,
623 ptr->GatewayList.IpMask.String);
625 if (winsEnabled) {
626 ptr->HaveWins = TRUE;
627 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
628 primaryWINS.String, sizeof(primaryWINS.String));
629 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
630 secondaryWINS.String, sizeof(secondaryWINS.String));
632 if (ndx < table->numIndexes - 1)
633 ptr->Next = &pAdapterInfo[ndx + 1];
634 else
635 ptr->Next = NULL;
637 ptr->DhcpEnabled = TRUE;
639 ret = NO_ERROR;
641 HeapFree(GetProcessHeap(), 0, table);
643 else
644 ret = ERROR_OUTOFMEMORY;
645 HeapFree(GetProcessHeap(), 0, routeTable);
646 HeapFree(GetProcessHeap(), 0, ipAddrTable);
649 else
650 ret = ERROR_NO_DATA;
652 TRACE("returning %d\n", ret);
653 return ret;
656 static DWORD typeFromMibType(DWORD mib_type)
658 switch (mib_type)
660 case MIB_IF_TYPE_ETHERNET: return IF_TYPE_ETHERNET_CSMACD;
661 case MIB_IF_TYPE_TOKENRING: return IF_TYPE_ISO88025_TOKENRING;
662 case MIB_IF_TYPE_PPP: return IF_TYPE_PPP;
663 case MIB_IF_TYPE_LOOPBACK: return IF_TYPE_SOFTWARE_LOOPBACK;
664 default: return IF_TYPE_OTHER;
668 static NET_IF_CONNECTION_TYPE connectionTypeFromMibType(DWORD mib_type)
670 switch (mib_type)
672 case MIB_IF_TYPE_PPP: return NET_IF_CONNECTION_DEMAND;
673 case MIB_IF_TYPE_SLIP: return NET_IF_CONNECTION_DEMAND;
674 default: return NET_IF_CONNECTION_DEDICATED;
678 static ULONG v4addressesFromIndex(IF_INDEX index, DWORD **addrs, ULONG *num_addrs, DWORD **masks)
680 ULONG ret, i, j;
681 MIB_IPADDRTABLE *at;
683 *num_addrs = 0;
684 if ((ret = getIPAddrTable(&at, GetProcessHeap(), 0))) return ret;
685 for (i = 0; i < at->dwNumEntries; i++)
687 if (at->table[i].dwIndex == index) (*num_addrs)++;
689 if (!(*addrs = HeapAlloc(GetProcessHeap(), 0, *num_addrs * sizeof(DWORD))))
691 HeapFree(GetProcessHeap(), 0, at);
692 return ERROR_OUTOFMEMORY;
694 if (!(*masks = HeapAlloc(GetProcessHeap(), 0, *num_addrs * sizeof(DWORD))))
696 HeapFree(GetProcessHeap(), 0, *addrs);
697 HeapFree(GetProcessHeap(), 0, at);
698 return ERROR_OUTOFMEMORY;
700 for (i = 0, j = 0; i < at->dwNumEntries; i++)
702 if (at->table[i].dwIndex == index)
704 (*addrs)[j] = at->table[i].dwAddr;
705 (*masks)[j] = at->table[i].dwMask;
706 j++;
709 HeapFree(GetProcessHeap(), 0, at);
710 return ERROR_SUCCESS;
713 static char *debugstr_ipv4(const in_addr_t *in_addr, char *buf)
715 const BYTE *addrp;
716 char *p = buf;
718 for (addrp = (const BYTE *)in_addr;
719 addrp - (const BYTE *)in_addr < sizeof(*in_addr);
720 addrp++)
722 if (addrp == (const BYTE *)in_addr + sizeof(*in_addr) - 1)
723 sprintf(p, "%d", *addrp);
724 else
725 p += sprintf(p, "%d.", *addrp);
727 return buf;
730 static char *debugstr_ipv6(const struct WS_sockaddr_in6 *sin, char *buf)
732 const IN6_ADDR *addr = &sin->sin6_addr;
733 char *p = buf;
734 int i;
735 BOOL in_zero = FALSE;
737 for (i = 0; i < 7; i++)
739 if (!addr->u.Word[i])
741 if (i == 0)
742 *p++ = ':';
743 if (!in_zero)
745 *p++ = ':';
746 in_zero = TRUE;
749 else
751 p += sprintf(p, "%x:", ntohs(addr->u.Word[i]));
752 in_zero = FALSE;
755 sprintf(p, "%x", ntohs(addr->u.Word[7]));
756 return buf;
759 static ULONG count_v4_gateways(DWORD index, PMIB_IPFORWARDTABLE routeTable)
761 DWORD i, num_gateways = 0;
763 for (i = 0; i < routeTable->dwNumEntries; i++)
765 if (routeTable->table[i].dwForwardIfIndex == index &&
766 routeTable->table[i].u1.ForwardType == MIB_IPROUTE_TYPE_INDIRECT)
767 num_gateways++;
769 return num_gateways;
772 static PMIB_IPFORWARDROW findIPv4Gateway(DWORD index,
773 PMIB_IPFORWARDTABLE routeTable)
775 DWORD i;
776 PMIB_IPFORWARDROW row = NULL;
778 for (i = 0; !row && i < routeTable->dwNumEntries; i++)
780 if (routeTable->table[i].dwForwardIfIndex == index &&
781 routeTable->table[i].u1.ForwardType == MIB_IPROUTE_TYPE_INDIRECT)
782 row = &routeTable->table[i];
784 return row;
787 static ULONG adapterAddressesFromIndex(ULONG family, ULONG flags, IF_INDEX index,
788 IP_ADAPTER_ADDRESSES *aa, ULONG *size)
790 ULONG ret = ERROR_SUCCESS, i, j, num_v4addrs = 0, num_v4_gateways = 0, num_v6addrs = 0, total_size;
791 DWORD *v4addrs = NULL, *v4masks = NULL;
792 SOCKET_ADDRESS *v6addrs = NULL, *v6masks = NULL;
793 PMIB_IPFORWARDTABLE routeTable = NULL;
795 if (family == WS_AF_INET)
797 ret = v4addressesFromIndex(index, &v4addrs, &num_v4addrs, &v4masks);
799 if (!ret && flags & GAA_FLAG_INCLUDE_ALL_GATEWAYS)
801 ret = AllocateAndGetIpForwardTableFromStack(&routeTable, FALSE, GetProcessHeap(), 0);
802 if (!ret) num_v4_gateways = count_v4_gateways(index, routeTable);
805 else if (family == WS_AF_INET6)
807 ret = v6addressesFromIndex(index, &v6addrs, &num_v6addrs, &v6masks);
809 else if (family == WS_AF_UNSPEC)
811 ret = v4addressesFromIndex(index, &v4addrs, &num_v4addrs, &v4masks);
813 if (!ret && flags & GAA_FLAG_INCLUDE_ALL_GATEWAYS)
815 ret = AllocateAndGetIpForwardTableFromStack(&routeTable, FALSE, GetProcessHeap(), 0);
816 if (!ret) num_v4_gateways = count_v4_gateways(index, routeTable);
818 if (!ret) ret = v6addressesFromIndex(index, &v6addrs, &num_v6addrs, &v6masks);
820 else
822 FIXME("address family %u unsupported\n", family);
823 ret = ERROR_NO_DATA;
825 if (ret)
827 HeapFree(GetProcessHeap(), 0, v4addrs);
828 HeapFree(GetProcessHeap(), 0, v4masks);
829 HeapFree(GetProcessHeap(), 0, v6addrs);
830 HeapFree(GetProcessHeap(), 0, v6masks);
831 HeapFree(GetProcessHeap(), 0, routeTable);
832 return ret;
835 total_size = sizeof(IP_ADAPTER_ADDRESSES);
836 total_size += IF_NAMESIZE;
837 total_size += IF_NAMESIZE * sizeof(WCHAR);
838 if (!(flags & GAA_FLAG_SKIP_FRIENDLY_NAME))
839 total_size += IF_NAMESIZE * sizeof(WCHAR);
840 if (flags & GAA_FLAG_INCLUDE_PREFIX)
842 total_size += sizeof(IP_ADAPTER_PREFIX) * num_v4addrs;
843 total_size += sizeof(IP_ADAPTER_PREFIX) * num_v6addrs;
844 total_size += sizeof(struct sockaddr_in) * num_v4addrs;
845 for (i = 0; i < num_v6addrs; i++)
846 total_size += v6masks[i].iSockaddrLength;
848 total_size += sizeof(IP_ADAPTER_UNICAST_ADDRESS) * num_v4addrs;
849 total_size += sizeof(struct sockaddr_in) * num_v4addrs;
850 total_size += (sizeof(IP_ADAPTER_GATEWAY_ADDRESS) + sizeof(SOCKADDR_IN)) * num_v4_gateways;
851 total_size += sizeof(IP_ADAPTER_UNICAST_ADDRESS) * num_v6addrs;
852 total_size += sizeof(SOCKET_ADDRESS) * num_v6addrs;
853 for (i = 0; i < num_v6addrs; i++)
854 total_size += v6addrs[i].iSockaddrLength;
856 if (aa && *size >= total_size)
858 char name[IF_NAMESIZE], *ptr = (char *)aa + sizeof(IP_ADAPTER_ADDRESSES), *src;
859 WCHAR *dst;
860 DWORD buflen, type;
861 INTERNAL_IF_OPER_STATUS status;
863 memset(aa, 0, sizeof(IP_ADAPTER_ADDRESSES));
864 aa->u.s.Length = sizeof(IP_ADAPTER_ADDRESSES);
865 aa->u.s.IfIndex = index;
867 getInterfaceNameByIndex(index, name);
868 memcpy(ptr, name, IF_NAMESIZE);
869 aa->AdapterName = ptr;
870 ptr += IF_NAMESIZE;
871 if (!(flags & GAA_FLAG_SKIP_FRIENDLY_NAME))
873 aa->FriendlyName = (WCHAR *)ptr;
874 for (src = name, dst = (WCHAR *)ptr; *src; src++, dst++)
875 *dst = *src;
876 *dst++ = 0;
877 ptr = (char *)dst;
879 aa->Description = (WCHAR *)ptr;
880 for (src = name, dst = (WCHAR *)ptr; *src; src++, dst++)
881 *dst = *src;
882 *dst++ = 0;
883 ptr = (char *)dst;
885 TRACE("%s: %d IPv4 addresses, %d IPv6 addresses:\n", name, num_v4addrs,
886 num_v6addrs);
887 if (num_v4_gateways)
889 PMIB_IPFORWARDROW adapterRow;
891 if ((adapterRow = findIPv4Gateway(index, routeTable)))
893 PIP_ADAPTER_GATEWAY_ADDRESS gw;
894 PSOCKADDR_IN sin;
896 gw = (PIP_ADAPTER_GATEWAY_ADDRESS)ptr;
897 aa->FirstGatewayAddress = gw;
899 gw->u.s.Length = sizeof(IP_ADAPTER_GATEWAY_ADDRESS);
900 ptr += sizeof(IP_ADAPTER_GATEWAY_ADDRESS);
901 sin = (PSOCKADDR_IN)ptr;
902 sin->sin_family = AF_INET;
903 sin->sin_port = 0;
904 memcpy(&sin->sin_addr, &adapterRow->dwForwardNextHop,
905 sizeof(DWORD));
906 gw->Address.lpSockaddr = (LPSOCKADDR)sin;
907 gw->Address.iSockaddrLength = sizeof(SOCKADDR_IN);
908 gw->Next = NULL;
909 ptr += sizeof(SOCKADDR_IN);
912 if (num_v4addrs && !(flags & GAA_FLAG_SKIP_UNICAST))
914 IP_ADAPTER_UNICAST_ADDRESS *ua;
915 struct WS_sockaddr_in *sa;
916 aa->Flags |= IP_ADAPTER_IPV4_ENABLED;
917 ua = aa->FirstUnicastAddress = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
918 for (i = 0; i < num_v4addrs; i++)
920 char addr_buf[16];
922 memset(ua, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS));
923 ua->u.s.Length = sizeof(IP_ADAPTER_UNICAST_ADDRESS);
924 ua->Address.iSockaddrLength = sizeof(struct sockaddr_in);
925 ua->Address.lpSockaddr = (SOCKADDR *)((char *)ua + ua->u.s.Length);
927 sa = (struct WS_sockaddr_in *)ua->Address.lpSockaddr;
928 sa->sin_family = WS_AF_INET;
929 sa->sin_addr.S_un.S_addr = v4addrs[i];
930 sa->sin_port = 0;
931 TRACE("IPv4 %d/%d: %s\n", i + 1, num_v4addrs,
932 debugstr_ipv4(&sa->sin_addr.S_un.S_addr, addr_buf));
934 ptr += ua->u.s.Length + ua->Address.iSockaddrLength;
935 if (i < num_v4addrs - 1)
937 ua->Next = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
938 ua = ua->Next;
942 if (num_v6addrs && !(flags & GAA_FLAG_SKIP_UNICAST))
944 IP_ADAPTER_UNICAST_ADDRESS *ua;
945 struct WS_sockaddr_in6 *sa;
947 aa->Flags |= IP_ADAPTER_IPV6_ENABLED;
948 if (aa->FirstUnicastAddress)
950 for (ua = aa->FirstUnicastAddress; ua->Next; ua = ua->Next)
952 ua->Next = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
953 ua = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
955 else
956 ua = aa->FirstUnicastAddress = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
957 for (i = 0; i < num_v6addrs; i++)
959 char addr_buf[46];
961 memset(ua, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS));
962 ua->u.s.Length = sizeof(IP_ADAPTER_UNICAST_ADDRESS);
963 ua->Address.iSockaddrLength = v6addrs[i].iSockaddrLength;
964 ua->Address.lpSockaddr = (SOCKADDR *)((char *)ua + ua->u.s.Length);
966 sa = (struct WS_sockaddr_in6 *)ua->Address.lpSockaddr;
967 memcpy(sa, v6addrs[i].lpSockaddr, sizeof(*sa));
968 TRACE("IPv6 %d/%d: %s\n", i + 1, num_v6addrs,
969 debugstr_ipv6(sa, addr_buf));
971 ptr += ua->u.s.Length + ua->Address.iSockaddrLength;
972 if (i < num_v6addrs - 1)
974 ua->Next = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
975 ua = ua->Next;
979 if (num_v4addrs && (flags & GAA_FLAG_INCLUDE_PREFIX))
981 IP_ADAPTER_PREFIX *prefix;
983 prefix = aa->FirstPrefix = (IP_ADAPTER_PREFIX *)ptr;
984 for (i = 0; i < num_v4addrs; i++)
986 char addr_buf[16];
987 struct WS_sockaddr_in *sa;
989 prefix->u.s.Length = sizeof(*prefix);
990 prefix->u.s.Flags = 0;
991 prefix->Next = NULL;
992 prefix->Address.iSockaddrLength = sizeof(struct sockaddr_in);
993 prefix->Address.lpSockaddr = (SOCKADDR *)((char *)prefix + prefix->u.s.Length);
995 sa = (struct WS_sockaddr_in *)prefix->Address.lpSockaddr;
996 sa->sin_family = WS_AF_INET;
997 sa->sin_addr.S_un.S_addr = v4addrs[i] & v4masks[i];
998 sa->sin_port = 0;
1000 prefix->PrefixLength = 0;
1001 for (j = 0; j < sizeof(*v4masks) * 8; j++)
1003 if (v4masks[i] & 1 << j) prefix->PrefixLength++;
1004 else break;
1006 TRACE("IPv4 network: %s/%u\n",
1007 debugstr_ipv4((const in_addr_t *)&sa->sin_addr.S_un.S_addr, addr_buf),
1008 prefix->PrefixLength);
1010 ptr += prefix->u.s.Length + prefix->Address.iSockaddrLength;
1011 if (i < num_v4addrs - 1)
1013 prefix->Next = (IP_ADAPTER_PREFIX *)ptr;
1014 prefix = prefix->Next;
1018 if (num_v6addrs && (flags & GAA_FLAG_INCLUDE_PREFIX))
1020 IP_ADAPTER_PREFIX *prefix;
1022 if (aa->FirstPrefix)
1024 for (prefix = aa->FirstPrefix; prefix->Next; prefix = prefix->Next)
1026 prefix->Next = (IP_ADAPTER_PREFIX *)ptr;
1027 prefix = (IP_ADAPTER_PREFIX *)ptr;
1029 else
1030 prefix = aa->FirstPrefix = (IP_ADAPTER_PREFIX *)ptr;
1031 for (i = 0; i < num_v6addrs; i++)
1033 char addr_buf[46];
1034 struct WS_sockaddr_in6 *sa;
1035 const IN6_ADDR *addr, *mask;
1036 BOOL done = FALSE;
1037 ULONG k;
1039 prefix->u.s.Length = sizeof(*prefix);
1040 prefix->u.s.Flags = 0;
1041 prefix->Next = NULL;
1042 prefix->Address.iSockaddrLength = sizeof(struct sockaddr_in6);
1043 prefix->Address.lpSockaddr = (SOCKADDR *)((char *)prefix + prefix->u.s.Length);
1045 sa = (struct WS_sockaddr_in6 *)prefix->Address.lpSockaddr;
1046 sa->sin6_family = WS_AF_INET6;
1047 sa->sin6_port = 0;
1048 sa->sin6_flowinfo = 0;
1049 addr = &((struct WS_sockaddr_in6 *)v6addrs[i].lpSockaddr)->sin6_addr;
1050 mask = &((struct WS_sockaddr_in6 *)v6masks[i].lpSockaddr)->sin6_addr;
1051 for (j = 0; j < 8; j++) sa->sin6_addr.u.Word[j] = addr->u.Word[j] & mask->u.Word[j];
1052 sa->sin6_scope_id = 0;
1054 prefix->PrefixLength = 0;
1055 for (k = 0; k < 8 && !done; k++)
1057 for (j = 0; j < sizeof(WORD) * 8 && !done; j++)
1059 if (mask->u.Word[k] & 1 << j) prefix->PrefixLength++;
1060 else done = TRUE;
1063 TRACE("IPv6 network: %s/%u\n", debugstr_ipv6(sa, addr_buf), prefix->PrefixLength);
1065 ptr += prefix->u.s.Length + prefix->Address.iSockaddrLength;
1066 if (i < num_v6addrs - 1)
1068 prefix->Next = (IP_ADAPTER_PREFIX *)ptr;
1069 prefix = prefix->Next;
1074 buflen = MAX_INTERFACE_PHYSADDR;
1075 getInterfacePhysicalByIndex(index, &buflen, aa->PhysicalAddress, &type);
1076 aa->PhysicalAddressLength = buflen;
1077 aa->IfType = typeFromMibType(type);
1078 aa->ConnectionType = connectionTypeFromMibType(type);
1080 getInterfaceMtuByName(name, &aa->Mtu);
1082 getInterfaceStatusByName(name, &status);
1083 if (status == MIB_IF_OPER_STATUS_OPERATIONAL) aa->OperStatus = IfOperStatusUp;
1084 else if (status == MIB_IF_OPER_STATUS_NON_OPERATIONAL) aa->OperStatus = IfOperStatusDown;
1085 else aa->OperStatus = IfOperStatusUnknown;
1087 *size = total_size;
1088 HeapFree(GetProcessHeap(), 0, routeTable);
1089 HeapFree(GetProcessHeap(), 0, v6addrs);
1090 HeapFree(GetProcessHeap(), 0, v6masks);
1091 HeapFree(GetProcessHeap(), 0, v4addrs);
1092 HeapFree(GetProcessHeap(), 0, v4masks);
1093 return ERROR_SUCCESS;
1096 static void sockaddr_in_to_WS_storage( SOCKADDR_STORAGE *dst, const struct sockaddr_in *src )
1098 SOCKADDR_IN *s = (SOCKADDR_IN *)dst;
1100 s->sin_family = WS_AF_INET;
1101 s->sin_port = src->sin_port;
1102 memcpy( &s->sin_addr, &src->sin_addr, sizeof(IN_ADDR) );
1103 memset( (char *)s + FIELD_OFFSET( SOCKADDR_IN, sin_zero ), 0,
1104 sizeof(SOCKADDR_STORAGE) - FIELD_OFFSET( SOCKADDR_IN, sin_zero) );
1107 static void sockaddr_in6_to_WS_storage( SOCKADDR_STORAGE *dst, const struct sockaddr_in6 *src )
1109 SOCKADDR_IN6 *s = (SOCKADDR_IN6 *)dst;
1111 s->sin6_family = WS_AF_INET6;
1112 s->sin6_port = src->sin6_port;
1113 s->sin6_flowinfo = src->sin6_flowinfo;
1114 memcpy( &s->sin6_addr, &src->sin6_addr, sizeof(IN6_ADDR) );
1115 s->sin6_scope_id = src->sin6_scope_id;
1116 memset( (char *)s + sizeof(SOCKADDR_IN6), 0,
1117 sizeof(SOCKADDR_STORAGE) - sizeof(SOCKADDR_IN6) );
1120 #ifdef HAVE_STRUCT___RES_STATE
1121 /* call res_init() just once because of a bug in Mac OS X 10.4 */
1122 /* Call once per thread on systems that have per-thread _res. */
1124 static CRITICAL_SECTION res_init_cs;
1125 static CRITICAL_SECTION_DEBUG res_init_cs_debug = {
1126 0, 0, &res_init_cs,
1127 { &res_init_cs_debug.ProcessLocksList, &res_init_cs_debug.ProcessLocksList },
1128 0, 0, { (DWORD_PTR)(__FILE__ ": res_init_cs") }
1130 static CRITICAL_SECTION res_init_cs = { &res_init_cs_debug, -1, 0, 0, 0, 0 };
1132 static void initialise_resolver(void)
1134 EnterCriticalSection(&res_init_cs);
1135 if ((_res.options & RES_INIT) == 0)
1136 res_init();
1137 LeaveCriticalSection(&res_init_cs);
1140 static int get_dns_servers( SOCKADDR_STORAGE *servers, int num, BOOL ip4_only )
1142 int i, ip6_count = 0;
1143 SOCKADDR_STORAGE *addr;
1145 initialise_resolver();
1147 #ifdef HAVE_STRUCT___RES_STATE__U__EXT_NSCOUNT6
1148 ip6_count = _res._u._ext.nscount6;
1149 #endif
1151 if (!servers || !num)
1153 num = _res.nscount;
1154 if (ip4_only) num -= ip6_count;
1155 return num;
1158 for (i = 0, addr = servers; addr < (servers + num) && i < _res.nscount; i++)
1160 #ifdef HAVE_STRUCT___RES_STATE__U__EXT_NSCOUNT6
1161 if (_res._u._ext.nsaddrs[i])
1163 if (ip4_only) continue;
1164 sockaddr_in6_to_WS_storage( addr, _res._u._ext.nsaddrs[i] );
1166 else
1167 #endif
1169 sockaddr_in_to_WS_storage( addr, _res.nsaddr_list + i );
1171 addr++;
1173 return addr - servers;
1175 #elif defined(HAVE___RES_GET_STATE) && defined(HAVE___RES_GETSERVERS)
1177 static int get_dns_servers( SOCKADDR_STORAGE *servers, int num, BOOL ip4_only )
1179 extern struct res_state *__res_get_state( void );
1180 extern int __res_getservers( struct res_state *, struct sockaddr_storage *, int );
1181 struct res_state *state = __res_get_state();
1182 int i, found = 0, total = __res_getservers( state, NULL, 0 );
1183 SOCKADDR_STORAGE *addr = servers;
1184 struct sockaddr_storage *buf;
1186 if ((!servers || !num) && !ip4_only) return total;
1188 buf = HeapAlloc( GetProcessHeap(), 0, total * sizeof(struct sockaddr_storage) );
1189 total = __res_getservers( state, buf, total );
1191 for (i = 0; i < total; i++)
1193 if (buf[i].ss_family == AF_INET6 && ip4_only) continue;
1194 if (buf[i].ss_family != AF_INET && buf[i].ss_family != AF_INET6) continue;
1196 found++;
1197 if (!servers || !num) continue;
1199 if (buf[i].ss_family == AF_INET6)
1201 sockaddr_in6_to_WS_storage( addr, (struct sockaddr_in6 *)(buf + i) );
1203 else
1205 sockaddr_in_to_WS_storage( addr, (struct sockaddr_in *)(buf + i) );
1207 if (++addr >= servers + num) break;
1210 HeapFree( GetProcessHeap(), 0, buf );
1211 return found;
1213 #else
1215 static int get_dns_servers( SOCKADDR_STORAGE *servers, int num, BOOL ip4_only )
1217 FIXME("Unimplemented on this system\n");
1218 return 0;
1220 #endif
1222 static ULONG get_dns_server_addresses(PIP_ADAPTER_DNS_SERVER_ADDRESS address, ULONG *len)
1224 int num = get_dns_servers( NULL, 0, FALSE );
1225 DWORD size;
1227 size = num * (sizeof(IP_ADAPTER_DNS_SERVER_ADDRESS) + sizeof(SOCKADDR_STORAGE));
1228 if (!address || *len < size)
1230 *len = size;
1231 return ERROR_BUFFER_OVERFLOW;
1233 *len = size;
1234 if (num > 0)
1236 PIP_ADAPTER_DNS_SERVER_ADDRESS addr = address;
1237 SOCKADDR_STORAGE *sock_addrs = (SOCKADDR_STORAGE *)(address + num);
1238 int i;
1240 get_dns_servers( sock_addrs, num, FALSE );
1242 for (i = 0; i < num; i++, addr = addr->Next)
1244 addr->u.s.Length = sizeof(*addr);
1245 if (sock_addrs[i].ss_family == WS_AF_INET6)
1246 addr->Address.iSockaddrLength = sizeof(SOCKADDR_IN6);
1247 else
1248 addr->Address.iSockaddrLength = sizeof(SOCKADDR_IN);
1249 addr->Address.lpSockaddr = (SOCKADDR *)(sock_addrs + i);
1250 if (i == num - 1)
1251 addr->Next = NULL;
1252 else
1253 addr->Next = addr + 1;
1256 return ERROR_SUCCESS;
1259 #ifdef HAVE_STRUCT___RES_STATE
1260 static BOOL is_ip_address_string(const char *str)
1262 struct in_addr in;
1263 int ret;
1265 ret = inet_aton(str, &in);
1266 return ret != 0;
1268 #endif
1270 static ULONG get_dns_suffix(WCHAR *suffix, ULONG *len)
1272 ULONG size;
1273 const char *found_suffix = "";
1274 /* Always return a NULL-terminated string, even if it's empty. */
1276 #ifdef HAVE_STRUCT___RES_STATE
1278 ULONG i;
1279 initialise_resolver();
1280 for (i = 0; !*found_suffix && i < MAXDNSRCH + 1 && _res.dnsrch[i]; i++)
1282 /* This uses a heuristic to select a DNS suffix:
1283 * the first, non-IP address string is selected.
1285 if (!is_ip_address_string(_res.dnsrch[i]))
1286 found_suffix = _res.dnsrch[i];
1289 #endif
1291 size = MultiByteToWideChar( CP_UNIXCP, 0, found_suffix, -1, NULL, 0 ) * sizeof(WCHAR);
1292 if (!suffix || *len < size)
1294 *len = size;
1295 return ERROR_BUFFER_OVERFLOW;
1297 *len = MultiByteToWideChar( CP_UNIXCP, 0, found_suffix, -1, suffix, *len / sizeof(WCHAR) ) * sizeof(WCHAR);
1298 return ERROR_SUCCESS;
1301 ULONG WINAPI DECLSPEC_HOTPATCH GetAdaptersAddresses(ULONG family, ULONG flags, PVOID reserved,
1302 PIP_ADAPTER_ADDRESSES aa, PULONG buflen)
1304 InterfaceIndexTable *table;
1305 ULONG i, size, dns_server_size = 0, dns_suffix_size, total_size, ret = ERROR_NO_DATA;
1307 TRACE("(%d, %08x, %p, %p, %p)\n", family, flags, reserved, aa, buflen);
1309 if (!buflen) return ERROR_INVALID_PARAMETER;
1311 get_interface_indices( FALSE, &table );
1312 if (!table || !table->numIndexes)
1314 HeapFree(GetProcessHeap(), 0, table);
1315 return ERROR_NO_DATA;
1317 total_size = 0;
1318 for (i = 0; i < table->numIndexes; i++)
1320 size = 0;
1321 if ((ret = adapterAddressesFromIndex(family, flags, table->indexes[i], NULL, &size)))
1323 HeapFree(GetProcessHeap(), 0, table);
1324 return ret;
1326 total_size += size;
1328 if (!(flags & GAA_FLAG_SKIP_DNS_SERVER))
1330 /* Since DNS servers aren't really per adapter, get enough space for a
1331 * single copy of them.
1333 get_dns_server_addresses(NULL, &dns_server_size);
1334 total_size += dns_server_size;
1336 /* Since DNS suffix also isn't really per adapter, get enough space for a
1337 * single copy of it.
1339 get_dns_suffix(NULL, &dns_suffix_size);
1340 total_size += dns_suffix_size;
1341 if (aa && *buflen >= total_size)
1343 ULONG bytes_left = size = total_size;
1344 PIP_ADAPTER_ADDRESSES first_aa = aa;
1345 PIP_ADAPTER_DNS_SERVER_ADDRESS firstDns;
1346 WCHAR *dnsSuffix;
1348 for (i = 0; i < table->numIndexes; i++)
1350 if ((ret = adapterAddressesFromIndex(family, flags, table->indexes[i], aa, &size)))
1352 HeapFree(GetProcessHeap(), 0, table);
1353 return ret;
1355 if (i < table->numIndexes - 1)
1357 aa->Next = (IP_ADAPTER_ADDRESSES *)((char *)aa + size);
1358 aa = aa->Next;
1359 size = bytes_left -= size;
1362 if (dns_server_size)
1364 firstDns = (PIP_ADAPTER_DNS_SERVER_ADDRESS)((BYTE *)first_aa + total_size - dns_server_size - dns_suffix_size);
1365 get_dns_server_addresses(firstDns, &dns_server_size);
1366 for (aa = first_aa; aa; aa = aa->Next)
1368 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK && aa->OperStatus == IfOperStatusUp)
1369 aa->FirstDnsServerAddress = firstDns;
1372 aa = first_aa;
1373 dnsSuffix = (WCHAR *)((BYTE *)aa + total_size - dns_suffix_size);
1374 get_dns_suffix(dnsSuffix, &dns_suffix_size);
1375 for (; aa; aa = aa->Next)
1377 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK && aa->OperStatus == IfOperStatusUp)
1378 aa->DnsSuffix = dnsSuffix;
1379 else
1380 aa->DnsSuffix = dnsSuffix + dns_suffix_size / sizeof(WCHAR) - 1;
1382 ret = ERROR_SUCCESS;
1384 else
1385 ret = ERROR_BUFFER_OVERFLOW;
1386 *buflen = total_size;
1388 TRACE("num adapters %u\n", table->numIndexes);
1389 HeapFree(GetProcessHeap(), 0, table);
1390 return ret;
1393 /******************************************************************
1394 * GetBestInterface (IPHLPAPI.@)
1396 * Get the interface, with the best route for the given IP address.
1398 * PARAMS
1399 * dwDestAddr [In] IP address to search the interface for
1400 * pdwBestIfIndex [Out] found best interface
1402 * RETURNS
1403 * Success: NO_ERROR
1404 * Failure: error code from winerror.h
1406 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
1408 struct WS_sockaddr_in sa_in;
1409 memset(&sa_in, 0, sizeof(sa_in));
1410 sa_in.sin_family = AF_INET;
1411 sa_in.sin_addr.S_un.S_addr = dwDestAddr;
1412 return GetBestInterfaceEx((struct WS_sockaddr *)&sa_in, pdwBestIfIndex);
1415 /******************************************************************
1416 * GetBestInterfaceEx (IPHLPAPI.@)
1418 * Get the interface, with the best route for the given IP address.
1420 * PARAMS
1421 * dwDestAddr [In] IP address to search the interface for
1422 * pdwBestIfIndex [Out] found best interface
1424 * RETURNS
1425 * Success: NO_ERROR
1426 * Failure: error code from winerror.h
1428 DWORD WINAPI GetBestInterfaceEx(struct WS_sockaddr *pDestAddr, PDWORD pdwBestIfIndex)
1430 DWORD ret;
1432 TRACE("pDestAddr %p, pdwBestIfIndex %p\n", pDestAddr, pdwBestIfIndex);
1433 if (!pDestAddr || !pdwBestIfIndex)
1434 ret = ERROR_INVALID_PARAMETER;
1435 else {
1436 MIB_IPFORWARDROW ipRow;
1438 if (pDestAddr->sa_family == AF_INET) {
1439 ret = GetBestRoute(((struct WS_sockaddr_in *)pDestAddr)->sin_addr.S_un.S_addr, 0, &ipRow);
1440 if (ret == ERROR_SUCCESS)
1441 *pdwBestIfIndex = ipRow.dwForwardIfIndex;
1442 } else {
1443 FIXME("address family %d not supported\n", pDestAddr->sa_family);
1444 ret = ERROR_NOT_SUPPORTED;
1447 TRACE("returning %d\n", ret);
1448 return ret;
1452 /******************************************************************
1453 * GetBestRoute (IPHLPAPI.@)
1455 * Get the best route for the given IP address.
1457 * PARAMS
1458 * dwDestAddr [In] IP address to search the best route for
1459 * dwSourceAddr [In] optional source IP address
1460 * pBestRoute [Out] found best route
1462 * RETURNS
1463 * Success: NO_ERROR
1464 * Failure: error code from winerror.h
1466 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
1468 PMIB_IPFORWARDTABLE table;
1469 DWORD ret;
1471 TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr,
1472 dwSourceAddr, pBestRoute);
1473 if (!pBestRoute)
1474 return ERROR_INVALID_PARAMETER;
1476 ret = AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
1477 if (!ret) {
1478 DWORD ndx, matchedBits, matchedNdx = table->dwNumEntries;
1480 for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
1481 if (table->table[ndx].u1.ForwardType != MIB_IPROUTE_TYPE_INVALID &&
1482 (dwDestAddr & table->table[ndx].dwForwardMask) ==
1483 (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
1484 DWORD numShifts, mask;
1486 for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
1487 mask && mask & 1; mask >>= 1, numShifts++)
1489 if (numShifts > matchedBits) {
1490 matchedBits = numShifts;
1491 matchedNdx = ndx;
1493 else if (!matchedBits) {
1494 matchedNdx = ndx;
1498 if (matchedNdx < table->dwNumEntries) {
1499 memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
1500 ret = ERROR_SUCCESS;
1502 else {
1503 /* No route matches, which can happen if there's no default route. */
1504 ret = ERROR_HOST_UNREACHABLE;
1506 HeapFree(GetProcessHeap(), 0, table);
1508 TRACE("returning %d\n", ret);
1509 return ret;
1513 /******************************************************************
1514 * GetFriendlyIfIndex (IPHLPAPI.@)
1516 * Get a "friendly" version of IfIndex, which is one that doesn't
1517 * have the top byte set. Doesn't validate whether IfIndex is a valid
1518 * adapter index.
1520 * PARAMS
1521 * IfIndex [In] interface index to get the friendly one for
1523 * RETURNS
1524 * A friendly version of IfIndex.
1526 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
1528 /* windows doesn't validate these, either, just makes sure the top byte is
1529 cleared. I assume my ifenum module never gives an index with the top
1530 byte set. */
1531 TRACE("returning %d\n", IfIndex);
1532 return IfIndex;
1536 /******************************************************************
1537 * GetIfEntry (IPHLPAPI.@)
1539 * Get information about an interface.
1541 * PARAMS
1542 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
1543 * Out: interface information
1545 * RETURNS
1546 * Success: NO_ERROR
1547 * Failure: error code from winerror.h
1549 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
1551 DWORD ret;
1552 char nameBuf[MAX_ADAPTER_NAME];
1553 char *name;
1555 TRACE("pIfRow %p\n", pIfRow);
1556 if (!pIfRow)
1557 return ERROR_INVALID_PARAMETER;
1559 name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf);
1560 if (name) {
1561 ret = getInterfaceEntryByName(name, pIfRow);
1562 if (ret == NO_ERROR)
1563 ret = getInterfaceStatsByName(name, pIfRow);
1565 else
1566 ret = ERROR_INVALID_DATA;
1567 TRACE("returning %d\n", ret);
1568 return ret;
1572 static int IfTableSorter(const void *a, const void *b)
1574 int ret;
1576 if (a && b)
1577 ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
1578 else
1579 ret = 0;
1580 return ret;
1584 /******************************************************************
1585 * GetIfTable (IPHLPAPI.@)
1587 * Get a table of local interfaces.
1589 * PARAMS
1590 * pIfTable [Out] buffer for local interfaces table
1591 * pdwSize [In/Out] length of output buffer
1592 * bOrder [In] whether to sort the table
1594 * RETURNS
1595 * Success: NO_ERROR
1596 * Failure: error code from winerror.h
1598 * NOTES
1599 * If pdwSize is less than required, the function will return
1600 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1601 * size.
1602 * If bOrder is true, the returned table will be sorted by interface index.
1604 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
1606 DWORD ret;
1608 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize, pdwSize,
1609 (DWORD)bOrder);
1610 if (!pdwSize)
1611 ret = ERROR_INVALID_PARAMETER;
1612 else {
1613 DWORD numInterfaces = get_interface_indices( FALSE, NULL );
1614 ULONG size = sizeof(MIB_IFTABLE);
1616 if (numInterfaces > 1)
1617 size += (numInterfaces - 1) * sizeof(MIB_IFROW);
1618 if (!pIfTable || *pdwSize < size) {
1619 *pdwSize = size;
1620 ret = ERROR_INSUFFICIENT_BUFFER;
1622 else {
1623 InterfaceIndexTable *table;
1624 get_interface_indices( FALSE, &table );
1626 if (table) {
1627 size = sizeof(MIB_IFTABLE);
1628 if (table->numIndexes > 1)
1629 size += (table->numIndexes - 1) * sizeof(MIB_IFROW);
1630 if (*pdwSize < size) {
1631 *pdwSize = size;
1632 ret = ERROR_INSUFFICIENT_BUFFER;
1634 else {
1635 DWORD ndx;
1637 *pdwSize = size;
1638 pIfTable->dwNumEntries = 0;
1639 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1640 pIfTable->table[ndx].dwIndex = table->indexes[ndx];
1641 GetIfEntry(&pIfTable->table[ndx]);
1642 pIfTable->dwNumEntries++;
1644 if (bOrder)
1645 qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
1646 IfTableSorter);
1647 ret = NO_ERROR;
1649 HeapFree(GetProcessHeap(), 0, table);
1651 else
1652 ret = ERROR_OUTOFMEMORY;
1655 TRACE("returning %d\n", ret);
1656 return ret;
1660 /******************************************************************
1661 * GetInterfaceInfo (IPHLPAPI.@)
1663 * Get a list of network interface adapters.
1665 * PARAMS
1666 * pIfTable [Out] buffer for interface adapters
1667 * dwOutBufLen [Out] if buffer is too small, returns required size
1669 * RETURNS
1670 * Success: NO_ERROR
1671 * Failure: error code from winerror.h
1673 * BUGS
1674 * MSDN states this should return non-loopback interfaces only.
1676 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
1678 DWORD ret;
1680 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1681 if (!dwOutBufLen)
1682 ret = ERROR_INVALID_PARAMETER;
1683 else {
1684 DWORD numInterfaces = get_interface_indices( FALSE, NULL );
1685 ULONG size = sizeof(IP_INTERFACE_INFO);
1687 if (numInterfaces > 1)
1688 size += (numInterfaces - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
1689 if (!pIfTable || *dwOutBufLen < size) {
1690 *dwOutBufLen = size;
1691 ret = ERROR_INSUFFICIENT_BUFFER;
1693 else {
1694 InterfaceIndexTable *table;
1695 get_interface_indices( FALSE, &table );
1697 if (table) {
1698 size = sizeof(IP_INTERFACE_INFO);
1699 if (table->numIndexes > 1)
1700 size += (table->numIndexes - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
1701 if (*dwOutBufLen < size) {
1702 *dwOutBufLen = size;
1703 ret = ERROR_INSUFFICIENT_BUFFER;
1705 else {
1706 DWORD ndx;
1707 char nameBuf[MAX_ADAPTER_NAME];
1709 *dwOutBufLen = size;
1710 pIfTable->NumAdapters = 0;
1711 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1712 const char *walker, *name;
1713 WCHAR *assigner;
1715 pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1716 name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
1717 for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
1718 walker && *walker &&
1719 assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
1720 walker++, assigner++)
1721 *assigner = *walker;
1722 *assigner = 0;
1723 pIfTable->NumAdapters++;
1725 ret = NO_ERROR;
1727 HeapFree(GetProcessHeap(), 0, table);
1729 else
1730 ret = ERROR_OUTOFMEMORY;
1733 TRACE("returning %d\n", ret);
1734 return ret;
1738 /******************************************************************
1739 * GetIpAddrTable (IPHLPAPI.@)
1741 * Get interface-to-IP address mapping table.
1743 * PARAMS
1744 * pIpAddrTable [Out] buffer for mapping table
1745 * pdwSize [In/Out] length of output buffer
1746 * bOrder [In] whether to sort the table
1748 * RETURNS
1749 * Success: NO_ERROR
1750 * Failure: error code from winerror.h
1752 * NOTES
1753 * If pdwSize is less than required, the function will return
1754 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1755 * size.
1756 * If bOrder is true, the returned table will be sorted by the next hop and
1757 * an assortment of arbitrary parameters.
1759 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1761 DWORD ret;
1763 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable, pdwSize,
1764 (DWORD)bOrder);
1765 if (!pdwSize)
1766 ret = ERROR_INVALID_PARAMETER;
1767 else {
1768 PMIB_IPADDRTABLE table;
1770 ret = getIPAddrTable(&table, GetProcessHeap(), 0);
1771 if (ret == NO_ERROR)
1773 ULONG size = FIELD_OFFSET(MIB_IPADDRTABLE, table[table->dwNumEntries]);
1775 if (!pIpAddrTable || *pdwSize < size) {
1776 *pdwSize = size;
1777 ret = ERROR_INSUFFICIENT_BUFFER;
1779 else {
1780 *pdwSize = size;
1781 memcpy(pIpAddrTable, table, size);
1782 if (bOrder)
1783 qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1784 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1785 ret = NO_ERROR;
1787 HeapFree(GetProcessHeap(), 0, table);
1790 TRACE("returning %d\n", ret);
1791 return ret;
1795 /******************************************************************
1796 * GetIpForwardTable (IPHLPAPI.@)
1798 * Get the route table.
1800 * PARAMS
1801 * pIpForwardTable [Out] buffer for route table
1802 * pdwSize [In/Out] length of output buffer
1803 * bOrder [In] whether to sort the table
1805 * RETURNS
1806 * Success: NO_ERROR
1807 * Failure: error code from winerror.h
1809 * NOTES
1810 * If pdwSize is less than required, the function will return
1811 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1812 * size.
1813 * If bOrder is true, the returned table will be sorted by the next hop and
1814 * an assortment of arbitrary parameters.
1816 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1818 DWORD ret;
1819 PMIB_IPFORWARDTABLE table;
1821 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable, pdwSize, bOrder);
1823 if (!pdwSize) return ERROR_INVALID_PARAMETER;
1825 ret = AllocateAndGetIpForwardTableFromStack(&table, bOrder, GetProcessHeap(), 0);
1826 if (!ret) {
1827 DWORD size = FIELD_OFFSET( MIB_IPFORWARDTABLE, table[table->dwNumEntries] );
1828 if (!pIpForwardTable || *pdwSize < size) {
1829 *pdwSize = size;
1830 ret = ERROR_INSUFFICIENT_BUFFER;
1832 else {
1833 *pdwSize = size;
1834 memcpy(pIpForwardTable, table, size);
1836 HeapFree(GetProcessHeap(), 0, table);
1838 TRACE("returning %d\n", ret);
1839 return ret;
1843 /******************************************************************
1844 * GetIpNetTable (IPHLPAPI.@)
1846 * Get the IP-to-physical address mapping table.
1848 * PARAMS
1849 * pIpNetTable [Out] buffer for mapping table
1850 * pdwSize [In/Out] length of output buffer
1851 * bOrder [In] whether to sort the table
1853 * RETURNS
1854 * Success: NO_ERROR
1855 * Failure: error code from winerror.h
1857 * NOTES
1858 * If pdwSize is less than required, the function will return
1859 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1860 * size.
1861 * If bOrder is true, the returned table will be sorted by IP address.
1863 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1865 DWORD ret;
1866 PMIB_IPNETTABLE table;
1868 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable, pdwSize, bOrder);
1870 if (!pdwSize) return ERROR_INVALID_PARAMETER;
1872 ret = AllocateAndGetIpNetTableFromStack( &table, bOrder, GetProcessHeap(), 0 );
1873 if (!ret) {
1874 DWORD size = FIELD_OFFSET( MIB_IPNETTABLE, table[table->dwNumEntries] );
1875 if (!pIpNetTable || *pdwSize < size) {
1876 *pdwSize = size;
1877 ret = ERROR_INSUFFICIENT_BUFFER;
1879 else {
1880 *pdwSize = size;
1881 memcpy(pIpNetTable, table, size);
1883 HeapFree(GetProcessHeap(), 0, table);
1885 TRACE("returning %d\n", ret);
1886 return ret;
1889 /* Gets the DNS server list into the list beginning at list. Assumes that
1890 * a single server address may be placed at list if *len is at least
1891 * sizeof(IP_ADDR_STRING) long. Otherwise, list->Next is set to firstDynamic,
1892 * and assumes that all remaining DNS servers are contiguously located
1893 * beginning at firstDynamic. On input, *len is assumed to be the total number
1894 * of bytes available for all DNS servers, and is ignored if list is NULL.
1895 * On return, *len is set to the total number of bytes required for all DNS
1896 * servers.
1897 * Returns ERROR_BUFFER_OVERFLOW if *len is insufficient,
1898 * ERROR_SUCCESS otherwise.
1900 static DWORD get_dns_server_list(PIP_ADDR_STRING list,
1901 PIP_ADDR_STRING firstDynamic, DWORD *len)
1903 DWORD size;
1904 int num = get_dns_servers( NULL, 0, TRUE );
1906 size = num * sizeof(IP_ADDR_STRING);
1907 if (!list || *len < size) {
1908 *len = size;
1909 return ERROR_BUFFER_OVERFLOW;
1911 *len = size;
1912 if (num > 0) {
1913 PIP_ADDR_STRING ptr;
1914 int i;
1915 SOCKADDR_STORAGE *addr = HeapAlloc( GetProcessHeap(), 0, num * sizeof(SOCKADDR_STORAGE) );
1917 get_dns_servers( addr, num, TRUE );
1919 for (i = 0, ptr = list; i < num; i++, ptr = ptr->Next) {
1920 toIPAddressString(((struct sockaddr_in *)(addr + i))->sin_addr.s_addr,
1921 ptr->IpAddress.String);
1922 if (i == num - 1)
1923 ptr->Next = NULL;
1924 else if (i == 0)
1925 ptr->Next = firstDynamic;
1926 else
1927 ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1929 HeapFree( GetProcessHeap(), 0, addr );
1931 return ERROR_SUCCESS;
1934 /******************************************************************
1935 * GetNetworkParams (IPHLPAPI.@)
1937 * Get the network parameters for the local computer.
1939 * PARAMS
1940 * pFixedInfo [Out] buffer for network parameters
1941 * pOutBufLen [In/Out] length of output buffer
1943 * RETURNS
1944 * Success: NO_ERROR
1945 * Failure: error code from winerror.h
1947 * NOTES
1948 * If pOutBufLen is less than required, the function will return
1949 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1950 * size.
1952 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1954 DWORD ret, size, serverListSize;
1955 LONG regReturn;
1956 HKEY hKey;
1958 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1959 if (!pOutBufLen)
1960 return ERROR_INVALID_PARAMETER;
1962 get_dns_server_list(NULL, NULL, &serverListSize);
1963 size = sizeof(FIXED_INFO) + serverListSize - sizeof(IP_ADDR_STRING);
1964 if (!pFixedInfo || *pOutBufLen < size) {
1965 *pOutBufLen = size;
1966 return ERROR_BUFFER_OVERFLOW;
1969 memset(pFixedInfo, 0, size);
1970 size = sizeof(pFixedInfo->HostName);
1971 GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1972 size = sizeof(pFixedInfo->DomainName);
1973 GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1974 get_dns_server_list(&pFixedInfo->DnsServerList,
1975 (PIP_ADDR_STRING)((BYTE *)pFixedInfo + sizeof(FIXED_INFO)),
1976 &serverListSize);
1977 /* Assume the first DNS server in the list is the "current" DNS server: */
1978 pFixedInfo->CurrentDnsServer = &pFixedInfo->DnsServerList;
1979 pFixedInfo->NodeType = HYBRID_NODETYPE;
1980 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1981 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1982 if (regReturn != ERROR_SUCCESS)
1983 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1984 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1985 &hKey);
1986 if (regReturn == ERROR_SUCCESS)
1988 DWORD size = sizeof(pFixedInfo->ScopeId);
1990 RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1991 RegCloseKey(hKey);
1994 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1995 I suppose could also check for a listener on port 53 to set EnableDns */
1996 ret = NO_ERROR;
1997 TRACE("returning %d\n", ret);
1998 return ret;
2002 /******************************************************************
2003 * GetNumberOfInterfaces (IPHLPAPI.@)
2005 * Get the number of interfaces.
2007 * PARAMS
2008 * pdwNumIf [Out] number of interfaces
2010 * RETURNS
2011 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
2013 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
2015 DWORD ret;
2017 TRACE("pdwNumIf %p\n", pdwNumIf);
2018 if (!pdwNumIf)
2019 ret = ERROR_INVALID_PARAMETER;
2020 else {
2021 *pdwNumIf = get_interface_indices( FALSE, NULL );
2022 ret = NO_ERROR;
2024 TRACE("returning %d\n", ret);
2025 return ret;
2029 /******************************************************************
2030 * GetPerAdapterInfo (IPHLPAPI.@)
2032 * Get information about an adapter corresponding to an interface.
2034 * PARAMS
2035 * IfIndex [In] interface info
2036 * pPerAdapterInfo [Out] buffer for per adapter info
2037 * pOutBufLen [In/Out] length of output buffer
2039 * RETURNS
2040 * Success: NO_ERROR
2041 * Failure: error code from winerror.h
2043 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
2045 ULONG bytesNeeded = sizeof(IP_PER_ADAPTER_INFO), serverListSize = 0;
2046 DWORD ret = NO_ERROR;
2048 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex, pPerAdapterInfo, pOutBufLen);
2050 if (!pOutBufLen) return ERROR_INVALID_PARAMETER;
2052 if (!isIfIndexLoopback(IfIndex)) {
2053 get_dns_server_list(NULL, NULL, &serverListSize);
2054 if (serverListSize > sizeof(IP_ADDR_STRING))
2055 bytesNeeded += serverListSize - sizeof(IP_ADDR_STRING);
2057 if (!pPerAdapterInfo || *pOutBufLen < bytesNeeded)
2059 *pOutBufLen = bytesNeeded;
2060 return ERROR_BUFFER_OVERFLOW;
2063 memset(pPerAdapterInfo, 0, bytesNeeded);
2064 if (!isIfIndexLoopback(IfIndex)) {
2065 ret = get_dns_server_list(&pPerAdapterInfo->DnsServerList,
2066 (PIP_ADDR_STRING)((PBYTE)pPerAdapterInfo + sizeof(IP_PER_ADAPTER_INFO)),
2067 &serverListSize);
2068 /* Assume the first DNS server in the list is the "current" DNS server: */
2069 pPerAdapterInfo->CurrentDnsServer = &pPerAdapterInfo->DnsServerList;
2071 return ret;
2075 /******************************************************************
2076 * GetRTTAndHopCount (IPHLPAPI.@)
2078 * Get round-trip time (RTT) and hop count.
2080 * PARAMS
2082 * DestIpAddress [In] destination address to get the info for
2083 * HopCount [Out] retrieved hop count
2084 * MaxHops [In] maximum hops to search for the destination
2085 * RTT [Out] RTT in milliseconds
2087 * RETURNS
2088 * Success: TRUE
2089 * Failure: FALSE
2091 * FIXME
2092 * Stub, returns FALSE.
2094 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
2096 FIXME("(DestIpAddress 0x%08x, HopCount %p, MaxHops %d, RTT %p): stub\n",
2097 DestIpAddress, HopCount, MaxHops, RTT);
2098 return FALSE;
2102 /******************************************************************
2103 * GetTcpTable (IPHLPAPI.@)
2105 * Get the table of active TCP connections.
2107 * PARAMS
2108 * pTcpTable [Out] buffer for TCP connections table
2109 * pdwSize [In/Out] length of output buffer
2110 * bOrder [In] whether to order the table
2112 * RETURNS
2113 * Success: NO_ERROR
2114 * Failure: error code from winerror.h
2116 * NOTES
2117 * If pdwSize is less than required, the function will return
2118 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
2119 * the required byte size.
2120 * If bOrder is true, the returned table will be sorted, first by
2121 * local address and port number, then by remote address and port
2122 * number.
2124 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
2126 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize, bOrder);
2127 return GetExtendedTcpTable(pTcpTable, pdwSize, bOrder, AF_INET, TCP_TABLE_BASIC_ALL, 0);
2130 /******************************************************************
2131 * GetExtendedTcpTable (IPHLPAPI.@)
2133 DWORD WINAPI GetExtendedTcpTable(PVOID pTcpTable, PDWORD pdwSize, BOOL bOrder,
2134 ULONG ulAf, TCP_TABLE_CLASS TableClass, ULONG Reserved)
2136 DWORD ret, size;
2137 void *table;
2139 TRACE("pTcpTable %p, pdwSize %p, bOrder %d, ulAf %u, TableClass %u, Reserved %u\n",
2140 pTcpTable, pdwSize, bOrder, ulAf, TableClass, Reserved);
2142 if (!pdwSize) return ERROR_INVALID_PARAMETER;
2144 if (ulAf != AF_INET)
2146 FIXME("ulAf = %u not supported\n", ulAf);
2147 return ERROR_NOT_SUPPORTED;
2149 if (TableClass >= TCP_TABLE_OWNER_MODULE_LISTENER)
2150 FIXME("module classes not fully supported\n");
2152 if ((ret = build_tcp_table(TableClass, &table, bOrder, GetProcessHeap(), 0, &size)))
2153 return ret;
2155 if (!pTcpTable || *pdwSize < size)
2157 *pdwSize = size;
2158 ret = ERROR_INSUFFICIENT_BUFFER;
2160 else
2162 *pdwSize = size;
2163 memcpy(pTcpTable, table, size);
2165 HeapFree(GetProcessHeap(), 0, table);
2166 return ret;
2169 /******************************************************************
2170 * GetUdpTable (IPHLPAPI.@)
2172 * Get a table of active UDP connections.
2174 * PARAMS
2175 * pUdpTable [Out] buffer for UDP connections table
2176 * pdwSize [In/Out] length of output buffer
2177 * bOrder [In] whether to order the table
2179 * RETURNS
2180 * Success: NO_ERROR
2181 * Failure: error code from winerror.h
2183 * NOTES
2184 * If pdwSize is less than required, the function will return
2185 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
2186 * required byte size.
2187 * If bOrder is true, the returned table will be sorted, first by
2188 * local address, then by local port number.
2190 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
2192 return GetExtendedUdpTable(pUdpTable, pdwSize, bOrder, AF_INET, UDP_TABLE_BASIC, 0);
2195 /******************************************************************
2196 * GetExtendedUdpTable (IPHLPAPI.@)
2198 DWORD WINAPI GetExtendedUdpTable(PVOID pUdpTable, PDWORD pdwSize, BOOL bOrder,
2199 ULONG ulAf, UDP_TABLE_CLASS TableClass, ULONG Reserved)
2201 DWORD ret, size;
2202 void *table;
2204 TRACE("pUdpTable %p, pdwSize %p, bOrder %d, ulAf %u, TableClass %u, Reserved %u\n",
2205 pUdpTable, pdwSize, bOrder, ulAf, TableClass, Reserved);
2207 if (!pdwSize) return ERROR_INVALID_PARAMETER;
2209 if (ulAf != AF_INET)
2211 FIXME("ulAf = %u not supported\n", ulAf);
2212 return ERROR_NOT_SUPPORTED;
2214 if (TableClass == UDP_TABLE_OWNER_MODULE)
2215 FIXME("UDP_TABLE_OWNER_MODULE not fully supported\n");
2217 if ((ret = build_udp_table(TableClass, &table, bOrder, GetProcessHeap(), 0, &size)))
2218 return ret;
2220 if (!pUdpTable || *pdwSize < size)
2222 *pdwSize = size;
2223 ret = ERROR_INSUFFICIENT_BUFFER;
2225 else
2227 *pdwSize = size;
2228 memcpy(pUdpTable, table, size);
2230 HeapFree(GetProcessHeap(), 0, table);
2231 return ret;
2234 /******************************************************************
2235 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
2237 * This is a Win98-only function to get information on "unidirectional"
2238 * adapters. Since this is pretty nonsensical in other contexts, it
2239 * never returns anything.
2241 * PARAMS
2242 * pIPIfInfo [Out] buffer for adapter infos
2243 * dwOutBufLen [Out] length of the output buffer
2245 * RETURNS
2246 * Success: NO_ERROR
2247 * Failure: error code from winerror.h
2249 * FIXME
2250 * Stub, returns ERROR_NOT_SUPPORTED.
2252 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
2254 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
2255 /* a unidirectional adapter?? not bloody likely! */
2256 return ERROR_NOT_SUPPORTED;
2260 /******************************************************************
2261 * IpReleaseAddress (IPHLPAPI.@)
2263 * Release an IP obtained through DHCP,
2265 * PARAMS
2266 * AdapterInfo [In] adapter to release IP address
2268 * RETURNS
2269 * Success: NO_ERROR
2270 * Failure: error code from winerror.h
2272 * NOTES
2273 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
2274 * this function does nothing.
2276 * FIXME
2277 * Stub, returns ERROR_NOT_SUPPORTED.
2279 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
2281 FIXME("Stub AdapterInfo %p\n", AdapterInfo);
2282 return ERROR_NOT_SUPPORTED;
2286 /******************************************************************
2287 * IpRenewAddress (IPHLPAPI.@)
2289 * Renew an IP obtained through DHCP.
2291 * PARAMS
2292 * AdapterInfo [In] adapter to renew IP address
2294 * RETURNS
2295 * Success: NO_ERROR
2296 * Failure: error code from winerror.h
2298 * NOTES
2299 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
2300 * this function does nothing.
2302 * FIXME
2303 * Stub, returns ERROR_NOT_SUPPORTED.
2305 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
2307 FIXME("Stub AdapterInfo %p\n", AdapterInfo);
2308 return ERROR_NOT_SUPPORTED;
2312 /******************************************************************
2313 * NotifyAddrChange (IPHLPAPI.@)
2315 * Notify caller whenever the ip-interface map is changed.
2317 * PARAMS
2318 * Handle [Out] handle usable in asynchronous notification
2319 * overlapped [In] overlapped structure that notifies the caller
2321 * RETURNS
2322 * Success: NO_ERROR
2323 * Failure: error code from winerror.h
2325 * FIXME
2326 * Stub, returns ERROR_NOT_SUPPORTED.
2328 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
2330 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
2331 if (Handle) *Handle = INVALID_HANDLE_VALUE;
2332 if (overlapped) ((IO_STATUS_BLOCK *) overlapped)->u.Status = STATUS_PENDING;
2333 return ERROR_IO_PENDING;
2337 /******************************************************************
2338 * NotifyIpInterfaceChange (IPHLPAPI.@)
2340 DWORD WINAPI NotifyIpInterfaceChange(ULONG family, PVOID callback, PVOID context,
2341 BOOLEAN init_notify, PHANDLE handle)
2343 FIXME("(family %d, callback %p, context %p, init_notify %d, handle %p): stub\n",
2344 family, callback, context, init_notify, handle);
2345 if (handle) *handle = NULL;
2346 return ERROR_NOT_SUPPORTED;
2350 /******************************************************************
2351 * NotifyRouteChange (IPHLPAPI.@)
2353 * Notify caller whenever the ip routing table is changed.
2355 * PARAMS
2356 * Handle [Out] handle usable in asynchronous notification
2357 * overlapped [In] overlapped structure that notifies the caller
2359 * RETURNS
2360 * Success: NO_ERROR
2361 * Failure: error code from winerror.h
2363 * FIXME
2364 * Stub, returns ERROR_NOT_SUPPORTED.
2366 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
2368 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
2369 return ERROR_NOT_SUPPORTED;
2373 /******************************************************************
2374 * SendARP (IPHLPAPI.@)
2376 * Send an ARP request.
2378 * PARAMS
2379 * DestIP [In] attempt to obtain this IP
2380 * SrcIP [In] optional sender IP address
2381 * pMacAddr [Out] buffer for the mac address
2382 * PhyAddrLen [In/Out] length of the output buffer
2384 * RETURNS
2385 * Success: NO_ERROR
2386 * Failure: error code from winerror.h
2388 * FIXME
2389 * Stub, returns ERROR_NOT_SUPPORTED.
2391 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
2393 FIXME("(DestIP 0x%08x, SrcIP 0x%08x, pMacAddr %p, PhyAddrLen %p): stub\n",
2394 DestIP, SrcIP, pMacAddr, PhyAddrLen);
2395 return ERROR_NOT_SUPPORTED;
2399 /******************************************************************
2400 * SetIfEntry (IPHLPAPI.@)
2402 * Set the administrative status of an interface.
2404 * PARAMS
2405 * pIfRow [In] dwAdminStatus member specifies the new status.
2407 * RETURNS
2408 * Success: NO_ERROR
2409 * Failure: error code from winerror.h
2411 * FIXME
2412 * Stub, returns ERROR_NOT_SUPPORTED.
2414 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
2416 FIXME("(pIfRow %p): stub\n", pIfRow);
2417 /* this is supposed to set an interface administratively up or down.
2418 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2419 this sort of down is indistinguishable from other sorts of down (e.g. no
2420 link). */
2421 return ERROR_NOT_SUPPORTED;
2425 /******************************************************************
2426 * SetIpForwardEntry (IPHLPAPI.@)
2428 * Modify an existing route.
2430 * PARAMS
2431 * pRoute [In] route with the new information
2433 * RETURNS
2434 * Success: NO_ERROR
2435 * Failure: error code from winerror.h
2437 * FIXME
2438 * Stub, returns NO_ERROR.
2440 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
2442 FIXME("(pRoute %p): stub\n", pRoute);
2443 /* this is to add a route entry, how's it distinguishable from
2444 CreateIpForwardEntry?
2445 could use SIOCADDRT, not sure I want to */
2446 return 0;
2450 /******************************************************************
2451 * SetIpNetEntry (IPHLPAPI.@)
2453 * Modify an existing ARP entry.
2455 * PARAMS
2456 * pArpEntry [In] ARP entry with the new information
2458 * RETURNS
2459 * Success: NO_ERROR
2460 * Failure: error code from winerror.h
2462 * FIXME
2463 * Stub, returns NO_ERROR.
2465 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
2467 FIXME("(pArpEntry %p): stub\n", pArpEntry);
2468 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
2469 return 0;
2473 /******************************************************************
2474 * SetIpStatistics (IPHLPAPI.@)
2476 * Toggle IP forwarding and det the default TTL value.
2478 * PARAMS
2479 * pIpStats [In] IP statistics with the new information
2481 * RETURNS
2482 * Success: NO_ERROR
2483 * Failure: error code from winerror.h
2485 * FIXME
2486 * Stub, returns NO_ERROR.
2488 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
2490 FIXME("(pIpStats %p): stub\n", pIpStats);
2491 return 0;
2495 /******************************************************************
2496 * SetIpTTL (IPHLPAPI.@)
2498 * Set the default TTL value.
2500 * PARAMS
2501 * nTTL [In] new TTL value
2503 * RETURNS
2504 * Success: NO_ERROR
2505 * Failure: error code from winerror.h
2507 * FIXME
2508 * Stub, returns NO_ERROR.
2510 DWORD WINAPI SetIpTTL(UINT nTTL)
2512 FIXME("(nTTL %d): stub\n", nTTL);
2513 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
2514 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
2515 return 0;
2519 /******************************************************************
2520 * SetTcpEntry (IPHLPAPI.@)
2522 * Set the state of a TCP connection.
2524 * PARAMS
2525 * pTcpRow [In] specifies connection with new state
2527 * RETURNS
2528 * Success: NO_ERROR
2529 * Failure: error code from winerror.h
2531 * FIXME
2532 * Stub, returns NO_ERROR.
2534 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
2536 FIXME("(pTcpRow %p): stub\n", pTcpRow);
2537 return 0;
2541 /******************************************************************
2542 * UnenableRouter (IPHLPAPI.@)
2544 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2545 * if it reaches zero.
2547 * PARAMS
2548 * pOverlapped [In/Out] should be the same as in EnableRouter()
2549 * lpdwEnableCount [Out] optional, receives reference count
2551 * RETURNS
2552 * Success: NO_ERROR
2553 * Failure: error code from winerror.h
2555 * FIXME
2556 * Stub, returns ERROR_NOT_SUPPORTED.
2558 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
2560 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
2561 lpdwEnableCount);
2562 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
2563 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
2565 return ERROR_NOT_SUPPORTED;
2568 /******************************************************************
2569 * PfCreateInterface (IPHLPAPI.@)
2571 DWORD WINAPI PfCreateInterface(DWORD dwName, PFFORWARD_ACTION inAction, PFFORWARD_ACTION outAction,
2572 BOOL bUseLog, BOOL bMustBeUnique, INTERFACE_HANDLE *ppInterface)
2574 FIXME("(%d %d %d %x %x %p) stub\n", dwName, inAction, outAction, bUseLog, bMustBeUnique, ppInterface);
2575 return ERROR_CALL_NOT_IMPLEMENTED;
2578 /******************************************************************
2579 * PfUnBindInterface (IPHLPAPI.@)
2581 DWORD WINAPI PfUnBindInterface(INTERFACE_HANDLE interface)
2583 FIXME("(%p) stub\n", interface);
2584 return ERROR_CALL_NOT_IMPLEMENTED;
2587 /******************************************************************
2588 * PfDeleteInterface(IPHLPAPI.@)
2590 DWORD WINAPI PfDeleteInterface(INTERFACE_HANDLE interface)
2592 FIXME("(%p) stub\n", interface);
2593 return ERROR_CALL_NOT_IMPLEMENTED;
2596 /******************************************************************
2597 * PfBindInterfaceToIPAddress(IPHLPAPI.@)
2599 DWORD WINAPI PfBindInterfaceToIPAddress(INTERFACE_HANDLE interface, PFADDRESSTYPE type, PBYTE ip)
2601 FIXME("(%p %d %p) stub\n", interface, type, ip);
2602 return ERROR_CALL_NOT_IMPLEMENTED;
2605 /******************************************************************
2606 * GetTcpTable2 (IPHLPAPI.@)
2608 ULONG WINAPI GetTcpTable2(PMIB_TCPTABLE2 table, PULONG size, BOOL order)
2610 FIXME("pTcpTable2 %p, pdwSize %p, bOrder %d: stub\n", table, size, order);
2611 return ERROR_NOT_SUPPORTED;
2614 /******************************************************************
2615 * GetTcp6Table (IPHLPAPI.@)
2617 ULONG WINAPI GetTcp6Table(PMIB_TCP6TABLE table, PULONG size, BOOL order)
2619 FIXME("pTcp6Table %p, size %p, order %d: stub\n", table, size, order);
2620 return ERROR_NOT_SUPPORTED;
2623 /******************************************************************
2624 * GetTcp6Table2 (IPHLPAPI.@)
2626 ULONG WINAPI GetTcp6Table2(PMIB_TCP6TABLE2 table, PULONG size, BOOL order)
2628 FIXME("pTcp6Table2 %p, size %p, order %d: stub\n", table, size, order);
2629 return ERROR_NOT_SUPPORTED;