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
26 #include <sys/types.h>
27 #ifdef HAVE_NETINET_IN_H
28 # include <netinet/in.h>
30 #ifdef HAVE_ARPA_INET_H
31 # include <arpa/inet.h>
33 #ifdef HAVE_ARPA_NAMESER_H
34 # include <arpa/nameser.h>
40 #define NONAMELESSUNION
41 #define NONAMELESSSTRUCT
57 #include "tcpestats.h"
58 #include "ip2string.h"
60 #include "wine/debug.h"
61 #include "wine/unicode.h"
63 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
66 #define IF_NAMESIZE 16
70 #define INADDR_NONE ~0UL
73 /******************************************************************
74 * AddIPAddress (IPHLPAPI.@)
76 * Add an IP address to an adapter.
79 * Address [In] IP address to add to the adapter
80 * IpMask [In] subnet mask for the IP address
81 * IfIndex [In] adapter index to add the address
82 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
83 * NTEInstance [Out] NTE instance for the IP address
87 * Failure: error code from winerror.h
90 * Stub. Currently returns ERROR_NOT_SUPPORTED.
92 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask IpMask
, DWORD IfIndex
, PULONG NTEContext
, PULONG NTEInstance
)
95 return ERROR_NOT_SUPPORTED
;
99 /******************************************************************
100 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
102 * Get table of local interfaces.
103 * Like GetIfTable(), but allocate the returned table from heap.
106 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
107 * allocated and returned.
108 * bOrder [In] whether to sort the table
109 * heap [In] heap from which the table is allocated
110 * flags [In] flags to HeapAlloc
113 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
114 * GetIfTable() returns otherwise.
116 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
117 BOOL bOrder
, HANDLE heap
, DWORD flags
)
121 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable
,
122 bOrder
, heap
, flags
);
124 ret
= ERROR_INVALID_PARAMETER
;
128 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
129 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
130 *ppIfTable
= HeapAlloc(heap
, flags
, dwSize
);
131 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
134 TRACE("returning %d\n", ret
);
139 static int IpAddrTableNumericSorter(const void *a
, const void *b
)
144 ret
= ((const MIB_IPADDRROW
*)a
)->dwAddr
- ((const MIB_IPADDRROW
*)b
)->dwAddr
;
148 static int IpAddrTableLoopbackSorter(const void *a
, const void *b
)
150 const MIB_IPADDRROW
*left
= a
, *right
= b
;
153 if (isIfIndexLoopback(left
->dwIndex
))
155 else if (isIfIndexLoopback(right
->dwIndex
))
161 /******************************************************************
162 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
164 * Get interface-to-IP address mapping table.
165 * Like GetIpAddrTable(), but allocate the returned table from heap.
168 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
169 * allocated and returned.
170 * bOrder [In] whether to sort the table
171 * heap [In] heap from which the table is allocated
172 * flags [In] flags to HeapAlloc
175 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
176 * failure, NO_ERROR on success.
178 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
179 BOOL bOrder
, HANDLE heap
, DWORD flags
)
183 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
184 ppIpAddrTable
, bOrder
, heap
, flags
);
185 ret
= getIPAddrTable(ppIpAddrTable
, heap
, flags
);
187 qsort((*ppIpAddrTable
)->table
, (*ppIpAddrTable
)->dwNumEntries
,
188 sizeof(MIB_IPADDRROW
), IpAddrTableNumericSorter
);
189 TRACE("returning %d\n", ret
);
194 /******************************************************************
195 * CancelIPChangeNotify (IPHLPAPI.@)
197 * Cancel a previous notification created by NotifyAddrChange or
201 * overlapped [In] overlapped structure that notifies the caller
208 * Stub, returns FALSE.
210 BOOL WINAPI
CancelIPChangeNotify(LPOVERLAPPED overlapped
)
212 FIXME("(overlapped %p): stub\n", overlapped
);
217 /******************************************************************
218 * CancelMibChangeNotify2 (IPHLPAPI.@)
220 DWORD WINAPI
CancelMibChangeNotify2(HANDLE handle
)
222 FIXME("(handle %p): stub\n", handle
);
227 /******************************************************************
228 * CreateIpForwardEntry (IPHLPAPI.@)
230 * Create a route in the local computer's IP table.
233 * pRoute [In] new route information
237 * Failure: error code from winerror.h
240 * Stub, always returns NO_ERROR.
242 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
244 FIXME("(pRoute %p): stub\n", pRoute
);
245 /* could use SIOCADDRT, not sure I want to */
250 /******************************************************************
251 * CreateIpNetEntry (IPHLPAPI.@)
253 * Create entry in the ARP table.
256 * pArpEntry [In] new ARP entry
260 * Failure: error code from winerror.h
263 * Stub, always returns NO_ERROR.
265 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
267 FIXME("(pArpEntry %p)\n", pArpEntry
);
268 /* could use SIOCSARP on systems that support it, not sure I want to */
273 /******************************************************************
274 * CreateProxyArpEntry (IPHLPAPI.@)
276 * Create a Proxy ARP (PARP) entry for an IP address.
279 * dwAddress [In] IP address for which this computer acts as a proxy.
280 * dwMask [In] subnet mask for dwAddress
281 * dwIfIndex [In] interface index
285 * Failure: error code from winerror.h
288 * Stub, returns ERROR_NOT_SUPPORTED.
290 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
292 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
293 dwAddress
, dwMask
, dwIfIndex
);
294 return ERROR_NOT_SUPPORTED
;
297 static char *debugstr_ipv6(const struct WS_sockaddr_in6
*sin
, char *buf
)
299 const IN6_ADDR
*addr
= &sin
->sin6_addr
;
302 BOOL in_zero
= FALSE
;
304 for (i
= 0; i
< 7; i
++)
306 if (!addr
->u
.Word
[i
])
318 p
+= sprintf(p
, "%x:", ntohs(addr
->u
.Word
[i
]));
322 sprintf(p
, "%x", ntohs(addr
->u
.Word
[7]));
326 static BOOL
map_address_6to4( const SOCKADDR_IN6
*addr6
, SOCKADDR_IN
*addr4
)
330 if (addr6
->sin6_family
!= WS_AF_INET6
) return FALSE
;
332 for (i
= 0; i
< 5; i
++)
333 if (addr6
->sin6_addr
.u
.Word
[i
]) return FALSE
;
335 if (addr6
->sin6_addr
.u
.Word
[5] != 0xffff) return FALSE
;
337 addr4
->sin_family
= WS_AF_INET
;
338 addr4
->sin_port
= addr6
->sin6_port
;
339 addr4
->sin_addr
.S_un
.S_addr
= addr6
->sin6_addr
.u
.Word
[6] << 16 | addr6
->sin6_addr
.u
.Word
[7];
340 memset( &addr4
->sin_zero
, 0, sizeof(addr4
->sin_zero
) );
345 static BOOL
find_src_address( MIB_IPADDRTABLE
*table
, const SOCKADDR_IN
*dst
, SOCKADDR_IN6
*src
)
347 MIB_IPFORWARDROW row
;
350 if (GetBestRoute( dst
->sin_addr
.S_un
.S_addr
, 0, &row
)) return FALSE
;
352 for (i
= 0; i
< table
->dwNumEntries
; i
++)
354 /* take the first address */
355 if (table
->table
[i
].dwIndex
== row
.dwForwardIfIndex
)
357 src
->sin6_family
= WS_AF_INET6
;
359 src
->sin6_flowinfo
= 0;
360 for (j
= 0; j
< 5; j
++) src
->sin6_addr
.u
.Word
[j
] = 0;
361 src
->sin6_addr
.u
.Word
[5] = 0xffff;
362 src
->sin6_addr
.u
.Word
[6] = table
->table
[i
].dwAddr
& 0xffff;
363 src
->sin6_addr
.u
.Word
[7] = table
->table
[i
].dwAddr
>> 16;
371 /******************************************************************
372 * CreateSortedAddressPairs (IPHLPAPI.@)
374 DWORD WINAPI
CreateSortedAddressPairs( const PSOCKADDR_IN6 src_list
, DWORD src_count
,
375 const PSOCKADDR_IN6 dst_list
, DWORD dst_count
,
376 DWORD options
, PSOCKADDR_IN6_PAIR
*pair_list
,
380 SOCKADDR_IN6_PAIR
*pairs
;
383 MIB_IPADDRTABLE
*table
;
385 FIXME( "(src_list %p src_count %u dst_list %p dst_count %u options %x pair_list %p pair_count %p): stub\n",
386 src_list
, src_count
, dst_list
, dst_count
, options
, pair_list
, pair_count
);
388 if (src_list
|| src_count
|| !dst_list
|| !pair_list
|| !pair_count
|| dst_count
> 500)
389 return ERROR_INVALID_PARAMETER
;
391 for (i
= 0; i
< dst_count
; i
++)
393 if (!map_address_6to4( &dst_list
[i
], &addr4
))
395 FIXME("only mapped IPv4 addresses are supported\n");
396 return ERROR_NOT_SUPPORTED
;
400 size
= dst_count
* sizeof(*pairs
);
401 size
+= dst_count
* sizeof(SOCKADDR_IN6
) * 2; /* source address + destination address */
402 if (!(pairs
= HeapAlloc( GetProcessHeap(), 0, size
))) return ERROR_NOT_ENOUGH_MEMORY
;
403 ptr
= (SOCKADDR_IN6
*)&pairs
[dst_count
];
405 if ((ret
= getIPAddrTable( &table
, GetProcessHeap(), 0 )))
407 HeapFree( GetProcessHeap(), 0, pairs
);
411 for (i
= 0; i
< dst_count
; i
++)
413 pairs
[i
].SourceAddress
= ptr
++;
414 if (!map_address_6to4( &dst_list
[i
], &addr4
) ||
415 !find_src_address( table
, &addr4
, pairs
[i
].SourceAddress
))
418 FIXME( "source address for %s not found\n", debugstr_ipv6(&dst_list
[i
], buf
) );
419 memset( pairs
[i
].SourceAddress
, 0, sizeof(*pairs
[i
].SourceAddress
) );
420 pairs
[i
].SourceAddress
->sin6_family
= WS_AF_INET6
;
423 pairs
[i
].DestinationAddress
= ptr
++;
424 memcpy( pairs
[i
].DestinationAddress
, &dst_list
[i
], sizeof(*pairs
[i
].DestinationAddress
) );
427 *pair_count
= dst_count
;
429 HeapFree( GetProcessHeap(), 0, table
);
434 /******************************************************************
435 * DeleteIPAddress (IPHLPAPI.@)
437 * Delete an IP address added with AddIPAddress().
440 * NTEContext [In] NTE context from AddIPAddress();
444 * Failure: error code from winerror.h
447 * Stub, returns ERROR_NOT_SUPPORTED.
449 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
451 FIXME("(NTEContext %d): stub\n", NTEContext
);
452 return ERROR_NOT_SUPPORTED
;
456 /******************************************************************
457 * DeleteIpForwardEntry (IPHLPAPI.@)
462 * pRoute [In] route to delete
466 * Failure: error code from winerror.h
469 * Stub, returns NO_ERROR.
471 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
473 FIXME("(pRoute %p): stub\n", pRoute
);
474 /* could use SIOCDELRT, not sure I want to */
479 /******************************************************************
480 * DeleteIpNetEntry (IPHLPAPI.@)
482 * Delete an ARP entry.
485 * pArpEntry [In] ARP entry to delete
489 * Failure: error code from winerror.h
492 * Stub, returns NO_ERROR.
494 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
496 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
497 /* could use SIOCDARP on systems that support it, not sure I want to */
502 /******************************************************************
503 * DeleteProxyArpEntry (IPHLPAPI.@)
505 * Delete a Proxy ARP entry.
508 * dwAddress [In] IP address for which this computer acts as a proxy.
509 * dwMask [In] subnet mask for dwAddress
510 * dwIfIndex [In] interface index
514 * Failure: error code from winerror.h
517 * Stub, returns ERROR_NOT_SUPPORTED.
519 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
521 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
522 dwAddress
, dwMask
, dwIfIndex
);
523 return ERROR_NOT_SUPPORTED
;
527 /******************************************************************
528 * EnableRouter (IPHLPAPI.@)
530 * Turn on ip forwarding.
534 * pOverlapped [In/Out] hEvent member should contain a valid handle.
537 * Success: ERROR_IO_PENDING
538 * Failure: error code from winerror.h
541 * Stub, returns ERROR_NOT_SUPPORTED.
543 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
545 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle
, pOverlapped
);
546 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
547 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
549 return ERROR_NOT_SUPPORTED
;
553 /******************************************************************
554 * FlushIpNetTable (IPHLPAPI.@)
556 * Delete all ARP entries of an interface
559 * dwIfIndex [In] interface index
563 * Failure: error code from winerror.h
566 * Stub, returns ERROR_NOT_SUPPORTED.
568 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
570 FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex
);
571 /* this flushes the arp cache of the given index */
572 return ERROR_NOT_SUPPORTED
;
575 /******************************************************************
576 * FreeMibTable (IPHLPAPI.@)
578 * Free buffer allocated by network functions
581 * ptr [In] pointer to the buffer to free
584 void WINAPI
FreeMibTable(void *ptr
)
586 TRACE("(%p)\n", ptr
);
587 HeapFree(GetProcessHeap(), 0, ptr
);
590 /******************************************************************
591 * GetAdapterIndex (IPHLPAPI.@)
593 * Get interface index from its name.
596 * AdapterName [In] unicode string with the adapter name
597 * IfIndex [Out] returns found interface index
601 * Failure: error code from winerror.h
603 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
605 char adapterName
[MAX_ADAPTER_NAME
];
609 TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName
, IfIndex
);
610 /* The adapter name is guaranteed not to have any unicode characters, so
611 * this translation is never lossy */
612 for (i
= 0; i
< sizeof(adapterName
) - 1 && AdapterName
[i
]; i
++)
613 adapterName
[i
] = (char)AdapterName
[i
];
614 adapterName
[i
] = '\0';
615 ret
= getInterfaceIndexByName(adapterName
, IfIndex
);
616 TRACE("returning %d\n", ret
);
621 /******************************************************************
622 * GetAdaptersInfo (IPHLPAPI.@)
624 * Get information about adapters.
627 * pAdapterInfo [Out] buffer for adapter infos
628 * pOutBufLen [In] length of output buffer
632 * Failure: error code from winerror.h
634 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
638 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
640 ret
= ERROR_INVALID_PARAMETER
;
642 DWORD numNonLoopbackInterfaces
= get_interface_indices( TRUE
, NULL
);
644 if (numNonLoopbackInterfaces
> 0) {
645 DWORD numIPAddresses
= getNumIPAddresses();
648 /* This may slightly overestimate the amount of space needed, because
649 * the IP addresses include the loopback address, but it's easier
650 * to make sure there's more than enough space than to make sure there's
651 * precisely enough space.
653 size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
654 size
+= numIPAddresses
* sizeof(IP_ADDR_STRING
);
655 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
657 ret
= ERROR_BUFFER_OVERFLOW
;
660 InterfaceIndexTable
*table
= NULL
;
661 PMIB_IPADDRTABLE ipAddrTable
= NULL
;
662 PMIB_IPFORWARDTABLE routeTable
= NULL
;
664 ret
= getIPAddrTable(&ipAddrTable
, GetProcessHeap(), 0);
666 ret
= AllocateAndGetIpForwardTableFromStack(&routeTable
, FALSE
, GetProcessHeap(), 0);
668 get_interface_indices( TRUE
, &table
);
670 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
671 size
+= ipAddrTable
->dwNumEntries
* sizeof(IP_ADDR_STRING
);
672 if (*pOutBufLen
< size
) {
674 ret
= ERROR_INSUFFICIENT_BUFFER
;
679 BOOL winsEnabled
= FALSE
;
680 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
681 PIP_ADDR_STRING nextIPAddr
= (PIP_ADDR_STRING
)((LPBYTE
)pAdapterInfo
682 + numNonLoopbackInterfaces
* sizeof(IP_ADAPTER_INFO
));
684 memset(pAdapterInfo
, 0, size
);
685 /* @@ Wine registry key: HKCU\Software\Wine\Network */
686 if (RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Network",
687 &hKey
) == ERROR_SUCCESS
) {
688 DWORD size
= sizeof(primaryWINS
.String
);
691 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
692 (LPBYTE
)primaryWINS
.String
, &size
);
693 addr
= inet_addr(primaryWINS
.String
);
694 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
696 size
= sizeof(secondaryWINS
.String
);
697 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
698 (LPBYTE
)secondaryWINS
.String
, &size
);
699 addr
= inet_addr(secondaryWINS
.String
);
700 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
704 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
705 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
707 PIP_ADDR_STRING currentIPAddr
= &ptr
->IpAddressList
;
708 BOOL firstIPAddr
= TRUE
;
710 /* on Win98 this is left empty, but whatever */
711 getInterfaceNameByIndex(table
->indexes
[ndx
], ptr
->AdapterName
);
712 getInterfaceNameByIndex(table
->indexes
[ndx
], ptr
->Description
);
713 ptr
->AddressLength
= sizeof(ptr
->Address
);
714 getInterfacePhysicalByIndex(table
->indexes
[ndx
],
715 &ptr
->AddressLength
, ptr
->Address
, &ptr
->Type
);
716 ptr
->Index
= table
->indexes
[ndx
];
717 for (i
= 0; i
< ipAddrTable
->dwNumEntries
; i
++) {
718 if (ipAddrTable
->table
[i
].dwIndex
== ptr
->Index
) {
720 RtlIpv4AddressToStringA((IN_ADDR
*)&ipAddrTable
->table
[i
].dwAddr
,
721 ptr
->IpAddressList
.IpAddress
.String
);
722 RtlIpv4AddressToStringA((IN_ADDR
*)&ipAddrTable
->table
[i
].dwMask
,
723 ptr
->IpAddressList
.IpMask
.String
);
727 currentIPAddr
->Next
= nextIPAddr
;
728 currentIPAddr
= nextIPAddr
;
729 RtlIpv4AddressToStringA((IN_ADDR
*)&ipAddrTable
->table
[i
].dwAddr
,
730 currentIPAddr
->IpAddress
.String
);
731 RtlIpv4AddressToStringA((IN_ADDR
*)&ipAddrTable
->table
[i
].dwMask
,
732 currentIPAddr
->IpMask
.String
);
737 /* If no IP was found it probably means that the interface is not
738 * configured. In this case we have to return a zeroed IP and mask. */
740 strcpy(ptr
->IpAddressList
.IpAddress
.String
, "0.0.0.0");
741 strcpy(ptr
->IpAddressList
.IpMask
.String
, "0.0.0.0");
743 /* Find first router through this interface, which we'll assume
744 * is the default gateway for this adapter */
745 strcpy(ptr
->GatewayList
.IpAddress
.String
, "0.0.0.0");
746 strcpy(ptr
->GatewayList
.IpMask
.String
, "255.255.255.255");
747 for (i
= 0; i
< routeTable
->dwNumEntries
; i
++)
748 if (routeTable
->table
[i
].dwForwardIfIndex
== ptr
->Index
749 && routeTable
->table
[i
].u1
.ForwardType
==
750 MIB_IPROUTE_TYPE_INDIRECT
)
752 RtlIpv4AddressToStringA((IN_ADDR
*)&routeTable
->table
[i
].dwForwardNextHop
,
753 ptr
->GatewayList
.IpAddress
.String
);
754 RtlIpv4AddressToStringA((IN_ADDR
*)&routeTable
->table
[i
].dwForwardMask
,
755 ptr
->GatewayList
.IpMask
.String
);
758 ptr
->HaveWins
= TRUE
;
759 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
760 primaryWINS
.String
, sizeof(primaryWINS
.String
));
761 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
762 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
764 if (ndx
< table
->numIndexes
- 1)
765 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
769 ptr
->DhcpEnabled
= TRUE
;
773 HeapFree(GetProcessHeap(), 0, table
);
776 ret
= ERROR_OUTOFMEMORY
;
777 HeapFree(GetProcessHeap(), 0, routeTable
);
778 HeapFree(GetProcessHeap(), 0, ipAddrTable
);
784 TRACE("returning %d\n", ret
);
788 static DWORD
typeFromMibType(DWORD mib_type
)
792 case MIB_IF_TYPE_ETHERNET
: return IF_TYPE_ETHERNET_CSMACD
;
793 case MIB_IF_TYPE_TOKENRING
: return IF_TYPE_ISO88025_TOKENRING
;
794 case MIB_IF_TYPE_PPP
: return IF_TYPE_PPP
;
795 case MIB_IF_TYPE_LOOPBACK
: return IF_TYPE_SOFTWARE_LOOPBACK
;
796 default: return IF_TYPE_OTHER
;
800 static NET_IF_CONNECTION_TYPE
connectionTypeFromMibType(DWORD mib_type
)
804 case MIB_IF_TYPE_PPP
: return NET_IF_CONNECTION_DEMAND
;
805 case MIB_IF_TYPE_SLIP
: return NET_IF_CONNECTION_DEMAND
;
806 default: return NET_IF_CONNECTION_DEDICATED
;
810 static ULONG
v4addressesFromIndex(IF_INDEX index
, DWORD
**addrs
, ULONG
*num_addrs
, DWORD
**masks
)
816 if ((ret
= getIPAddrTable(&at
, GetProcessHeap(), 0))) return ret
;
817 for (i
= 0; i
< at
->dwNumEntries
; i
++)
819 if (at
->table
[i
].dwIndex
== index
) (*num_addrs
)++;
821 if (!(*addrs
= HeapAlloc(GetProcessHeap(), 0, *num_addrs
* sizeof(DWORD
))))
823 HeapFree(GetProcessHeap(), 0, at
);
824 return ERROR_OUTOFMEMORY
;
826 if (!(*masks
= HeapAlloc(GetProcessHeap(), 0, *num_addrs
* sizeof(DWORD
))))
828 HeapFree(GetProcessHeap(), 0, *addrs
);
829 HeapFree(GetProcessHeap(), 0, at
);
830 return ERROR_OUTOFMEMORY
;
832 for (i
= 0, j
= 0; i
< at
->dwNumEntries
; i
++)
834 if (at
->table
[i
].dwIndex
== index
)
836 (*addrs
)[j
] = at
->table
[i
].dwAddr
;
837 (*masks
)[j
] = at
->table
[i
].dwMask
;
841 HeapFree(GetProcessHeap(), 0, at
);
842 return ERROR_SUCCESS
;
845 static char *debugstr_ipv4(const in_addr_t
*in_addr
, char *buf
)
850 for (addrp
= (const BYTE
*)in_addr
;
851 addrp
- (const BYTE
*)in_addr
< sizeof(*in_addr
);
854 if (addrp
== (const BYTE
*)in_addr
+ sizeof(*in_addr
) - 1)
855 sprintf(p
, "%d", *addrp
);
857 p
+= sprintf(p
, "%d.", *addrp
);
862 static ULONG
count_v4_gateways(DWORD index
, PMIB_IPFORWARDTABLE routeTable
)
864 DWORD i
, num_gateways
= 0;
866 for (i
= 0; i
< routeTable
->dwNumEntries
; i
++)
868 if (routeTable
->table
[i
].dwForwardIfIndex
== index
&&
869 routeTable
->table
[i
].u1
.ForwardType
== MIB_IPROUTE_TYPE_INDIRECT
)
875 static DWORD
mask_v4_to_prefix(DWORD m
)
877 #ifdef HAVE___BUILTIN_POPCOUNT
878 return __builtin_popcount(m
);
880 m
-= m
>> 1 & 0x55555555;
881 m
= (m
& 0x33333333) + (m
>> 2 & 0x33333333);
882 return ((m
+ (m
>> 4)) & 0x0f0f0f0f) * 0x01010101 >> 24;
886 static DWORD
mask_v6_to_prefix(SOCKET_ADDRESS
*m
)
888 const IN6_ADDR
*mask
= &((struct WS_sockaddr_in6
*)m
->lpSockaddr
)->sin6_addr
;
891 for (i
= 0; i
< 8; i
++)
892 ret
+= mask_v4_to_prefix(mask
->u
.Word
[i
]);
896 static PMIB_IPFORWARDROW
findIPv4Gateway(DWORD index
,
897 PMIB_IPFORWARDTABLE routeTable
)
900 PMIB_IPFORWARDROW row
= NULL
;
902 for (i
= 0; !row
&& i
< routeTable
->dwNumEntries
; i
++)
904 if (routeTable
->table
[i
].dwForwardIfIndex
== index
&&
905 routeTable
->table
[i
].u1
.ForwardType
== MIB_IPROUTE_TYPE_INDIRECT
)
906 row
= &routeTable
->table
[i
];
911 static void fill_unicast_addr_data(IP_ADAPTER_ADDRESSES
*aa
, IP_ADAPTER_UNICAST_ADDRESS
*ua
)
913 /* Actually this information should be read somewhere from the system
914 * but it doesn't matter much for the bugs found so far.
915 * This information is required for DirectPlay8 games. */
916 if (aa
->IfType
!= IF_TYPE_SOFTWARE_LOOPBACK
)
918 ua
->PrefixOrigin
= IpPrefixOriginDhcp
;
919 ua
->SuffixOrigin
= IpSuffixOriginDhcp
;
923 ua
->PrefixOrigin
= IpPrefixOriginManual
;
924 ua
->SuffixOrigin
= IpSuffixOriginManual
;
927 /* The address is not duplicated in the network */
928 ua
->DadState
= IpDadStatePreferred
;
930 /* Some address life time values, required even for non-dhcp addresses */
931 ua
->ValidLifetime
= 60000;
932 ua
->PreferredLifetime
= 60000;
933 ua
->LeaseLifetime
= 60000;
936 static ULONG
adapterAddressesFromIndex(ULONG family
, ULONG flags
, IF_INDEX index
,
937 IP_ADAPTER_ADDRESSES
*aa
, ULONG
*size
)
939 ULONG ret
= ERROR_SUCCESS
, i
, j
, num_v4addrs
= 0, num_v4_gateways
= 0, num_v6addrs
= 0, total_size
;
940 DWORD
*v4addrs
= NULL
, *v4masks
= NULL
;
941 SOCKET_ADDRESS
*v6addrs
= NULL
, *v6masks
= NULL
;
942 PMIB_IPFORWARDTABLE routeTable
= NULL
;
943 BOOL output_gateways
;
945 if ((flags
& GAA_FLAG_INCLUDE_ALL_GATEWAYS
) || !(flags
& GAA_FLAG_SKIP_UNICAST
))
947 ret
= AllocateAndGetIpForwardTableFromStack(&routeTable
, FALSE
, GetProcessHeap(), 0);
949 num_v4_gateways
= count_v4_gateways(index
, routeTable
);
951 output_gateways
= (flags
& GAA_FLAG_INCLUDE_ALL_GATEWAYS
) && (family
== WS_AF_INET
|| family
== WS_AF_UNSPEC
);
953 if (family
== WS_AF_INET
)
955 ret
= v4addressesFromIndex(index
, &v4addrs
, &num_v4addrs
, &v4masks
);
957 else if (family
== WS_AF_INET6
)
959 ret
= v6addressesFromIndex(index
, &v6addrs
, &num_v6addrs
, &v6masks
);
961 else if (family
== WS_AF_UNSPEC
)
963 ret
= v4addressesFromIndex(index
, &v4addrs
, &num_v4addrs
, &v4masks
);
964 if (!ret
) ret
= v6addressesFromIndex(index
, &v6addrs
, &num_v6addrs
, &v6masks
);
968 FIXME("address family %u unsupported\n", family
);
973 HeapFree(GetProcessHeap(), 0, v4addrs
);
974 HeapFree(GetProcessHeap(), 0, v4masks
);
975 HeapFree(GetProcessHeap(), 0, v6addrs
);
976 HeapFree(GetProcessHeap(), 0, v6masks
);
977 HeapFree(GetProcessHeap(), 0, routeTable
);
981 total_size
= sizeof(IP_ADAPTER_ADDRESSES
);
982 total_size
+= 39; /* "{00000000-0000-0000-0000-000000000000}" */
983 total_size
+= IF_NAMESIZE
* sizeof(WCHAR
);
984 if (!(flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
985 total_size
+= IF_NAMESIZE
* sizeof(WCHAR
);
986 if (flags
& GAA_FLAG_INCLUDE_PREFIX
)
988 total_size
+= sizeof(IP_ADAPTER_PREFIX
) * num_v4addrs
;
989 total_size
+= sizeof(IP_ADAPTER_PREFIX
) * num_v6addrs
;
990 total_size
+= sizeof(struct sockaddr_in
) * num_v4addrs
;
991 for (i
= 0; i
< num_v6addrs
; i
++)
992 total_size
+= v6masks
[i
].iSockaddrLength
;
994 total_size
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
) * num_v4addrs
;
995 total_size
+= sizeof(struct sockaddr_in
) * num_v4addrs
;
997 total_size
+= (sizeof(IP_ADAPTER_GATEWAY_ADDRESS
) + sizeof(SOCKADDR_IN
)) * num_v4_gateways
;
998 total_size
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
) * num_v6addrs
;
999 total_size
+= sizeof(SOCKET_ADDRESS
) * num_v6addrs
;
1000 for (i
= 0; i
< num_v6addrs
; i
++)
1001 total_size
+= v6addrs
[i
].iSockaddrLength
;
1003 if (aa
&& *size
>= total_size
)
1005 char name
[IF_NAMESIZE
], *ptr
= (char *)aa
+ sizeof(IP_ADAPTER_ADDRESSES
), *src
;
1008 INTERNAL_IF_OPER_STATUS status
;
1012 memset(aa
, 0, sizeof(IP_ADAPTER_ADDRESSES
));
1013 aa
->u
.s
.Length
= sizeof(IP_ADAPTER_ADDRESSES
);
1014 aa
->u
.s
.IfIndex
= index
;
1016 ConvertInterfaceIndexToLuid(index
, &luid
);
1017 ConvertInterfaceLuidToGuid(&luid
, &guid
);
1018 sprintf(ptr
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
1019 guid
.Data1
, guid
.Data2
, guid
.Data3
, guid
.Data4
[0], guid
.Data4
[1],
1020 guid
.Data4
[2], guid
.Data4
[3], guid
.Data4
[4], guid
.Data4
[5],
1021 guid
.Data4
[6], guid
.Data4
[7]);
1022 aa
->AdapterName
= ptr
;
1025 getInterfaceNameByIndex(index
, name
);
1026 if (!(flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
1028 aa
->FriendlyName
= (WCHAR
*)ptr
;
1029 for (src
= name
, dst
= (WCHAR
*)ptr
; *src
; src
++, dst
++)
1034 aa
->Description
= (WCHAR
*)ptr
;
1035 for (src
= name
, dst
= (WCHAR
*)ptr
; *src
; src
++, dst
++)
1040 TRACE("%s: %d IPv4 addresses, %d IPv6 addresses:\n", name
, num_v4addrs
,
1043 buflen
= MAX_INTERFACE_PHYSADDR
;
1044 getInterfacePhysicalByIndex(index
, &buflen
, aa
->PhysicalAddress
, &type
);
1045 aa
->PhysicalAddressLength
= buflen
;
1046 aa
->IfType
= typeFromMibType(type
);
1047 aa
->ConnectionType
= connectionTypeFromMibType(type
);
1048 aa
->Luid
.Info
.NetLuidIndex
= index
;
1049 aa
->Luid
.Info
.IfType
= aa
->IfType
;
1051 if (output_gateways
&& num_v4_gateways
)
1053 PMIB_IPFORWARDROW adapterRow
;
1055 if ((adapterRow
= findIPv4Gateway(index
, routeTable
)))
1057 PIP_ADAPTER_GATEWAY_ADDRESS gw
;
1060 gw
= (PIP_ADAPTER_GATEWAY_ADDRESS
)ptr
;
1061 aa
->FirstGatewayAddress
= gw
;
1063 gw
->u
.s
.Length
= sizeof(IP_ADAPTER_GATEWAY_ADDRESS
);
1064 ptr
+= sizeof(IP_ADAPTER_GATEWAY_ADDRESS
);
1065 sin
= (PSOCKADDR_IN
)ptr
;
1066 sin
->sin_family
= WS_AF_INET
;
1068 memcpy(&sin
->sin_addr
, &adapterRow
->dwForwardNextHop
,
1070 gw
->Address
.lpSockaddr
= (LPSOCKADDR
)sin
;
1071 gw
->Address
.iSockaddrLength
= sizeof(SOCKADDR_IN
);
1073 ptr
+= sizeof(SOCKADDR_IN
);
1076 if (num_v4addrs
&& !(flags
& GAA_FLAG_SKIP_UNICAST
))
1078 IP_ADAPTER_UNICAST_ADDRESS
*ua
;
1079 struct WS_sockaddr_in
*sa
;
1080 aa
->u1
.s1
.Ipv4Enabled
= TRUE
;
1081 ua
= aa
->FirstUnicastAddress
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1082 for (i
= 0; i
< num_v4addrs
; i
++)
1086 memset(ua
, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS
));
1087 ua
->u
.s
.Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
1088 ua
->Address
.iSockaddrLength
= sizeof(struct sockaddr_in
);
1089 ua
->Address
.lpSockaddr
= (SOCKADDR
*)((char *)ua
+ ua
->u
.s
.Length
);
1090 if (num_v4_gateways
)
1091 ua
->u
.s
.Flags
|= IP_ADAPTER_ADDRESS_DNS_ELIGIBLE
;
1093 sa
= (struct WS_sockaddr_in
*)ua
->Address
.lpSockaddr
;
1094 sa
->sin_family
= WS_AF_INET
;
1095 sa
->sin_addr
.S_un
.S_addr
= v4addrs
[i
];
1097 TRACE("IPv4 %d/%d: %s\n", i
+ 1, num_v4addrs
,
1098 debugstr_ipv4(&sa
->sin_addr
.S_un
.S_addr
, addr_buf
));
1099 fill_unicast_addr_data(aa
, ua
);
1101 ua
->OnLinkPrefixLength
= mask_v4_to_prefix(v4masks
[i
]);
1103 ptr
+= ua
->u
.s
.Length
+ ua
->Address
.iSockaddrLength
;
1104 if (i
< num_v4addrs
- 1)
1106 ua
->Next
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1111 if (num_v6addrs
&& !(flags
& GAA_FLAG_SKIP_UNICAST
))
1113 IP_ADAPTER_UNICAST_ADDRESS
*ua
;
1114 struct WS_sockaddr_in6
*sa
;
1116 aa
->u1
.s1
.Ipv6Enabled
= TRUE
;
1117 if (aa
->FirstUnicastAddress
)
1119 for (ua
= aa
->FirstUnicastAddress
; ua
->Next
; ua
= ua
->Next
)
1121 ua
->Next
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1122 ua
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1125 ua
= aa
->FirstUnicastAddress
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1126 for (i
= 0; i
< num_v6addrs
; i
++)
1130 memset(ua
, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS
));
1131 ua
->u
.s
.Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
1132 ua
->Address
.iSockaddrLength
= v6addrs
[i
].iSockaddrLength
;
1133 ua
->Address
.lpSockaddr
= (SOCKADDR
*)((char *)ua
+ ua
->u
.s
.Length
);
1135 sa
= (struct WS_sockaddr_in6
*)ua
->Address
.lpSockaddr
;
1136 memcpy(sa
, v6addrs
[i
].lpSockaddr
, sizeof(*sa
));
1137 TRACE("IPv6 %d/%d: %s\n", i
+ 1, num_v6addrs
,
1138 debugstr_ipv6(sa
, addr_buf
));
1139 fill_unicast_addr_data(aa
, ua
);
1141 ua
->OnLinkPrefixLength
= mask_v6_to_prefix(&v6masks
[i
]);
1143 ptr
+= ua
->u
.s
.Length
+ ua
->Address
.iSockaddrLength
;
1144 if (i
< num_v6addrs
- 1)
1146 ua
->Next
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1151 if (num_v4addrs
&& (flags
& GAA_FLAG_INCLUDE_PREFIX
))
1153 IP_ADAPTER_PREFIX
*prefix
;
1155 prefix
= aa
->FirstPrefix
= (IP_ADAPTER_PREFIX
*)ptr
;
1156 for (i
= 0; i
< num_v4addrs
; i
++)
1159 struct WS_sockaddr_in
*sa
;
1161 prefix
->u
.s
.Length
= sizeof(*prefix
);
1162 prefix
->u
.s
.Flags
= 0;
1163 prefix
->Next
= NULL
;
1164 prefix
->Address
.iSockaddrLength
= sizeof(struct sockaddr_in
);
1165 prefix
->Address
.lpSockaddr
= (SOCKADDR
*)((char *)prefix
+ prefix
->u
.s
.Length
);
1167 sa
= (struct WS_sockaddr_in
*)prefix
->Address
.lpSockaddr
;
1168 sa
->sin_family
= WS_AF_INET
;
1169 sa
->sin_addr
.S_un
.S_addr
= v4addrs
[i
] & v4masks
[i
];
1172 prefix
->PrefixLength
= mask_v4_to_prefix(v4masks
[i
]);
1174 TRACE("IPv4 network: %s/%u\n",
1175 debugstr_ipv4((const in_addr_t
*)&sa
->sin_addr
.S_un
.S_addr
, addr_buf
),
1176 prefix
->PrefixLength
);
1178 ptr
+= prefix
->u
.s
.Length
+ prefix
->Address
.iSockaddrLength
;
1179 if (i
< num_v4addrs
- 1)
1181 prefix
->Next
= (IP_ADAPTER_PREFIX
*)ptr
;
1182 prefix
= prefix
->Next
;
1186 if (num_v6addrs
&& (flags
& GAA_FLAG_INCLUDE_PREFIX
))
1188 IP_ADAPTER_PREFIX
*prefix
;
1190 if (aa
->FirstPrefix
)
1192 for (prefix
= aa
->FirstPrefix
; prefix
->Next
; prefix
= prefix
->Next
)
1194 prefix
->Next
= (IP_ADAPTER_PREFIX
*)ptr
;
1195 prefix
= (IP_ADAPTER_PREFIX
*)ptr
;
1198 prefix
= aa
->FirstPrefix
= (IP_ADAPTER_PREFIX
*)ptr
;
1199 for (i
= 0; i
< num_v6addrs
; i
++)
1202 struct WS_sockaddr_in6
*sa
;
1203 const IN6_ADDR
*addr
, *mask
;
1205 prefix
->u
.s
.Length
= sizeof(*prefix
);
1206 prefix
->u
.s
.Flags
= 0;
1207 prefix
->Next
= NULL
;
1208 prefix
->Address
.iSockaddrLength
= sizeof(struct sockaddr_in6
);
1209 prefix
->Address
.lpSockaddr
= (SOCKADDR
*)((char *)prefix
+ prefix
->u
.s
.Length
);
1211 sa
= (struct WS_sockaddr_in6
*)prefix
->Address
.lpSockaddr
;
1212 sa
->sin6_family
= WS_AF_INET6
;
1214 sa
->sin6_flowinfo
= 0;
1215 addr
= &((struct WS_sockaddr_in6
*)v6addrs
[i
].lpSockaddr
)->sin6_addr
;
1216 mask
= &((struct WS_sockaddr_in6
*)v6masks
[i
].lpSockaddr
)->sin6_addr
;
1217 for (j
= 0; j
< 8; j
++) sa
->sin6_addr
.u
.Word
[j
] = addr
->u
.Word
[j
] & mask
->u
.Word
[j
];
1218 sa
->sin6_scope_id
= 0;
1220 prefix
->PrefixLength
= mask_v6_to_prefix(&v6masks
[i
]);
1222 TRACE("IPv6 network: %s/%u\n", debugstr_ipv6(sa
, addr_buf
), prefix
->PrefixLength
);
1224 ptr
+= prefix
->u
.s
.Length
+ prefix
->Address
.iSockaddrLength
;
1225 if (i
< num_v6addrs
- 1)
1227 prefix
->Next
= (IP_ADAPTER_PREFIX
*)ptr
;
1228 prefix
= prefix
->Next
;
1233 getInterfaceMtuByName(name
, &aa
->Mtu
);
1235 getInterfaceStatusByName(name
, &status
);
1236 if (status
== MIB_IF_OPER_STATUS_OPERATIONAL
) aa
->OperStatus
= IfOperStatusUp
;
1237 else if (status
== MIB_IF_OPER_STATUS_NON_OPERATIONAL
) aa
->OperStatus
= IfOperStatusDown
;
1238 else aa
->OperStatus
= IfOperStatusUnknown
;
1241 HeapFree(GetProcessHeap(), 0, routeTable
);
1242 HeapFree(GetProcessHeap(), 0, v6addrs
);
1243 HeapFree(GetProcessHeap(), 0, v6masks
);
1244 HeapFree(GetProcessHeap(), 0, v4addrs
);
1245 HeapFree(GetProcessHeap(), 0, v4masks
);
1246 return ERROR_SUCCESS
;
1249 static void sockaddr_in_to_WS_storage( SOCKADDR_STORAGE
*dst
, const struct sockaddr_in
*src
)
1251 SOCKADDR_IN
*s
= (SOCKADDR_IN
*)dst
;
1253 s
->sin_family
= WS_AF_INET
;
1254 s
->sin_port
= src
->sin_port
;
1255 memcpy( &s
->sin_addr
, &src
->sin_addr
, sizeof(IN_ADDR
) );
1256 memset( (char *)s
+ FIELD_OFFSET( SOCKADDR_IN
, sin_zero
), 0,
1257 sizeof(SOCKADDR_STORAGE
) - FIELD_OFFSET( SOCKADDR_IN
, sin_zero
) );
1260 #if defined(HAVE_STRUCT___RES_STATE__U__EXT_NSCOUNT6) || \
1261 (defined(HAVE___RES_GET_STATE) && defined(HAVE___RES_GETSERVERS)) || \
1262 defined(HAVE_RES_GETSERVERS)
1263 static void sockaddr_in6_to_WS_storage( SOCKADDR_STORAGE
*dst
, const struct sockaddr_in6
*src
)
1265 SOCKADDR_IN6
*s
= (SOCKADDR_IN6
*)dst
;
1267 s
->sin6_family
= WS_AF_INET6
;
1268 s
->sin6_port
= src
->sin6_port
;
1269 s
->sin6_flowinfo
= src
->sin6_flowinfo
;
1270 memcpy( &s
->sin6_addr
, &src
->sin6_addr
, sizeof(IN6_ADDR
) );
1271 s
->sin6_scope_id
= src
->sin6_scope_id
;
1272 memset( (char *)s
+ sizeof(SOCKADDR_IN6
), 0,
1273 sizeof(SOCKADDR_STORAGE
) - sizeof(SOCKADDR_IN6
) );
1277 #ifdef HAVE_STRUCT___RES_STATE
1278 /* call res_init() just once because of a bug in Mac OS X 10.4 */
1279 /* Call once per thread on systems that have per-thread _res. */
1281 static CRITICAL_SECTION res_init_cs
;
1282 static CRITICAL_SECTION_DEBUG res_init_cs_debug
= {
1284 { &res_init_cs_debug
.ProcessLocksList
, &res_init_cs_debug
.ProcessLocksList
},
1285 0, 0, { (DWORD_PTR
)(__FILE__
": res_init_cs") }
1287 static CRITICAL_SECTION res_init_cs
= { &res_init_cs_debug
, -1, 0, 0, 0, 0 };
1289 static void initialise_resolver(void)
1291 EnterCriticalSection(&res_init_cs
);
1292 if ((_res
.options
& RES_INIT
) == 0)
1294 LeaveCriticalSection(&res_init_cs
);
1297 #ifdef HAVE_RES_GETSERVERS
1298 static int get_dns_servers( SOCKADDR_STORAGE
*servers
, int num
, BOOL ip4_only
)
1300 struct __res_state
*state
= &_res
;
1301 int i
, found
= 0, total
;
1302 SOCKADDR_STORAGE
*addr
= servers
;
1303 union res_sockaddr_union
*buf
;
1305 initialise_resolver();
1307 total
= res_getservers( state
, NULL
, 0 );
1309 if ((!servers
|| !num
) && !ip4_only
) return total
;
1311 buf
= HeapAlloc( GetProcessHeap(), 0, total
* sizeof(union res_sockaddr_union
) );
1312 total
= res_getservers( state
, buf
, total
);
1314 for (i
= 0; i
< total
; i
++)
1316 if (buf
[i
].sin6
.sin6_family
== AF_INET6
&& ip4_only
) continue;
1317 if (buf
[i
].sin
.sin_family
!= AF_INET
&& buf
[i
].sin6
.sin6_family
!= AF_INET6
) continue;
1320 if (!servers
|| !num
) continue;
1322 if (buf
[i
].sin6
.sin6_family
== AF_INET6
)
1324 sockaddr_in6_to_WS_storage( addr
, &buf
[i
].sin6
);
1328 sockaddr_in_to_WS_storage( addr
, &buf
[i
].sin
);
1330 if (++addr
>= servers
+ num
) break;
1333 HeapFree( GetProcessHeap(), 0, buf
);
1338 static int get_dns_servers( SOCKADDR_STORAGE
*servers
, int num
, BOOL ip4_only
)
1340 int i
, ip6_count
= 0;
1341 SOCKADDR_STORAGE
*addr
;
1343 initialise_resolver();
1345 #ifdef HAVE_STRUCT___RES_STATE__U__EXT_NSCOUNT6
1346 ip6_count
= _res
._u
._ext
.nscount6
;
1349 if (!servers
|| !num
)
1352 if (ip4_only
) num
-= ip6_count
;
1356 for (i
= 0, addr
= servers
; addr
< (servers
+ num
) && i
< _res
.nscount
; i
++)
1358 #ifdef HAVE_STRUCT___RES_STATE__U__EXT_NSCOUNT6
1359 if (_res
._u
._ext
.nsaddrs
[i
] && _res
._u
._ext
.nsaddrs
[i
]->sin6_family
== AF_INET6
)
1361 if (ip4_only
) continue;
1362 sockaddr_in6_to_WS_storage( addr
, _res
._u
._ext
.nsaddrs
[i
] );
1367 sockaddr_in_to_WS_storage( addr
, _res
.nsaddr_list
+ i
);
1371 return addr
- servers
;
1374 #elif defined(HAVE___RES_GET_STATE) && defined(HAVE___RES_GETSERVERS)
1376 static int get_dns_servers( SOCKADDR_STORAGE
*servers
, int num
, BOOL ip4_only
)
1378 extern struct res_state
*__res_get_state( void );
1379 extern int __res_getservers( struct res_state
*, struct sockaddr_storage
*, int );
1380 struct res_state
*state
= __res_get_state();
1381 int i
, found
= 0, total
= __res_getservers( state
, NULL
, 0 );
1382 SOCKADDR_STORAGE
*addr
= servers
;
1383 struct sockaddr_storage
*buf
;
1385 if ((!servers
|| !num
) && !ip4_only
) return total
;
1387 buf
= HeapAlloc( GetProcessHeap(), 0, total
* sizeof(struct sockaddr_storage
) );
1388 total
= __res_getservers( state
, buf
, total
);
1390 for (i
= 0; i
< total
; i
++)
1392 if (buf
[i
].ss_family
== AF_INET6
&& ip4_only
) continue;
1393 if (buf
[i
].ss_family
!= AF_INET
&& buf
[i
].ss_family
!= AF_INET6
) continue;
1396 if (!servers
|| !num
) continue;
1398 if (buf
[i
].ss_family
== AF_INET6
)
1400 sockaddr_in6_to_WS_storage( addr
, (struct sockaddr_in6
*)(buf
+ i
) );
1404 sockaddr_in_to_WS_storage( addr
, (struct sockaddr_in
*)(buf
+ i
) );
1406 if (++addr
>= servers
+ num
) break;
1409 HeapFree( GetProcessHeap(), 0, buf
);
1414 static int get_dns_servers( SOCKADDR_STORAGE
*servers
, int num
, BOOL ip4_only
)
1416 FIXME("Unimplemented on this system\n");
1421 static ULONG
get_dns_server_addresses(PIP_ADAPTER_DNS_SERVER_ADDRESS address
, ULONG
*len
)
1423 int num
= get_dns_servers( NULL
, 0, FALSE
);
1426 size
= num
* (sizeof(IP_ADAPTER_DNS_SERVER_ADDRESS
) + sizeof(SOCKADDR_STORAGE
));
1427 if (!address
|| *len
< size
)
1430 return ERROR_BUFFER_OVERFLOW
;
1435 PIP_ADAPTER_DNS_SERVER_ADDRESS addr
= address
;
1436 SOCKADDR_STORAGE
*sock_addrs
= (SOCKADDR_STORAGE
*)(address
+ num
);
1439 get_dns_servers( sock_addrs
, num
, FALSE
);
1441 for (i
= 0; i
< num
; i
++, addr
= addr
->Next
)
1443 addr
->u
.s
.Length
= sizeof(*addr
);
1444 if (sock_addrs
[i
].ss_family
== WS_AF_INET6
)
1445 addr
->Address
.iSockaddrLength
= sizeof(SOCKADDR_IN6
);
1447 addr
->Address
.iSockaddrLength
= sizeof(SOCKADDR_IN
);
1448 addr
->Address
.lpSockaddr
= (SOCKADDR
*)(sock_addrs
+ i
);
1452 addr
->Next
= addr
+ 1;
1455 return ERROR_SUCCESS
;
1458 #ifdef HAVE_STRUCT___RES_STATE
1459 static BOOL
is_ip_address_string(const char *str
)
1464 ret
= inet_aton(str
, &in
);
1469 static ULONG
get_dns_suffix(WCHAR
*suffix
, ULONG
*len
)
1472 const char *found_suffix
= "";
1473 /* Always return a NULL-terminated string, even if it's empty. */
1475 #ifdef HAVE_STRUCT___RES_STATE
1478 initialise_resolver();
1479 for (i
= 0; !*found_suffix
&& i
< MAXDNSRCH
+ 1 && _res
.dnsrch
[i
]; i
++)
1481 /* This uses a heuristic to select a DNS suffix:
1482 * the first, non-IP address string is selected.
1484 if (!is_ip_address_string(_res
.dnsrch
[i
]))
1485 found_suffix
= _res
.dnsrch
[i
];
1490 size
= MultiByteToWideChar( CP_UNIXCP
, 0, found_suffix
, -1, NULL
, 0 ) * sizeof(WCHAR
);
1491 if (!suffix
|| *len
< size
)
1494 return ERROR_BUFFER_OVERFLOW
;
1496 *len
= MultiByteToWideChar( CP_UNIXCP
, 0, found_suffix
, -1, suffix
, *len
/ sizeof(WCHAR
) ) * sizeof(WCHAR
);
1497 return ERROR_SUCCESS
;
1500 ULONG WINAPI DECLSPEC_HOTPATCH
GetAdaptersAddresses(ULONG family
, ULONG flags
, PVOID reserved
,
1501 PIP_ADAPTER_ADDRESSES aa
, PULONG buflen
)
1503 InterfaceIndexTable
*table
;
1504 ULONG i
, size
, dns_server_size
= 0, dns_suffix_size
, total_size
, ret
= ERROR_NO_DATA
;
1506 TRACE("(%d, %08x, %p, %p, %p)\n", family
, flags
, reserved
, aa
, buflen
);
1508 if (!buflen
) return ERROR_INVALID_PARAMETER
;
1510 get_interface_indices( FALSE
, &table
);
1511 if (!table
|| !table
->numIndexes
)
1513 HeapFree(GetProcessHeap(), 0, table
);
1514 return ERROR_NO_DATA
;
1517 for (i
= 0; i
< table
->numIndexes
; i
++)
1520 if ((ret
= adapterAddressesFromIndex(family
, flags
, table
->indexes
[i
], NULL
, &size
)))
1522 HeapFree(GetProcessHeap(), 0, table
);
1527 if (!(flags
& GAA_FLAG_SKIP_DNS_SERVER
))
1529 /* Since DNS servers aren't really per adapter, get enough space for a
1530 * single copy of them.
1532 get_dns_server_addresses(NULL
, &dns_server_size
);
1533 total_size
+= dns_server_size
;
1535 /* Since DNS suffix also isn't really per adapter, get enough space for a
1536 * single copy of it.
1538 get_dns_suffix(NULL
, &dns_suffix_size
);
1539 total_size
+= dns_suffix_size
;
1540 if (aa
&& *buflen
>= total_size
)
1542 ULONG bytes_left
= size
= total_size
;
1543 PIP_ADAPTER_ADDRESSES first_aa
= aa
;
1544 PIP_ADAPTER_DNS_SERVER_ADDRESS firstDns
;
1547 for (i
= 0; i
< table
->numIndexes
; i
++)
1549 if ((ret
= adapterAddressesFromIndex(family
, flags
, table
->indexes
[i
], aa
, &size
)))
1551 HeapFree(GetProcessHeap(), 0, table
);
1554 if (i
< table
->numIndexes
- 1)
1556 aa
->Next
= (IP_ADAPTER_ADDRESSES
*)((char *)aa
+ size
);
1558 size
= bytes_left
-= size
;
1561 if (dns_server_size
)
1563 firstDns
= (PIP_ADAPTER_DNS_SERVER_ADDRESS
)((BYTE
*)first_aa
+ total_size
- dns_server_size
- dns_suffix_size
);
1564 get_dns_server_addresses(firstDns
, &dns_server_size
);
1565 for (aa
= first_aa
; aa
; aa
= aa
->Next
)
1567 if (aa
->IfType
!= IF_TYPE_SOFTWARE_LOOPBACK
&& aa
->OperStatus
== IfOperStatusUp
)
1568 aa
->FirstDnsServerAddress
= firstDns
;
1572 dnsSuffix
= (WCHAR
*)((BYTE
*)aa
+ total_size
- dns_suffix_size
);
1573 get_dns_suffix(dnsSuffix
, &dns_suffix_size
);
1574 for (; aa
; aa
= aa
->Next
)
1576 if (aa
->IfType
!= IF_TYPE_SOFTWARE_LOOPBACK
&& aa
->OperStatus
== IfOperStatusUp
)
1577 aa
->DnsSuffix
= dnsSuffix
;
1579 aa
->DnsSuffix
= dnsSuffix
+ dns_suffix_size
/ sizeof(WCHAR
) - 1;
1581 ret
= ERROR_SUCCESS
;
1585 ret
= ERROR_BUFFER_OVERFLOW
;
1586 *buflen
= total_size
;
1589 TRACE("num adapters %u\n", table
->numIndexes
);
1590 HeapFree(GetProcessHeap(), 0, table
);
1594 /******************************************************************
1595 * GetBestInterface (IPHLPAPI.@)
1597 * Get the interface, with the best route for the given IP address.
1600 * dwDestAddr [In] IP address to search the interface for
1601 * pdwBestIfIndex [Out] found best interface
1605 * Failure: error code from winerror.h
1607 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
1609 struct WS_sockaddr_in sa_in
;
1610 memset(&sa_in
, 0, sizeof(sa_in
));
1611 sa_in
.sin_family
= WS_AF_INET
;
1612 sa_in
.sin_addr
.S_un
.S_addr
= dwDestAddr
;
1613 return GetBestInterfaceEx((struct WS_sockaddr
*)&sa_in
, pdwBestIfIndex
);
1616 /******************************************************************
1617 * GetBestInterfaceEx (IPHLPAPI.@)
1619 * Get the interface, with the best route for the given IP address.
1622 * dwDestAddr [In] IP address to search the interface for
1623 * pdwBestIfIndex [Out] found best interface
1627 * Failure: error code from winerror.h
1629 DWORD WINAPI
GetBestInterfaceEx(struct WS_sockaddr
*pDestAddr
, PDWORD pdwBestIfIndex
)
1633 TRACE("pDestAddr %p, pdwBestIfIndex %p\n", pDestAddr
, pdwBestIfIndex
);
1634 if (!pDestAddr
|| !pdwBestIfIndex
)
1635 ret
= ERROR_INVALID_PARAMETER
;
1637 MIB_IPFORWARDROW ipRow
;
1639 if (pDestAddr
->sa_family
== WS_AF_INET
) {
1640 ret
= GetBestRoute(((struct WS_sockaddr_in
*)pDestAddr
)->sin_addr
.S_un
.S_addr
, 0, &ipRow
);
1641 if (ret
== ERROR_SUCCESS
)
1642 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
1644 FIXME("address family %d not supported\n", pDestAddr
->sa_family
);
1645 ret
= ERROR_NOT_SUPPORTED
;
1648 TRACE("returning %d\n", ret
);
1653 /******************************************************************
1654 * GetBestRoute (IPHLPAPI.@)
1656 * Get the best route for the given IP address.
1659 * dwDestAddr [In] IP address to search the best route for
1660 * dwSourceAddr [In] optional source IP address
1661 * pBestRoute [Out] found best route
1665 * Failure: error code from winerror.h
1667 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
1669 PMIB_IPFORWARDTABLE table
;
1672 TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr
,
1673 dwSourceAddr
, pBestRoute
);
1675 return ERROR_INVALID_PARAMETER
;
1677 ret
= AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
1679 DWORD ndx
, matchedBits
, matchedNdx
= table
->dwNumEntries
;
1681 for (ndx
= 0, matchedBits
= 0; ndx
< table
->dwNumEntries
; ndx
++) {
1682 if (table
->table
[ndx
].u1
.ForwardType
!= MIB_IPROUTE_TYPE_INVALID
&&
1683 (dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
1684 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
1685 DWORD numShifts
, mask
;
1687 for (numShifts
= 0, mask
= table
->table
[ndx
].dwForwardMask
;
1688 mask
&& mask
& 1; mask
>>= 1, numShifts
++)
1690 if (numShifts
> matchedBits
) {
1691 matchedBits
= numShifts
;
1694 else if (!matchedBits
) {
1699 if (matchedNdx
< table
->dwNumEntries
) {
1700 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
1701 ret
= ERROR_SUCCESS
;
1704 /* No route matches, which can happen if there's no default route. */
1705 ret
= ERROR_HOST_UNREACHABLE
;
1707 HeapFree(GetProcessHeap(), 0, table
);
1709 TRACE("returning %d\n", ret
);
1714 /******************************************************************
1715 * GetFriendlyIfIndex (IPHLPAPI.@)
1717 * Get a "friendly" version of IfIndex, which is one that doesn't
1718 * have the top byte set. Doesn't validate whether IfIndex is a valid
1722 * IfIndex [In] interface index to get the friendly one for
1725 * A friendly version of IfIndex.
1727 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
1729 /* windows doesn't validate these, either, just makes sure the top byte is
1730 cleared. I assume my ifenum module never gives an index with the top
1732 TRACE("returning %d\n", IfIndex
);
1737 /******************************************************************
1738 * GetIfEntry (IPHLPAPI.@)
1740 * Get information about an interface.
1743 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
1744 * Out: interface information
1748 * Failure: error code from winerror.h
1750 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
1753 char nameBuf
[MAX_ADAPTER_NAME
];
1756 TRACE("pIfRow %p\n", pIfRow
);
1758 return ERROR_INVALID_PARAMETER
;
1760 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
, nameBuf
);
1762 ret
= getInterfaceEntryByName(name
, pIfRow
);
1763 if (ret
== NO_ERROR
)
1764 ret
= getInterfaceStatsByName(name
, pIfRow
);
1767 ret
= ERROR_INVALID_DATA
;
1768 TRACE("returning %d\n", ret
);
1772 /******************************************************************
1773 * GetIfEntry2 (IPHLPAPI.@)
1775 DWORD WINAPI
GetIfEntry2( MIB_IF_ROW2
*row2
)
1777 DWORD ret
, len
= ARRAY_SIZE(row2
->Description
);
1778 char buf
[MAX_ADAPTER_NAME
], *name
;
1781 TRACE("%p\n", row2
);
1783 if (!row2
|| (!(name
= getInterfaceNameByIndex( row2
->InterfaceIndex
, buf
)) &&
1784 !(name
= getInterfaceNameByIndex( row2
->InterfaceLuid
.Info
.NetLuidIndex
, buf
))))
1786 return ERROR_INVALID_PARAMETER
;
1788 if ((ret
= getInterfaceEntryByName( name
, &row
))) return ret
;
1789 if ((ret
= getInterfaceStatsByName( name
, &row
))) return ret
;
1791 memset( row2
, 0, sizeof(*row2
) );
1792 row2
->InterfaceLuid
.Info
.Reserved
= 0;
1793 row2
->InterfaceLuid
.Info
.NetLuidIndex
= row
.dwIndex
;
1794 row2
->InterfaceLuid
.Info
.IfType
= row
.dwType
;
1795 row2
->InterfaceIndex
= row
.dwIndex
;
1796 ConvertInterfaceLuidToGuid( &row2
->InterfaceLuid
, &row2
->InterfaceGuid
);
1797 row2
->Type
= row
.dwType
;
1798 row2
->Mtu
= row
.dwMtu
;
1799 MultiByteToWideChar( CP_UNIXCP
, 0, (const char *)row
.bDescr
, -1, row2
->Description
, len
);
1800 row2
->PhysicalAddressLength
= row
.dwPhysAddrLen
;
1801 memcpy( &row2
->PhysicalAddress
, &row
.bPhysAddr
, row
.dwPhysAddrLen
);
1802 memcpy( &row2
->PermanentPhysicalAddress
, &row
.bPhysAddr
, row
.dwPhysAddrLen
);
1803 row2
->OperStatus
= IfOperStatusUp
;
1804 row2
->AdminStatus
= NET_IF_ADMIN_STATUS_UP
;
1805 row2
->MediaConnectState
= MediaConnectStateConnected
;
1806 row2
->ConnectionType
= NET_IF_CONNECTION_DEDICATED
;
1809 row2
->InOctets
= row
.dwInOctets
;
1810 row2
->InUcastPkts
= row
.dwInUcastPkts
;
1811 row2
->InNUcastPkts
= row
.dwInNUcastPkts
;
1812 row2
->InDiscards
= row
.dwInDiscards
;
1813 row2
->InErrors
= row
.dwInErrors
;
1814 row2
->InUnknownProtos
= row
.dwInUnknownProtos
;
1815 row2
->OutOctets
= row
.dwOutOctets
;
1816 row2
->OutUcastPkts
= row
.dwOutUcastPkts
;
1817 row2
->OutNUcastPkts
= row
.dwOutNUcastPkts
;
1818 row2
->OutDiscards
= row
.dwOutDiscards
;
1819 row2
->OutErrors
= row
.dwOutErrors
;
1824 static int IfTableSorter(const void *a
, const void *b
)
1829 ret
= ((const MIB_IFROW
*)a
)->dwIndex
- ((const MIB_IFROW
*)b
)->dwIndex
;
1836 /******************************************************************
1837 * GetIfTable (IPHLPAPI.@)
1839 * Get a table of local interfaces.
1842 * pIfTable [Out] buffer for local interfaces table
1843 * pdwSize [In/Out] length of output buffer
1844 * bOrder [In] whether to sort the table
1848 * Failure: error code from winerror.h
1851 * If pdwSize is less than required, the function will return
1852 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1854 * If bOrder is true, the returned table will be sorted by interface index.
1856 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
1860 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pIfTable
, pdwSize
, bOrder
);
1863 ret
= ERROR_INVALID_PARAMETER
;
1865 DWORD numInterfaces
= get_interface_indices( FALSE
, NULL
);
1866 ULONG size
= sizeof(MIB_IFTABLE
);
1868 if (numInterfaces
> 1)
1869 size
+= (numInterfaces
- 1) * sizeof(MIB_IFROW
);
1870 if (!pIfTable
|| *pdwSize
< size
) {
1872 ret
= ERROR_INSUFFICIENT_BUFFER
;
1875 InterfaceIndexTable
*table
;
1876 get_interface_indices( FALSE
, &table
);
1879 size
= sizeof(MIB_IFTABLE
);
1880 if (table
->numIndexes
> 1)
1881 size
+= (table
->numIndexes
- 1) * sizeof(MIB_IFROW
);
1882 if (*pdwSize
< size
) {
1884 ret
= ERROR_INSUFFICIENT_BUFFER
;
1890 pIfTable
->dwNumEntries
= 0;
1891 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1892 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1893 GetIfEntry(&pIfTable
->table
[ndx
]);
1894 pIfTable
->dwNumEntries
++;
1897 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
1901 HeapFree(GetProcessHeap(), 0, table
);
1904 ret
= ERROR_OUTOFMEMORY
;
1907 TRACE("returning %d\n", ret
);
1911 /******************************************************************
1912 * GetIfTable2Ex (IPHLPAPI.@)
1914 DWORD WINAPI
GetIfTable2Ex( MIB_IF_TABLE_LEVEL level
, MIB_IF_TABLE2
**table
)
1916 DWORD i
, nb_interfaces
, size
= sizeof(MIB_IF_TABLE2
);
1917 InterfaceIndexTable
*index_table
;
1920 TRACE( "level %u, table %p\n", level
, table
);
1922 if (!table
|| level
> MibIfTableNormalWithoutStatistics
)
1923 return ERROR_INVALID_PARAMETER
;
1925 if (level
!= MibIfTableNormal
)
1926 FIXME("level %u not fully supported\n", level
);
1928 if ((nb_interfaces
= get_interface_indices( FALSE
, NULL
)) > 1)
1929 size
+= (nb_interfaces
- 1) * sizeof(MIB_IF_ROW2
);
1931 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, size
))) return ERROR_OUTOFMEMORY
;
1933 get_interface_indices( FALSE
, &index_table
);
1936 HeapFree( GetProcessHeap(), 0, ret
);
1937 return ERROR_OUTOFMEMORY
;
1940 ret
->NumEntries
= 0;
1941 for (i
= 0; i
< index_table
->numIndexes
; i
++)
1943 ret
->Table
[i
].InterfaceIndex
= index_table
->indexes
[i
];
1944 GetIfEntry2( &ret
->Table
[i
] );
1948 HeapFree( GetProcessHeap(), 0, index_table
);
1953 /******************************************************************
1954 * GetIfTable2 (IPHLPAPI.@)
1956 DWORD WINAPI
GetIfTable2( MIB_IF_TABLE2
**table
)
1958 TRACE( "table %p\n", table
);
1959 return GetIfTable2Ex(MibIfTableNormal
, table
);
1962 /******************************************************************
1963 * GetInterfaceInfo (IPHLPAPI.@)
1965 * Get a list of network interface adapters.
1968 * pIfTable [Out] buffer for interface adapters
1969 * dwOutBufLen [Out] if buffer is too small, returns required size
1973 * Failure: error code from winerror.h
1976 * MSDN states this should return non-loopback interfaces only.
1978 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1982 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1984 ret
= ERROR_INVALID_PARAMETER
;
1986 DWORD numInterfaces
= get_interface_indices( FALSE
, NULL
);
1987 ULONG size
= sizeof(IP_INTERFACE_INFO
);
1989 if (numInterfaces
> 1)
1990 size
+= (numInterfaces
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
1991 if (!pIfTable
|| *dwOutBufLen
< size
) {
1992 *dwOutBufLen
= size
;
1993 ret
= ERROR_INSUFFICIENT_BUFFER
;
1996 InterfaceIndexTable
*table
;
1997 get_interface_indices( FALSE
, &table
);
2000 size
= sizeof(IP_INTERFACE_INFO
);
2001 if (table
->numIndexes
> 1)
2002 size
+= (table
->numIndexes
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
2003 if (*dwOutBufLen
< size
) {
2004 *dwOutBufLen
= size
;
2005 ret
= ERROR_INSUFFICIENT_BUFFER
;
2009 char nameBuf
[MAX_ADAPTER_NAME
];
2011 *dwOutBufLen
= size
;
2012 pIfTable
->NumAdapters
= 0;
2013 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
2014 const char *walker
, *name
;
2017 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
2018 name
= getInterfaceNameByIndex(table
->indexes
[ndx
], nameBuf
);
2019 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
2020 walker
&& *walker
&&
2021 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
2022 walker
++, assigner
++)
2023 *assigner
= *walker
;
2025 pIfTable
->NumAdapters
++;
2029 HeapFree(GetProcessHeap(), 0, table
);
2032 ret
= ERROR_OUTOFMEMORY
;
2035 TRACE("returning %d\n", ret
);
2040 /******************************************************************
2041 * GetIpAddrTable (IPHLPAPI.@)
2043 * Get interface-to-IP address mapping table.
2046 * pIpAddrTable [Out] buffer for mapping table
2047 * pdwSize [In/Out] length of output buffer
2048 * bOrder [In] whether to sort the table
2052 * Failure: error code from winerror.h
2055 * If pdwSize is less than required, the function will return
2056 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
2058 * If bOrder is true, the returned table will be sorted by the next hop and
2059 * an assortment of arbitrary parameters.
2061 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
2065 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable
, pdwSize
,
2068 ret
= ERROR_INVALID_PARAMETER
;
2070 PMIB_IPADDRTABLE table
;
2072 ret
= getIPAddrTable(&table
, GetProcessHeap(), 0);
2073 if (ret
== NO_ERROR
)
2075 ULONG size
= FIELD_OFFSET(MIB_IPADDRTABLE
, table
[table
->dwNumEntries
]);
2077 if (!pIpAddrTable
|| *pdwSize
< size
) {
2079 ret
= ERROR_INSUFFICIENT_BUFFER
;
2083 memcpy(pIpAddrTable
, table
, size
);
2084 /* sort by numeric IP value */
2086 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
2087 sizeof(MIB_IPADDRROW
), IpAddrTableNumericSorter
);
2088 /* sort ensuring loopback interfaces are in the end */
2090 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
2091 sizeof(MIB_IPADDRROW
), IpAddrTableLoopbackSorter
);
2094 HeapFree(GetProcessHeap(), 0, table
);
2097 TRACE("returning %d\n", ret
);
2102 /******************************************************************
2103 * GetIpForwardTable (IPHLPAPI.@)
2105 * Get the route table.
2108 * pIpForwardTable [Out] buffer for route table
2109 * pdwSize [In/Out] length of output buffer
2110 * bOrder [In] whether to sort the table
2114 * Failure: error code from winerror.h
2117 * If pdwSize is less than required, the function will return
2118 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
2120 * If bOrder is true, the returned table will be sorted by the next hop and
2121 * an assortment of arbitrary parameters.
2123 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
2126 PMIB_IPFORWARDTABLE table
;
2128 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable
, pdwSize
, bOrder
);
2130 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
2132 ret
= AllocateAndGetIpForwardTableFromStack(&table
, bOrder
, GetProcessHeap(), 0);
2134 DWORD size
= FIELD_OFFSET( MIB_IPFORWARDTABLE
, table
[table
->dwNumEntries
] );
2135 if (!pIpForwardTable
|| *pdwSize
< size
) {
2137 ret
= ERROR_INSUFFICIENT_BUFFER
;
2141 memcpy(pIpForwardTable
, table
, size
);
2143 HeapFree(GetProcessHeap(), 0, table
);
2145 TRACE("returning %d\n", ret
);
2150 /******************************************************************
2151 * GetIpNetTable (IPHLPAPI.@)
2153 * Get the IP-to-physical address mapping table.
2156 * pIpNetTable [Out] buffer for mapping table
2157 * pdwSize [In/Out] length of output buffer
2158 * bOrder [In] whether to sort the table
2162 * Failure: error code from winerror.h
2165 * If pdwSize is less than required, the function will return
2166 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
2168 * If bOrder is true, the returned table will be sorted by IP address.
2170 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
2173 PMIB_IPNETTABLE table
;
2175 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
, bOrder
);
2177 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
2179 ret
= AllocateAndGetIpNetTableFromStack( &table
, bOrder
, GetProcessHeap(), 0 );
2181 DWORD size
= FIELD_OFFSET( MIB_IPNETTABLE
, table
[table
->dwNumEntries
] );
2182 if (!pIpNetTable
|| *pdwSize
< size
) {
2184 ret
= ERROR_INSUFFICIENT_BUFFER
;
2188 memcpy(pIpNetTable
, table
, size
);
2190 HeapFree(GetProcessHeap(), 0, table
);
2192 TRACE("returning %d\n", ret
);
2196 /* Gets the DNS server list into the list beginning at list. Assumes that
2197 * a single server address may be placed at list if *len is at least
2198 * sizeof(IP_ADDR_STRING) long. Otherwise, list->Next is set to firstDynamic,
2199 * and assumes that all remaining DNS servers are contiguously located
2200 * beginning at firstDynamic. On input, *len is assumed to be the total number
2201 * of bytes available for all DNS servers, and is ignored if list is NULL.
2202 * On return, *len is set to the total number of bytes required for all DNS
2204 * Returns ERROR_BUFFER_OVERFLOW if *len is insufficient,
2205 * ERROR_SUCCESS otherwise.
2207 static DWORD
get_dns_server_list(PIP_ADDR_STRING list
,
2208 PIP_ADDR_STRING firstDynamic
, DWORD
*len
)
2211 int num
= get_dns_servers( NULL
, 0, TRUE
);
2213 size
= num
* sizeof(IP_ADDR_STRING
);
2214 if (!list
|| *len
< size
) {
2216 return ERROR_BUFFER_OVERFLOW
;
2220 PIP_ADDR_STRING ptr
;
2222 SOCKADDR_STORAGE
*addr
= HeapAlloc( GetProcessHeap(), 0, num
* sizeof(SOCKADDR_STORAGE
) );
2224 get_dns_servers( addr
, num
, TRUE
);
2226 for (i
= 0, ptr
= list
; i
< num
; i
++, ptr
= ptr
->Next
) {
2227 RtlIpv4AddressToStringA((IN_ADDR
*)&((struct sockaddr_in
*)(addr
+ i
))->sin_addr
.s_addr
,
2228 ptr
->IpAddress
.String
);
2232 ptr
->Next
= firstDynamic
;
2234 ptr
->Next
= (PIP_ADDR_STRING
)((PBYTE
)ptr
+ sizeof(IP_ADDR_STRING
));
2236 HeapFree( GetProcessHeap(), 0, addr
);
2238 return ERROR_SUCCESS
;
2241 /******************************************************************
2242 * GetNetworkParams (IPHLPAPI.@)
2244 * Get the network parameters for the local computer.
2247 * pFixedInfo [Out] buffer for network parameters
2248 * pOutBufLen [In/Out] length of output buffer
2252 * Failure: error code from winerror.h
2255 * If pOutBufLen is less than required, the function will return
2256 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
2259 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
2261 DWORD ret
, size
, serverListSize
;
2265 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
2267 return ERROR_INVALID_PARAMETER
;
2269 get_dns_server_list(NULL
, NULL
, &serverListSize
);
2270 size
= sizeof(FIXED_INFO
) + serverListSize
- sizeof(IP_ADDR_STRING
);
2271 if (!pFixedInfo
|| *pOutBufLen
< size
) {
2273 return ERROR_BUFFER_OVERFLOW
;
2276 memset(pFixedInfo
, 0, size
);
2277 size
= sizeof(pFixedInfo
->HostName
);
2278 GetComputerNameExA(ComputerNameDnsHostname
, pFixedInfo
->HostName
, &size
);
2279 size
= sizeof(pFixedInfo
->DomainName
);
2280 GetComputerNameExA(ComputerNameDnsDomain
, pFixedInfo
->DomainName
, &size
);
2281 get_dns_server_list(&pFixedInfo
->DnsServerList
,
2282 (PIP_ADDR_STRING
)((BYTE
*)pFixedInfo
+ sizeof(FIXED_INFO
)),
2284 /* Assume the first DNS server in the list is the "current" DNS server: */
2285 pFixedInfo
->CurrentDnsServer
= &pFixedInfo
->DnsServerList
;
2286 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
2287 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2288 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
2289 if (regReturn
!= ERROR_SUCCESS
)
2290 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2291 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
2293 if (regReturn
== ERROR_SUCCESS
)
2295 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
2297 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (LPBYTE
)pFixedInfo
->ScopeId
, &size
);
2301 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
2302 I suppose could also check for a listener on port 53 to set EnableDns */
2304 TRACE("returning %d\n", ret
);
2309 /******************************************************************
2310 * GetNumberOfInterfaces (IPHLPAPI.@)
2312 * Get the number of interfaces.
2315 * pdwNumIf [Out] number of interfaces
2318 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
2320 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
2324 TRACE("pdwNumIf %p\n", pdwNumIf
);
2326 ret
= ERROR_INVALID_PARAMETER
;
2328 *pdwNumIf
= get_interface_indices( FALSE
, NULL
);
2331 TRACE("returning %d\n", ret
);
2336 /******************************************************************
2337 * GetPerAdapterInfo (IPHLPAPI.@)
2339 * Get information about an adapter corresponding to an interface.
2342 * IfIndex [In] interface info
2343 * pPerAdapterInfo [Out] buffer for per adapter info
2344 * pOutBufLen [In/Out] length of output buffer
2348 * Failure: error code from winerror.h
2350 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
2352 ULONG bytesNeeded
= sizeof(IP_PER_ADAPTER_INFO
), serverListSize
= 0;
2353 DWORD ret
= NO_ERROR
;
2355 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex
, pPerAdapterInfo
, pOutBufLen
);
2357 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
2359 if (!isIfIndexLoopback(IfIndex
)) {
2360 get_dns_server_list(NULL
, NULL
, &serverListSize
);
2361 if (serverListSize
> sizeof(IP_ADDR_STRING
))
2362 bytesNeeded
+= serverListSize
- sizeof(IP_ADDR_STRING
);
2364 if (!pPerAdapterInfo
|| *pOutBufLen
< bytesNeeded
)
2366 *pOutBufLen
= bytesNeeded
;
2367 return ERROR_BUFFER_OVERFLOW
;
2370 memset(pPerAdapterInfo
, 0, bytesNeeded
);
2371 if (!isIfIndexLoopback(IfIndex
)) {
2372 ret
= get_dns_server_list(&pPerAdapterInfo
->DnsServerList
,
2373 (PIP_ADDR_STRING
)((PBYTE
)pPerAdapterInfo
+ sizeof(IP_PER_ADAPTER_INFO
)),
2375 /* Assume the first DNS server in the list is the "current" DNS server: */
2376 pPerAdapterInfo
->CurrentDnsServer
= &pPerAdapterInfo
->DnsServerList
;
2382 /******************************************************************
2383 * GetRTTAndHopCount (IPHLPAPI.@)
2385 * Get round-trip time (RTT) and hop count.
2389 * DestIpAddress [In] destination address to get the info for
2390 * HopCount [Out] retrieved hop count
2391 * MaxHops [In] maximum hops to search for the destination
2392 * RTT [Out] RTT in milliseconds
2399 * Stub, returns FALSE.
2401 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
2403 FIXME("(DestIpAddress 0x%08x, HopCount %p, MaxHops %d, RTT %p): stub\n",
2404 DestIpAddress
, HopCount
, MaxHops
, RTT
);
2409 /******************************************************************
2410 * GetTcpTable (IPHLPAPI.@)
2412 * Get the table of active TCP connections.
2415 * pTcpTable [Out] buffer for TCP connections table
2416 * pdwSize [In/Out] length of output buffer
2417 * bOrder [In] whether to order the table
2421 * Failure: error code from winerror.h
2424 * If pdwSize is less than required, the function will return
2425 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
2426 * the required byte size.
2427 * If bOrder is true, the returned table will be sorted, first by
2428 * local address and port number, then by remote address and port
2431 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
2433 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable
, pdwSize
, bOrder
);
2434 return GetExtendedTcpTable(pTcpTable
, pdwSize
, bOrder
, WS_AF_INET
, TCP_TABLE_BASIC_ALL
, 0);
2437 /******************************************************************
2438 * GetExtendedTcpTable (IPHLPAPI.@)
2440 DWORD WINAPI
GetExtendedTcpTable(PVOID pTcpTable
, PDWORD pdwSize
, BOOL bOrder
,
2441 ULONG ulAf
, TCP_TABLE_CLASS TableClass
, ULONG Reserved
)
2446 TRACE("pTcpTable %p, pdwSize %p, bOrder %d, ulAf %u, TableClass %u, Reserved %u\n",
2447 pTcpTable
, pdwSize
, bOrder
, ulAf
, TableClass
, Reserved
);
2449 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
2451 if (TableClass
>= TCP_TABLE_OWNER_MODULE_LISTENER
)
2452 FIXME("module classes not fully supported\n");
2457 ret
= build_tcp_table(TableClass
, &table
, bOrder
, GetProcessHeap(), 0, &size
);
2461 ret
= build_tcp6_table(TableClass
, &table
, bOrder
, GetProcessHeap(), 0, &size
);
2465 FIXME("ulAf = %u not supported\n", ulAf
);
2466 ret
= ERROR_NOT_SUPPORTED
;
2472 if (!pTcpTable
|| *pdwSize
< size
)
2475 ret
= ERROR_INSUFFICIENT_BUFFER
;
2480 memcpy(pTcpTable
, table
, size
);
2482 HeapFree(GetProcessHeap(), 0, table
);
2486 /******************************************************************
2487 * GetUdpTable (IPHLPAPI.@)
2489 * Get a table of active UDP connections.
2492 * pUdpTable [Out] buffer for UDP connections table
2493 * pdwSize [In/Out] length of output buffer
2494 * bOrder [In] whether to order the table
2498 * Failure: error code from winerror.h
2501 * If pdwSize is less than required, the function will return
2502 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
2503 * required byte size.
2504 * If bOrder is true, the returned table will be sorted, first by
2505 * local address, then by local port number.
2507 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
2509 return GetExtendedUdpTable(pUdpTable
, pdwSize
, bOrder
, WS_AF_INET
, UDP_TABLE_BASIC
, 0);
2512 /******************************************************************
2513 * GetUdp6Table (IPHLPAPI.@)
2515 DWORD WINAPI
GetUdp6Table(PMIB_UDP6TABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
2517 return GetExtendedUdpTable(pUdpTable
, pdwSize
, bOrder
, WS_AF_INET6
, UDP_TABLE_BASIC
, 0);
2520 /******************************************************************
2521 * GetExtendedUdpTable (IPHLPAPI.@)
2523 DWORD WINAPI
GetExtendedUdpTable(PVOID pUdpTable
, PDWORD pdwSize
, BOOL bOrder
,
2524 ULONG ulAf
, UDP_TABLE_CLASS TableClass
, ULONG Reserved
)
2529 TRACE("pUdpTable %p, pdwSize %p, bOrder %d, ulAf %u, TableClass %u, Reserved %u\n",
2530 pUdpTable
, pdwSize
, bOrder
, ulAf
, TableClass
, Reserved
);
2532 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
2534 if (TableClass
== UDP_TABLE_OWNER_MODULE
)
2535 FIXME("UDP_TABLE_OWNER_MODULE not fully supported\n");
2540 ret
= build_udp_table(TableClass
, &table
, bOrder
, GetProcessHeap(), 0, &size
);
2544 ret
= build_udp6_table(TableClass
, &table
, bOrder
, GetProcessHeap(), 0, &size
);
2548 FIXME("ulAf = %u not supported\n", ulAf
);
2549 ret
= ERROR_NOT_SUPPORTED
;
2555 if (!pUdpTable
|| *pdwSize
< size
)
2558 ret
= ERROR_INSUFFICIENT_BUFFER
;
2563 memcpy(pUdpTable
, table
, size
);
2565 HeapFree(GetProcessHeap(), 0, table
);
2569 DWORD WINAPI
GetUnicastIpAddressEntry(MIB_UNICASTIPADDRESS_ROW
*row
)
2571 IP_ADAPTER_ADDRESSES
*aa
, *ptr
;
2578 return ERROR_INVALID_PARAMETER
;
2580 ret
= GetAdaptersAddresses(row
->Address
.si_family
, 0, NULL
, NULL
, &size
);
2581 if (ret
!= ERROR_BUFFER_OVERFLOW
)
2583 if (!(ptr
= HeapAlloc(GetProcessHeap(), 0, size
)))
2584 return ERROR_OUTOFMEMORY
;
2585 if ((ret
= GetAdaptersAddresses(row
->Address
.si_family
, 0, NULL
, ptr
, &size
)))
2587 HeapFree(GetProcessHeap(), 0, ptr
);
2591 ret
= ERROR_FILE_NOT_FOUND
;
2592 for (aa
= ptr
; aa
; aa
= aa
->Next
)
2594 IP_ADAPTER_UNICAST_ADDRESS
*ua
;
2596 if (aa
->u
.s
.IfIndex
!= row
->InterfaceIndex
&&
2597 memcmp(&aa
->Luid
, &row
->InterfaceLuid
, sizeof(row
->InterfaceLuid
)))
2599 ret
= ERROR_NOT_FOUND
;
2601 ua
= aa
->FirstUnicastAddress
;
2604 SOCKADDR_INET
*uaaddr
= (SOCKADDR_INET
*)ua
->Address
.lpSockaddr
;
2606 if ((row
->Address
.si_family
== WS_AF_INET6
&&
2607 !memcmp(&row
->Address
.Ipv6
.sin6_addr
, &uaaddr
->Ipv6
.sin6_addr
, sizeof(uaaddr
->Ipv6
.sin6_addr
))) ||
2608 (row
->Address
.si_family
== WS_AF_INET
&&
2609 row
->Address
.Ipv4
.sin_addr
.S_un
.S_addr
== uaaddr
->Ipv4
.sin_addr
.S_un
.S_addr
))
2611 memcpy(&row
->InterfaceLuid
, &aa
->Luid
, sizeof(aa
->Luid
));
2612 row
->InterfaceIndex
= aa
->u
.s
.IfIndex
;
2613 row
->PrefixOrigin
= ua
->PrefixOrigin
;
2614 row
->SuffixOrigin
= ua
->SuffixOrigin
;
2615 row
->ValidLifetime
= ua
->ValidLifetime
;
2616 row
->PreferredLifetime
= ua
->PreferredLifetime
;
2617 row
->OnLinkPrefixLength
= ua
->OnLinkPrefixLength
;
2618 row
->SkipAsSource
= 0;
2619 row
->DadState
= ua
->DadState
;
2620 if (row
->Address
.si_family
== WS_AF_INET6
)
2621 row
->ScopeId
.u
.Value
= row
->Address
.Ipv6
.sin6_scope_id
;
2623 row
->ScopeId
.u
.Value
= 0;
2624 NtQuerySystemTime(&row
->CreationTimeStamp
);
2625 HeapFree(GetProcessHeap(), 0, ptr
);
2631 HeapFree(GetProcessHeap(), 0, ptr
);
2636 DWORD WINAPI
GetUnicastIpAddressTable(ADDRESS_FAMILY family
, MIB_UNICASTIPADDRESS_TABLE
**table
)
2638 IP_ADAPTER_ADDRESSES
*aa
, *ptr
;
2639 MIB_UNICASTIPADDRESS_TABLE
*data
;
2640 DWORD ret
, count
= 0;
2643 TRACE("%u, %p\n", family
, table
);
2645 if (!table
|| (family
!= WS_AF_INET
&& family
!= WS_AF_INET6
&& family
!= WS_AF_UNSPEC
))
2646 return ERROR_INVALID_PARAMETER
;
2648 flags
= GAA_FLAG_SKIP_ANYCAST
|
2649 GAA_FLAG_SKIP_MULTICAST
|
2650 GAA_FLAG_SKIP_DNS_SERVER
|
2651 GAA_FLAG_SKIP_FRIENDLY_NAME
;
2653 ret
= GetAdaptersAddresses(family
, flags
, NULL
, NULL
, &size
);
2654 if (ret
!= ERROR_BUFFER_OVERFLOW
)
2656 if (!(ptr
= HeapAlloc(GetProcessHeap(), 0, size
)))
2657 return ERROR_OUTOFMEMORY
;
2658 if ((ret
= GetAdaptersAddresses(family
, flags
, NULL
, ptr
, &size
)))
2660 HeapFree(GetProcessHeap(), 0, ptr
);
2664 for (aa
= ptr
; aa
; aa
= aa
->Next
)
2666 IP_ADAPTER_UNICAST_ADDRESS
*ua
= aa
->FirstUnicastAddress
;
2674 if (!(data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
) + (count
- 1) * sizeof(data
->Table
[0]))))
2676 HeapFree(GetProcessHeap(), 0, ptr
);
2677 return ERROR_OUTOFMEMORY
;
2680 data
->NumEntries
= 0;
2681 for (aa
= ptr
; aa
; aa
= aa
->Next
)
2683 IP_ADAPTER_UNICAST_ADDRESS
*ua
= aa
->FirstUnicastAddress
;
2686 MIB_UNICASTIPADDRESS_ROW
*row
= &data
->Table
[data
->NumEntries
];
2687 memcpy(&row
->Address
, ua
->Address
.lpSockaddr
, ua
->Address
.iSockaddrLength
);
2688 memcpy(&row
->InterfaceLuid
, &aa
->Luid
, sizeof(aa
->Luid
));
2689 row
->InterfaceIndex
= aa
->u
.s
.IfIndex
;
2690 row
->PrefixOrigin
= ua
->PrefixOrigin
;
2691 row
->SuffixOrigin
= ua
->SuffixOrigin
;
2692 row
->ValidLifetime
= ua
->ValidLifetime
;
2693 row
->PreferredLifetime
= ua
->PreferredLifetime
;
2694 row
->OnLinkPrefixLength
= ua
->OnLinkPrefixLength
;
2695 row
->SkipAsSource
= 0;
2696 row
->DadState
= ua
->DadState
;
2697 if (row
->Address
.si_family
== WS_AF_INET6
)
2698 row
->ScopeId
.u
.Value
= row
->Address
.Ipv6
.sin6_scope_id
;
2700 row
->ScopeId
.u
.Value
= 0;
2701 NtQuerySystemTime(&row
->CreationTimeStamp
);
2708 HeapFree(GetProcessHeap(), 0, ptr
);
2714 /******************************************************************
2715 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
2717 * This is a Win98-only function to get information on "unidirectional"
2718 * adapters. Since this is pretty nonsensical in other contexts, it
2719 * never returns anything.
2722 * pIPIfInfo [Out] buffer for adapter infos
2723 * dwOutBufLen [Out] length of the output buffer
2727 * Failure: error code from winerror.h
2730 * Stub, returns ERROR_NOT_SUPPORTED.
2732 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
2734 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
2735 /* a unidirectional adapter?? not bloody likely! */
2736 return ERROR_NOT_SUPPORTED
;
2740 /******************************************************************
2741 * IpReleaseAddress (IPHLPAPI.@)
2743 * Release an IP obtained through DHCP,
2746 * AdapterInfo [In] adapter to release IP address
2750 * Failure: error code from winerror.h
2753 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
2754 * this function does nothing.
2757 * Stub, returns ERROR_NOT_SUPPORTED.
2759 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2761 FIXME("Stub AdapterInfo %p\n", AdapterInfo
);
2762 return ERROR_NOT_SUPPORTED
;
2766 /******************************************************************
2767 * IpRenewAddress (IPHLPAPI.@)
2769 * Renew an IP obtained through DHCP.
2772 * AdapterInfo [In] adapter to renew IP address
2776 * Failure: error code from winerror.h
2779 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
2780 * this function does nothing.
2783 * Stub, returns ERROR_NOT_SUPPORTED.
2785 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2787 FIXME("Stub AdapterInfo %p\n", AdapterInfo
);
2788 return ERROR_NOT_SUPPORTED
;
2792 /******************************************************************
2793 * NotifyAddrChange (IPHLPAPI.@)
2795 * Notify caller whenever the ip-interface map is changed.
2798 * Handle [Out] handle usable in asynchronous notification
2799 * overlapped [In] overlapped structure that notifies the caller
2803 * Failure: error code from winerror.h
2806 * Stub, returns ERROR_NOT_SUPPORTED.
2808 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2810 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2811 if (Handle
) *Handle
= INVALID_HANDLE_VALUE
;
2812 if (overlapped
) ((IO_STATUS_BLOCK
*) overlapped
)->u
.Status
= STATUS_PENDING
;
2813 return ERROR_IO_PENDING
;
2817 /******************************************************************
2818 * NotifyIpInterfaceChange (IPHLPAPI.@)
2820 DWORD WINAPI
NotifyIpInterfaceChange(ADDRESS_FAMILY family
, PIPINTERFACE_CHANGE_CALLBACK callback
,
2821 PVOID context
, BOOLEAN init_notify
, PHANDLE handle
)
2823 FIXME("(family %d, callback %p, context %p, init_notify %d, handle %p): stub\n",
2824 family
, callback
, context
, init_notify
, handle
);
2825 if (handle
) *handle
= NULL
;
2829 /******************************************************************
2830 * NotifyRouteChange2 (IPHLPAPI.@)
2832 DWORD WINAPI
NotifyRouteChange2(ADDRESS_FAMILY family
, PIPFORWARD_CHANGE_CALLBACK callback
, VOID
* context
,
2833 BOOLEAN init_notify
, HANDLE
* handle
)
2835 FIXME("(family %d, callback %p, context %p, init_notify %d, handle %p): stub\n",
2836 family
, callback
, context
, init_notify
, handle
);
2837 if (handle
) *handle
= NULL
;
2842 /******************************************************************
2843 * NotifyRouteChange (IPHLPAPI.@)
2845 * Notify caller whenever the ip routing table is changed.
2848 * Handle [Out] handle usable in asynchronous notification
2849 * overlapped [In] overlapped structure that notifies the caller
2853 * Failure: error code from winerror.h
2856 * Stub, returns ERROR_NOT_SUPPORTED.
2858 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2860 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2861 return ERROR_NOT_SUPPORTED
;
2865 /******************************************************************
2866 * NotifyUnicastIpAddressChange (IPHLPAPI.@)
2868 DWORD WINAPI
NotifyUnicastIpAddressChange(ADDRESS_FAMILY family
, PUNICAST_IPADDRESS_CHANGE_CALLBACK callback
,
2869 PVOID context
, BOOLEAN init_notify
, PHANDLE handle
)
2871 FIXME("(family %d, callback %p, context %p, init_notify %d, handle %p): semi-stub\n",
2872 family
, callback
, context
, init_notify
, handle
);
2873 if (handle
) *handle
= NULL
;
2876 callback(context
, NULL
, MibInitialNotification
);
2881 /******************************************************************
2882 * SendARP (IPHLPAPI.@)
2884 * Send an ARP request.
2887 * DestIP [In] attempt to obtain this IP
2888 * SrcIP [In] optional sender IP address
2889 * pMacAddr [Out] buffer for the mac address
2890 * PhyAddrLen [In/Out] length of the output buffer
2894 * Failure: error code from winerror.h
2897 * Stub, returns ERROR_NOT_SUPPORTED.
2899 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
2901 FIXME("(DestIP 0x%08x, SrcIP 0x%08x, pMacAddr %p, PhyAddrLen %p): stub\n",
2902 DestIP
, SrcIP
, pMacAddr
, PhyAddrLen
);
2903 return ERROR_NOT_SUPPORTED
;
2907 /******************************************************************
2908 * SetIfEntry (IPHLPAPI.@)
2910 * Set the administrative status of an interface.
2913 * pIfRow [In] dwAdminStatus member specifies the new status.
2917 * Failure: error code from winerror.h
2920 * Stub, returns ERROR_NOT_SUPPORTED.
2922 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
2924 FIXME("(pIfRow %p): stub\n", pIfRow
);
2925 /* this is supposed to set an interface administratively up or down.
2926 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2927 this sort of down is indistinguishable from other sorts of down (e.g. no
2929 return ERROR_NOT_SUPPORTED
;
2933 /******************************************************************
2934 * SetIpForwardEntry (IPHLPAPI.@)
2936 * Modify an existing route.
2939 * pRoute [In] route with the new information
2943 * Failure: error code from winerror.h
2946 * Stub, returns NO_ERROR.
2948 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
2950 FIXME("(pRoute %p): stub\n", pRoute
);
2951 /* this is to add a route entry, how's it distinguishable from
2952 CreateIpForwardEntry?
2953 could use SIOCADDRT, not sure I want to */
2958 /******************************************************************
2959 * SetIpNetEntry (IPHLPAPI.@)
2961 * Modify an existing ARP entry.
2964 * pArpEntry [In] ARP entry with the new information
2968 * Failure: error code from winerror.h
2971 * Stub, returns NO_ERROR.
2973 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
2975 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
2976 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
2981 /******************************************************************
2982 * SetIpStatistics (IPHLPAPI.@)
2984 * Toggle IP forwarding and det the default TTL value.
2987 * pIpStats [In] IP statistics with the new information
2991 * Failure: error code from winerror.h
2994 * Stub, returns NO_ERROR.
2996 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
2998 FIXME("(pIpStats %p): stub\n", pIpStats
);
3003 /******************************************************************
3004 * SetIpTTL (IPHLPAPI.@)
3006 * Set the default TTL value.
3009 * nTTL [In] new TTL value
3013 * Failure: error code from winerror.h
3016 * Stub, returns NO_ERROR.
3018 DWORD WINAPI
SetIpTTL(UINT nTTL
)
3020 FIXME("(nTTL %d): stub\n", nTTL
);
3021 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
3022 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
3027 /******************************************************************
3028 * SetTcpEntry (IPHLPAPI.@)
3030 * Set the state of a TCP connection.
3033 * pTcpRow [In] specifies connection with new state
3037 * Failure: error code from winerror.h
3040 * Stub, returns NO_ERROR.
3042 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
3044 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
3048 /******************************************************************
3049 * SetPerTcpConnectionEStats (IPHLPAPI.@)
3051 DWORD WINAPI
SetPerTcpConnectionEStats(PMIB_TCPROW row
, TCP_ESTATS_TYPE state
, PBYTE rw
,
3052 ULONG version
, ULONG size
, ULONG offset
)
3054 FIXME("(row %p, state %d, rw %p, version %u, size %u, offset %u): stub\n",
3055 row
, state
, rw
, version
, size
, offset
);
3056 return ERROR_NOT_SUPPORTED
;
3060 /******************************************************************
3061 * UnenableRouter (IPHLPAPI.@)
3063 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
3064 * if it reaches zero.
3067 * pOverlapped [In/Out] should be the same as in EnableRouter()
3068 * lpdwEnableCount [Out] optional, receives reference count
3072 * Failure: error code from winerror.h
3075 * Stub, returns ERROR_NOT_SUPPORTED.
3077 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
3079 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
3081 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
3082 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
3084 return ERROR_NOT_SUPPORTED
;
3087 /******************************************************************
3088 * PfCreateInterface (IPHLPAPI.@)
3090 DWORD WINAPI
PfCreateInterface(DWORD dwName
, PFFORWARD_ACTION inAction
, PFFORWARD_ACTION outAction
,
3091 BOOL bUseLog
, BOOL bMustBeUnique
, INTERFACE_HANDLE
*ppInterface
)
3093 FIXME("(%d %d %d %x %x %p) stub\n", dwName
, inAction
, outAction
, bUseLog
, bMustBeUnique
, ppInterface
);
3094 return ERROR_CALL_NOT_IMPLEMENTED
;
3097 /******************************************************************
3098 * PfUnBindInterface (IPHLPAPI.@)
3100 DWORD WINAPI
PfUnBindInterface(INTERFACE_HANDLE interface
)
3102 FIXME("(%p) stub\n", interface
);
3103 return ERROR_CALL_NOT_IMPLEMENTED
;
3106 /******************************************************************
3107 * PfDeleteInterface(IPHLPAPI.@)
3109 DWORD WINAPI
PfDeleteInterface(INTERFACE_HANDLE interface
)
3111 FIXME("(%p) stub\n", interface
);
3112 return ERROR_CALL_NOT_IMPLEMENTED
;
3115 /******************************************************************
3116 * PfBindInterfaceToIPAddress(IPHLPAPI.@)
3118 DWORD WINAPI
PfBindInterfaceToIPAddress(INTERFACE_HANDLE interface
, PFADDRESSTYPE type
, PBYTE ip
)
3120 FIXME("(%p %d %p) stub\n", interface
, type
, ip
);
3121 return ERROR_CALL_NOT_IMPLEMENTED
;
3124 /******************************************************************
3125 * GetTcpTable2 (IPHLPAPI.@)
3127 ULONG WINAPI
GetTcpTable2(PMIB_TCPTABLE2 table
, PULONG size
, BOOL order
)
3129 FIXME("pTcpTable2 %p, pdwSize %p, bOrder %d: stub\n", table
, size
, order
);
3130 return ERROR_NOT_SUPPORTED
;
3133 /******************************************************************
3134 * GetTcp6Table (IPHLPAPI.@)
3136 ULONG WINAPI
GetTcp6Table(PMIB_TCP6TABLE table
, PULONG size
, BOOL order
)
3138 TRACE("(table %p, size %p, order %d)\n", table
, size
, order
);
3139 return GetExtendedTcpTable(table
, size
, order
, WS_AF_INET6
, TCP_TABLE_BASIC_ALL
, 0);
3142 /******************************************************************
3143 * GetTcp6Table2 (IPHLPAPI.@)
3145 ULONG WINAPI
GetTcp6Table2(PMIB_TCP6TABLE2 table
, PULONG size
, BOOL order
)
3147 FIXME("pTcp6Table2 %p, size %p, order %d: stub\n", table
, size
, order
);
3148 return ERROR_NOT_SUPPORTED
;
3151 /******************************************************************
3152 * ConvertInterfaceGuidToLuid (IPHLPAPI.@)
3154 DWORD WINAPI
ConvertInterfaceGuidToLuid(const GUID
*guid
, NET_LUID
*luid
)
3159 TRACE("(%s %p)\n", debugstr_guid(guid
), luid
);
3161 if (!guid
|| !luid
) return ERROR_INVALID_PARAMETER
;
3163 row
.dwIndex
= guid
->Data1
;
3164 if ((ret
= GetIfEntry( &row
))) return ret
;
3166 luid
->Info
.Reserved
= 0;
3167 luid
->Info
.NetLuidIndex
= guid
->Data1
;
3168 luid
->Info
.IfType
= row
.dwType
;
3172 /******************************************************************
3173 * ConvertInterfaceIndexToLuid (IPHLPAPI.@)
3175 DWORD WINAPI
ConvertInterfaceIndexToLuid(NET_IFINDEX index
, NET_LUID
*luid
)
3179 TRACE("(%u %p)\n", index
, luid
);
3181 if (!luid
) return ERROR_INVALID_PARAMETER
;
3182 memset( luid
, 0, sizeof(*luid
) );
3184 row
.dwIndex
= index
;
3185 if (GetIfEntry( &row
)) return ERROR_FILE_NOT_FOUND
;
3187 luid
->Info
.Reserved
= 0;
3188 luid
->Info
.NetLuidIndex
= index
;
3189 luid
->Info
.IfType
= row
.dwType
;
3193 /******************************************************************
3194 * ConvertInterfaceLuidToGuid (IPHLPAPI.@)
3196 DWORD WINAPI
ConvertInterfaceLuidToGuid(const NET_LUID
*luid
, GUID
*guid
)
3201 TRACE("(%p %p)\n", luid
, guid
);
3203 if (!luid
|| !guid
) return ERROR_INVALID_PARAMETER
;
3205 row
.dwIndex
= luid
->Info
.NetLuidIndex
;
3206 if ((ret
= GetIfEntry( &row
))) return ret
;
3208 memset( guid
, 0, sizeof(*guid
) );
3209 guid
->Data1
= luid
->Info
.NetLuidIndex
;
3210 memcpy( guid
->Data4
+2, "NetDev", 6 );
3214 /******************************************************************
3215 * ConvertInterfaceLuidToIndex (IPHLPAPI.@)
3217 DWORD WINAPI
ConvertInterfaceLuidToIndex(const NET_LUID
*luid
, NET_IFINDEX
*index
)
3222 TRACE("(%p %p)\n", luid
, index
);
3224 if (!luid
|| !index
) return ERROR_INVALID_PARAMETER
;
3226 row
.dwIndex
= luid
->Info
.NetLuidIndex
;
3227 if ((ret
= GetIfEntry( &row
))) return ret
;
3229 *index
= luid
->Info
.NetLuidIndex
;
3233 /******************************************************************
3234 * ConvertInterfaceLuidToNameA (IPHLPAPI.@)
3236 DWORD WINAPI
ConvertInterfaceLuidToNameA(const NET_LUID
*luid
, char *name
, SIZE_T len
)
3241 TRACE("(%p %p %u)\n", luid
, name
, (DWORD
)len
);
3243 if (!luid
) return ERROR_INVALID_PARAMETER
;
3245 row
.dwIndex
= luid
->Info
.NetLuidIndex
;
3246 if ((ret
= GetIfEntry( &row
))) return ret
;
3248 if (!name
|| len
< WideCharToMultiByte( CP_UNIXCP
, 0, row
.wszName
, -1, NULL
, 0, NULL
, NULL
))
3249 return ERROR_NOT_ENOUGH_MEMORY
;
3251 WideCharToMultiByte( CP_UNIXCP
, 0, row
.wszName
, -1, name
, len
, NULL
, NULL
);
3255 /******************************************************************
3256 * ConvertInterfaceLuidToNameW (IPHLPAPI.@)
3258 DWORD WINAPI
ConvertInterfaceLuidToNameW(const NET_LUID
*luid
, WCHAR
*name
, SIZE_T len
)
3263 TRACE("(%p %p %u)\n", luid
, name
, (DWORD
)len
);
3265 if (!luid
|| !name
) return ERROR_INVALID_PARAMETER
;
3267 row
.dwIndex
= luid
->Info
.NetLuidIndex
;
3268 if ((ret
= GetIfEntry( &row
))) return ret
;
3270 if (len
< strlenW( row
.wszName
) + 1) return ERROR_NOT_ENOUGH_MEMORY
;
3271 strcpyW( name
, row
.wszName
);
3275 /******************************************************************
3276 * ConvertInterfaceNameToLuidA (IPHLPAPI.@)
3278 DWORD WINAPI
ConvertInterfaceNameToLuidA(const char *name
, NET_LUID
*luid
)
3284 TRACE("(%s %p)\n", debugstr_a(name
), luid
);
3286 if ((ret
= getInterfaceIndexByName( name
, &index
))) return ERROR_INVALID_NAME
;
3287 if (!luid
) return ERROR_INVALID_PARAMETER
;
3289 row
.dwIndex
= index
;
3290 if ((ret
= GetIfEntry( &row
))) return ret
;
3292 luid
->Info
.Reserved
= 0;
3293 luid
->Info
.NetLuidIndex
= index
;
3294 luid
->Info
.IfType
= row
.dwType
;
3298 /******************************************************************
3299 * ConvertInterfaceNameToLuidW (IPHLPAPI.@)
3301 DWORD WINAPI
ConvertInterfaceNameToLuidW(const WCHAR
*name
, NET_LUID
*luid
)
3306 char nameA
[IF_MAX_STRING_SIZE
+ 1];
3308 TRACE("(%s %p)\n", debugstr_w(name
), luid
);
3310 if (!luid
) return ERROR_INVALID_PARAMETER
;
3311 memset( luid
, 0, sizeof(*luid
) );
3313 if (!WideCharToMultiByte( CP_UNIXCP
, 0, name
, -1, nameA
, sizeof(nameA
), NULL
, NULL
))
3314 return ERROR_INVALID_NAME
;
3316 if ((ret
= getInterfaceIndexByName( nameA
, &index
))) return ret
;
3318 row
.dwIndex
= index
;
3319 if ((ret
= GetIfEntry( &row
))) return ret
;
3321 luid
->Info
.Reserved
= 0;
3322 luid
->Info
.NetLuidIndex
= index
;
3323 luid
->Info
.IfType
= row
.dwType
;
3327 /******************************************************************
3328 * ConvertLengthToIpv4Mask (IPHLPAPI.@)
3330 DWORD WINAPI
ConvertLengthToIpv4Mask(ULONG mask_len
, ULONG
*mask
)
3334 *mask
= INADDR_NONE
;
3335 return ERROR_INVALID_PARAMETER
;
3341 *mask
= htonl(~0u << (32 - mask_len
));
3346 /******************************************************************
3347 * if_nametoindex (IPHLPAPI.@)
3349 IF_INDEX WINAPI
IPHLP_if_nametoindex(const char *name
)
3353 TRACE("(%s)\n", name
);
3354 if (getInterfaceIndexByName(name
, &idx
) == NO_ERROR
)
3360 /******************************************************************
3361 * if_indextoname (IPHLPAPI.@)
3363 PCHAR WINAPI
IPHLP_if_indextoname(NET_IFINDEX index
, PCHAR name
)
3365 TRACE("(%u, %p)\n", index
, name
);
3367 return getInterfaceNameByIndex(index
, name
);
3370 /******************************************************************
3371 * GetIpForwardTable2 (IPHLPAPI.@)
3373 DWORD WINAPI
GetIpForwardTable2(ADDRESS_FAMILY family
, PMIB_IPFORWARD_TABLE2
*table
)
3377 if (!once
++) FIXME("(%u %p): stub\n", family
, table
);
3378 return ERROR_NOT_SUPPORTED
;
3381 /******************************************************************
3382 * GetIpNetTable2 (IPHLPAPI.@)
3384 DWORD WINAPI
GetIpNetTable2(ADDRESS_FAMILY family
, PMIB_IPNET_TABLE2
*table
)
3388 if (!once
++) FIXME("(%u %p): stub\n", family
, table
);
3389 return ERROR_NOT_SUPPORTED
;
3392 /******************************************************************
3393 * GetIpInterfaceTable (IPHLPAPI.@)
3395 DWORD WINAPI
GetIpInterfaceTable(ADDRESS_FAMILY family
, PMIB_IPINTERFACE_TABLE
*table
)
3397 FIXME("(%u %p): stub\n", family
, table
);
3398 return ERROR_NOT_SUPPORTED
;
3401 /******************************************************************
3402 * GetBestRoute2 (IPHLPAPI.@)
3404 DWORD WINAPI
GetBestRoute2(NET_LUID
*luid
, NET_IFINDEX index
,
3405 const SOCKADDR_INET
*source
, const SOCKADDR_INET
*destination
,
3406 ULONG options
, PMIB_IPFORWARD_ROW2 bestroute
,
3407 SOCKADDR_INET
*bestaddress
)
3412 FIXME("(%p, %d, %p, %p, 0x%08x, %p, %p): stub\n", luid
, index
, source
,
3413 destination
, options
, bestroute
, bestaddress
);
3415 if (!destination
|| !bestroute
|| !bestaddress
)
3416 return ERROR_INVALID_PARAMETER
;
3418 return ERROR_NOT_SUPPORTED
;
3421 /******************************************************************
3422 * ParseNetworkString (IPHLPAPI.@)
3424 DWORD WINAPI
ParseNetworkString(const WCHAR
*str
, DWORD type
,
3425 NET_ADDRESS_INFO
*info
, USHORT
*port
, BYTE
*prefix_len
)
3428 IN6_ADDR temp_addr6
;
3430 USHORT temp_port
= 0;
3433 TRACE("(%s, %d, %p, %p, %p)\n", debugstr_w(str
), type
, info
, port
, prefix_len
);
3436 return ERROR_INVALID_PARAMETER
;
3438 if (type
& NET_STRING_IPV4_ADDRESS
)
3440 status
= RtlIpv4StringToAddressExW(str
, TRUE
, &temp_addr4
, &temp_port
);
3441 if (SUCCEEDED(status
) && !temp_port
)
3445 info
->Format
= NET_ADDRESS_IPV4
;
3446 info
->u
.Ipv4Address
.sin_addr
= temp_addr4
;
3447 info
->u
.Ipv4Address
.sin_port
= 0;
3449 if (port
) *port
= 0;
3450 if (prefix_len
) *prefix_len
= 255;
3451 return ERROR_SUCCESS
;
3454 if (type
& NET_STRING_IPV4_SERVICE
)
3456 status
= RtlIpv4StringToAddressExW(str
, TRUE
, &temp_addr4
, &temp_port
);
3457 if (SUCCEEDED(status
) && temp_port
)
3461 info
->Format
= NET_ADDRESS_IPV4
;
3462 info
->u
.Ipv4Address
.sin_addr
= temp_addr4
;
3463 info
->u
.Ipv4Address
.sin_port
= temp_port
;
3465 if (port
) *port
= ntohs(temp_port
);
3466 if (prefix_len
) *prefix_len
= 255;
3467 return ERROR_SUCCESS
;
3470 if (type
& NET_STRING_IPV6_ADDRESS
)
3472 status
= RtlIpv6StringToAddressExW(str
, &temp_addr6
, &temp_scope
, &temp_port
);
3473 if (SUCCEEDED(status
) && !temp_port
)
3477 info
->Format
= NET_ADDRESS_IPV6
;
3478 info
->u
.Ipv6Address
.sin6_addr
= temp_addr6
;
3479 info
->u
.Ipv6Address
.sin6_scope_id
= temp_scope
;
3480 info
->u
.Ipv6Address
.sin6_port
= 0;
3482 if (port
) *port
= 0;
3483 if (prefix_len
) *prefix_len
= 255;
3484 return ERROR_SUCCESS
;
3487 if (type
& NET_STRING_IPV6_SERVICE
)
3489 status
= RtlIpv6StringToAddressExW(str
, &temp_addr6
, &temp_scope
, &temp_port
);
3490 if (SUCCEEDED(status
) && temp_port
)
3494 info
->Format
= NET_ADDRESS_IPV6
;
3495 info
->u
.Ipv6Address
.sin6_addr
= temp_addr6
;
3496 info
->u
.Ipv6Address
.sin6_scope_id
= temp_scope
;
3497 info
->u
.Ipv6Address
.sin6_port
= temp_port
;
3499 if (port
) *port
= ntohs(temp_port
);
3500 if (prefix_len
) *prefix_len
= 255;
3501 return ERROR_SUCCESS
;
3505 if (info
) info
->Format
= NET_ADDRESS_FORMAT_UNSPECIFIED
;
3507 if (type
& ~(NET_STRING_IPV4_ADDRESS
|NET_STRING_IPV4_SERVICE
|NET_STRING_IPV6_ADDRESS
|NET_STRING_IPV6_SERVICE
))
3509 FIXME("Unimplemented type 0x%x\n", type
);
3510 return ERROR_NOT_SUPPORTED
;
3513 return ERROR_INVALID_PARAMETER
;