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
56 #include "tcpestats.h"
58 #include "wine/debug.h"
59 #include "wine/unicode.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
64 #define IF_NAMESIZE 16
68 #define INADDR_NONE ~0UL
71 /******************************************************************
72 * AddIPAddress (IPHLPAPI.@)
74 * Add an IP address to an adapter.
77 * Address [In] IP address to add to the adapter
78 * IpMask [In] subnet mask for the IP address
79 * IfIndex [In] adapter index to add the address
80 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
81 * NTEInstance [Out] NTE instance for the IP address
85 * Failure: error code from winerror.h
88 * Stub. Currently returns ERROR_NOT_SUPPORTED.
90 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask IpMask
, DWORD IfIndex
, PULONG NTEContext
, PULONG NTEInstance
)
93 return ERROR_NOT_SUPPORTED
;
97 /******************************************************************
98 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
100 * Get table of local interfaces.
101 * Like GetIfTable(), but allocate the returned table from heap.
104 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
105 * allocated and returned.
106 * bOrder [In] whether to sort the table
107 * heap [In] heap from which the table is allocated
108 * flags [In] flags to HeapAlloc
111 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
112 * GetIfTable() returns otherwise.
114 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
115 BOOL bOrder
, HANDLE heap
, DWORD flags
)
119 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable
,
120 bOrder
, heap
, flags
);
122 ret
= ERROR_INVALID_PARAMETER
;
126 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
127 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
128 *ppIfTable
= HeapAlloc(heap
, flags
, dwSize
);
129 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
132 TRACE("returning %d\n", ret
);
137 static int IpAddrTableSorter(const void *a
, const void *b
)
142 ret
= ((const MIB_IPADDRROW
*)a
)->dwAddr
- ((const MIB_IPADDRROW
*)b
)->dwAddr
;
149 /******************************************************************
150 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
152 * Get interface-to-IP address mapping table.
153 * Like GetIpAddrTable(), but allocate the returned table from heap.
156 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
157 * allocated and returned.
158 * bOrder [In] whether to sort the table
159 * heap [In] heap from which the table is allocated
160 * flags [In] flags to HeapAlloc
163 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
164 * failure, NO_ERROR on success.
166 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
167 BOOL bOrder
, HANDLE heap
, DWORD flags
)
171 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
172 ppIpAddrTable
, bOrder
, heap
, flags
);
173 ret
= getIPAddrTable(ppIpAddrTable
, heap
, flags
);
175 qsort((*ppIpAddrTable
)->table
, (*ppIpAddrTable
)->dwNumEntries
,
176 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
177 TRACE("returning %d\n", ret
);
182 /******************************************************************
183 * CancelIPChangeNotify (IPHLPAPI.@)
185 * Cancel a previous notification created by NotifyAddrChange or
189 * overlapped [In] overlapped structure that notifies the caller
196 * Stub, returns FALSE.
198 BOOL WINAPI
CancelIPChangeNotify(LPOVERLAPPED overlapped
)
200 FIXME("(overlapped %p): stub\n", overlapped
);
205 /******************************************************************
206 * CancelMibChangeNotify2 (IPHLPAPI.@)
208 DWORD WINAPI
CancelMibChangeNotify2(HANDLE handle
)
210 FIXME("(handle %p): stub\n", handle
);
215 /******************************************************************
216 * CreateIpForwardEntry (IPHLPAPI.@)
218 * Create a route in the local computer's IP table.
221 * pRoute [In] new route information
225 * Failure: error code from winerror.h
228 * Stub, always returns NO_ERROR.
230 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
232 FIXME("(pRoute %p): stub\n", pRoute
);
233 /* could use SIOCADDRT, not sure I want to */
238 /******************************************************************
239 * CreateIpNetEntry (IPHLPAPI.@)
241 * Create entry in the ARP table.
244 * pArpEntry [In] new ARP entry
248 * Failure: error code from winerror.h
251 * Stub, always returns NO_ERROR.
253 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
255 FIXME("(pArpEntry %p)\n", pArpEntry
);
256 /* could use SIOCSARP on systems that support it, not sure I want to */
261 /******************************************************************
262 * CreateProxyArpEntry (IPHLPAPI.@)
264 * Create a Proxy ARP (PARP) entry for an IP address.
267 * dwAddress [In] IP address for which this computer acts as a proxy.
268 * dwMask [In] subnet mask for dwAddress
269 * dwIfIndex [In] interface index
273 * Failure: error code from winerror.h
276 * Stub, returns ERROR_NOT_SUPPORTED.
278 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
280 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
281 dwAddress
, dwMask
, dwIfIndex
);
282 return ERROR_NOT_SUPPORTED
;
285 static char *debugstr_ipv6(const struct WS_sockaddr_in6
*sin
, char *buf
)
287 const IN6_ADDR
*addr
= &sin
->sin6_addr
;
290 BOOL in_zero
= FALSE
;
292 for (i
= 0; i
< 7; i
++)
294 if (!addr
->u
.Word
[i
])
306 p
+= sprintf(p
, "%x:", ntohs(addr
->u
.Word
[i
]));
310 sprintf(p
, "%x", ntohs(addr
->u
.Word
[7]));
314 static BOOL
map_address_6to4( SOCKADDR_IN6
*addr6
, SOCKADDR_IN
*addr4
)
318 if (addr6
->sin6_family
!= WS_AF_INET6
) return FALSE
;
320 for (i
= 0; i
< 5; i
++)
321 if (addr6
->sin6_addr
.u
.Word
[i
]) return FALSE
;
323 if (addr6
->sin6_addr
.u
.Word
[5] != 0xffff) return FALSE
;
325 addr4
->sin_family
= AF_INET
;
326 addr4
->sin_port
= addr6
->sin6_port
;
327 addr4
->sin_addr
.S_un
.S_addr
= addr6
->sin6_addr
.u
.Word
[6] << 16 | addr6
->sin6_addr
.u
.Word
[7];
328 memset( &addr4
->sin_zero
, 0, sizeof(addr4
->sin_zero
) );
333 static BOOL
find_src_address( MIB_IPADDRTABLE
*table
, SOCKADDR_IN
*dst
, SOCKADDR_IN6
*src
)
335 MIB_IPFORWARDROW row
;
338 if (GetBestRoute( dst
->sin_addr
.S_un
.S_addr
, 0, &row
)) return FALSE
;
340 for (i
= 0; i
< table
->dwNumEntries
; i
++)
342 /* take the first address */
343 if (table
->table
[i
].dwIndex
== row
.dwForwardIfIndex
)
345 src
->sin6_family
= WS_AF_INET6
;
347 src
->sin6_flowinfo
= 0;
348 for (j
= 0; j
< 5; j
++) src
->sin6_addr
.u
.Word
[j
] = 0;
349 src
->sin6_addr
.u
.Word
[5] = 0xffff;
350 src
->sin6_addr
.u
.Word
[6] = table
->table
[i
].dwAddr
& 0xffff;
351 src
->sin6_addr
.u
.Word
[7] = table
->table
[i
].dwAddr
>> 16;
359 /******************************************************************
360 * CreateSortedAddressPairs (IPHLPAPI.@)
362 DWORD WINAPI
CreateSortedAddressPairs( const PSOCKADDR_IN6 src_list
, DWORD src_count
,
363 const PSOCKADDR_IN6 dst_list
, DWORD dst_count
,
364 DWORD options
, PSOCKADDR_IN6_PAIR
*pair_list
,
368 SOCKADDR_IN6_PAIR
*pairs
;
371 MIB_IPADDRTABLE
*table
;
373 FIXME( "(src_list %p src_count %u dst_list %p dst_count %u options %x pair_list %p pair_count %p): stub\n",
374 src_list
, src_count
, dst_list
, dst_count
, options
, pair_list
, pair_count
);
376 if (src_list
|| src_count
|| !dst_list
|| !pair_list
|| !pair_count
|| dst_count
> 500)
377 return ERROR_INVALID_PARAMETER
;
379 for (i
= 0; i
< dst_count
; i
++)
381 if (!map_address_6to4( &dst_list
[i
], &addr4
))
383 FIXME("only mapped IPv4 addresses are supported\n");
384 return ERROR_NOT_SUPPORTED
;
388 size
= dst_count
* sizeof(*pairs
);
389 size
+= dst_count
* sizeof(SOCKADDR_IN6
) * 2; /* source address + destination address */
390 if (!(pairs
= HeapAlloc( GetProcessHeap(), 0, size
))) return ERROR_NOT_ENOUGH_MEMORY
;
391 ptr
= (SOCKADDR_IN6
*)&pairs
[dst_count
];
393 if ((ret
= getIPAddrTable( &table
, GetProcessHeap(), 0 )))
395 HeapFree( GetProcessHeap(), 0, pairs
);
399 for (i
= 0; i
< dst_count
; i
++)
401 pairs
[i
].SourceAddress
= ptr
++;
402 if (!map_address_6to4( &dst_list
[i
], &addr4
) ||
403 !find_src_address( table
, &addr4
, pairs
[i
].SourceAddress
))
406 FIXME( "source address for %s not found\n", debugstr_ipv6(&dst_list
[i
], buf
) );
407 memset( pairs
[i
].SourceAddress
, 0, sizeof(*pairs
[i
].SourceAddress
) );
408 pairs
[i
].SourceAddress
->sin6_family
= WS_AF_INET6
;
411 pairs
[i
].DestinationAddress
= ptr
++;
412 memcpy( pairs
[i
].DestinationAddress
, &dst_list
[i
], sizeof(*pairs
[i
].DestinationAddress
) );
415 *pair_count
= dst_count
;
417 HeapFree( GetProcessHeap(), 0, table
);
422 /******************************************************************
423 * DeleteIPAddress (IPHLPAPI.@)
425 * Delete an IP address added with AddIPAddress().
428 * NTEContext [In] NTE context from AddIPAddress();
432 * Failure: error code from winerror.h
435 * Stub, returns ERROR_NOT_SUPPORTED.
437 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
439 FIXME("(NTEContext %d): stub\n", NTEContext
);
440 return ERROR_NOT_SUPPORTED
;
444 /******************************************************************
445 * DeleteIpForwardEntry (IPHLPAPI.@)
450 * pRoute [In] route to delete
454 * Failure: error code from winerror.h
457 * Stub, returns NO_ERROR.
459 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
461 FIXME("(pRoute %p): stub\n", pRoute
);
462 /* could use SIOCDELRT, not sure I want to */
467 /******************************************************************
468 * DeleteIpNetEntry (IPHLPAPI.@)
470 * Delete an ARP entry.
473 * pArpEntry [In] ARP entry to delete
477 * Failure: error code from winerror.h
480 * Stub, returns NO_ERROR.
482 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
484 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
485 /* could use SIOCDARP on systems that support it, not sure I want to */
490 /******************************************************************
491 * DeleteProxyArpEntry (IPHLPAPI.@)
493 * Delete a Proxy ARP entry.
496 * dwAddress [In] IP address for which this computer acts as a proxy.
497 * dwMask [In] subnet mask for dwAddress
498 * dwIfIndex [In] interface index
502 * Failure: error code from winerror.h
505 * Stub, returns ERROR_NOT_SUPPORTED.
507 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
509 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
510 dwAddress
, dwMask
, dwIfIndex
);
511 return ERROR_NOT_SUPPORTED
;
515 /******************************************************************
516 * EnableRouter (IPHLPAPI.@)
518 * Turn on ip forwarding.
522 * pOverlapped [In/Out] hEvent member should contain a valid handle.
525 * Success: ERROR_IO_PENDING
526 * Failure: error code from winerror.h
529 * Stub, returns ERROR_NOT_SUPPORTED.
531 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
533 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle
, pOverlapped
);
534 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
535 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
537 return ERROR_NOT_SUPPORTED
;
541 /******************************************************************
542 * FlushIpNetTable (IPHLPAPI.@)
544 * Delete all ARP entries of an interface
547 * dwIfIndex [In] interface index
551 * Failure: error code from winerror.h
554 * Stub, returns ERROR_NOT_SUPPORTED.
556 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
558 FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex
);
559 /* this flushes the arp cache of the given index */
560 return ERROR_NOT_SUPPORTED
;
563 /******************************************************************
564 * FreeMibTable (IPHLPAPI.@)
566 * Free buffer allocated by network functions
569 * ptr [In] pointer to the buffer to free
572 void WINAPI
FreeMibTable(void *ptr
)
574 TRACE("(%p)\n", ptr
);
575 HeapFree(GetProcessHeap(), 0, ptr
);
578 /******************************************************************
579 * GetAdapterIndex (IPHLPAPI.@)
581 * Get interface index from its name.
584 * AdapterName [In] unicode string with the adapter name
585 * IfIndex [Out] returns found interface index
589 * Failure: error code from winerror.h
591 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
593 char adapterName
[MAX_ADAPTER_NAME
];
597 TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName
, IfIndex
);
598 /* The adapter name is guaranteed not to have any unicode characters, so
599 * this translation is never lossy */
600 for (i
= 0; i
< sizeof(adapterName
) - 1 && AdapterName
[i
]; i
++)
601 adapterName
[i
] = (char)AdapterName
[i
];
602 adapterName
[i
] = '\0';
603 ret
= getInterfaceIndexByName(adapterName
, IfIndex
);
604 TRACE("returning %d\n", ret
);
609 /******************************************************************
610 * GetAdaptersInfo (IPHLPAPI.@)
612 * Get information about adapters.
615 * pAdapterInfo [Out] buffer for adapter infos
616 * pOutBufLen [In] length of output buffer
620 * Failure: error code from winerror.h
622 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
626 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
628 ret
= ERROR_INVALID_PARAMETER
;
630 DWORD numNonLoopbackInterfaces
= get_interface_indices( TRUE
, NULL
);
632 if (numNonLoopbackInterfaces
> 0) {
633 DWORD numIPAddresses
= getNumIPAddresses();
636 /* This may slightly overestimate the amount of space needed, because
637 * the IP addresses include the loopback address, but it's easier
638 * to make sure there's more than enough space than to make sure there's
639 * precisely enough space.
641 size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
642 size
+= numIPAddresses
* sizeof(IP_ADDR_STRING
);
643 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
645 ret
= ERROR_BUFFER_OVERFLOW
;
648 InterfaceIndexTable
*table
= NULL
;
649 PMIB_IPADDRTABLE ipAddrTable
= NULL
;
650 PMIB_IPFORWARDTABLE routeTable
= NULL
;
652 ret
= getIPAddrTable(&ipAddrTable
, GetProcessHeap(), 0);
654 ret
= AllocateAndGetIpForwardTableFromStack(&routeTable
, FALSE
, GetProcessHeap(), 0);
656 get_interface_indices( TRUE
, &table
);
658 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
659 size
+= ipAddrTable
->dwNumEntries
* sizeof(IP_ADDR_STRING
);
660 if (*pOutBufLen
< size
) {
662 ret
= ERROR_INSUFFICIENT_BUFFER
;
667 BOOL winsEnabled
= FALSE
;
668 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
669 PIP_ADDR_STRING nextIPAddr
= (PIP_ADDR_STRING
)((LPBYTE
)pAdapterInfo
670 + numNonLoopbackInterfaces
* sizeof(IP_ADAPTER_INFO
));
672 memset(pAdapterInfo
, 0, size
);
673 /* @@ Wine registry key: HKCU\Software\Wine\Network */
674 if (RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Network",
675 &hKey
) == ERROR_SUCCESS
) {
676 DWORD size
= sizeof(primaryWINS
.String
);
679 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
680 (LPBYTE
)primaryWINS
.String
, &size
);
681 addr
= inet_addr(primaryWINS
.String
);
682 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
684 size
= sizeof(secondaryWINS
.String
);
685 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
686 (LPBYTE
)secondaryWINS
.String
, &size
);
687 addr
= inet_addr(secondaryWINS
.String
);
688 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
692 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
693 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
695 PIP_ADDR_STRING currentIPAddr
= &ptr
->IpAddressList
;
696 BOOL firstIPAddr
= TRUE
;
698 /* on Win98 this is left empty, but whatever */
699 getInterfaceNameByIndex(table
->indexes
[ndx
], ptr
->AdapterName
);
700 getInterfaceNameByIndex(table
->indexes
[ndx
], ptr
->Description
);
701 ptr
->AddressLength
= sizeof(ptr
->Address
);
702 getInterfacePhysicalByIndex(table
->indexes
[ndx
],
703 &ptr
->AddressLength
, ptr
->Address
, &ptr
->Type
);
704 ptr
->Index
= table
->indexes
[ndx
];
705 for (i
= 0; i
< ipAddrTable
->dwNumEntries
; i
++) {
706 if (ipAddrTable
->table
[i
].dwIndex
== ptr
->Index
) {
708 toIPAddressString(ipAddrTable
->table
[i
].dwAddr
,
709 ptr
->IpAddressList
.IpAddress
.String
);
710 toIPAddressString(ipAddrTable
->table
[i
].dwMask
,
711 ptr
->IpAddressList
.IpMask
.String
);
715 currentIPAddr
->Next
= nextIPAddr
;
716 currentIPAddr
= nextIPAddr
;
717 toIPAddressString(ipAddrTable
->table
[i
].dwAddr
,
718 currentIPAddr
->IpAddress
.String
);
719 toIPAddressString(ipAddrTable
->table
[i
].dwMask
,
720 currentIPAddr
->IpMask
.String
);
725 /* If no IP was found it probably means that the interface is not
726 * configured. In this case we have to return a zeroed IP and mask. */
728 strcpy(ptr
->IpAddressList
.IpAddress
.String
, "0.0.0.0");
729 strcpy(ptr
->IpAddressList
.IpMask
.String
, "0.0.0.0");
731 /* Find first router through this interface, which we'll assume
732 * is the default gateway for this adapter */
733 for (i
= 0; i
< routeTable
->dwNumEntries
; i
++)
734 if (routeTable
->table
[i
].dwForwardIfIndex
== ptr
->Index
735 && routeTable
->table
[i
].u1
.ForwardType
==
736 MIB_IPROUTE_TYPE_INDIRECT
)
738 toIPAddressString(routeTable
->table
[i
].dwForwardNextHop
,
739 ptr
->GatewayList
.IpAddress
.String
);
740 toIPAddressString(routeTable
->table
[i
].dwForwardMask
,
741 ptr
->GatewayList
.IpMask
.String
);
744 ptr
->HaveWins
= TRUE
;
745 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
746 primaryWINS
.String
, sizeof(primaryWINS
.String
));
747 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
748 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
750 if (ndx
< table
->numIndexes
- 1)
751 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
755 ptr
->DhcpEnabled
= TRUE
;
759 HeapFree(GetProcessHeap(), 0, table
);
762 ret
= ERROR_OUTOFMEMORY
;
763 HeapFree(GetProcessHeap(), 0, routeTable
);
764 HeapFree(GetProcessHeap(), 0, ipAddrTable
);
770 TRACE("returning %d\n", ret
);
774 static DWORD
typeFromMibType(DWORD mib_type
)
778 case MIB_IF_TYPE_ETHERNET
: return IF_TYPE_ETHERNET_CSMACD
;
779 case MIB_IF_TYPE_TOKENRING
: return IF_TYPE_ISO88025_TOKENRING
;
780 case MIB_IF_TYPE_PPP
: return IF_TYPE_PPP
;
781 case MIB_IF_TYPE_LOOPBACK
: return IF_TYPE_SOFTWARE_LOOPBACK
;
782 default: return IF_TYPE_OTHER
;
786 static NET_IF_CONNECTION_TYPE
connectionTypeFromMibType(DWORD mib_type
)
790 case MIB_IF_TYPE_PPP
: return NET_IF_CONNECTION_DEMAND
;
791 case MIB_IF_TYPE_SLIP
: return NET_IF_CONNECTION_DEMAND
;
792 default: return NET_IF_CONNECTION_DEDICATED
;
796 static ULONG
v4addressesFromIndex(IF_INDEX index
, DWORD
**addrs
, ULONG
*num_addrs
, DWORD
**masks
)
802 if ((ret
= getIPAddrTable(&at
, GetProcessHeap(), 0))) return ret
;
803 for (i
= 0; i
< at
->dwNumEntries
; i
++)
805 if (at
->table
[i
].dwIndex
== index
) (*num_addrs
)++;
807 if (!(*addrs
= HeapAlloc(GetProcessHeap(), 0, *num_addrs
* sizeof(DWORD
))))
809 HeapFree(GetProcessHeap(), 0, at
);
810 return ERROR_OUTOFMEMORY
;
812 if (!(*masks
= HeapAlloc(GetProcessHeap(), 0, *num_addrs
* sizeof(DWORD
))))
814 HeapFree(GetProcessHeap(), 0, *addrs
);
815 HeapFree(GetProcessHeap(), 0, at
);
816 return ERROR_OUTOFMEMORY
;
818 for (i
= 0, j
= 0; i
< at
->dwNumEntries
; i
++)
820 if (at
->table
[i
].dwIndex
== index
)
822 (*addrs
)[j
] = at
->table
[i
].dwAddr
;
823 (*masks
)[j
] = at
->table
[i
].dwMask
;
827 HeapFree(GetProcessHeap(), 0, at
);
828 return ERROR_SUCCESS
;
831 static char *debugstr_ipv4(const in_addr_t
*in_addr
, char *buf
)
836 for (addrp
= (const BYTE
*)in_addr
;
837 addrp
- (const BYTE
*)in_addr
< sizeof(*in_addr
);
840 if (addrp
== (const BYTE
*)in_addr
+ sizeof(*in_addr
) - 1)
841 sprintf(p
, "%d", *addrp
);
843 p
+= sprintf(p
, "%d.", *addrp
);
848 static ULONG
count_v4_gateways(DWORD index
, PMIB_IPFORWARDTABLE routeTable
)
850 DWORD i
, num_gateways
= 0;
852 for (i
= 0; i
< routeTable
->dwNumEntries
; i
++)
854 if (routeTable
->table
[i
].dwForwardIfIndex
== index
&&
855 routeTable
->table
[i
].u1
.ForwardType
== MIB_IPROUTE_TYPE_INDIRECT
)
861 static PMIB_IPFORWARDROW
findIPv4Gateway(DWORD index
,
862 PMIB_IPFORWARDTABLE routeTable
)
865 PMIB_IPFORWARDROW row
= NULL
;
867 for (i
= 0; !row
&& i
< routeTable
->dwNumEntries
; i
++)
869 if (routeTable
->table
[i
].dwForwardIfIndex
== index
&&
870 routeTable
->table
[i
].u1
.ForwardType
== MIB_IPROUTE_TYPE_INDIRECT
)
871 row
= &routeTable
->table
[i
];
876 static void fill_unicast_addr_data(IP_ADAPTER_ADDRESSES
*aa
, IP_ADAPTER_UNICAST_ADDRESS
*ua
)
878 /* Actually this information should be read somewhere from the system
879 * but it doesn't matter much for the bugs found so far.
880 * This information is required for DirectPlay8 games. */
881 if (aa
->IfType
!= IF_TYPE_SOFTWARE_LOOPBACK
)
883 ua
->PrefixOrigin
= IpPrefixOriginDhcp
;
884 ua
->SuffixOrigin
= IpSuffixOriginDhcp
;
888 ua
->PrefixOrigin
= IpPrefixOriginManual
;
889 ua
->SuffixOrigin
= IpSuffixOriginManual
;
892 /* The address is not duplicated in the network */
893 ua
->DadState
= IpDadStatePreferred
;
895 /* Some address life time values, required even for non-dhcp addresses */
896 ua
->ValidLifetime
= 60000;
897 ua
->PreferredLifetime
= 60000;
898 ua
->LeaseLifetime
= 60000;
901 static ULONG
adapterAddressesFromIndex(ULONG family
, ULONG flags
, IF_INDEX index
,
902 IP_ADAPTER_ADDRESSES
*aa
, ULONG
*size
)
904 ULONG ret
= ERROR_SUCCESS
, i
, j
, num_v4addrs
= 0, num_v4_gateways
= 0, num_v6addrs
= 0, total_size
;
905 DWORD
*v4addrs
= NULL
, *v4masks
= NULL
;
906 SOCKET_ADDRESS
*v6addrs
= NULL
, *v6masks
= NULL
;
907 PMIB_IPFORWARDTABLE routeTable
= NULL
;
909 if (family
== WS_AF_INET
)
911 ret
= v4addressesFromIndex(index
, &v4addrs
, &num_v4addrs
, &v4masks
);
913 if (!ret
&& flags
& GAA_FLAG_INCLUDE_ALL_GATEWAYS
)
915 ret
= AllocateAndGetIpForwardTableFromStack(&routeTable
, FALSE
, GetProcessHeap(), 0);
916 if (!ret
) num_v4_gateways
= count_v4_gateways(index
, routeTable
);
919 else if (family
== WS_AF_INET6
)
921 ret
= v6addressesFromIndex(index
, &v6addrs
, &num_v6addrs
, &v6masks
);
923 else if (family
== WS_AF_UNSPEC
)
925 ret
= v4addressesFromIndex(index
, &v4addrs
, &num_v4addrs
, &v4masks
);
927 if (!ret
&& flags
& GAA_FLAG_INCLUDE_ALL_GATEWAYS
)
929 ret
= AllocateAndGetIpForwardTableFromStack(&routeTable
, FALSE
, GetProcessHeap(), 0);
930 if (!ret
) num_v4_gateways
= count_v4_gateways(index
, routeTable
);
932 if (!ret
) ret
= v6addressesFromIndex(index
, &v6addrs
, &num_v6addrs
, &v6masks
);
936 FIXME("address family %u unsupported\n", family
);
941 HeapFree(GetProcessHeap(), 0, v4addrs
);
942 HeapFree(GetProcessHeap(), 0, v4masks
);
943 HeapFree(GetProcessHeap(), 0, v6addrs
);
944 HeapFree(GetProcessHeap(), 0, v6masks
);
945 HeapFree(GetProcessHeap(), 0, routeTable
);
949 total_size
= sizeof(IP_ADAPTER_ADDRESSES
);
950 total_size
+= IF_NAMESIZE
;
951 total_size
+= IF_NAMESIZE
* sizeof(WCHAR
);
952 if (!(flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
953 total_size
+= IF_NAMESIZE
* sizeof(WCHAR
);
954 if (flags
& GAA_FLAG_INCLUDE_PREFIX
)
956 total_size
+= sizeof(IP_ADAPTER_PREFIX
) * num_v4addrs
;
957 total_size
+= sizeof(IP_ADAPTER_PREFIX
) * num_v6addrs
;
958 total_size
+= sizeof(struct sockaddr_in
) * num_v4addrs
;
959 for (i
= 0; i
< num_v6addrs
; i
++)
960 total_size
+= v6masks
[i
].iSockaddrLength
;
962 total_size
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
) * num_v4addrs
;
963 total_size
+= sizeof(struct sockaddr_in
) * num_v4addrs
;
964 total_size
+= (sizeof(IP_ADAPTER_GATEWAY_ADDRESS
) + sizeof(SOCKADDR_IN
)) * num_v4_gateways
;
965 total_size
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
) * num_v6addrs
;
966 total_size
+= sizeof(SOCKET_ADDRESS
) * num_v6addrs
;
967 for (i
= 0; i
< num_v6addrs
; i
++)
968 total_size
+= v6addrs
[i
].iSockaddrLength
;
970 if (aa
&& *size
>= total_size
)
972 char name
[IF_NAMESIZE
], *ptr
= (char *)aa
+ sizeof(IP_ADAPTER_ADDRESSES
), *src
;
975 INTERNAL_IF_OPER_STATUS status
;
977 memset(aa
, 0, sizeof(IP_ADAPTER_ADDRESSES
));
978 aa
->u
.s
.Length
= sizeof(IP_ADAPTER_ADDRESSES
);
979 aa
->u
.s
.IfIndex
= index
;
981 getInterfaceNameByIndex(index
, name
);
982 memcpy(ptr
, name
, IF_NAMESIZE
);
983 aa
->AdapterName
= ptr
;
985 if (!(flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
987 aa
->FriendlyName
= (WCHAR
*)ptr
;
988 for (src
= name
, dst
= (WCHAR
*)ptr
; *src
; src
++, dst
++)
993 aa
->Description
= (WCHAR
*)ptr
;
994 for (src
= name
, dst
= (WCHAR
*)ptr
; *src
; src
++, dst
++)
999 TRACE("%s: %d IPv4 addresses, %d IPv6 addresses:\n", name
, num_v4addrs
,
1002 buflen
= MAX_INTERFACE_PHYSADDR
;
1003 getInterfacePhysicalByIndex(index
, &buflen
, aa
->PhysicalAddress
, &type
);
1004 aa
->PhysicalAddressLength
= buflen
;
1005 aa
->IfType
= typeFromMibType(type
);
1006 aa
->ConnectionType
= connectionTypeFromMibType(type
);
1007 aa
->Luid
.Info
.NetLuidIndex
= index
;
1008 aa
->Luid
.Info
.IfType
= aa
->IfType
;
1010 if (num_v4_gateways
)
1012 PMIB_IPFORWARDROW adapterRow
;
1014 if ((adapterRow
= findIPv4Gateway(index
, routeTable
)))
1016 PIP_ADAPTER_GATEWAY_ADDRESS gw
;
1019 gw
= (PIP_ADAPTER_GATEWAY_ADDRESS
)ptr
;
1020 aa
->FirstGatewayAddress
= gw
;
1022 gw
->u
.s
.Length
= sizeof(IP_ADAPTER_GATEWAY_ADDRESS
);
1023 ptr
+= sizeof(IP_ADAPTER_GATEWAY_ADDRESS
);
1024 sin
= (PSOCKADDR_IN
)ptr
;
1025 sin
->sin_family
= AF_INET
;
1027 memcpy(&sin
->sin_addr
, &adapterRow
->dwForwardNextHop
,
1029 gw
->Address
.lpSockaddr
= (LPSOCKADDR
)sin
;
1030 gw
->Address
.iSockaddrLength
= sizeof(SOCKADDR_IN
);
1032 ptr
+= sizeof(SOCKADDR_IN
);
1035 if (num_v4addrs
&& !(flags
& GAA_FLAG_SKIP_UNICAST
))
1037 IP_ADAPTER_UNICAST_ADDRESS
*ua
;
1038 struct WS_sockaddr_in
*sa
;
1039 aa
->Flags
|= IP_ADAPTER_IPV4_ENABLED
;
1040 ua
= aa
->FirstUnicastAddress
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1041 for (i
= 0; i
< num_v4addrs
; i
++)
1045 memset(ua
, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS
));
1046 ua
->u
.s
.Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
1047 ua
->Address
.iSockaddrLength
= sizeof(struct sockaddr_in
);
1048 ua
->Address
.lpSockaddr
= (SOCKADDR
*)((char *)ua
+ ua
->u
.s
.Length
);
1050 sa
= (struct WS_sockaddr_in
*)ua
->Address
.lpSockaddr
;
1051 sa
->sin_family
= WS_AF_INET
;
1052 sa
->sin_addr
.S_un
.S_addr
= v4addrs
[i
];
1054 TRACE("IPv4 %d/%d: %s\n", i
+ 1, num_v4addrs
,
1055 debugstr_ipv4(&sa
->sin_addr
.S_un
.S_addr
, addr_buf
));
1056 fill_unicast_addr_data(aa
, ua
);
1058 ptr
+= ua
->u
.s
.Length
+ ua
->Address
.iSockaddrLength
;
1059 if (i
< num_v4addrs
- 1)
1061 ua
->Next
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1066 if (num_v6addrs
&& !(flags
& GAA_FLAG_SKIP_UNICAST
))
1068 IP_ADAPTER_UNICAST_ADDRESS
*ua
;
1069 struct WS_sockaddr_in6
*sa
;
1071 aa
->Flags
|= IP_ADAPTER_IPV6_ENABLED
;
1072 if (aa
->FirstUnicastAddress
)
1074 for (ua
= aa
->FirstUnicastAddress
; ua
->Next
; ua
= ua
->Next
)
1076 ua
->Next
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1077 ua
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1080 ua
= aa
->FirstUnicastAddress
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1081 for (i
= 0; i
< num_v6addrs
; i
++)
1085 memset(ua
, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS
));
1086 ua
->u
.s
.Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
1087 ua
->Address
.iSockaddrLength
= v6addrs
[i
].iSockaddrLength
;
1088 ua
->Address
.lpSockaddr
= (SOCKADDR
*)((char *)ua
+ ua
->u
.s
.Length
);
1090 sa
= (struct WS_sockaddr_in6
*)ua
->Address
.lpSockaddr
;
1091 memcpy(sa
, v6addrs
[i
].lpSockaddr
, sizeof(*sa
));
1092 TRACE("IPv6 %d/%d: %s\n", i
+ 1, num_v6addrs
,
1093 debugstr_ipv6(sa
, addr_buf
));
1094 fill_unicast_addr_data(aa
, ua
);
1096 ptr
+= ua
->u
.s
.Length
+ ua
->Address
.iSockaddrLength
;
1097 if (i
< num_v6addrs
- 1)
1099 ua
->Next
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
1104 if (num_v4addrs
&& (flags
& GAA_FLAG_INCLUDE_PREFIX
))
1106 IP_ADAPTER_PREFIX
*prefix
;
1108 prefix
= aa
->FirstPrefix
= (IP_ADAPTER_PREFIX
*)ptr
;
1109 for (i
= 0; i
< num_v4addrs
; i
++)
1112 struct WS_sockaddr_in
*sa
;
1114 prefix
->u
.s
.Length
= sizeof(*prefix
);
1115 prefix
->u
.s
.Flags
= 0;
1116 prefix
->Next
= NULL
;
1117 prefix
->Address
.iSockaddrLength
= sizeof(struct sockaddr_in
);
1118 prefix
->Address
.lpSockaddr
= (SOCKADDR
*)((char *)prefix
+ prefix
->u
.s
.Length
);
1120 sa
= (struct WS_sockaddr_in
*)prefix
->Address
.lpSockaddr
;
1121 sa
->sin_family
= WS_AF_INET
;
1122 sa
->sin_addr
.S_un
.S_addr
= v4addrs
[i
] & v4masks
[i
];
1125 prefix
->PrefixLength
= 0;
1126 for (j
= 0; j
< sizeof(*v4masks
) * 8; j
++)
1128 if (v4masks
[i
] & 1 << j
) prefix
->PrefixLength
++;
1131 TRACE("IPv4 network: %s/%u\n",
1132 debugstr_ipv4((const in_addr_t
*)&sa
->sin_addr
.S_un
.S_addr
, addr_buf
),
1133 prefix
->PrefixLength
);
1135 ptr
+= prefix
->u
.s
.Length
+ prefix
->Address
.iSockaddrLength
;
1136 if (i
< num_v4addrs
- 1)
1138 prefix
->Next
= (IP_ADAPTER_PREFIX
*)ptr
;
1139 prefix
= prefix
->Next
;
1143 if (num_v6addrs
&& (flags
& GAA_FLAG_INCLUDE_PREFIX
))
1145 IP_ADAPTER_PREFIX
*prefix
;
1147 if (aa
->FirstPrefix
)
1149 for (prefix
= aa
->FirstPrefix
; prefix
->Next
; prefix
= prefix
->Next
)
1151 prefix
->Next
= (IP_ADAPTER_PREFIX
*)ptr
;
1152 prefix
= (IP_ADAPTER_PREFIX
*)ptr
;
1155 prefix
= aa
->FirstPrefix
= (IP_ADAPTER_PREFIX
*)ptr
;
1156 for (i
= 0; i
< num_v6addrs
; i
++)
1159 struct WS_sockaddr_in6
*sa
;
1160 const IN6_ADDR
*addr
, *mask
;
1164 prefix
->u
.s
.Length
= sizeof(*prefix
);
1165 prefix
->u
.s
.Flags
= 0;
1166 prefix
->Next
= NULL
;
1167 prefix
->Address
.iSockaddrLength
= sizeof(struct sockaddr_in6
);
1168 prefix
->Address
.lpSockaddr
= (SOCKADDR
*)((char *)prefix
+ prefix
->u
.s
.Length
);
1170 sa
= (struct WS_sockaddr_in6
*)prefix
->Address
.lpSockaddr
;
1171 sa
->sin6_family
= WS_AF_INET6
;
1173 sa
->sin6_flowinfo
= 0;
1174 addr
= &((struct WS_sockaddr_in6
*)v6addrs
[i
].lpSockaddr
)->sin6_addr
;
1175 mask
= &((struct WS_sockaddr_in6
*)v6masks
[i
].lpSockaddr
)->sin6_addr
;
1176 for (j
= 0; j
< 8; j
++) sa
->sin6_addr
.u
.Word
[j
] = addr
->u
.Word
[j
] & mask
->u
.Word
[j
];
1177 sa
->sin6_scope_id
= 0;
1179 prefix
->PrefixLength
= 0;
1180 for (k
= 0; k
< 8 && !done
; k
++)
1182 for (j
= 0; j
< sizeof(WORD
) * 8 && !done
; j
++)
1184 if (mask
->u
.Word
[k
] & 1 << j
) prefix
->PrefixLength
++;
1188 TRACE("IPv6 network: %s/%u\n", debugstr_ipv6(sa
, addr_buf
), prefix
->PrefixLength
);
1190 ptr
+= prefix
->u
.s
.Length
+ prefix
->Address
.iSockaddrLength
;
1191 if (i
< num_v6addrs
- 1)
1193 prefix
->Next
= (IP_ADAPTER_PREFIX
*)ptr
;
1194 prefix
= prefix
->Next
;
1199 getInterfaceMtuByName(name
, &aa
->Mtu
);
1201 getInterfaceStatusByName(name
, &status
);
1202 if (status
== MIB_IF_OPER_STATUS_OPERATIONAL
) aa
->OperStatus
= IfOperStatusUp
;
1203 else if (status
== MIB_IF_OPER_STATUS_NON_OPERATIONAL
) aa
->OperStatus
= IfOperStatusDown
;
1204 else aa
->OperStatus
= IfOperStatusUnknown
;
1207 HeapFree(GetProcessHeap(), 0, routeTable
);
1208 HeapFree(GetProcessHeap(), 0, v6addrs
);
1209 HeapFree(GetProcessHeap(), 0, v6masks
);
1210 HeapFree(GetProcessHeap(), 0, v4addrs
);
1211 HeapFree(GetProcessHeap(), 0, v4masks
);
1212 return ERROR_SUCCESS
;
1215 static void sockaddr_in_to_WS_storage( SOCKADDR_STORAGE
*dst
, const struct sockaddr_in
*src
)
1217 SOCKADDR_IN
*s
= (SOCKADDR_IN
*)dst
;
1219 s
->sin_family
= WS_AF_INET
;
1220 s
->sin_port
= src
->sin_port
;
1221 memcpy( &s
->sin_addr
, &src
->sin_addr
, sizeof(IN_ADDR
) );
1222 memset( (char *)s
+ FIELD_OFFSET( SOCKADDR_IN
, sin_zero
), 0,
1223 sizeof(SOCKADDR_STORAGE
) - FIELD_OFFSET( SOCKADDR_IN
, sin_zero
) );
1226 static void sockaddr_in6_to_WS_storage( SOCKADDR_STORAGE
*dst
, const struct sockaddr_in6
*src
)
1228 SOCKADDR_IN6
*s
= (SOCKADDR_IN6
*)dst
;
1230 s
->sin6_family
= WS_AF_INET6
;
1231 s
->sin6_port
= src
->sin6_port
;
1232 s
->sin6_flowinfo
= src
->sin6_flowinfo
;
1233 memcpy( &s
->sin6_addr
, &src
->sin6_addr
, sizeof(IN6_ADDR
) );
1234 s
->sin6_scope_id
= src
->sin6_scope_id
;
1235 memset( (char *)s
+ sizeof(SOCKADDR_IN6
), 0,
1236 sizeof(SOCKADDR_STORAGE
) - sizeof(SOCKADDR_IN6
) );
1239 #ifdef HAVE_STRUCT___RES_STATE
1240 /* call res_init() just once because of a bug in Mac OS X 10.4 */
1241 /* Call once per thread on systems that have per-thread _res. */
1243 static CRITICAL_SECTION res_init_cs
;
1244 static CRITICAL_SECTION_DEBUG res_init_cs_debug
= {
1246 { &res_init_cs_debug
.ProcessLocksList
, &res_init_cs_debug
.ProcessLocksList
},
1247 0, 0, { (DWORD_PTR
)(__FILE__
": res_init_cs") }
1249 static CRITICAL_SECTION res_init_cs
= { &res_init_cs_debug
, -1, 0, 0, 0, 0 };
1251 static void initialise_resolver(void)
1253 EnterCriticalSection(&res_init_cs
);
1254 if ((_res
.options
& RES_INIT
) == 0)
1256 LeaveCriticalSection(&res_init_cs
);
1259 static int get_dns_servers( SOCKADDR_STORAGE
*servers
, int num
, BOOL ip4_only
)
1261 int i
, ip6_count
= 0;
1262 SOCKADDR_STORAGE
*addr
;
1264 initialise_resolver();
1266 #ifdef HAVE_STRUCT___RES_STATE__U__EXT_NSCOUNT6
1267 ip6_count
= _res
._u
._ext
.nscount6
;
1270 if (!servers
|| !num
)
1273 if (ip4_only
) num
-= ip6_count
;
1277 for (i
= 0, addr
= servers
; addr
< (servers
+ num
) && i
< _res
.nscount
; i
++)
1279 #ifdef HAVE_STRUCT___RES_STATE__U__EXT_NSCOUNT6
1280 if (_res
._u
._ext
.nsaddrs
[i
])
1282 if (ip4_only
) continue;
1283 sockaddr_in6_to_WS_storage( addr
, _res
._u
._ext
.nsaddrs
[i
] );
1288 sockaddr_in_to_WS_storage( addr
, _res
.nsaddr_list
+ i
);
1292 return addr
- servers
;
1294 #elif defined(HAVE___RES_GET_STATE) && defined(HAVE___RES_GETSERVERS)
1296 static int get_dns_servers( SOCKADDR_STORAGE
*servers
, int num
, BOOL ip4_only
)
1298 extern struct res_state
*__res_get_state( void );
1299 extern int __res_getservers( struct res_state
*, struct sockaddr_storage
*, int );
1300 struct res_state
*state
= __res_get_state();
1301 int i
, found
= 0, total
= __res_getservers( state
, NULL
, 0 );
1302 SOCKADDR_STORAGE
*addr
= servers
;
1303 struct sockaddr_storage
*buf
;
1305 if ((!servers
|| !num
) && !ip4_only
) return total
;
1307 buf
= HeapAlloc( GetProcessHeap(), 0, total
* sizeof(struct sockaddr_storage
) );
1308 total
= __res_getservers( state
, buf
, total
);
1310 for (i
= 0; i
< total
; i
++)
1312 if (buf
[i
].ss_family
== AF_INET6
&& ip4_only
) continue;
1313 if (buf
[i
].ss_family
!= AF_INET
&& buf
[i
].ss_family
!= AF_INET6
) continue;
1316 if (!servers
|| !num
) continue;
1318 if (buf
[i
].ss_family
== AF_INET6
)
1320 sockaddr_in6_to_WS_storage( addr
, (struct sockaddr_in6
*)(buf
+ i
) );
1324 sockaddr_in_to_WS_storage( addr
, (struct sockaddr_in
*)(buf
+ i
) );
1326 if (++addr
>= servers
+ num
) break;
1329 HeapFree( GetProcessHeap(), 0, buf
);
1334 static int get_dns_servers( SOCKADDR_STORAGE
*servers
, int num
, BOOL ip4_only
)
1336 FIXME("Unimplemented on this system\n");
1341 static ULONG
get_dns_server_addresses(PIP_ADAPTER_DNS_SERVER_ADDRESS address
, ULONG
*len
)
1343 int num
= get_dns_servers( NULL
, 0, FALSE
);
1346 size
= num
* (sizeof(IP_ADAPTER_DNS_SERVER_ADDRESS
) + sizeof(SOCKADDR_STORAGE
));
1347 if (!address
|| *len
< size
)
1350 return ERROR_BUFFER_OVERFLOW
;
1355 PIP_ADAPTER_DNS_SERVER_ADDRESS addr
= address
;
1356 SOCKADDR_STORAGE
*sock_addrs
= (SOCKADDR_STORAGE
*)(address
+ num
);
1359 get_dns_servers( sock_addrs
, num
, FALSE
);
1361 for (i
= 0; i
< num
; i
++, addr
= addr
->Next
)
1363 addr
->u
.s
.Length
= sizeof(*addr
);
1364 if (sock_addrs
[i
].ss_family
== WS_AF_INET6
)
1365 addr
->Address
.iSockaddrLength
= sizeof(SOCKADDR_IN6
);
1367 addr
->Address
.iSockaddrLength
= sizeof(SOCKADDR_IN
);
1368 addr
->Address
.lpSockaddr
= (SOCKADDR
*)(sock_addrs
+ i
);
1372 addr
->Next
= addr
+ 1;
1375 return ERROR_SUCCESS
;
1378 #ifdef HAVE_STRUCT___RES_STATE
1379 static BOOL
is_ip_address_string(const char *str
)
1384 ret
= inet_aton(str
, &in
);
1389 static ULONG
get_dns_suffix(WCHAR
*suffix
, ULONG
*len
)
1392 const char *found_suffix
= "";
1393 /* Always return a NULL-terminated string, even if it's empty. */
1395 #ifdef HAVE_STRUCT___RES_STATE
1398 initialise_resolver();
1399 for (i
= 0; !*found_suffix
&& i
< MAXDNSRCH
+ 1 && _res
.dnsrch
[i
]; i
++)
1401 /* This uses a heuristic to select a DNS suffix:
1402 * the first, non-IP address string is selected.
1404 if (!is_ip_address_string(_res
.dnsrch
[i
]))
1405 found_suffix
= _res
.dnsrch
[i
];
1410 size
= MultiByteToWideChar( CP_UNIXCP
, 0, found_suffix
, -1, NULL
, 0 ) * sizeof(WCHAR
);
1411 if (!suffix
|| *len
< size
)
1414 return ERROR_BUFFER_OVERFLOW
;
1416 *len
= MultiByteToWideChar( CP_UNIXCP
, 0, found_suffix
, -1, suffix
, *len
/ sizeof(WCHAR
) ) * sizeof(WCHAR
);
1417 return ERROR_SUCCESS
;
1420 ULONG WINAPI DECLSPEC_HOTPATCH
GetAdaptersAddresses(ULONG family
, ULONG flags
, PVOID reserved
,
1421 PIP_ADAPTER_ADDRESSES aa
, PULONG buflen
)
1423 InterfaceIndexTable
*table
;
1424 ULONG i
, size
, dns_server_size
= 0, dns_suffix_size
, total_size
, ret
= ERROR_NO_DATA
;
1426 TRACE("(%d, %08x, %p, %p, %p)\n", family
, flags
, reserved
, aa
, buflen
);
1428 if (!buflen
) return ERROR_INVALID_PARAMETER
;
1430 get_interface_indices( FALSE
, &table
);
1431 if (!table
|| !table
->numIndexes
)
1433 HeapFree(GetProcessHeap(), 0, table
);
1434 return ERROR_NO_DATA
;
1437 for (i
= 0; i
< table
->numIndexes
; i
++)
1440 if ((ret
= adapterAddressesFromIndex(family
, flags
, table
->indexes
[i
], NULL
, &size
)))
1442 HeapFree(GetProcessHeap(), 0, table
);
1447 if (!(flags
& GAA_FLAG_SKIP_DNS_SERVER
))
1449 /* Since DNS servers aren't really per adapter, get enough space for a
1450 * single copy of them.
1452 get_dns_server_addresses(NULL
, &dns_server_size
);
1453 total_size
+= dns_server_size
;
1455 /* Since DNS suffix also isn't really per adapter, get enough space for a
1456 * single copy of it.
1458 get_dns_suffix(NULL
, &dns_suffix_size
);
1459 total_size
+= dns_suffix_size
;
1460 if (aa
&& *buflen
>= total_size
)
1462 ULONG bytes_left
= size
= total_size
;
1463 PIP_ADAPTER_ADDRESSES first_aa
= aa
;
1464 PIP_ADAPTER_DNS_SERVER_ADDRESS firstDns
;
1467 for (i
= 0; i
< table
->numIndexes
; i
++)
1469 if ((ret
= adapterAddressesFromIndex(family
, flags
, table
->indexes
[i
], aa
, &size
)))
1471 HeapFree(GetProcessHeap(), 0, table
);
1474 if (i
< table
->numIndexes
- 1)
1476 aa
->Next
= (IP_ADAPTER_ADDRESSES
*)((char *)aa
+ size
);
1478 size
= bytes_left
-= size
;
1481 if (dns_server_size
)
1483 firstDns
= (PIP_ADAPTER_DNS_SERVER_ADDRESS
)((BYTE
*)first_aa
+ total_size
- dns_server_size
- dns_suffix_size
);
1484 get_dns_server_addresses(firstDns
, &dns_server_size
);
1485 for (aa
= first_aa
; aa
; aa
= aa
->Next
)
1487 if (aa
->IfType
!= IF_TYPE_SOFTWARE_LOOPBACK
&& aa
->OperStatus
== IfOperStatusUp
)
1488 aa
->FirstDnsServerAddress
= firstDns
;
1492 dnsSuffix
= (WCHAR
*)((BYTE
*)aa
+ total_size
- dns_suffix_size
);
1493 get_dns_suffix(dnsSuffix
, &dns_suffix_size
);
1494 for (; aa
; aa
= aa
->Next
)
1496 if (aa
->IfType
!= IF_TYPE_SOFTWARE_LOOPBACK
&& aa
->OperStatus
== IfOperStatusUp
)
1497 aa
->DnsSuffix
= dnsSuffix
;
1499 aa
->DnsSuffix
= dnsSuffix
+ dns_suffix_size
/ sizeof(WCHAR
) - 1;
1501 ret
= ERROR_SUCCESS
;
1505 ret
= ERROR_BUFFER_OVERFLOW
;
1506 *buflen
= total_size
;
1509 TRACE("num adapters %u\n", table
->numIndexes
);
1510 HeapFree(GetProcessHeap(), 0, table
);
1514 /******************************************************************
1515 * GetBestInterface (IPHLPAPI.@)
1517 * Get the interface, with the best route for the given IP address.
1520 * dwDestAddr [In] IP address to search the interface for
1521 * pdwBestIfIndex [Out] found best interface
1525 * Failure: error code from winerror.h
1527 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
1529 struct WS_sockaddr_in sa_in
;
1530 memset(&sa_in
, 0, sizeof(sa_in
));
1531 sa_in
.sin_family
= AF_INET
;
1532 sa_in
.sin_addr
.S_un
.S_addr
= dwDestAddr
;
1533 return GetBestInterfaceEx((struct WS_sockaddr
*)&sa_in
, pdwBestIfIndex
);
1536 /******************************************************************
1537 * GetBestInterfaceEx (IPHLPAPI.@)
1539 * Get the interface, with the best route for the given IP address.
1542 * dwDestAddr [In] IP address to search the interface for
1543 * pdwBestIfIndex [Out] found best interface
1547 * Failure: error code from winerror.h
1549 DWORD WINAPI
GetBestInterfaceEx(struct WS_sockaddr
*pDestAddr
, PDWORD pdwBestIfIndex
)
1553 TRACE("pDestAddr %p, pdwBestIfIndex %p\n", pDestAddr
, pdwBestIfIndex
);
1554 if (!pDestAddr
|| !pdwBestIfIndex
)
1555 ret
= ERROR_INVALID_PARAMETER
;
1557 MIB_IPFORWARDROW ipRow
;
1559 if (pDestAddr
->sa_family
== AF_INET
) {
1560 ret
= GetBestRoute(((struct WS_sockaddr_in
*)pDestAddr
)->sin_addr
.S_un
.S_addr
, 0, &ipRow
);
1561 if (ret
== ERROR_SUCCESS
)
1562 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
1564 FIXME("address family %d not supported\n", pDestAddr
->sa_family
);
1565 ret
= ERROR_NOT_SUPPORTED
;
1568 TRACE("returning %d\n", ret
);
1573 /******************************************************************
1574 * GetBestRoute (IPHLPAPI.@)
1576 * Get the best route for the given IP address.
1579 * dwDestAddr [In] IP address to search the best route for
1580 * dwSourceAddr [In] optional source IP address
1581 * pBestRoute [Out] found best route
1585 * Failure: error code from winerror.h
1587 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
1589 PMIB_IPFORWARDTABLE table
;
1592 TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr
,
1593 dwSourceAddr
, pBestRoute
);
1595 return ERROR_INVALID_PARAMETER
;
1597 ret
= AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
1599 DWORD ndx
, matchedBits
, matchedNdx
= table
->dwNumEntries
;
1601 for (ndx
= 0, matchedBits
= 0; ndx
< table
->dwNumEntries
; ndx
++) {
1602 if (table
->table
[ndx
].u1
.ForwardType
!= MIB_IPROUTE_TYPE_INVALID
&&
1603 (dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
1604 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
1605 DWORD numShifts
, mask
;
1607 for (numShifts
= 0, mask
= table
->table
[ndx
].dwForwardMask
;
1608 mask
&& mask
& 1; mask
>>= 1, numShifts
++)
1610 if (numShifts
> matchedBits
) {
1611 matchedBits
= numShifts
;
1614 else if (!matchedBits
) {
1619 if (matchedNdx
< table
->dwNumEntries
) {
1620 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
1621 ret
= ERROR_SUCCESS
;
1624 /* No route matches, which can happen if there's no default route. */
1625 ret
= ERROR_HOST_UNREACHABLE
;
1627 HeapFree(GetProcessHeap(), 0, table
);
1629 TRACE("returning %d\n", ret
);
1634 /******************************************************************
1635 * GetFriendlyIfIndex (IPHLPAPI.@)
1637 * Get a "friendly" version of IfIndex, which is one that doesn't
1638 * have the top byte set. Doesn't validate whether IfIndex is a valid
1642 * IfIndex [In] interface index to get the friendly one for
1645 * A friendly version of IfIndex.
1647 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
1649 /* windows doesn't validate these, either, just makes sure the top byte is
1650 cleared. I assume my ifenum module never gives an index with the top
1652 TRACE("returning %d\n", IfIndex
);
1657 /******************************************************************
1658 * GetIfEntry (IPHLPAPI.@)
1660 * Get information about an interface.
1663 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
1664 * Out: interface information
1668 * Failure: error code from winerror.h
1670 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
1673 char nameBuf
[MAX_ADAPTER_NAME
];
1676 TRACE("pIfRow %p\n", pIfRow
);
1678 return ERROR_INVALID_PARAMETER
;
1680 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
, nameBuf
);
1682 ret
= getInterfaceEntryByName(name
, pIfRow
);
1683 if (ret
== NO_ERROR
)
1684 ret
= getInterfaceStatsByName(name
, pIfRow
);
1687 ret
= ERROR_INVALID_DATA
;
1688 TRACE("returning %d\n", ret
);
1692 /******************************************************************
1693 * GetIfEntry2 (IPHLPAPI.@)
1695 DWORD WINAPI
GetIfEntry2( MIB_IF_ROW2
*row2
)
1697 DWORD ret
, len
= sizeof(row2
->Description
)/sizeof(row2
->Description
[0]);
1698 char buf
[MAX_ADAPTER_NAME
], *name
;
1701 TRACE("%p\n", row2
);
1703 if (!row2
|| (!(name
= getInterfaceNameByIndex( row2
->InterfaceIndex
, buf
)) &&
1704 !(name
= getInterfaceNameByIndex( row2
->InterfaceLuid
.Info
.NetLuidIndex
, buf
))))
1706 return ERROR_INVALID_PARAMETER
;
1708 if ((ret
= getInterfaceEntryByName( name
, &row
))) return ret
;
1709 if ((ret
= getInterfaceStatsByName( name
, &row
))) return ret
;
1711 memset( row2
, 0, sizeof(*row2
) );
1712 row2
->InterfaceLuid
.Info
.Reserved
= 0;
1713 row2
->InterfaceLuid
.Info
.NetLuidIndex
= row
.dwIndex
;
1714 row2
->InterfaceLuid
.Info
.IfType
= row
.dwType
;
1715 row2
->InterfaceIndex
= row
.dwIndex
;
1716 row2
->InterfaceGuid
.Data1
= row
.dwIndex
;
1717 row2
->Type
= row
.dwType
;
1718 row2
->Mtu
= row
.dwMtu
;
1719 MultiByteToWideChar( CP_UNIXCP
, 0, (const char *)row
.bDescr
, -1, row2
->Description
, len
);
1720 row2
->PhysicalAddressLength
= row
.dwPhysAddrLen
;
1721 memcpy( &row2
->PhysicalAddress
, &row
.bPhysAddr
, row
.dwPhysAddrLen
);
1722 memcpy( &row2
->PermanentPhysicalAddress
, &row
.bPhysAddr
, row
.dwPhysAddrLen
);
1723 row2
->OperStatus
= IfOperStatusUp
;
1724 row2
->AdminStatus
= NET_IF_ADMIN_STATUS_UP
;
1725 row2
->MediaConnectState
= MediaConnectStateConnected
;
1726 row2
->ConnectionType
= NET_IF_CONNECTION_DEDICATED
;
1729 row2
->InOctets
= row
.dwInOctets
;
1730 row2
->InUcastPkts
= row
.dwInUcastPkts
;
1731 row2
->InNUcastPkts
= row
.dwInNUcastPkts
;
1732 row2
->InDiscards
= row
.dwInDiscards
;
1733 row2
->InErrors
= row
.dwInErrors
;
1734 row2
->InUnknownProtos
= row
.dwInUnknownProtos
;
1735 row2
->OutOctets
= row
.dwOutOctets
;
1736 row2
->OutUcastPkts
= row
.dwOutUcastPkts
;
1737 row2
->OutNUcastPkts
= row
.dwOutNUcastPkts
;
1738 row2
->OutDiscards
= row
.dwOutDiscards
;
1739 row2
->OutErrors
= row
.dwOutErrors
;
1744 static int IfTableSorter(const void *a
, const void *b
)
1749 ret
= ((const MIB_IFROW
*)a
)->dwIndex
- ((const MIB_IFROW
*)b
)->dwIndex
;
1756 /******************************************************************
1757 * GetIfTable (IPHLPAPI.@)
1759 * Get a table of local interfaces.
1762 * pIfTable [Out] buffer for local interfaces table
1763 * pdwSize [In/Out] length of output buffer
1764 * bOrder [In] whether to sort the table
1768 * Failure: error code from winerror.h
1771 * If pdwSize is less than required, the function will return
1772 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1774 * If bOrder is true, the returned table will be sorted by interface index.
1776 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
1780 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize
, pdwSize
,
1783 ret
= ERROR_INVALID_PARAMETER
;
1785 DWORD numInterfaces
= get_interface_indices( FALSE
, NULL
);
1786 ULONG size
= sizeof(MIB_IFTABLE
);
1788 if (numInterfaces
> 1)
1789 size
+= (numInterfaces
- 1) * sizeof(MIB_IFROW
);
1790 if (!pIfTable
|| *pdwSize
< size
) {
1792 ret
= ERROR_INSUFFICIENT_BUFFER
;
1795 InterfaceIndexTable
*table
;
1796 get_interface_indices( FALSE
, &table
);
1799 size
= sizeof(MIB_IFTABLE
);
1800 if (table
->numIndexes
> 1)
1801 size
+= (table
->numIndexes
- 1) * sizeof(MIB_IFROW
);
1802 if (*pdwSize
< size
) {
1804 ret
= ERROR_INSUFFICIENT_BUFFER
;
1810 pIfTable
->dwNumEntries
= 0;
1811 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1812 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1813 GetIfEntry(&pIfTable
->table
[ndx
]);
1814 pIfTable
->dwNumEntries
++;
1817 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
1821 HeapFree(GetProcessHeap(), 0, table
);
1824 ret
= ERROR_OUTOFMEMORY
;
1827 TRACE("returning %d\n", ret
);
1832 /******************************************************************
1833 * GetInterfaceInfo (IPHLPAPI.@)
1835 * Get a list of network interface adapters.
1838 * pIfTable [Out] buffer for interface adapters
1839 * dwOutBufLen [Out] if buffer is too small, returns required size
1843 * Failure: error code from winerror.h
1846 * MSDN states this should return non-loopback interfaces only.
1848 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1852 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1854 ret
= ERROR_INVALID_PARAMETER
;
1856 DWORD numInterfaces
= get_interface_indices( FALSE
, NULL
);
1857 ULONG size
= sizeof(IP_INTERFACE_INFO
);
1859 if (numInterfaces
> 1)
1860 size
+= (numInterfaces
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
1861 if (!pIfTable
|| *dwOutBufLen
< size
) {
1862 *dwOutBufLen
= size
;
1863 ret
= ERROR_INSUFFICIENT_BUFFER
;
1866 InterfaceIndexTable
*table
;
1867 get_interface_indices( FALSE
, &table
);
1870 size
= sizeof(IP_INTERFACE_INFO
);
1871 if (table
->numIndexes
> 1)
1872 size
+= (table
->numIndexes
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
1873 if (*dwOutBufLen
< size
) {
1874 *dwOutBufLen
= size
;
1875 ret
= ERROR_INSUFFICIENT_BUFFER
;
1879 char nameBuf
[MAX_ADAPTER_NAME
];
1881 *dwOutBufLen
= size
;
1882 pIfTable
->NumAdapters
= 0;
1883 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1884 const char *walker
, *name
;
1887 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1888 name
= getInterfaceNameByIndex(table
->indexes
[ndx
], nameBuf
);
1889 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1890 walker
&& *walker
&&
1891 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1892 walker
++, assigner
++)
1893 *assigner
= *walker
;
1895 pIfTable
->NumAdapters
++;
1899 HeapFree(GetProcessHeap(), 0, table
);
1902 ret
= ERROR_OUTOFMEMORY
;
1905 TRACE("returning %d\n", ret
);
1910 /******************************************************************
1911 * GetIpAddrTable (IPHLPAPI.@)
1913 * Get interface-to-IP address mapping table.
1916 * pIpAddrTable [Out] buffer for mapping table
1917 * pdwSize [In/Out] length of output buffer
1918 * bOrder [In] whether to sort the table
1922 * Failure: error code from winerror.h
1925 * If pdwSize is less than required, the function will return
1926 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1928 * If bOrder is true, the returned table will be sorted by the next hop and
1929 * an assortment of arbitrary parameters.
1931 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1935 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable
, pdwSize
,
1938 ret
= ERROR_INVALID_PARAMETER
;
1940 PMIB_IPADDRTABLE table
;
1942 ret
= getIPAddrTable(&table
, GetProcessHeap(), 0);
1943 if (ret
== NO_ERROR
)
1945 ULONG size
= FIELD_OFFSET(MIB_IPADDRTABLE
, table
[table
->dwNumEntries
]);
1947 if (!pIpAddrTable
|| *pdwSize
< size
) {
1949 ret
= ERROR_INSUFFICIENT_BUFFER
;
1953 memcpy(pIpAddrTable
, table
, size
);
1955 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1956 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1959 HeapFree(GetProcessHeap(), 0, table
);
1962 TRACE("returning %d\n", ret
);
1967 /******************************************************************
1968 * GetIpForwardTable (IPHLPAPI.@)
1970 * Get the route table.
1973 * pIpForwardTable [Out] buffer for route table
1974 * pdwSize [In/Out] length of output buffer
1975 * bOrder [In] whether to sort the table
1979 * Failure: error code from winerror.h
1982 * If pdwSize is less than required, the function will return
1983 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1985 * If bOrder is true, the returned table will be sorted by the next hop and
1986 * an assortment of arbitrary parameters.
1988 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1991 PMIB_IPFORWARDTABLE table
;
1993 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable
, pdwSize
, bOrder
);
1995 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1997 ret
= AllocateAndGetIpForwardTableFromStack(&table
, bOrder
, GetProcessHeap(), 0);
1999 DWORD size
= FIELD_OFFSET( MIB_IPFORWARDTABLE
, table
[table
->dwNumEntries
] );
2000 if (!pIpForwardTable
|| *pdwSize
< size
) {
2002 ret
= ERROR_INSUFFICIENT_BUFFER
;
2006 memcpy(pIpForwardTable
, table
, size
);
2008 HeapFree(GetProcessHeap(), 0, table
);
2010 TRACE("returning %d\n", ret
);
2015 /******************************************************************
2016 * GetIpNetTable (IPHLPAPI.@)
2018 * Get the IP-to-physical address mapping table.
2021 * pIpNetTable [Out] buffer for mapping table
2022 * pdwSize [In/Out] length of output buffer
2023 * bOrder [In] whether to sort the table
2027 * Failure: error code from winerror.h
2030 * If pdwSize is less than required, the function will return
2031 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
2033 * If bOrder is true, the returned table will be sorted by IP address.
2035 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
2038 PMIB_IPNETTABLE table
;
2040 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
, bOrder
);
2042 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
2044 ret
= AllocateAndGetIpNetTableFromStack( &table
, bOrder
, GetProcessHeap(), 0 );
2046 DWORD size
= FIELD_OFFSET( MIB_IPNETTABLE
, table
[table
->dwNumEntries
] );
2047 if (!pIpNetTable
|| *pdwSize
< size
) {
2049 ret
= ERROR_INSUFFICIENT_BUFFER
;
2053 memcpy(pIpNetTable
, table
, size
);
2055 HeapFree(GetProcessHeap(), 0, table
);
2057 TRACE("returning %d\n", ret
);
2061 /* Gets the DNS server list into the list beginning at list. Assumes that
2062 * a single server address may be placed at list if *len is at least
2063 * sizeof(IP_ADDR_STRING) long. Otherwise, list->Next is set to firstDynamic,
2064 * and assumes that all remaining DNS servers are contiguously located
2065 * beginning at firstDynamic. On input, *len is assumed to be the total number
2066 * of bytes available for all DNS servers, and is ignored if list is NULL.
2067 * On return, *len is set to the total number of bytes required for all DNS
2069 * Returns ERROR_BUFFER_OVERFLOW if *len is insufficient,
2070 * ERROR_SUCCESS otherwise.
2072 static DWORD
get_dns_server_list(PIP_ADDR_STRING list
,
2073 PIP_ADDR_STRING firstDynamic
, DWORD
*len
)
2076 int num
= get_dns_servers( NULL
, 0, TRUE
);
2078 size
= num
* sizeof(IP_ADDR_STRING
);
2079 if (!list
|| *len
< size
) {
2081 return ERROR_BUFFER_OVERFLOW
;
2085 PIP_ADDR_STRING ptr
;
2087 SOCKADDR_STORAGE
*addr
= HeapAlloc( GetProcessHeap(), 0, num
* sizeof(SOCKADDR_STORAGE
) );
2089 get_dns_servers( addr
, num
, TRUE
);
2091 for (i
= 0, ptr
= list
; i
< num
; i
++, ptr
= ptr
->Next
) {
2092 toIPAddressString(((struct sockaddr_in
*)(addr
+ i
))->sin_addr
.s_addr
,
2093 ptr
->IpAddress
.String
);
2097 ptr
->Next
= firstDynamic
;
2099 ptr
->Next
= (PIP_ADDR_STRING
)((PBYTE
)ptr
+ sizeof(IP_ADDR_STRING
));
2101 HeapFree( GetProcessHeap(), 0, addr
);
2103 return ERROR_SUCCESS
;
2106 /******************************************************************
2107 * GetNetworkParams (IPHLPAPI.@)
2109 * Get the network parameters for the local computer.
2112 * pFixedInfo [Out] buffer for network parameters
2113 * pOutBufLen [In/Out] length of output buffer
2117 * Failure: error code from winerror.h
2120 * If pOutBufLen is less than required, the function will return
2121 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
2124 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
2126 DWORD ret
, size
, serverListSize
;
2130 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
2132 return ERROR_INVALID_PARAMETER
;
2134 get_dns_server_list(NULL
, NULL
, &serverListSize
);
2135 size
= sizeof(FIXED_INFO
) + serverListSize
- sizeof(IP_ADDR_STRING
);
2136 if (!pFixedInfo
|| *pOutBufLen
< size
) {
2138 return ERROR_BUFFER_OVERFLOW
;
2141 memset(pFixedInfo
, 0, size
);
2142 size
= sizeof(pFixedInfo
->HostName
);
2143 GetComputerNameExA(ComputerNameDnsHostname
, pFixedInfo
->HostName
, &size
);
2144 size
= sizeof(pFixedInfo
->DomainName
);
2145 GetComputerNameExA(ComputerNameDnsDomain
, pFixedInfo
->DomainName
, &size
);
2146 get_dns_server_list(&pFixedInfo
->DnsServerList
,
2147 (PIP_ADDR_STRING
)((BYTE
*)pFixedInfo
+ sizeof(FIXED_INFO
)),
2149 /* Assume the first DNS server in the list is the "current" DNS server: */
2150 pFixedInfo
->CurrentDnsServer
= &pFixedInfo
->DnsServerList
;
2151 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
2152 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2153 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
2154 if (regReturn
!= ERROR_SUCCESS
)
2155 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2156 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
2158 if (regReturn
== ERROR_SUCCESS
)
2160 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
2162 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (LPBYTE
)pFixedInfo
->ScopeId
, &size
);
2166 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
2167 I suppose could also check for a listener on port 53 to set EnableDns */
2169 TRACE("returning %d\n", ret
);
2174 /******************************************************************
2175 * GetNumberOfInterfaces (IPHLPAPI.@)
2177 * Get the number of interfaces.
2180 * pdwNumIf [Out] number of interfaces
2183 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
2185 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
2189 TRACE("pdwNumIf %p\n", pdwNumIf
);
2191 ret
= ERROR_INVALID_PARAMETER
;
2193 *pdwNumIf
= get_interface_indices( FALSE
, NULL
);
2196 TRACE("returning %d\n", ret
);
2201 /******************************************************************
2202 * GetPerAdapterInfo (IPHLPAPI.@)
2204 * Get information about an adapter corresponding to an interface.
2207 * IfIndex [In] interface info
2208 * pPerAdapterInfo [Out] buffer for per adapter info
2209 * pOutBufLen [In/Out] length of output buffer
2213 * Failure: error code from winerror.h
2215 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
2217 ULONG bytesNeeded
= sizeof(IP_PER_ADAPTER_INFO
), serverListSize
= 0;
2218 DWORD ret
= NO_ERROR
;
2220 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex
, pPerAdapterInfo
, pOutBufLen
);
2222 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
2224 if (!isIfIndexLoopback(IfIndex
)) {
2225 get_dns_server_list(NULL
, NULL
, &serverListSize
);
2226 if (serverListSize
> sizeof(IP_ADDR_STRING
))
2227 bytesNeeded
+= serverListSize
- sizeof(IP_ADDR_STRING
);
2229 if (!pPerAdapterInfo
|| *pOutBufLen
< bytesNeeded
)
2231 *pOutBufLen
= bytesNeeded
;
2232 return ERROR_BUFFER_OVERFLOW
;
2235 memset(pPerAdapterInfo
, 0, bytesNeeded
);
2236 if (!isIfIndexLoopback(IfIndex
)) {
2237 ret
= get_dns_server_list(&pPerAdapterInfo
->DnsServerList
,
2238 (PIP_ADDR_STRING
)((PBYTE
)pPerAdapterInfo
+ sizeof(IP_PER_ADAPTER_INFO
)),
2240 /* Assume the first DNS server in the list is the "current" DNS server: */
2241 pPerAdapterInfo
->CurrentDnsServer
= &pPerAdapterInfo
->DnsServerList
;
2247 /******************************************************************
2248 * GetRTTAndHopCount (IPHLPAPI.@)
2250 * Get round-trip time (RTT) and hop count.
2254 * DestIpAddress [In] destination address to get the info for
2255 * HopCount [Out] retrieved hop count
2256 * MaxHops [In] maximum hops to search for the destination
2257 * RTT [Out] RTT in milliseconds
2264 * Stub, returns FALSE.
2266 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
2268 FIXME("(DestIpAddress 0x%08x, HopCount %p, MaxHops %d, RTT %p): stub\n",
2269 DestIpAddress
, HopCount
, MaxHops
, RTT
);
2274 /******************************************************************
2275 * GetTcpTable (IPHLPAPI.@)
2277 * Get the table of active TCP connections.
2280 * pTcpTable [Out] buffer for TCP connections table
2281 * pdwSize [In/Out] length of output buffer
2282 * bOrder [In] whether to order the table
2286 * Failure: error code from winerror.h
2289 * If pdwSize is less than required, the function will return
2290 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
2291 * the required byte size.
2292 * If bOrder is true, the returned table will be sorted, first by
2293 * local address and port number, then by remote address and port
2296 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
2298 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable
, pdwSize
, bOrder
);
2299 return GetExtendedTcpTable(pTcpTable
, pdwSize
, bOrder
, AF_INET
, TCP_TABLE_BASIC_ALL
, 0);
2302 /******************************************************************
2303 * GetExtendedTcpTable (IPHLPAPI.@)
2305 DWORD WINAPI
GetExtendedTcpTable(PVOID pTcpTable
, PDWORD pdwSize
, BOOL bOrder
,
2306 ULONG ulAf
, TCP_TABLE_CLASS TableClass
, ULONG Reserved
)
2311 TRACE("pTcpTable %p, pdwSize %p, bOrder %d, ulAf %u, TableClass %u, Reserved %u\n",
2312 pTcpTable
, pdwSize
, bOrder
, ulAf
, TableClass
, Reserved
);
2314 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
2316 if (ulAf
!= AF_INET
)
2318 FIXME("ulAf = %u not supported\n", ulAf
);
2319 return ERROR_NOT_SUPPORTED
;
2321 if (TableClass
>= TCP_TABLE_OWNER_MODULE_LISTENER
)
2322 FIXME("module classes not fully supported\n");
2324 if ((ret
= build_tcp_table(TableClass
, &table
, bOrder
, GetProcessHeap(), 0, &size
)))
2327 if (!pTcpTable
|| *pdwSize
< size
)
2330 ret
= ERROR_INSUFFICIENT_BUFFER
;
2335 memcpy(pTcpTable
, table
, size
);
2337 HeapFree(GetProcessHeap(), 0, table
);
2341 /******************************************************************
2342 * GetUdpTable (IPHLPAPI.@)
2344 * Get a table of active UDP connections.
2347 * pUdpTable [Out] buffer for UDP connections table
2348 * pdwSize [In/Out] length of output buffer
2349 * bOrder [In] whether to order the table
2353 * Failure: error code from winerror.h
2356 * If pdwSize is less than required, the function will return
2357 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
2358 * required byte size.
2359 * If bOrder is true, the returned table will be sorted, first by
2360 * local address, then by local port number.
2362 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
2364 return GetExtendedUdpTable(pUdpTable
, pdwSize
, bOrder
, AF_INET
, UDP_TABLE_BASIC
, 0);
2367 /******************************************************************
2368 * GetExtendedUdpTable (IPHLPAPI.@)
2370 DWORD WINAPI
GetExtendedUdpTable(PVOID pUdpTable
, PDWORD pdwSize
, BOOL bOrder
,
2371 ULONG ulAf
, UDP_TABLE_CLASS TableClass
, ULONG Reserved
)
2376 TRACE("pUdpTable %p, pdwSize %p, bOrder %d, ulAf %u, TableClass %u, Reserved %u\n",
2377 pUdpTable
, pdwSize
, bOrder
, ulAf
, TableClass
, Reserved
);
2379 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
2381 if (ulAf
!= AF_INET
)
2383 FIXME("ulAf = %u not supported\n", ulAf
);
2384 return ERROR_NOT_SUPPORTED
;
2386 if (TableClass
== UDP_TABLE_OWNER_MODULE
)
2387 FIXME("UDP_TABLE_OWNER_MODULE not fully supported\n");
2389 if ((ret
= build_udp_table(TableClass
, &table
, bOrder
, GetProcessHeap(), 0, &size
)))
2392 if (!pUdpTable
|| *pdwSize
< size
)
2395 ret
= ERROR_INSUFFICIENT_BUFFER
;
2400 memcpy(pUdpTable
, table
, size
);
2402 HeapFree(GetProcessHeap(), 0, table
);
2406 /******************************************************************
2407 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
2409 * This is a Win98-only function to get information on "unidirectional"
2410 * adapters. Since this is pretty nonsensical in other contexts, it
2411 * never returns anything.
2414 * pIPIfInfo [Out] buffer for adapter infos
2415 * dwOutBufLen [Out] length of the output buffer
2419 * Failure: error code from winerror.h
2422 * Stub, returns ERROR_NOT_SUPPORTED.
2424 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
2426 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
2427 /* a unidirectional adapter?? not bloody likely! */
2428 return ERROR_NOT_SUPPORTED
;
2432 /******************************************************************
2433 * IpReleaseAddress (IPHLPAPI.@)
2435 * Release an IP obtained through DHCP,
2438 * AdapterInfo [In] adapter to release IP address
2442 * Failure: error code from winerror.h
2445 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
2446 * this function does nothing.
2449 * Stub, returns ERROR_NOT_SUPPORTED.
2451 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2453 FIXME("Stub AdapterInfo %p\n", AdapterInfo
);
2454 return ERROR_NOT_SUPPORTED
;
2458 /******************************************************************
2459 * IpRenewAddress (IPHLPAPI.@)
2461 * Renew an IP obtained through DHCP.
2464 * AdapterInfo [In] adapter to renew IP address
2468 * Failure: error code from winerror.h
2471 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
2472 * this function does nothing.
2475 * Stub, returns ERROR_NOT_SUPPORTED.
2477 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2479 FIXME("Stub AdapterInfo %p\n", AdapterInfo
);
2480 return ERROR_NOT_SUPPORTED
;
2484 /******************************************************************
2485 * NotifyAddrChange (IPHLPAPI.@)
2487 * Notify caller whenever the ip-interface map is changed.
2490 * Handle [Out] handle usable in asynchronous notification
2491 * overlapped [In] overlapped structure that notifies the caller
2495 * Failure: error code from winerror.h
2498 * Stub, returns ERROR_NOT_SUPPORTED.
2500 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2502 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2503 if (Handle
) *Handle
= INVALID_HANDLE_VALUE
;
2504 if (overlapped
) ((IO_STATUS_BLOCK
*) overlapped
)->u
.Status
= STATUS_PENDING
;
2505 return ERROR_IO_PENDING
;
2509 /******************************************************************
2510 * NotifyIpInterfaceChange (IPHLPAPI.@)
2512 DWORD WINAPI
NotifyIpInterfaceChange(ULONG family
, PVOID callback
, PVOID context
,
2513 BOOLEAN init_notify
, PHANDLE handle
)
2515 FIXME("(family %d, callback %p, context %p, init_notify %d, handle %p): stub\n",
2516 family
, callback
, context
, init_notify
, handle
);
2517 if (handle
) *handle
= NULL
;
2518 return ERROR_NOT_SUPPORTED
;
2522 /******************************************************************
2523 * NotifyRouteChange (IPHLPAPI.@)
2525 * Notify caller whenever the ip routing table is changed.
2528 * Handle [Out] handle usable in asynchronous notification
2529 * overlapped [In] overlapped structure that notifies the caller
2533 * Failure: error code from winerror.h
2536 * Stub, returns ERROR_NOT_SUPPORTED.
2538 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2540 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2541 return ERROR_NOT_SUPPORTED
;
2545 /******************************************************************
2546 * SendARP (IPHLPAPI.@)
2548 * Send an ARP request.
2551 * DestIP [In] attempt to obtain this IP
2552 * SrcIP [In] optional sender IP address
2553 * pMacAddr [Out] buffer for the mac address
2554 * PhyAddrLen [In/Out] length of the output buffer
2558 * Failure: error code from winerror.h
2561 * Stub, returns ERROR_NOT_SUPPORTED.
2563 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
2565 FIXME("(DestIP 0x%08x, SrcIP 0x%08x, pMacAddr %p, PhyAddrLen %p): stub\n",
2566 DestIP
, SrcIP
, pMacAddr
, PhyAddrLen
);
2567 return ERROR_NOT_SUPPORTED
;
2571 /******************************************************************
2572 * SetIfEntry (IPHLPAPI.@)
2574 * Set the administrative status of an interface.
2577 * pIfRow [In] dwAdminStatus member specifies the new status.
2581 * Failure: error code from winerror.h
2584 * Stub, returns ERROR_NOT_SUPPORTED.
2586 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
2588 FIXME("(pIfRow %p): stub\n", pIfRow
);
2589 /* this is supposed to set an interface administratively up or down.
2590 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2591 this sort of down is indistinguishable from other sorts of down (e.g. no
2593 return ERROR_NOT_SUPPORTED
;
2597 /******************************************************************
2598 * SetIpForwardEntry (IPHLPAPI.@)
2600 * Modify an existing route.
2603 * pRoute [In] route with the new information
2607 * Failure: error code from winerror.h
2610 * Stub, returns NO_ERROR.
2612 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
2614 FIXME("(pRoute %p): stub\n", pRoute
);
2615 /* this is to add a route entry, how's it distinguishable from
2616 CreateIpForwardEntry?
2617 could use SIOCADDRT, not sure I want to */
2622 /******************************************************************
2623 * SetIpNetEntry (IPHLPAPI.@)
2625 * Modify an existing ARP entry.
2628 * pArpEntry [In] ARP entry with the new information
2632 * Failure: error code from winerror.h
2635 * Stub, returns NO_ERROR.
2637 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
2639 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
2640 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
2645 /******************************************************************
2646 * SetIpStatistics (IPHLPAPI.@)
2648 * Toggle IP forwarding and det the default TTL value.
2651 * pIpStats [In] IP statistics with the new information
2655 * Failure: error code from winerror.h
2658 * Stub, returns NO_ERROR.
2660 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
2662 FIXME("(pIpStats %p): stub\n", pIpStats
);
2667 /******************************************************************
2668 * SetIpTTL (IPHLPAPI.@)
2670 * Set the default TTL value.
2673 * nTTL [In] new TTL value
2677 * Failure: error code from winerror.h
2680 * Stub, returns NO_ERROR.
2682 DWORD WINAPI
SetIpTTL(UINT nTTL
)
2684 FIXME("(nTTL %d): stub\n", nTTL
);
2685 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
2686 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
2691 /******************************************************************
2692 * SetTcpEntry (IPHLPAPI.@)
2694 * Set the state of a TCP connection.
2697 * pTcpRow [In] specifies connection with new state
2701 * Failure: error code from winerror.h
2704 * Stub, returns NO_ERROR.
2706 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
2708 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
2712 /******************************************************************
2713 * SetPerTcpConnectionEStats (IPHLPAPI.@)
2715 DWORD WINAPI
SetPerTcpConnectionEStats(PMIB_TCPROW row
, TCP_ESTATS_TYPE state
, PBYTE rw
,
2716 ULONG version
, ULONG size
, ULONG offset
)
2718 FIXME("(row %p, state %d, rw %p, version %u, size %u, offset %u): stub\n",
2719 row
, state
, rw
, version
, size
, offset
);
2720 return ERROR_NOT_SUPPORTED
;
2724 /******************************************************************
2725 * UnenableRouter (IPHLPAPI.@)
2727 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2728 * if it reaches zero.
2731 * pOverlapped [In/Out] should be the same as in EnableRouter()
2732 * lpdwEnableCount [Out] optional, receives reference count
2736 * Failure: error code from winerror.h
2739 * Stub, returns ERROR_NOT_SUPPORTED.
2741 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
2743 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
2745 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
2746 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
2748 return ERROR_NOT_SUPPORTED
;
2751 /******************************************************************
2752 * PfCreateInterface (IPHLPAPI.@)
2754 DWORD WINAPI
PfCreateInterface(DWORD dwName
, PFFORWARD_ACTION inAction
, PFFORWARD_ACTION outAction
,
2755 BOOL bUseLog
, BOOL bMustBeUnique
, INTERFACE_HANDLE
*ppInterface
)
2757 FIXME("(%d %d %d %x %x %p) stub\n", dwName
, inAction
, outAction
, bUseLog
, bMustBeUnique
, ppInterface
);
2758 return ERROR_CALL_NOT_IMPLEMENTED
;
2761 /******************************************************************
2762 * PfUnBindInterface (IPHLPAPI.@)
2764 DWORD WINAPI
PfUnBindInterface(INTERFACE_HANDLE interface
)
2766 FIXME("(%p) stub\n", interface
);
2767 return ERROR_CALL_NOT_IMPLEMENTED
;
2770 /******************************************************************
2771 * PfDeleteInterface(IPHLPAPI.@)
2773 DWORD WINAPI
PfDeleteInterface(INTERFACE_HANDLE interface
)
2775 FIXME("(%p) stub\n", interface
);
2776 return ERROR_CALL_NOT_IMPLEMENTED
;
2779 /******************************************************************
2780 * PfBindInterfaceToIPAddress(IPHLPAPI.@)
2782 DWORD WINAPI
PfBindInterfaceToIPAddress(INTERFACE_HANDLE interface
, PFADDRESSTYPE type
, PBYTE ip
)
2784 FIXME("(%p %d %p) stub\n", interface
, type
, ip
);
2785 return ERROR_CALL_NOT_IMPLEMENTED
;
2788 /******************************************************************
2789 * GetTcpTable2 (IPHLPAPI.@)
2791 ULONG WINAPI
GetTcpTable2(PMIB_TCPTABLE2 table
, PULONG size
, BOOL order
)
2793 FIXME("pTcpTable2 %p, pdwSize %p, bOrder %d: stub\n", table
, size
, order
);
2794 return ERROR_NOT_SUPPORTED
;
2797 /******************************************************************
2798 * GetTcp6Table (IPHLPAPI.@)
2800 ULONG WINAPI
GetTcp6Table(PMIB_TCP6TABLE table
, PULONG size
, BOOL order
)
2802 FIXME("pTcp6Table %p, size %p, order %d: stub\n", table
, size
, order
);
2803 return ERROR_NOT_SUPPORTED
;
2806 /******************************************************************
2807 * GetTcp6Table2 (IPHLPAPI.@)
2809 ULONG WINAPI
GetTcp6Table2(PMIB_TCP6TABLE2 table
, PULONG size
, BOOL order
)
2811 FIXME("pTcp6Table2 %p, size %p, order %d: stub\n", table
, size
, order
);
2812 return ERROR_NOT_SUPPORTED
;
2815 /******************************************************************
2816 * ConvertInterfaceGuidToLuid (IPHLPAPI.@)
2818 DWORD WINAPI
ConvertInterfaceGuidToLuid(const GUID
*guid
, NET_LUID
*luid
)
2823 TRACE("(%s %p)\n", debugstr_guid(guid
), luid
);
2825 if (!guid
|| !luid
) return ERROR_INVALID_PARAMETER
;
2827 row
.dwIndex
= guid
->Data1
;
2828 if ((ret
= GetIfEntry( &row
))) return ret
;
2830 luid
->Info
.Reserved
= 0;
2831 luid
->Info
.NetLuidIndex
= guid
->Data1
;
2832 luid
->Info
.IfType
= row
.dwType
;
2836 /******************************************************************
2837 * ConvertInterfaceIndexToLuid (IPHLPAPI.@)
2839 DWORD WINAPI
ConvertInterfaceIndexToLuid(NET_IFINDEX index
, NET_LUID
*luid
)
2843 TRACE("(%u %p)\n", index
, luid
);
2845 if (!luid
) return ERROR_INVALID_PARAMETER
;
2846 memset( luid
, 0, sizeof(*luid
) );
2848 row
.dwIndex
= index
;
2849 if (GetIfEntry( &row
)) return ERROR_FILE_NOT_FOUND
;
2851 luid
->Info
.Reserved
= 0;
2852 luid
->Info
.NetLuidIndex
= index
;
2853 luid
->Info
.IfType
= row
.dwType
;
2857 /******************************************************************
2858 * ConvertInterfaceLuidToGuid (IPHLPAPI.@)
2860 DWORD WINAPI
ConvertInterfaceLuidToGuid(const NET_LUID
*luid
, GUID
*guid
)
2865 TRACE("(%p %p)\n", luid
, guid
);
2867 if (!luid
|| !guid
) return ERROR_INVALID_PARAMETER
;
2869 row
.dwIndex
= luid
->Info
.NetLuidIndex
;
2870 if ((ret
= GetIfEntry( &row
))) return ret
;
2872 guid
->Data1
= luid
->Info
.NetLuidIndex
;
2876 /******************************************************************
2877 * ConvertInterfaceLuidToIndex (IPHLPAPI.@)
2879 DWORD WINAPI
ConvertInterfaceLuidToIndex(const NET_LUID
*luid
, NET_IFINDEX
*index
)
2884 TRACE("(%p %p)\n", luid
, index
);
2886 if (!luid
|| !index
) return ERROR_INVALID_PARAMETER
;
2888 row
.dwIndex
= luid
->Info
.NetLuidIndex
;
2889 if ((ret
= GetIfEntry( &row
))) return ret
;
2891 *index
= luid
->Info
.NetLuidIndex
;
2895 /******************************************************************
2896 * ConvertInterfaceLuidToNameA (IPHLPAPI.@)
2898 DWORD WINAPI
ConvertInterfaceLuidToNameA(const NET_LUID
*luid
, char *name
, SIZE_T len
)
2903 TRACE("(%p %p %u)\n", luid
, name
, (DWORD
)len
);
2905 if (!luid
) return ERROR_INVALID_PARAMETER
;
2907 row
.dwIndex
= luid
->Info
.NetLuidIndex
;
2908 if ((ret
= GetIfEntry( &row
))) return ret
;
2910 if (!name
|| len
< WideCharToMultiByte( CP_UNIXCP
, 0, row
.wszName
, -1, NULL
, 0, NULL
, NULL
))
2911 return ERROR_NOT_ENOUGH_MEMORY
;
2913 WideCharToMultiByte( CP_UNIXCP
, 0, row
.wszName
, -1, name
, len
, NULL
, NULL
);
2917 /******************************************************************
2918 * ConvertInterfaceLuidToNameW (IPHLPAPI.@)
2920 DWORD WINAPI
ConvertInterfaceLuidToNameW(const NET_LUID
*luid
, WCHAR
*name
, SIZE_T len
)
2925 TRACE("(%p %p %u)\n", luid
, name
, (DWORD
)len
);
2927 if (!luid
|| !name
) return ERROR_INVALID_PARAMETER
;
2929 row
.dwIndex
= luid
->Info
.NetLuidIndex
;
2930 if ((ret
= GetIfEntry( &row
))) return ret
;
2932 if (len
< strlenW( row
.wszName
) + 1) return ERROR_NOT_ENOUGH_MEMORY
;
2933 strcpyW( name
, row
.wszName
);
2937 /******************************************************************
2938 * ConvertInterfaceNameToLuidA (IPHLPAPI.@)
2940 DWORD WINAPI
ConvertInterfaceNameToLuidA(const char *name
, NET_LUID
*luid
)
2946 TRACE("(%s %p)\n", debugstr_a(name
), luid
);
2948 if ((ret
= getInterfaceIndexByName( name
, &index
))) return ERROR_INVALID_NAME
;
2949 if (!luid
) return ERROR_INVALID_PARAMETER
;
2951 row
.dwIndex
= index
;
2952 if ((ret
= GetIfEntry( &row
))) return ret
;
2954 luid
->Info
.Reserved
= 0;
2955 luid
->Info
.NetLuidIndex
= index
;
2956 luid
->Info
.IfType
= row
.dwType
;
2960 /******************************************************************
2961 * ConvertInterfaceNameToLuidW (IPHLPAPI.@)
2963 DWORD WINAPI
ConvertInterfaceNameToLuidW(const WCHAR
*name
, NET_LUID
*luid
)
2968 char nameA
[IF_MAX_STRING_SIZE
+ 1];
2970 TRACE("(%s %p)\n", debugstr_w(name
), luid
);
2972 if (!luid
) return ERROR_INVALID_PARAMETER
;
2973 memset( luid
, 0, sizeof(*luid
) );
2975 if (!WideCharToMultiByte( CP_UNIXCP
, 0, name
, -1, nameA
, sizeof(nameA
), NULL
, NULL
))
2976 return ERROR_INVALID_NAME
;
2978 if ((ret
= getInterfaceIndexByName( nameA
, &index
))) return ret
;
2980 row
.dwIndex
= index
;
2981 if ((ret
= GetIfEntry( &row
))) return ret
;
2983 luid
->Info
.Reserved
= 0;
2984 luid
->Info
.NetLuidIndex
= index
;
2985 luid
->Info
.IfType
= row
.dwType
;