2003-05-13 05:32:20 +02:00
|
|
|
/*
|
|
|
|
* iphlpapi dll implementation
|
|
|
|
*
|
2006-01-25 13:14:12 +01:00
|
|
|
* Copyright (C) 2003,2006 Juan Lang
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-05-13 05:32:20 +02:00
|
|
|
#include <stdlib.h>
|
2014-06-03 22:33:27 +02:00
|
|
|
#include <stdio.h>
|
2003-05-14 01:37:29 +02:00
|
|
|
#include <sys/types.h>
|
2003-05-19 23:41:00 +02:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
2003-08-08 23:07:23 +02:00
|
|
|
# include <netinet/in.h>
|
2003-05-19 23:41:00 +02:00
|
|
|
#endif
|
2004-01-02 04:55:05 +01:00
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
#endif
|
2003-05-19 23:41:00 +02:00
|
|
|
#ifdef HAVE_ARPA_NAMESER_H
|
2003-08-08 23:07:23 +02:00
|
|
|
# include <arpa/nameser.h>
|
2003-05-19 23:41:00 +02:00
|
|
|
#endif
|
2003-08-08 23:07:23 +02:00
|
|
|
#ifdef HAVE_RESOLV_H
|
|
|
|
# include <resolv.h>
|
|
|
|
#endif
|
|
|
|
|
2009-08-31 11:53:04 +02:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2003-05-13 05:32:20 +02:00
|
|
|
#include "winbase.h"
|
2003-09-08 21:00:25 +02:00
|
|
|
#include "winreg.h"
|
2008-01-17 13:26:14 +01:00
|
|
|
#define USE_WS_PREFIX
|
|
|
|
#include "winsock2.h"
|
2011-05-22 09:22:45 +02:00
|
|
|
#include "winternl.h"
|
2010-03-12 03:36:46 +01:00
|
|
|
#include "ws2ipdef.h"
|
2019-09-05 07:14:15 +02:00
|
|
|
#include "windns.h"
|
2003-05-13 05:32:20 +02:00
|
|
|
#include "iphlpapi.h"
|
|
|
|
#include "ifenum.h"
|
|
|
|
#include "ipstats.h"
|
2009-04-29 11:41:02 +02:00
|
|
|
#include "ipifcons.h"
|
2011-06-07 13:10:57 +02:00
|
|
|
#include "fltdefs.h"
|
2015-07-22 14:28:05 +02:00
|
|
|
#include "ifdef.h"
|
2015-07-22 14:26:59 +02:00
|
|
|
#include "netioapi.h"
|
2015-08-08 18:11:35 +02:00
|
|
|
#include "tcpestats.h"
|
2019-09-05 07:14:15 +02:00
|
|
|
#include "ip2string.h"
|
2008-01-17 13:26:14 +01:00
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
#include "wine/debug.h"
|
2015-07-22 14:26:59 +02:00
|
|
|
#include "wine/unicode.h"
|
2003-05-13 05:32:20 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
|
|
|
|
|
2009-04-29 11:41:02 +02:00
|
|
|
#ifndef IF_NAMESIZE
|
|
|
|
#define IF_NAMESIZE 16
|
|
|
|
#endif
|
|
|
|
|
2004-01-15 01:25:41 +01:00
|
|
|
#ifndef INADDR_NONE
|
|
|
|
#define INADDR_NONE ~0UL
|
|
|
|
#endif
|
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
/******************************************************************
|
|
|
|
* AddIPAddress (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Add an IP address to an adapter.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Address [In] IP address to add to the adapter
|
|
|
|
* IpMask [In] subnet mask for the IP address
|
|
|
|
* IfIndex [In] adapter index to add the address
|
|
|
|
* NTEContext [Out] Net Table Entry (NTE) context for the IP address
|
|
|
|
* NTEInstance [Out] NTE instance for the IP address
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub. Currently returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
|
|
|
|
{
|
|
|
|
FIXME(":stub\n");
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-08 21:00:25 +02:00
|
|
|
/******************************************************************
|
|
|
|
* AllocateAndGetIfTableFromStack (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get table of local interfaces.
|
|
|
|
* Like GetIfTable(), but allocate the returned table from heap.
|
2003-09-08 21:00:25 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* ppIfTable [Out] pointer into which the MIB_IFTABLE is
|
|
|
|
* allocated and returned.
|
2006-01-24 12:18:50 +01:00
|
|
|
* bOrder [In] whether to sort the table
|
2005-11-14 12:24:37 +01:00
|
|
|
* heap [In] heap from which the table is allocated
|
|
|
|
* flags [In] flags to HeapAlloc
|
2003-09-08 21:00:25 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* RETURNS
|
|
|
|
* ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
|
|
|
|
* GetIfTable() returns otherwise.
|
2003-09-08 21:00:25 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
|
|
|
|
BOOL bOrder, HANDLE heap, DWORD flags)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable,
|
2005-09-12 12:30:05 +02:00
|
|
|
bOrder, heap, flags);
|
2003-09-08 21:00:25 +02:00
|
|
|
if (!ppIfTable)
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
else {
|
|
|
|
DWORD dwSize = 0;
|
|
|
|
|
|
|
|
ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
|
|
|
|
if (ret == ERROR_INSUFFICIENT_BUFFER) {
|
2005-03-24 22:01:35 +01:00
|
|
|
*ppIfTable = HeapAlloc(heap, flags, dwSize);
|
2003-09-08 21:00:25 +02:00
|
|
|
ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
|
|
|
|
}
|
|
|
|
}
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2003-09-08 21:00:25 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-01 13:23:36 +01:00
|
|
|
static int IpAddrTableNumericSorter(const void *a, const void *b)
|
2006-01-24 12:18:50 +01:00
|
|
|
{
|
2016-12-01 13:23:36 +01:00
|
|
|
int ret = 0;
|
2006-01-24 12:18:50 +01:00
|
|
|
|
|
|
|
if (a && b)
|
|
|
|
ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-12-01 13:23:36 +01:00
|
|
|
static int IpAddrTableLoopbackSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const MIB_IPADDRROW *left = a, *right = b;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (isIfIndexLoopback(left->dwIndex))
|
|
|
|
ret = 1;
|
|
|
|
else if (isIfIndexLoopback(right->dwIndex))
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2006-01-24 12:18:50 +01:00
|
|
|
|
2003-09-08 21:00:25 +02:00
|
|
|
/******************************************************************
|
|
|
|
* AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get interface-to-IP address mapping table.
|
|
|
|
* Like GetIpAddrTable(), but allocate the returned table from heap.
|
2003-09-08 21:00:25 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
|
|
|
|
* allocated and returned.
|
2006-01-24 12:18:50 +01:00
|
|
|
* bOrder [In] whether to sort the table
|
2005-11-14 12:24:37 +01:00
|
|
|
* heap [In] heap from which the table is allocated
|
|
|
|
* flags [In] flags to HeapAlloc
|
2003-09-08 21:00:25 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2006-01-24 12:18:50 +01:00
|
|
|
* ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
|
|
|
|
* failure, NO_ERROR on success.
|
2003-09-08 21:00:25 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
|
|
|
|
BOOL bOrder, HANDLE heap, DWORD flags)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
|
2005-09-12 12:30:05 +02:00
|
|
|
ppIpAddrTable, bOrder, heap, flags);
|
2006-01-24 12:18:50 +01:00
|
|
|
ret = getIPAddrTable(ppIpAddrTable, heap, flags);
|
|
|
|
if (!ret && bOrder)
|
|
|
|
qsort((*ppIpAddrTable)->table, (*ppIpAddrTable)->dwNumEntries,
|
2016-12-01 13:23:36 +01:00
|
|
|
sizeof(MIB_IPADDRROW), IpAddrTableNumericSorter);
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2006-01-24 12:18:50 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2003-09-08 21:00:25 +02:00
|
|
|
|
2006-01-24 12:18:50 +01:00
|
|
|
|
2010-12-11 09:57:24 +01:00
|
|
|
/******************************************************************
|
|
|
|
* CancelIPChangeNotify (IPHLPAPI.@)
|
|
|
|
*
|
|
|
|
* Cancel a previous notification created by NotifyAddrChange or
|
|
|
|
* NotifyRouteChange.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* overlapped [In] overlapped structure that notifies the caller
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* FIXME
|
|
|
|
* Stub, returns FALSE.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CancelIPChangeNotify(LPOVERLAPPED overlapped)
|
|
|
|
{
|
|
|
|
FIXME("(overlapped %p): stub\n", overlapped);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-27 02:29:21 +01:00
|
|
|
/******************************************************************
|
|
|
|
* CancelMibChangeNotify2 (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CancelMibChangeNotify2(HANDLE handle)
|
|
|
|
{
|
|
|
|
FIXME("(handle %p): stub\n", handle);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-12-11 09:57:24 +01:00
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
/******************************************************************
|
|
|
|
* CreateIpForwardEntry (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Create a route in the local computer's IP table.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pRoute [In] new route information
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
2005-11-23 20:14:43 +01:00
|
|
|
* Stub, always returns NO_ERROR.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(pRoute %p): stub\n", pRoute);
|
2003-05-13 05:32:20 +02:00
|
|
|
/* could use SIOCADDRT, not sure I want to */
|
2008-11-03 22:34:55 +01:00
|
|
|
return 0;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CreateIpNetEntry (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Create entry in the ARP table.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pArpEntry [In] new ARP entry
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
2005-11-23 20:14:43 +01:00
|
|
|
* Stub, always returns NO_ERROR.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(pArpEntry %p)\n", pArpEntry);
|
2003-05-13 05:32:20 +02:00
|
|
|
/* could use SIOCSARP on systems that support it, not sure I want to */
|
2008-11-03 22:34:55 +01:00
|
|
|
return 0;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CreateProxyArpEntry (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Create a Proxy ARP (PARP) entry for an IP address.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* dwAddress [In] IP address for which this computer acts as a proxy.
|
|
|
|
* dwMask [In] subnet mask for dwAddress
|
|
|
|
* dwIfIndex [In] interface index
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
|
|
|
|
{
|
2006-10-07 20:18:10 +02:00
|
|
|
FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
|
2004-12-13 14:21:39 +01:00
|
|
|
dwAddress, dwMask, dwIfIndex);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ERROR_NOT_SUPPORTED;
|
2015-01-03 04:29:10 +01:00
|
|
|
}
|
|
|
|
|
2015-07-21 11:01:16 +02:00
|
|
|
static char *debugstr_ipv6(const struct WS_sockaddr_in6 *sin, char *buf)
|
|
|
|
{
|
|
|
|
const IN6_ADDR *addr = &sin->sin6_addr;
|
|
|
|
char *p = buf;
|
|
|
|
int i;
|
|
|
|
BOOL in_zero = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
if (!addr->u.Word[i])
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
*p++ = ':';
|
|
|
|
if (!in_zero)
|
|
|
|
{
|
|
|
|
*p++ = ':';
|
|
|
|
in_zero = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p += sprintf(p, "%x:", ntohs(addr->u.Word[i]));
|
|
|
|
in_zero = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sprintf(p, "%x", ntohs(addr->u.Word[7]));
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2015-08-18 09:40:58 +02:00
|
|
|
static BOOL map_address_6to4( const SOCKADDR_IN6 *addr6, SOCKADDR_IN *addr4 )
|
2015-07-21 11:01:16 +02:00
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
if (addr6->sin6_family != WS_AF_INET6) return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
if (addr6->sin6_addr.u.Word[i]) return FALSE;
|
|
|
|
|
|
|
|
if (addr6->sin6_addr.u.Word[5] != 0xffff) return FALSE;
|
|
|
|
|
2015-08-18 09:40:58 +02:00
|
|
|
addr4->sin_family = WS_AF_INET;
|
2015-07-21 11:01:16 +02:00
|
|
|
addr4->sin_port = addr6->sin6_port;
|
|
|
|
addr4->sin_addr.S_un.S_addr = addr6->sin6_addr.u.Word[6] << 16 | addr6->sin6_addr.u.Word[7];
|
|
|
|
memset( &addr4->sin_zero, 0, sizeof(addr4->sin_zero) );
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-18 09:40:58 +02:00
|
|
|
static BOOL find_src_address( MIB_IPADDRTABLE *table, const SOCKADDR_IN *dst, SOCKADDR_IN6 *src )
|
2015-07-21 11:01:16 +02:00
|
|
|
{
|
|
|
|
MIB_IPFORWARDROW row;
|
|
|
|
DWORD i, j;
|
|
|
|
|
|
|
|
if (GetBestRoute( dst->sin_addr.S_un.S_addr, 0, &row )) return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < table->dwNumEntries; i++)
|
|
|
|
{
|
|
|
|
/* take the first address */
|
|
|
|
if (table->table[i].dwIndex == row.dwForwardIfIndex)
|
|
|
|
{
|
|
|
|
src->sin6_family = WS_AF_INET6;
|
|
|
|
src->sin6_port = 0;
|
|
|
|
src->sin6_flowinfo = 0;
|
|
|
|
for (j = 0; j < 5; j++) src->sin6_addr.u.Word[j] = 0;
|
|
|
|
src->sin6_addr.u.Word[5] = 0xffff;
|
|
|
|
src->sin6_addr.u.Word[6] = table->table[i].dwAddr & 0xffff;
|
|
|
|
src->sin6_addr.u.Word[7] = table->table[i].dwAddr >> 16;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-01-03 04:29:10 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CreateSortedAddressPairs (IPHLPAPI.@)
|
|
|
|
*/
|
2015-07-21 11:01:16 +02:00
|
|
|
DWORD WINAPI CreateSortedAddressPairs( const PSOCKADDR_IN6 src_list, DWORD src_count,
|
|
|
|
const PSOCKADDR_IN6 dst_list, DWORD dst_count,
|
|
|
|
DWORD options, PSOCKADDR_IN6_PAIR *pair_list,
|
|
|
|
DWORD *pair_count )
|
2015-01-03 04:29:10 +01:00
|
|
|
{
|
2015-07-21 11:01:16 +02:00
|
|
|
DWORD i, size, ret;
|
|
|
|
SOCKADDR_IN6_PAIR *pairs;
|
|
|
|
SOCKADDR_IN6 *ptr;
|
|
|
|
SOCKADDR_IN addr4;
|
|
|
|
MIB_IPADDRTABLE *table;
|
2015-01-03 04:29:10 +01:00
|
|
|
|
2015-07-21 11:01:16 +02:00
|
|
|
FIXME( "(src_list %p src_count %u dst_list %p dst_count %u options %x pair_list %p pair_count %p): stub\n",
|
|
|
|
src_list, src_count, dst_list, dst_count, options, pair_list, pair_count );
|
2015-01-03 04:29:10 +01:00
|
|
|
|
2015-07-21 11:01:16 +02:00
|
|
|
if (src_list || src_count || !dst_list || !pair_list || !pair_count || dst_count > 500)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
for (i = 0; i < dst_count; i++)
|
|
|
|
{
|
|
|
|
if (!map_address_6to4( &dst_list[i], &addr4 ))
|
|
|
|
{
|
|
|
|
FIXME("only mapped IPv4 addresses are supported\n");
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size = dst_count * sizeof(*pairs);
|
|
|
|
size += dst_count * sizeof(SOCKADDR_IN6) * 2; /* source address + destination address */
|
|
|
|
if (!(pairs = HeapAlloc( GetProcessHeap(), 0, size ))) return ERROR_NOT_ENOUGH_MEMORY;
|
2015-08-09 13:13:52 +02:00
|
|
|
ptr = (SOCKADDR_IN6 *)&pairs[dst_count];
|
2015-07-21 11:01:16 +02:00
|
|
|
|
|
|
|
if ((ret = getIPAddrTable( &table, GetProcessHeap(), 0 )))
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, pairs );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dst_count; i++)
|
|
|
|
{
|
|
|
|
pairs[i].SourceAddress = ptr++;
|
|
|
|
if (!map_address_6to4( &dst_list[i], &addr4 ) ||
|
|
|
|
!find_src_address( table, &addr4, pairs[i].SourceAddress ))
|
|
|
|
{
|
|
|
|
char buf[46];
|
|
|
|
FIXME( "source address for %s not found\n", debugstr_ipv6(&dst_list[i], buf) );
|
|
|
|
memset( pairs[i].SourceAddress, 0, sizeof(*pairs[i].SourceAddress) );
|
|
|
|
pairs[i].SourceAddress->sin6_family = WS_AF_INET6;
|
|
|
|
}
|
|
|
|
|
|
|
|
pairs[i].DestinationAddress = ptr++;
|
|
|
|
memcpy( pairs[i].DestinationAddress, &dst_list[i], sizeof(*pairs[i].DestinationAddress) );
|
|
|
|
}
|
|
|
|
*pair_list = pairs;
|
|
|
|
*pair_count = dst_count;
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, table );
|
|
|
|
return NO_ERROR;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* DeleteIPAddress (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Delete an IP address added with AddIPAddress().
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* NTEContext [In] NTE context from AddIPAddress();
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
|
|
|
|
{
|
2006-10-07 20:18:10 +02:00
|
|
|
FIXME("(NTEContext %d): stub\n", NTEContext);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* DeleteIpForwardEntry (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Delete a route.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pRoute [In] route to delete
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns NO_ERROR.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(pRoute %p): stub\n", pRoute);
|
2003-05-13 05:32:20 +02:00
|
|
|
/* could use SIOCDELRT, not sure I want to */
|
2008-11-03 22:34:55 +01:00
|
|
|
return 0;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* DeleteIpNetEntry (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Delete an ARP entry.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pArpEntry [In] ARP entry to delete
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns NO_ERROR.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(pArpEntry %p): stub\n", pArpEntry);
|
2003-05-13 05:32:20 +02:00
|
|
|
/* could use SIOCDARP on systems that support it, not sure I want to */
|
2008-11-03 22:34:55 +01:00
|
|
|
return 0;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* DeleteProxyArpEntry (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Delete a Proxy ARP entry.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* dwAddress [In] IP address for which this computer acts as a proxy.
|
|
|
|
* dwMask [In] subnet mask for dwAddress
|
|
|
|
* dwIfIndex [In] interface index
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
|
|
|
|
{
|
2006-10-07 20:18:10 +02:00
|
|
|
FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
|
2004-12-13 14:21:39 +01:00
|
|
|
dwAddress, dwMask, dwIfIndex);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EnableRouter (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Turn on ip forwarding.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pHandle [In/Out]
|
|
|
|
* pOverlapped [In/Out] hEvent member should contain a valid handle.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: ERROR_IO_PENDING
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle, pOverlapped);
|
2003-05-13 05:32:20 +02:00
|
|
|
/* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
|
|
|
|
could map EACCESS to ERROR_ACCESS_DENIED, I suppose
|
2006-01-20 16:16:56 +01:00
|
|
|
*/
|
2003-05-13 05:32:20 +02:00
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* FlushIpNetTable (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Delete all ARP entries of an interface
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* dwIfIndex [In] interface index
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
|
|
|
|
{
|
2006-10-07 20:18:10 +02:00
|
|
|
FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex);
|
2006-01-20 16:16:56 +01:00
|
|
|
/* this flushes the arp cache of the given index */
|
2003-05-13 05:32:20 +02:00
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2015-01-12 23:50:43 +01:00
|
|
|
/******************************************************************
|
|
|
|
* FreeMibTable (IPHLPAPI.@)
|
|
|
|
*
|
|
|
|
* Free buffer allocated by network functions
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ptr [In] pointer to the buffer to free
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void WINAPI FreeMibTable(void *ptr)
|
|
|
|
{
|
|
|
|
TRACE("(%p)\n", ptr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
}
|
2003-05-13 05:32:20 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetAdapterIndex (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get interface index from its name.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* AdapterName [In] unicode string with the adapter name
|
|
|
|
* IfIndex [Out] returns found interface index
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
|
|
|
|
{
|
2007-10-14 01:39:10 +02:00
|
|
|
char adapterName[MAX_ADAPTER_NAME];
|
2008-08-27 21:53:37 +02:00
|
|
|
unsigned int i;
|
2007-10-14 01:39:10 +02:00
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName, IfIndex);
|
|
|
|
/* The adapter name is guaranteed not to have any unicode characters, so
|
|
|
|
* this translation is never lossy */
|
|
|
|
for (i = 0; i < sizeof(adapterName) - 1 && AdapterName[i]; i++)
|
|
|
|
adapterName[i] = (char)AdapterName[i];
|
|
|
|
adapterName[i] = '\0';
|
|
|
|
ret = getInterfaceIndexByName(adapterName, IfIndex);
|
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetAdaptersInfo (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get information about adapters.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* PARAMS
|
|
|
|
* pAdapterInfo [Out] buffer for adapter infos
|
|
|
|
* pOutBufLen [In] length of output buffer
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
2004-01-02 04:55:05 +01:00
|
|
|
TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (!pOutBufLen)
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
else {
|
2013-09-19 16:39:20 +02:00
|
|
|
DWORD numNonLoopbackInterfaces = get_interface_indices( TRUE, NULL );
|
2003-05-13 05:32:20 +02:00
|
|
|
|
|
|
|
if (numNonLoopbackInterfaces > 0) {
|
2006-01-25 13:14:12 +01:00
|
|
|
DWORD numIPAddresses = getNumIPAddresses();
|
|
|
|
ULONG size;
|
|
|
|
|
|
|
|
/* This may slightly overestimate the amount of space needed, because
|
|
|
|
* the IP addresses include the loopback address, but it's easier
|
|
|
|
* to make sure there's more than enough space than to make sure there's
|
|
|
|
* precisely enough space.
|
|
|
|
*/
|
|
|
|
size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
|
2006-01-30 18:16:22 +01:00
|
|
|
size += numIPAddresses * sizeof(IP_ADDR_STRING);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (!pAdapterInfo || *pOutBufLen < size) {
|
|
|
|
*pOutBufLen = size;
|
|
|
|
ret = ERROR_BUFFER_OVERFLOW;
|
|
|
|
}
|
|
|
|
else {
|
2006-01-25 13:14:12 +01:00
|
|
|
InterfaceIndexTable *table = NULL;
|
|
|
|
PMIB_IPADDRTABLE ipAddrTable = NULL;
|
2007-10-14 01:21:20 +02:00
|
|
|
PMIB_IPFORWARDTABLE routeTable = NULL;
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2006-01-25 13:14:12 +01:00
|
|
|
ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
|
2007-10-14 01:21:20 +02:00
|
|
|
if (!ret)
|
2009-03-02 12:52:45 +01:00
|
|
|
ret = AllocateAndGetIpForwardTableFromStack(&routeTable, FALSE, GetProcessHeap(), 0);
|
2006-01-25 13:14:12 +01:00
|
|
|
if (!ret)
|
2013-09-19 16:39:20 +02:00
|
|
|
get_interface_indices( TRUE, &table );
|
2003-05-13 05:32:20 +02:00
|
|
|
if (table) {
|
|
|
|
size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
|
2006-01-30 18:16:22 +01:00
|
|
|
size += ipAddrTable->dwNumEntries * sizeof(IP_ADDR_STRING);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (*pOutBufLen < size) {
|
|
|
|
*pOutBufLen = size;
|
|
|
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DWORD ndx;
|
2004-01-02 04:55:05 +01:00
|
|
|
HKEY hKey;
|
|
|
|
BOOL winsEnabled = FALSE;
|
|
|
|
IP_ADDRESS_STRING primaryWINS, secondaryWINS;
|
2006-01-25 13:14:12 +01:00
|
|
|
PIP_ADDR_STRING nextIPAddr = (PIP_ADDR_STRING)((LPBYTE)pAdapterInfo
|
|
|
|
+ numNonLoopbackInterfaces * sizeof(IP_ADAPTER_INFO));
|
2003-05-13 05:32:20 +02:00
|
|
|
|
|
|
|
memset(pAdapterInfo, 0, size);
|
2005-06-14 19:22:41 +02:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\Network */
|
2006-01-25 13:14:12 +01:00
|
|
|
if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network",
|
|
|
|
&hKey) == ERROR_SUCCESS) {
|
2004-01-02 04:55:05 +01:00
|
|
|
DWORD size = sizeof(primaryWINS.String);
|
|
|
|
unsigned long addr;
|
|
|
|
|
|
|
|
RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
|
2005-07-07 14:08:42 +02:00
|
|
|
(LPBYTE)primaryWINS.String, &size);
|
2004-01-02 04:55:05 +01:00
|
|
|
addr = inet_addr(primaryWINS.String);
|
|
|
|
if (addr != INADDR_NONE && addr != INADDR_ANY)
|
|
|
|
winsEnabled = TRUE;
|
|
|
|
size = sizeof(secondaryWINS.String);
|
|
|
|
RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
|
2005-07-07 14:08:42 +02:00
|
|
|
(LPBYTE)secondaryWINS.String, &size);
|
2004-01-02 04:55:05 +01:00
|
|
|
addr = inet_addr(secondaryWINS.String);
|
|
|
|
if (addr != INADDR_NONE && addr != INADDR_ANY)
|
|
|
|
winsEnabled = TRUE;
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
2003-05-13 05:32:20 +02:00
|
|
|
for (ndx = 0; ndx < table->numIndexes; ndx++) {
|
|
|
|
PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
|
2007-10-14 01:25:36 +02:00
|
|
|
DWORD i;
|
2006-01-25 13:14:12 +01:00
|
|
|
PIP_ADDR_STRING currentIPAddr = &ptr->IpAddressList;
|
|
|
|
BOOL firstIPAddr = TRUE;
|
2003-05-13 05:32:20 +02:00
|
|
|
|
|
|
|
/* on Win98 this is left empty, but whatever */
|
2006-01-27 19:19:32 +01:00
|
|
|
getInterfaceNameByIndex(table->indexes[ndx], ptr->AdapterName);
|
2008-05-20 21:38:12 +02:00
|
|
|
getInterfaceNameByIndex(table->indexes[ndx], ptr->Description);
|
2007-12-03 22:58:05 +01:00
|
|
|
ptr->AddressLength = sizeof(ptr->Address);
|
2007-10-14 01:25:36 +02:00
|
|
|
getInterfacePhysicalByIndex(table->indexes[ndx],
|
|
|
|
&ptr->AddressLength, ptr->Address, &ptr->Type);
|
2003-05-13 05:32:20 +02:00
|
|
|
ptr->Index = table->indexes[ndx];
|
2006-01-25 13:14:12 +01:00
|
|
|
for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
|
|
|
|
if (ipAddrTable->table[i].dwIndex == ptr->Index) {
|
|
|
|
if (firstIPAddr) {
|
|
|
|
toIPAddressString(ipAddrTable->table[i].dwAddr,
|
|
|
|
ptr->IpAddressList.IpAddress.String);
|
2006-10-27 16:03:06 +02:00
|
|
|
toIPAddressString(ipAddrTable->table[i].dwMask,
|
2006-01-25 13:14:12 +01:00
|
|
|
ptr->IpAddressList.IpMask.String);
|
|
|
|
firstIPAddr = FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
currentIPAddr->Next = nextIPAddr;
|
|
|
|
currentIPAddr = nextIPAddr;
|
|
|
|
toIPAddressString(ipAddrTable->table[i].dwAddr,
|
|
|
|
currentIPAddr->IpAddress.String);
|
2006-10-27 16:03:06 +02:00
|
|
|
toIPAddressString(ipAddrTable->table[i].dwMask,
|
2006-01-25 13:14:12 +01:00
|
|
|
currentIPAddr->IpMask.String);
|
|
|
|
nextIPAddr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 13:13:34 +01:00
|
|
|
/* If no IP was found it probably means that the interface is not
|
|
|
|
* configured. In this case we have to return a zeroed IP and mask. */
|
|
|
|
if (firstIPAddr) {
|
|
|
|
strcpy(ptr->IpAddressList.IpAddress.String, "0.0.0.0");
|
|
|
|
strcpy(ptr->IpAddressList.IpMask.String, "0.0.0.0");
|
|
|
|
}
|
2007-10-14 01:21:20 +02:00
|
|
|
/* Find first router through this interface, which we'll assume
|
|
|
|
* is the default gateway for this adapter */
|
2020-07-02 10:23:27 +02:00
|
|
|
strcpy(ptr->GatewayList.IpAddress.String, "0.0.0.0");
|
|
|
|
strcpy(ptr->GatewayList.IpMask.String, "255.255.255.255");
|
2007-10-14 01:21:20 +02:00
|
|
|
for (i = 0; i < routeTable->dwNumEntries; i++)
|
|
|
|
if (routeTable->table[i].dwForwardIfIndex == ptr->Index
|
2011-12-15 10:06:24 +01:00
|
|
|
&& routeTable->table[i].u1.ForwardType ==
|
2007-10-14 01:21:20 +02:00
|
|
|
MIB_IPROUTE_TYPE_INDIRECT)
|
2013-10-07 12:24:17 +02:00
|
|
|
{
|
2007-10-14 01:21:20 +02:00
|
|
|
toIPAddressString(routeTable->table[i].dwForwardNextHop,
|
|
|
|
ptr->GatewayList.IpAddress.String);
|
2013-10-07 12:24:17 +02:00
|
|
|
toIPAddressString(routeTable->table[i].dwForwardMask,
|
|
|
|
ptr->GatewayList.IpMask.String);
|
|
|
|
}
|
2004-01-02 04:55:05 +01:00
|
|
|
if (winsEnabled) {
|
|
|
|
ptr->HaveWins = TRUE;
|
|
|
|
memcpy(ptr->PrimaryWinsServer.IpAddress.String,
|
|
|
|
primaryWINS.String, sizeof(primaryWINS.String));
|
|
|
|
memcpy(ptr->SecondaryWinsServer.IpAddress.String,
|
|
|
|
secondaryWINS.String, sizeof(secondaryWINS.String));
|
|
|
|
}
|
2003-10-31 05:16:54 +01:00
|
|
|
if (ndx < table->numIndexes - 1)
|
|
|
|
ptr->Next = &pAdapterInfo[ndx + 1];
|
|
|
|
else
|
|
|
|
ptr->Next = NULL;
|
2012-09-27 17:14:32 +02:00
|
|
|
|
|
|
|
ptr->DhcpEnabled = TRUE;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
ret = NO_ERROR;
|
|
|
|
}
|
2004-12-13 14:21:39 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = ERROR_OUTOFMEMORY;
|
2007-10-14 01:21:20 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, routeTable);
|
2006-05-10 00:33:53 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, ipAddrTable);
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = ERROR_NO_DATA;
|
|
|
|
}
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-04-29 11:41:02 +02:00
|
|
|
static DWORD typeFromMibType(DWORD mib_type)
|
|
|
|
{
|
|
|
|
switch (mib_type)
|
|
|
|
{
|
|
|
|
case MIB_IF_TYPE_ETHERNET: return IF_TYPE_ETHERNET_CSMACD;
|
|
|
|
case MIB_IF_TYPE_TOKENRING: return IF_TYPE_ISO88025_TOKENRING;
|
|
|
|
case MIB_IF_TYPE_PPP: return IF_TYPE_PPP;
|
|
|
|
case MIB_IF_TYPE_LOOPBACK: return IF_TYPE_SOFTWARE_LOOPBACK;
|
|
|
|
default: return IF_TYPE_OTHER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-15 10:06:24 +01:00
|
|
|
static NET_IF_CONNECTION_TYPE connectionTypeFromMibType(DWORD mib_type)
|
2010-09-16 19:44:04 +02:00
|
|
|
{
|
|
|
|
switch (mib_type)
|
|
|
|
{
|
|
|
|
case MIB_IF_TYPE_PPP: return NET_IF_CONNECTION_DEMAND;
|
|
|
|
case MIB_IF_TYPE_SLIP: return NET_IF_CONNECTION_DEMAND;
|
|
|
|
default: return NET_IF_CONNECTION_DEDICATED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 13:30:00 +02:00
|
|
|
static ULONG v4addressesFromIndex(IF_INDEX index, DWORD **addrs, ULONG *num_addrs, DWORD **masks)
|
2009-04-29 11:41:02 +02:00
|
|
|
{
|
2009-07-07 10:12:56 +02:00
|
|
|
ULONG ret, i, j;
|
2009-04-29 11:41:02 +02:00
|
|
|
MIB_IPADDRTABLE *at;
|
|
|
|
|
|
|
|
*num_addrs = 0;
|
|
|
|
if ((ret = getIPAddrTable(&at, GetProcessHeap(), 0))) return ret;
|
|
|
|
for (i = 0; i < at->dwNumEntries; i++)
|
|
|
|
{
|
|
|
|
if (at->table[i].dwIndex == index) (*num_addrs)++;
|
|
|
|
}
|
|
|
|
if (!(*addrs = HeapAlloc(GetProcessHeap(), 0, *num_addrs * sizeof(DWORD))))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, at);
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2013-10-08 13:30:00 +02:00
|
|
|
if (!(*masks = HeapAlloc(GetProcessHeap(), 0, *num_addrs * sizeof(DWORD))))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, *addrs);
|
|
|
|
HeapFree(GetProcessHeap(), 0, at);
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2009-07-07 10:12:56 +02:00
|
|
|
for (i = 0, j = 0; i < at->dwNumEntries; i++)
|
2009-04-29 11:41:02 +02:00
|
|
|
{
|
2013-10-08 13:30:00 +02:00
|
|
|
if (at->table[i].dwIndex == index)
|
|
|
|
{
|
|
|
|
(*addrs)[j] = at->table[i].dwAddr;
|
|
|
|
(*masks)[j] = at->table[i].dwMask;
|
|
|
|
j++;
|
|
|
|
}
|
2009-04-29 11:41:02 +02:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, at);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-09-16 20:11:06 +02:00
|
|
|
static char *debugstr_ipv4(const in_addr_t *in_addr, char *buf)
|
|
|
|
{
|
|
|
|
const BYTE *addrp;
|
|
|
|
char *p = buf;
|
|
|
|
|
|
|
|
for (addrp = (const BYTE *)in_addr;
|
|
|
|
addrp - (const BYTE *)in_addr < sizeof(*in_addr);
|
|
|
|
addrp++)
|
|
|
|
{
|
|
|
|
if (addrp == (const BYTE *)in_addr + sizeof(*in_addr) - 1)
|
|
|
|
sprintf(p, "%d", *addrp);
|
|
|
|
else
|
2010-10-04 02:31:03 +02:00
|
|
|
p += sprintf(p, "%d.", *addrp);
|
2010-09-16 20:11:06 +02:00
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2010-09-16 19:14:18 +02:00
|
|
|
static ULONG count_v4_gateways(DWORD index, PMIB_IPFORWARDTABLE routeTable)
|
|
|
|
{
|
|
|
|
DWORD i, num_gateways = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < routeTable->dwNumEntries; i++)
|
|
|
|
{
|
|
|
|
if (routeTable->table[i].dwForwardIfIndex == index &&
|
2011-12-15 10:06:24 +01:00
|
|
|
routeTable->table[i].u1.ForwardType == MIB_IPROUTE_TYPE_INDIRECT)
|
2010-09-16 19:14:18 +02:00
|
|
|
num_gateways++;
|
|
|
|
}
|
|
|
|
return num_gateways;
|
|
|
|
}
|
|
|
|
|
2017-02-01 22:58:56 +01:00
|
|
|
static DWORD mask_v4_to_prefix(DWORD m)
|
|
|
|
{
|
|
|
|
#ifdef HAVE___BUILTIN_POPCOUNT
|
|
|
|
return __builtin_popcount(m);
|
|
|
|
#else
|
|
|
|
m -= m >> 1 & 0x55555555;
|
|
|
|
m = (m & 0x33333333) + (m >> 2 & 0x33333333);
|
|
|
|
return ((m + (m >> 4)) & 0x0f0f0f0f) * 0x01010101 >> 24;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD mask_v6_to_prefix(SOCKET_ADDRESS *m)
|
|
|
|
{
|
|
|
|
const IN6_ADDR *mask = &((struct WS_sockaddr_in6 *)m->lpSockaddr)->sin6_addr;
|
|
|
|
DWORD ret = 0, i;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
ret += mask_v4_to_prefix(mask->u.Word[i]);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-16 19:14:18 +02:00
|
|
|
static PMIB_IPFORWARDROW findIPv4Gateway(DWORD index,
|
|
|
|
PMIB_IPFORWARDTABLE routeTable)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
PMIB_IPFORWARDROW row = NULL;
|
|
|
|
|
|
|
|
for (i = 0; !row && i < routeTable->dwNumEntries; i++)
|
|
|
|
{
|
|
|
|
if (routeTable->table[i].dwForwardIfIndex == index &&
|
2011-12-15 10:06:24 +01:00
|
|
|
routeTable->table[i].u1.ForwardType == MIB_IPROUTE_TYPE_INDIRECT)
|
2010-09-16 19:14:18 +02:00
|
|
|
row = &routeTable->table[i];
|
|
|
|
}
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
2015-04-16 06:25:44 +02:00
|
|
|
static void fill_unicast_addr_data(IP_ADAPTER_ADDRESSES *aa, IP_ADAPTER_UNICAST_ADDRESS *ua)
|
|
|
|
{
|
|
|
|
/* Actually this information should be read somewhere from the system
|
|
|
|
* but it doesn't matter much for the bugs found so far.
|
|
|
|
* This information is required for DirectPlay8 games. */
|
|
|
|
if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK)
|
|
|
|
{
|
|
|
|
ua->PrefixOrigin = IpPrefixOriginDhcp;
|
|
|
|
ua->SuffixOrigin = IpSuffixOriginDhcp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ua->PrefixOrigin = IpPrefixOriginManual;
|
|
|
|
ua->SuffixOrigin = IpSuffixOriginManual;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The address is not duplicated in the network */
|
|
|
|
ua->DadState = IpDadStatePreferred;
|
|
|
|
|
|
|
|
/* Some address life time values, required even for non-dhcp addresses */
|
|
|
|
ua->ValidLifetime = 60000;
|
|
|
|
ua->PreferredLifetime = 60000;
|
|
|
|
ua->LeaseLifetime = 60000;
|
|
|
|
}
|
|
|
|
|
2011-12-15 10:06:24 +01:00
|
|
|
static ULONG adapterAddressesFromIndex(ULONG family, ULONG flags, IF_INDEX index,
|
2010-10-11 22:17:45 +02:00
|
|
|
IP_ADAPTER_ADDRESSES *aa, ULONG *size)
|
2009-04-29 11:41:02 +02:00
|
|
|
{
|
2013-10-08 13:30:00 +02:00
|
|
|
ULONG ret = ERROR_SUCCESS, i, j, num_v4addrs = 0, num_v4_gateways = 0, num_v6addrs = 0, total_size;
|
|
|
|
DWORD *v4addrs = NULL, *v4masks = NULL;
|
|
|
|
SOCKET_ADDRESS *v6addrs = NULL, *v6masks = NULL;
|
2010-09-16 19:14:18 +02:00
|
|
|
PMIB_IPFORWARDTABLE routeTable = NULL;
|
2009-04-29 11:41:02 +02:00
|
|
|
|
2010-10-11 10:56:07 +02:00
|
|
|
if (family == WS_AF_INET)
|
2010-09-16 19:14:18 +02:00
|
|
|
{
|
2013-10-08 13:30:00 +02:00
|
|
|
ret = v4addressesFromIndex(index, &v4addrs, &num_v4addrs, &v4masks);
|
|
|
|
|
2010-10-11 22:17:45 +02:00
|
|
|
if (!ret && flags & GAA_FLAG_INCLUDE_ALL_GATEWAYS)
|
2010-09-16 19:14:18 +02:00
|
|
|
{
|
2013-10-08 13:30:00 +02:00
|
|
|
ret = AllocateAndGetIpForwardTableFromStack(&routeTable, FALSE, GetProcessHeap(), 0);
|
|
|
|
if (!ret) num_v4_gateways = count_v4_gateways(index, routeTable);
|
2010-09-16 19:14:18 +02:00
|
|
|
}
|
|
|
|
}
|
2010-10-11 10:56:07 +02:00
|
|
|
else if (family == WS_AF_INET6)
|
2010-10-11 22:19:34 +02:00
|
|
|
{
|
2013-10-08 13:30:00 +02:00
|
|
|
ret = v6addressesFromIndex(index, &v6addrs, &num_v6addrs, &v6masks);
|
2010-10-11 22:19:34 +02:00
|
|
|
}
|
2010-10-11 10:56:07 +02:00
|
|
|
else if (family == WS_AF_UNSPEC)
|
2010-03-12 02:15:03 +01:00
|
|
|
{
|
2013-10-08 13:30:00 +02:00
|
|
|
ret = v4addressesFromIndex(index, &v4addrs, &num_v4addrs, &v4masks);
|
|
|
|
|
2010-10-11 22:17:45 +02:00
|
|
|
if (!ret && flags & GAA_FLAG_INCLUDE_ALL_GATEWAYS)
|
2010-09-16 19:14:18 +02:00
|
|
|
{
|
2013-10-08 13:30:00 +02:00
|
|
|
ret = AllocateAndGetIpForwardTableFromStack(&routeTable, FALSE, GetProcessHeap(), 0);
|
|
|
|
if (!ret) num_v4_gateways = count_v4_gateways(index, routeTable);
|
2010-09-16 19:14:18 +02:00
|
|
|
}
|
2013-10-08 13:30:00 +02:00
|
|
|
if (!ret) ret = v6addressesFromIndex(index, &v6addrs, &num_v6addrs, &v6masks);
|
2010-03-12 02:15:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-12 03:36:46 +01:00
|
|
|
FIXME("address family %u unsupported\n", family);
|
2010-03-12 02:15:03 +01:00
|
|
|
ret = ERROR_NO_DATA;
|
|
|
|
}
|
2010-09-16 19:14:18 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
2012-11-07 10:36:46 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, v4addrs);
|
2013-10-08 13:30:00 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, v4masks);
|
|
|
|
HeapFree(GetProcessHeap(), 0, v6addrs);
|
|
|
|
HeapFree(GetProcessHeap(), 0, v6masks);
|
2010-09-16 19:14:18 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, routeTable);
|
|
|
|
return ret;
|
|
|
|
}
|
2009-04-29 11:41:02 +02:00
|
|
|
|
|
|
|
total_size = sizeof(IP_ADAPTER_ADDRESSES);
|
2017-05-11 10:15:26 +02:00
|
|
|
total_size += 39; /* "{00000000-0000-0000-0000-000000000000}" */
|
2010-10-11 17:50:00 +02:00
|
|
|
total_size += IF_NAMESIZE * sizeof(WCHAR);
|
|
|
|
if (!(flags & GAA_FLAG_SKIP_FRIENDLY_NAME))
|
|
|
|
total_size += IF_NAMESIZE * sizeof(WCHAR);
|
2013-10-08 13:30:00 +02:00
|
|
|
if (flags & GAA_FLAG_INCLUDE_PREFIX)
|
|
|
|
{
|
|
|
|
total_size += sizeof(IP_ADAPTER_PREFIX) * num_v4addrs;
|
|
|
|
total_size += sizeof(IP_ADAPTER_PREFIX) * num_v6addrs;
|
|
|
|
total_size += sizeof(struct sockaddr_in) * num_v4addrs;
|
|
|
|
for (i = 0; i < num_v6addrs; i++)
|
|
|
|
total_size += v6masks[i].iSockaddrLength;
|
|
|
|
}
|
2010-03-12 02:07:37 +01:00
|
|
|
total_size += sizeof(IP_ADAPTER_UNICAST_ADDRESS) * num_v4addrs;
|
|
|
|
total_size += sizeof(struct sockaddr_in) * num_v4addrs;
|
2010-09-16 19:14:18 +02:00
|
|
|
total_size += (sizeof(IP_ADAPTER_GATEWAY_ADDRESS) + sizeof(SOCKADDR_IN)) * num_v4_gateways;
|
2010-03-12 03:36:46 +01:00
|
|
|
total_size += sizeof(IP_ADAPTER_UNICAST_ADDRESS) * num_v6addrs;
|
|
|
|
total_size += sizeof(SOCKET_ADDRESS) * num_v6addrs;
|
|
|
|
for (i = 0; i < num_v6addrs; i++)
|
|
|
|
total_size += v6addrs[i].iSockaddrLength;
|
2009-04-29 11:41:02 +02:00
|
|
|
|
|
|
|
if (aa && *size >= total_size)
|
|
|
|
{
|
2009-08-12 00:49:50 +02:00
|
|
|
char name[IF_NAMESIZE], *ptr = (char *)aa + sizeof(IP_ADAPTER_ADDRESSES), *src;
|
|
|
|
WCHAR *dst;
|
2011-12-13 21:10:40 +01:00
|
|
|
DWORD buflen, type;
|
|
|
|
INTERNAL_IF_OPER_STATUS status;
|
2020-09-01 13:41:14 +02:00
|
|
|
NET_LUID luid;
|
|
|
|
GUID guid;
|
2009-04-29 11:41:02 +02:00
|
|
|
|
|
|
|
memset(aa, 0, sizeof(IP_ADAPTER_ADDRESSES));
|
2009-08-31 11:53:04 +02:00
|
|
|
aa->u.s.Length = sizeof(IP_ADAPTER_ADDRESSES);
|
|
|
|
aa->u.s.IfIndex = index;
|
2009-04-29 11:41:02 +02:00
|
|
|
|
2020-09-01 13:41:14 +02:00
|
|
|
ConvertInterfaceIndexToLuid(index, &luid);
|
|
|
|
ConvertInterfaceLuidToGuid(&luid, &guid);
|
|
|
|
sprintf(ptr, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
|
|
|
|
guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1],
|
|
|
|
guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5],
|
|
|
|
guid.Data4[6], guid.Data4[7]);
|
2009-04-29 11:41:02 +02:00
|
|
|
aa->AdapterName = ptr;
|
2017-05-11 10:15:26 +02:00
|
|
|
ptr += 39;
|
|
|
|
|
|
|
|
getInterfaceNameByIndex(index, name);
|
2010-10-11 17:50:00 +02:00
|
|
|
if (!(flags & GAA_FLAG_SKIP_FRIENDLY_NAME))
|
|
|
|
{
|
|
|
|
aa->FriendlyName = (WCHAR *)ptr;
|
|
|
|
for (src = name, dst = (WCHAR *)ptr; *src; src++, dst++)
|
|
|
|
*dst = *src;
|
|
|
|
*dst++ = 0;
|
|
|
|
ptr = (char *)dst;
|
|
|
|
}
|
2010-09-20 18:47:25 +02:00
|
|
|
aa->Description = (WCHAR *)ptr;
|
|
|
|
for (src = name, dst = (WCHAR *)ptr; *src; src++, dst++)
|
2009-08-12 00:49:50 +02:00
|
|
|
*dst = *src;
|
|
|
|
*dst++ = 0;
|
|
|
|
ptr = (char *)dst;
|
2009-04-29 11:41:02 +02:00
|
|
|
|
2010-09-16 20:11:06 +02:00
|
|
|
TRACE("%s: %d IPv4 addresses, %d IPv6 addresses:\n", name, num_v4addrs,
|
|
|
|
num_v6addrs);
|
2015-04-16 06:25:44 +02:00
|
|
|
|
|
|
|
buflen = MAX_INTERFACE_PHYSADDR;
|
|
|
|
getInterfacePhysicalByIndex(index, &buflen, aa->PhysicalAddress, &type);
|
|
|
|
aa->PhysicalAddressLength = buflen;
|
|
|
|
aa->IfType = typeFromMibType(type);
|
|
|
|
aa->ConnectionType = connectionTypeFromMibType(type);
|
2015-08-14 14:58:41 +02:00
|
|
|
aa->Luid.Info.NetLuidIndex = index;
|
|
|
|
aa->Luid.Info.IfType = aa->IfType;
|
2015-04-16 06:25:44 +02:00
|
|
|
|
2010-09-16 19:14:18 +02:00
|
|
|
if (num_v4_gateways)
|
|
|
|
{
|
|
|
|
PMIB_IPFORWARDROW adapterRow;
|
|
|
|
|
|
|
|
if ((adapterRow = findIPv4Gateway(index, routeTable)))
|
|
|
|
{
|
|
|
|
PIP_ADAPTER_GATEWAY_ADDRESS gw;
|
|
|
|
PSOCKADDR_IN sin;
|
|
|
|
|
2010-09-27 11:30:38 +02:00
|
|
|
gw = (PIP_ADAPTER_GATEWAY_ADDRESS)ptr;
|
|
|
|
aa->FirstGatewayAddress = gw;
|
|
|
|
|
2010-09-16 19:14:18 +02:00
|
|
|
gw->u.s.Length = sizeof(IP_ADAPTER_GATEWAY_ADDRESS);
|
|
|
|
ptr += sizeof(IP_ADAPTER_GATEWAY_ADDRESS);
|
|
|
|
sin = (PSOCKADDR_IN)ptr;
|
2015-08-18 09:40:58 +02:00
|
|
|
sin->sin_family = WS_AF_INET;
|
2010-09-16 19:14:18 +02:00
|
|
|
sin->sin_port = 0;
|
|
|
|
memcpy(&sin->sin_addr, &adapterRow->dwForwardNextHop,
|
|
|
|
sizeof(DWORD));
|
|
|
|
gw->Address.lpSockaddr = (LPSOCKADDR)sin;
|
|
|
|
gw->Address.iSockaddrLength = sizeof(SOCKADDR_IN);
|
2010-09-27 11:30:38 +02:00
|
|
|
gw->Next = NULL;
|
2010-09-16 19:14:18 +02:00
|
|
|
ptr += sizeof(SOCKADDR_IN);
|
|
|
|
}
|
|
|
|
}
|
2013-10-08 13:30:00 +02:00
|
|
|
if (num_v4addrs && !(flags & GAA_FLAG_SKIP_UNICAST))
|
2009-04-29 11:41:02 +02:00
|
|
|
{
|
|
|
|
IP_ADAPTER_UNICAST_ADDRESS *ua;
|
2013-03-09 12:04:17 +01:00
|
|
|
struct WS_sockaddr_in *sa;
|
2017-03-13 19:39:50 +01:00
|
|
|
aa->u1.s1.Ipv4Enabled = TRUE;
|
2009-04-29 11:41:02 +02:00
|
|
|
ua = aa->FirstUnicastAddress = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
|
2010-03-12 02:07:37 +01:00
|
|
|
for (i = 0; i < num_v4addrs; i++)
|
2009-04-29 11:41:02 +02:00
|
|
|
{
|
2010-09-16 20:11:06 +02:00
|
|
|
char addr_buf[16];
|
|
|
|
|
2009-04-29 11:41:02 +02:00
|
|
|
memset(ua, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS));
|
2009-08-31 11:53:04 +02:00
|
|
|
ua->u.s.Length = sizeof(IP_ADAPTER_UNICAST_ADDRESS);
|
2009-04-29 11:41:02 +02:00
|
|
|
ua->Address.iSockaddrLength = sizeof(struct sockaddr_in);
|
2009-08-31 11:53:04 +02:00
|
|
|
ua->Address.lpSockaddr = (SOCKADDR *)((char *)ua + ua->u.s.Length);
|
2009-04-29 11:41:02 +02:00
|
|
|
|
2013-03-09 12:04:17 +01:00
|
|
|
sa = (struct WS_sockaddr_in *)ua->Address.lpSockaddr;
|
|
|
|
sa->sin_family = WS_AF_INET;
|
|
|
|
sa->sin_addr.S_un.S_addr = v4addrs[i];
|
|
|
|
sa->sin_port = 0;
|
2010-09-16 20:11:06 +02:00
|
|
|
TRACE("IPv4 %d/%d: %s\n", i + 1, num_v4addrs,
|
2013-03-09 12:04:17 +01:00
|
|
|
debugstr_ipv4(&sa->sin_addr.S_un.S_addr, addr_buf));
|
2015-04-16 06:25:44 +02:00
|
|
|
fill_unicast_addr_data(aa, ua);
|
2009-04-29 11:41:02 +02:00
|
|
|
|
2017-02-01 22:58:56 +01:00
|
|
|
ua->OnLinkPrefixLength = mask_v4_to_prefix(v4masks[i]);
|
|
|
|
|
2009-08-31 11:53:04 +02:00
|
|
|
ptr += ua->u.s.Length + ua->Address.iSockaddrLength;
|
2010-03-12 02:07:37 +01:00
|
|
|
if (i < num_v4addrs - 1)
|
2009-04-29 11:41:02 +02:00
|
|
|
{
|
|
|
|
ua->Next = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
|
|
|
|
ua = ua->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-08 13:30:00 +02:00
|
|
|
if (num_v6addrs && !(flags & GAA_FLAG_SKIP_UNICAST))
|
2010-03-12 03:36:46 +01:00
|
|
|
{
|
|
|
|
IP_ADAPTER_UNICAST_ADDRESS *ua;
|
|
|
|
struct WS_sockaddr_in6 *sa;
|
|
|
|
|
2017-03-13 19:39:50 +01:00
|
|
|
aa->u1.s1.Ipv6Enabled = TRUE;
|
2010-03-12 03:36:46 +01:00
|
|
|
if (aa->FirstUnicastAddress)
|
|
|
|
{
|
|
|
|
for (ua = aa->FirstUnicastAddress; ua->Next; ua = ua->Next)
|
|
|
|
;
|
|
|
|
ua->Next = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
|
2010-08-17 20:01:03 +02:00
|
|
|
ua = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
|
2010-03-12 03:36:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ua = aa->FirstUnicastAddress = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
|
|
|
|
for (i = 0; i < num_v6addrs; i++)
|
|
|
|
{
|
2010-09-16 20:11:06 +02:00
|
|
|
char addr_buf[46];
|
|
|
|
|
2010-03-12 03:36:46 +01:00
|
|
|
memset(ua, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS));
|
|
|
|
ua->u.s.Length = sizeof(IP_ADAPTER_UNICAST_ADDRESS);
|
|
|
|
ua->Address.iSockaddrLength = v6addrs[i].iSockaddrLength;
|
|
|
|
ua->Address.lpSockaddr = (SOCKADDR *)((char *)ua + ua->u.s.Length);
|
|
|
|
|
|
|
|
sa = (struct WS_sockaddr_in6 *)ua->Address.lpSockaddr;
|
|
|
|
memcpy(sa, v6addrs[i].lpSockaddr, sizeof(*sa));
|
2010-09-16 20:11:06 +02:00
|
|
|
TRACE("IPv6 %d/%d: %s\n", i + 1, num_v6addrs,
|
|
|
|
debugstr_ipv6(sa, addr_buf));
|
2015-04-16 06:25:44 +02:00
|
|
|
fill_unicast_addr_data(aa, ua);
|
2010-03-12 03:36:46 +01:00
|
|
|
|
2017-02-01 22:58:56 +01:00
|
|
|
ua->OnLinkPrefixLength = mask_v6_to_prefix(&v6masks[i]);
|
|
|
|
|
2010-03-12 03:36:46 +01:00
|
|
|
ptr += ua->u.s.Length + ua->Address.iSockaddrLength;
|
|
|
|
if (i < num_v6addrs - 1)
|
|
|
|
{
|
|
|
|
ua->Next = (IP_ADAPTER_UNICAST_ADDRESS *)ptr;
|
|
|
|
ua = ua->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-08 13:30:00 +02:00
|
|
|
if (num_v4addrs && (flags & GAA_FLAG_INCLUDE_PREFIX))
|
|
|
|
{
|
|
|
|
IP_ADAPTER_PREFIX *prefix;
|
|
|
|
|
|
|
|
prefix = aa->FirstPrefix = (IP_ADAPTER_PREFIX *)ptr;
|
|
|
|
for (i = 0; i < num_v4addrs; i++)
|
|
|
|
{
|
|
|
|
char addr_buf[16];
|
|
|
|
struct WS_sockaddr_in *sa;
|
|
|
|
|
|
|
|
prefix->u.s.Length = sizeof(*prefix);
|
|
|
|
prefix->u.s.Flags = 0;
|
|
|
|
prefix->Next = NULL;
|
|
|
|
prefix->Address.iSockaddrLength = sizeof(struct sockaddr_in);
|
|
|
|
prefix->Address.lpSockaddr = (SOCKADDR *)((char *)prefix + prefix->u.s.Length);
|
|
|
|
|
|
|
|
sa = (struct WS_sockaddr_in *)prefix->Address.lpSockaddr;
|
|
|
|
sa->sin_family = WS_AF_INET;
|
|
|
|
sa->sin_addr.S_un.S_addr = v4addrs[i] & v4masks[i];
|
|
|
|
sa->sin_port = 0;
|
|
|
|
|
2017-02-01 22:58:56 +01:00
|
|
|
prefix->PrefixLength = mask_v4_to_prefix(v4masks[i]);
|
|
|
|
|
2013-10-08 13:30:00 +02:00
|
|
|
TRACE("IPv4 network: %s/%u\n",
|
|
|
|
debugstr_ipv4((const in_addr_t *)&sa->sin_addr.S_un.S_addr, addr_buf),
|
|
|
|
prefix->PrefixLength);
|
|
|
|
|
|
|
|
ptr += prefix->u.s.Length + prefix->Address.iSockaddrLength;
|
|
|
|
if (i < num_v4addrs - 1)
|
|
|
|
{
|
|
|
|
prefix->Next = (IP_ADAPTER_PREFIX *)ptr;
|
|
|
|
prefix = prefix->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num_v6addrs && (flags & GAA_FLAG_INCLUDE_PREFIX))
|
|
|
|
{
|
|
|
|
IP_ADAPTER_PREFIX *prefix;
|
|
|
|
|
|
|
|
if (aa->FirstPrefix)
|
|
|
|
{
|
|
|
|
for (prefix = aa->FirstPrefix; prefix->Next; prefix = prefix->Next)
|
|
|
|
;
|
|
|
|
prefix->Next = (IP_ADAPTER_PREFIX *)ptr;
|
|
|
|
prefix = (IP_ADAPTER_PREFIX *)ptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
prefix = aa->FirstPrefix = (IP_ADAPTER_PREFIX *)ptr;
|
|
|
|
for (i = 0; i < num_v6addrs; i++)
|
|
|
|
{
|
|
|
|
char addr_buf[46];
|
|
|
|
struct WS_sockaddr_in6 *sa;
|
|
|
|
const IN6_ADDR *addr, *mask;
|
|
|
|
|
|
|
|
prefix->u.s.Length = sizeof(*prefix);
|
|
|
|
prefix->u.s.Flags = 0;
|
|
|
|
prefix->Next = NULL;
|
|
|
|
prefix->Address.iSockaddrLength = sizeof(struct sockaddr_in6);
|
|
|
|
prefix->Address.lpSockaddr = (SOCKADDR *)((char *)prefix + prefix->u.s.Length);
|
|
|
|
|
|
|
|
sa = (struct WS_sockaddr_in6 *)prefix->Address.lpSockaddr;
|
|
|
|
sa->sin6_family = WS_AF_INET6;
|
|
|
|
sa->sin6_port = 0;
|
|
|
|
sa->sin6_flowinfo = 0;
|
|
|
|
addr = &((struct WS_sockaddr_in6 *)v6addrs[i].lpSockaddr)->sin6_addr;
|
|
|
|
mask = &((struct WS_sockaddr_in6 *)v6masks[i].lpSockaddr)->sin6_addr;
|
|
|
|
for (j = 0; j < 8; j++) sa->sin6_addr.u.Word[j] = addr->u.Word[j] & mask->u.Word[j];
|
|
|
|
sa->sin6_scope_id = 0;
|
|
|
|
|
2017-02-01 22:58:56 +01:00
|
|
|
prefix->PrefixLength = mask_v6_to_prefix(&v6masks[i]);
|
|
|
|
|
2013-10-08 13:30:00 +02:00
|
|
|
TRACE("IPv6 network: %s/%u\n", debugstr_ipv6(sa, addr_buf), prefix->PrefixLength);
|
|
|
|
|
|
|
|
ptr += prefix->u.s.Length + prefix->Address.iSockaddrLength;
|
|
|
|
if (i < num_v6addrs - 1)
|
|
|
|
{
|
|
|
|
prefix->Next = (IP_ADAPTER_PREFIX *)ptr;
|
|
|
|
prefix = prefix->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-29 11:41:02 +02:00
|
|
|
|
|
|
|
getInterfaceMtuByName(name, &aa->Mtu);
|
|
|
|
|
|
|
|
getInterfaceStatusByName(name, &status);
|
|
|
|
if (status == MIB_IF_OPER_STATUS_OPERATIONAL) aa->OperStatus = IfOperStatusUp;
|
|
|
|
else if (status == MIB_IF_OPER_STATUS_NON_OPERATIONAL) aa->OperStatus = IfOperStatusDown;
|
|
|
|
else aa->OperStatus = IfOperStatusUnknown;
|
|
|
|
}
|
|
|
|
*size = total_size;
|
2010-09-16 19:14:18 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, routeTable);
|
2010-03-12 03:36:46 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, v6addrs);
|
2013-10-08 13:30:00 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, v6masks);
|
2010-03-12 02:07:37 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, v4addrs);
|
2013-10-08 13:30:00 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, v4masks);
|
2009-04-29 11:41:02 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-09-18 12:49:16 +02:00
|
|
|
static void sockaddr_in_to_WS_storage( SOCKADDR_STORAGE *dst, const struct sockaddr_in *src )
|
|
|
|
{
|
|
|
|
SOCKADDR_IN *s = (SOCKADDR_IN *)dst;
|
|
|
|
|
|
|
|
s->sin_family = WS_AF_INET;
|
|
|
|
s->sin_port = src->sin_port;
|
|
|
|
memcpy( &s->sin_addr, &src->sin_addr, sizeof(IN_ADDR) );
|
|
|
|
memset( (char *)s + FIELD_OFFSET( SOCKADDR_IN, sin_zero ), 0,
|
|
|
|
sizeof(SOCKADDR_STORAGE) - FIELD_OFFSET( SOCKADDR_IN, sin_zero) );
|
|
|
|
}
|
|
|
|
|
2020-04-03 18:24:11 +02:00
|
|
|
#if defined(HAVE_STRUCT___RES_STATE__U__EXT_NSCOUNT6) || \
|
2020-04-06 00:29:00 +02:00
|
|
|
(defined(HAVE___RES_GET_STATE) && defined(HAVE___RES_GETSERVERS)) || \
|
|
|
|
defined(HAVE_RES_GETSERVERS)
|
2013-09-18 12:49:16 +02:00
|
|
|
static void sockaddr_in6_to_WS_storage( SOCKADDR_STORAGE *dst, const struct sockaddr_in6 *src )
|
|
|
|
{
|
|
|
|
SOCKADDR_IN6 *s = (SOCKADDR_IN6 *)dst;
|
|
|
|
|
|
|
|
s->sin6_family = WS_AF_INET6;
|
|
|
|
s->sin6_port = src->sin6_port;
|
|
|
|
s->sin6_flowinfo = src->sin6_flowinfo;
|
|
|
|
memcpy( &s->sin6_addr, &src->sin6_addr, sizeof(IN6_ADDR) );
|
|
|
|
s->sin6_scope_id = src->sin6_scope_id;
|
|
|
|
memset( (char *)s + sizeof(SOCKADDR_IN6), 0,
|
|
|
|
sizeof(SOCKADDR_STORAGE) - sizeof(SOCKADDR_IN6) );
|
|
|
|
}
|
2020-04-03 18:24:11 +02:00
|
|
|
#endif
|
2013-09-18 12:49:16 +02:00
|
|
|
|
2013-09-17 14:09:15 +02:00
|
|
|
#ifdef HAVE_STRUCT___RES_STATE
|
|
|
|
/* call res_init() just once because of a bug in Mac OS X 10.4 */
|
|
|
|
/* Call once per thread on systems that have per-thread _res. */
|
2014-07-01 17:00:36 +02:00
|
|
|
|
|
|
|
static CRITICAL_SECTION res_init_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG res_init_cs_debug = {
|
|
|
|
0, 0, &res_init_cs,
|
|
|
|
{ &res_init_cs_debug.ProcessLocksList, &res_init_cs_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": res_init_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION res_init_cs = { &res_init_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2013-09-17 14:09:15 +02:00
|
|
|
static void initialise_resolver(void)
|
|
|
|
{
|
2014-07-01 17:00:36 +02:00
|
|
|
EnterCriticalSection(&res_init_cs);
|
2013-09-17 14:09:15 +02:00
|
|
|
if ((_res.options & RES_INIT) == 0)
|
|
|
|
res_init();
|
2014-07-01 17:00:36 +02:00
|
|
|
LeaveCriticalSection(&res_init_cs);
|
2013-09-17 14:09:15 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 00:29:00 +02:00
|
|
|
#ifdef HAVE_RES_GETSERVERS
|
|
|
|
static int get_dns_servers( SOCKADDR_STORAGE *servers, int num, BOOL ip4_only )
|
|
|
|
{
|
|
|
|
struct __res_state *state = &_res;
|
|
|
|
int i, found = 0, total;
|
|
|
|
SOCKADDR_STORAGE *addr = servers;
|
|
|
|
union res_sockaddr_union *buf;
|
|
|
|
|
|
|
|
initialise_resolver();
|
|
|
|
|
|
|
|
total = res_getservers( state, NULL, 0 );
|
|
|
|
|
|
|
|
if ((!servers || !num) && !ip4_only) return total;
|
|
|
|
|
|
|
|
buf = HeapAlloc( GetProcessHeap(), 0, total * sizeof(union res_sockaddr_union) );
|
|
|
|
total = res_getservers( state, buf, total );
|
|
|
|
|
|
|
|
for (i = 0; i < total; i++)
|
|
|
|
{
|
|
|
|
if (buf[i].sin6.sin6_family == AF_INET6 && ip4_only) continue;
|
|
|
|
if (buf[i].sin.sin_family != AF_INET && buf[i].sin6.sin6_family != AF_INET6) continue;
|
|
|
|
|
|
|
|
found++;
|
|
|
|
if (!servers || !num) continue;
|
|
|
|
|
|
|
|
if (buf[i].sin6.sin6_family == AF_INET6)
|
|
|
|
{
|
|
|
|
sockaddr_in6_to_WS_storage( addr, &buf[i].sin6 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sockaddr_in_to_WS_storage( addr, &buf[i].sin );
|
|
|
|
}
|
|
|
|
if (++addr >= servers + num) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, buf );
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
2013-09-13 13:52:54 +02:00
|
|
|
static int get_dns_servers( SOCKADDR_STORAGE *servers, int num, BOOL ip4_only )
|
2013-09-13 13:52:53 +02:00
|
|
|
{
|
2013-09-13 13:52:54 +02:00
|
|
|
int i, ip6_count = 0;
|
2013-09-13 13:52:53 +02:00
|
|
|
SOCKADDR_STORAGE *addr;
|
|
|
|
|
|
|
|
initialise_resolver();
|
|
|
|
|
2013-09-13 13:52:54 +02:00
|
|
|
#ifdef HAVE_STRUCT___RES_STATE__U__EXT_NSCOUNT6
|
|
|
|
ip6_count = _res._u._ext.nscount6;
|
|
|
|
#endif
|
|
|
|
|
2013-09-13 13:52:53 +02:00
|
|
|
if (!servers || !num)
|
|
|
|
{
|
|
|
|
num = _res.nscount;
|
2013-09-13 13:52:54 +02:00
|
|
|
if (ip4_only) num -= ip6_count;
|
2013-09-13 13:52:53 +02:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, addr = servers; addr < (servers + num) && i < _res.nscount; i++)
|
|
|
|
{
|
2013-09-13 13:52:54 +02:00
|
|
|
#ifdef HAVE_STRUCT___RES_STATE__U__EXT_NSCOUNT6
|
2018-02-20 07:40:21 +01:00
|
|
|
if (_res._u._ext.nsaddrs[i] && _res._u._ext.nsaddrs[i]->sin6_family == AF_INET6)
|
2013-09-13 13:52:54 +02:00
|
|
|
{
|
|
|
|
if (ip4_only) continue;
|
2013-09-18 12:49:16 +02:00
|
|
|
sockaddr_in6_to_WS_storage( addr, _res._u._ext.nsaddrs[i] );
|
2013-09-13 13:52:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2013-09-18 12:49:16 +02:00
|
|
|
sockaddr_in_to_WS_storage( addr, _res.nsaddr_list + i );
|
2013-09-13 13:52:54 +02:00
|
|
|
}
|
2013-09-13 13:52:53 +02:00
|
|
|
addr++;
|
|
|
|
}
|
|
|
|
return addr - servers;
|
|
|
|
}
|
2020-04-06 00:29:00 +02:00
|
|
|
#endif
|
2013-09-17 14:09:16 +02:00
|
|
|
#elif defined(HAVE___RES_GET_STATE) && defined(HAVE___RES_GETSERVERS)
|
|
|
|
|
|
|
|
static int get_dns_servers( SOCKADDR_STORAGE *servers, int num, BOOL ip4_only )
|
|
|
|
{
|
|
|
|
extern struct res_state *__res_get_state( void );
|
|
|
|
extern int __res_getservers( struct res_state *, struct sockaddr_storage *, int );
|
|
|
|
struct res_state *state = __res_get_state();
|
|
|
|
int i, found = 0, total = __res_getservers( state, NULL, 0 );
|
|
|
|
SOCKADDR_STORAGE *addr = servers;
|
|
|
|
struct sockaddr_storage *buf;
|
|
|
|
|
|
|
|
if ((!servers || !num) && !ip4_only) return total;
|
|
|
|
|
|
|
|
buf = HeapAlloc( GetProcessHeap(), 0, total * sizeof(struct sockaddr_storage) );
|
|
|
|
total = __res_getservers( state, buf, total );
|
|
|
|
|
|
|
|
for (i = 0; i < total; i++)
|
|
|
|
{
|
|
|
|
if (buf[i].ss_family == AF_INET6 && ip4_only) continue;
|
|
|
|
if (buf[i].ss_family != AF_INET && buf[i].ss_family != AF_INET6) continue;
|
|
|
|
|
|
|
|
found++;
|
|
|
|
if (!servers || !num) continue;
|
|
|
|
|
|
|
|
if (buf[i].ss_family == AF_INET6)
|
|
|
|
{
|
2013-09-18 12:49:16 +02:00
|
|
|
sockaddr_in6_to_WS_storage( addr, (struct sockaddr_in6 *)(buf + i) );
|
2013-09-17 14:09:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-18 12:49:16 +02:00
|
|
|
sockaddr_in_to_WS_storage( addr, (struct sockaddr_in *)(buf + i) );
|
2013-09-17 14:09:16 +02:00
|
|
|
}
|
|
|
|
if (++addr >= servers + num) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, buf );
|
|
|
|
return found;
|
|
|
|
}
|
2013-09-17 14:09:15 +02:00
|
|
|
#else
|
2013-09-17 14:09:16 +02:00
|
|
|
|
2013-09-17 14:09:15 +02:00
|
|
|
static int get_dns_servers( SOCKADDR_STORAGE *servers, int num, BOOL ip4_only )
|
|
|
|
{
|
|
|
|
FIXME("Unimplemented on this system\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2013-09-13 13:52:53 +02:00
|
|
|
|
2010-10-11 18:05:06 +02:00
|
|
|
static ULONG get_dns_server_addresses(PIP_ADAPTER_DNS_SERVER_ADDRESS address, ULONG *len)
|
|
|
|
{
|
2013-09-13 13:52:54 +02:00
|
|
|
int num = get_dns_servers( NULL, 0, FALSE );
|
2010-10-11 18:05:06 +02:00
|
|
|
DWORD size;
|
|
|
|
|
2013-09-13 13:52:53 +02:00
|
|
|
size = num * (sizeof(IP_ADAPTER_DNS_SERVER_ADDRESS) + sizeof(SOCKADDR_STORAGE));
|
2010-10-11 18:05:06 +02:00
|
|
|
if (!address || *len < size)
|
|
|
|
{
|
|
|
|
*len = size;
|
|
|
|
return ERROR_BUFFER_OVERFLOW;
|
|
|
|
}
|
|
|
|
*len = size;
|
2013-09-13 13:52:53 +02:00
|
|
|
if (num > 0)
|
2010-10-11 18:05:06 +02:00
|
|
|
{
|
2013-09-13 13:52:53 +02:00
|
|
|
PIP_ADAPTER_DNS_SERVER_ADDRESS addr = address;
|
|
|
|
SOCKADDR_STORAGE *sock_addrs = (SOCKADDR_STORAGE *)(address + num);
|
2010-10-11 18:05:06 +02:00
|
|
|
int i;
|
|
|
|
|
2013-09-13 13:52:54 +02:00
|
|
|
get_dns_servers( sock_addrs, num, FALSE );
|
2013-09-13 13:52:53 +02:00
|
|
|
|
|
|
|
for (i = 0; i < num; i++, addr = addr->Next)
|
2010-10-11 18:05:06 +02:00
|
|
|
{
|
2013-09-13 13:52:53 +02:00
|
|
|
addr->u.s.Length = sizeof(*addr);
|
2013-09-13 13:52:54 +02:00
|
|
|
if (sock_addrs[i].ss_family == WS_AF_INET6)
|
|
|
|
addr->Address.iSockaddrLength = sizeof(SOCKADDR_IN6);
|
|
|
|
else
|
|
|
|
addr->Address.iSockaddrLength = sizeof(SOCKADDR_IN);
|
2013-09-13 13:52:53 +02:00
|
|
|
addr->Address.lpSockaddr = (SOCKADDR *)(sock_addrs + i);
|
|
|
|
if (i == num - 1)
|
2010-10-11 18:05:06 +02:00
|
|
|
addr->Next = NULL;
|
|
|
|
else
|
2013-09-13 13:52:53 +02:00
|
|
|
addr->Next = addr + 1;
|
2010-10-11 18:05:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-09-17 14:09:15 +02:00
|
|
|
#ifdef HAVE_STRUCT___RES_STATE
|
2010-10-11 20:02:23 +02:00
|
|
|
static BOOL is_ip_address_string(const char *str)
|
|
|
|
{
|
|
|
|
struct in_addr in;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = inet_aton(str, &in);
|
|
|
|
return ret != 0;
|
|
|
|
}
|
2013-09-17 14:09:15 +02:00
|
|
|
#endif
|
2010-10-11 20:02:23 +02:00
|
|
|
|
|
|
|
static ULONG get_dns_suffix(WCHAR *suffix, ULONG *len)
|
|
|
|
{
|
2013-09-17 14:09:15 +02:00
|
|
|
ULONG size;
|
2013-09-16 14:50:38 +02:00
|
|
|
const char *found_suffix = "";
|
|
|
|
/* Always return a NULL-terminated string, even if it's empty. */
|
2010-10-11 20:02:23 +02:00
|
|
|
|
2013-09-17 14:09:15 +02:00
|
|
|
#ifdef HAVE_STRUCT___RES_STATE
|
2010-10-11 20:02:23 +02:00
|
|
|
{
|
2013-09-17 14:09:15 +02:00
|
|
|
ULONG i;
|
|
|
|
initialise_resolver();
|
|
|
|
for (i = 0; !*found_suffix && i < MAXDNSRCH + 1 && _res.dnsrch[i]; i++)
|
|
|
|
{
|
|
|
|
/* This uses a heuristic to select a DNS suffix:
|
|
|
|
* the first, non-IP address string is selected.
|
|
|
|
*/
|
|
|
|
if (!is_ip_address_string(_res.dnsrch[i]))
|
|
|
|
found_suffix = _res.dnsrch[i];
|
|
|
|
}
|
2010-10-11 20:02:23 +02:00
|
|
|
}
|
2013-09-17 14:09:15 +02:00
|
|
|
#endif
|
2013-09-16 14:50:38 +02:00
|
|
|
|
|
|
|
size = MultiByteToWideChar( CP_UNIXCP, 0, found_suffix, -1, NULL, 0 ) * sizeof(WCHAR);
|
2010-10-11 20:02:23 +02:00
|
|
|
if (!suffix || *len < size)
|
|
|
|
{
|
|
|
|
*len = size;
|
|
|
|
return ERROR_BUFFER_OVERFLOW;
|
|
|
|
}
|
2013-09-16 14:50:38 +02:00
|
|
|
*len = MultiByteToWideChar( CP_UNIXCP, 0, found_suffix, -1, suffix, *len / sizeof(WCHAR) ) * sizeof(WCHAR);
|
2010-10-11 20:02:23 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:05:54 +01:00
|
|
|
ULONG WINAPI DECLSPEC_HOTPATCH GetAdaptersAddresses(ULONG family, ULONG flags, PVOID reserved,
|
|
|
|
PIP_ADAPTER_ADDRESSES aa, PULONG buflen)
|
2009-04-29 11:41:02 +02:00
|
|
|
{
|
|
|
|
InterfaceIndexTable *table;
|
2014-10-24 06:42:37 +02:00
|
|
|
ULONG i, size, dns_server_size = 0, dns_suffix_size, total_size, ret = ERROR_NO_DATA;
|
2009-04-29 11:41:02 +02:00
|
|
|
|
2010-09-16 23:04:02 +02:00
|
|
|
TRACE("(%d, %08x, %p, %p, %p)\n", family, flags, reserved, aa, buflen);
|
|
|
|
|
2009-04-29 11:41:02 +02:00
|
|
|
if (!buflen) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2013-09-19 16:39:20 +02:00
|
|
|
get_interface_indices( FALSE, &table );
|
2009-04-29 11:41:02 +02:00
|
|
|
if (!table || !table->numIndexes)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
|
|
|
return ERROR_NO_DATA;
|
|
|
|
}
|
|
|
|
total_size = 0;
|
|
|
|
for (i = 0; i < table->numIndexes; i++)
|
|
|
|
{
|
|
|
|
size = 0;
|
2010-10-11 22:17:45 +02:00
|
|
|
if ((ret = adapterAddressesFromIndex(family, flags, table->indexes[i], NULL, &size)))
|
2009-04-29 11:41:02 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
total_size += size;
|
|
|
|
}
|
2010-10-11 18:05:06 +02:00
|
|
|
if (!(flags & GAA_FLAG_SKIP_DNS_SERVER))
|
|
|
|
{
|
|
|
|
/* Since DNS servers aren't really per adapter, get enough space for a
|
|
|
|
* single copy of them.
|
|
|
|
*/
|
|
|
|
get_dns_server_addresses(NULL, &dns_server_size);
|
|
|
|
total_size += dns_server_size;
|
|
|
|
}
|
2010-10-11 20:02:23 +02:00
|
|
|
/* Since DNS suffix also isn't really per adapter, get enough space for a
|
|
|
|
* single copy of it.
|
|
|
|
*/
|
|
|
|
get_dns_suffix(NULL, &dns_suffix_size);
|
|
|
|
total_size += dns_suffix_size;
|
2009-04-29 11:41:02 +02:00
|
|
|
if (aa && *buflen >= total_size)
|
|
|
|
{
|
|
|
|
ULONG bytes_left = size = total_size;
|
2010-10-11 18:05:06 +02:00
|
|
|
PIP_ADAPTER_ADDRESSES first_aa = aa;
|
|
|
|
PIP_ADAPTER_DNS_SERVER_ADDRESS firstDns;
|
2010-10-11 20:02:23 +02:00
|
|
|
WCHAR *dnsSuffix;
|
2010-10-11 18:05:06 +02:00
|
|
|
|
2009-04-29 11:41:02 +02:00
|
|
|
for (i = 0; i < table->numIndexes; i++)
|
|
|
|
{
|
2010-10-11 22:17:45 +02:00
|
|
|
if ((ret = adapterAddressesFromIndex(family, flags, table->indexes[i], aa, &size)))
|
2009-04-29 11:41:02 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (i < table->numIndexes - 1)
|
|
|
|
{
|
|
|
|
aa->Next = (IP_ADAPTER_ADDRESSES *)((char *)aa + size);
|
|
|
|
aa = aa->Next;
|
|
|
|
size = bytes_left -= size;
|
|
|
|
}
|
|
|
|
}
|
2014-10-24 06:42:37 +02:00
|
|
|
if (dns_server_size)
|
2010-10-11 18:05:06 +02:00
|
|
|
{
|
2011-01-15 09:28:02 +01:00
|
|
|
firstDns = (PIP_ADAPTER_DNS_SERVER_ADDRESS)((BYTE *)first_aa + total_size - dns_server_size - dns_suffix_size);
|
2010-10-11 18:05:06 +02:00
|
|
|
get_dns_server_addresses(firstDns, &dns_server_size);
|
|
|
|
for (aa = first_aa; aa; aa = aa->Next)
|
|
|
|
{
|
|
|
|
if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK && aa->OperStatus == IfOperStatusUp)
|
|
|
|
aa->FirstDnsServerAddress = firstDns;
|
|
|
|
}
|
|
|
|
}
|
2010-10-11 20:02:23 +02:00
|
|
|
aa = first_aa;
|
|
|
|
dnsSuffix = (WCHAR *)((BYTE *)aa + total_size - dns_suffix_size);
|
|
|
|
get_dns_suffix(dnsSuffix, &dns_suffix_size);
|
|
|
|
for (; aa; aa = aa->Next)
|
|
|
|
{
|
|
|
|
if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK && aa->OperStatus == IfOperStatusUp)
|
|
|
|
aa->DnsSuffix = dnsSuffix;
|
2010-12-27 08:56:21 +01:00
|
|
|
else
|
2013-09-16 14:50:38 +02:00
|
|
|
aa->DnsSuffix = dnsSuffix + dns_suffix_size / sizeof(WCHAR) - 1;
|
2010-10-11 20:02:23 +02:00
|
|
|
}
|
2009-04-29 11:41:02 +02:00
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
}
|
2010-12-27 08:56:21 +01:00
|
|
|
else
|
2015-04-16 06:23:50 +02:00
|
|
|
{
|
2010-12-27 08:56:21 +01:00
|
|
|
ret = ERROR_BUFFER_OVERFLOW;
|
2015-04-16 06:23:50 +02:00
|
|
|
*buflen = total_size;
|
|
|
|
}
|
2009-04-29 11:41:02 +02:00
|
|
|
|
|
|
|
TRACE("num adapters %u\n", table->numIndexes);
|
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
|
|
|
return ret;
|
|
|
|
}
|
2003-05-13 05:32:20 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetBestInterface (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get the interface, with the best route for the given IP address.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* PARAMS
|
|
|
|
* dwDestAddr [In] IP address to search the interface for
|
|
|
|
* pdwBestIfIndex [Out] found best interface
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
|
2008-01-17 13:26:14 +01:00
|
|
|
{
|
|
|
|
struct WS_sockaddr_in sa_in;
|
|
|
|
memset(&sa_in, 0, sizeof(sa_in));
|
2015-08-18 09:40:58 +02:00
|
|
|
sa_in.sin_family = WS_AF_INET;
|
2008-01-17 13:26:14 +01:00
|
|
|
sa_in.sin_addr.S_un.S_addr = dwDestAddr;
|
|
|
|
return GetBestInterfaceEx((struct WS_sockaddr *)&sa_in, pdwBestIfIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetBestInterfaceEx (IPHLPAPI.@)
|
|
|
|
*
|
|
|
|
* Get the interface, with the best route for the given IP address.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dwDestAddr [In] IP address to search the interface for
|
|
|
|
* pdwBestIfIndex [Out] found best interface
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetBestInterfaceEx(struct WS_sockaddr *pDestAddr, PDWORD pdwBestIfIndex)
|
2003-05-13 05:32:20 +02:00
|
|
|
{
|
2003-09-08 21:00:25 +02:00
|
|
|
DWORD ret;
|
|
|
|
|
2008-01-17 13:26:14 +01:00
|
|
|
TRACE("pDestAddr %p, pdwBestIfIndex %p\n", pDestAddr, pdwBestIfIndex);
|
|
|
|
if (!pDestAddr || !pdwBestIfIndex)
|
2003-09-08 21:00:25 +02:00
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
else {
|
|
|
|
MIB_IPFORWARDROW ipRow;
|
|
|
|
|
2015-08-18 09:40:58 +02:00
|
|
|
if (pDestAddr->sa_family == WS_AF_INET) {
|
2008-01-17 13:26:14 +01:00
|
|
|
ret = GetBestRoute(((struct WS_sockaddr_in *)pDestAddr)->sin_addr.S_un.S_addr, 0, &ipRow);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
*pdwBestIfIndex = ipRow.dwForwardIfIndex;
|
|
|
|
} else {
|
|
|
|
FIXME("address family %d not supported\n", pDestAddr->sa_family);
|
|
|
|
ret = ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2003-09-08 21:00:25 +02:00
|
|
|
}
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2003-09-08 21:00:25 +02:00
|
|
|
return ret;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetBestRoute (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get the best route for the given IP address.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* PARAMS
|
|
|
|
* dwDestAddr [In] IP address to search the best route for
|
|
|
|
* dwSourceAddr [In] optional source IP address
|
|
|
|
* pBestRoute [Out] found best route
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
|
|
|
|
{
|
2003-09-08 21:00:25 +02:00
|
|
|
PMIB_IPFORWARDTABLE table;
|
|
|
|
DWORD ret;
|
|
|
|
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr,
|
2004-01-02 04:55:05 +01:00
|
|
|
dwSourceAddr, pBestRoute);
|
2003-09-08 21:00:25 +02:00
|
|
|
if (!pBestRoute)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2007-10-24 18:15:39 +02:00
|
|
|
ret = AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
|
2007-11-15 18:38:12 +01:00
|
|
|
if (!ret) {
|
2007-10-24 21:47:42 +02:00
|
|
|
DWORD ndx, matchedBits, matchedNdx = table->dwNumEntries;
|
2003-09-08 21:00:25 +02:00
|
|
|
|
|
|
|
for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
|
2011-12-15 10:06:24 +01:00
|
|
|
if (table->table[ndx].u1.ForwardType != MIB_IPROUTE_TYPE_INVALID &&
|
2006-01-24 12:18:50 +01:00
|
|
|
(dwDestAddr & table->table[ndx].dwForwardMask) ==
|
2003-09-08 21:00:25 +02:00
|
|
|
(table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
|
|
|
|
DWORD numShifts, mask;
|
|
|
|
|
|
|
|
for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
|
2010-09-25 03:38:29 +02:00
|
|
|
mask && mask & 1; mask >>= 1, numShifts++)
|
2003-09-08 21:00:25 +02:00
|
|
|
;
|
|
|
|
if (numShifts > matchedBits) {
|
|
|
|
matchedBits = numShifts;
|
|
|
|
matchedNdx = ndx;
|
|
|
|
}
|
2009-10-12 13:39:30 +02:00
|
|
|
else if (!matchedBits) {
|
2007-11-15 18:38:12 +01:00
|
|
|
matchedNdx = ndx;
|
|
|
|
}
|
2003-09-08 21:00:25 +02:00
|
|
|
}
|
|
|
|
}
|
2006-01-24 12:18:50 +01:00
|
|
|
if (matchedNdx < table->dwNumEntries) {
|
|
|
|
memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* No route matches, which can happen if there's no default route. */
|
|
|
|
ret = ERROR_HOST_UNREACHABLE;
|
|
|
|
}
|
2003-09-08 21:00:25 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
|
|
|
}
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2003-09-08 21:00:25 +02:00
|
|
|
return ret;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetFriendlyIfIndex (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get a "friendly" version of IfIndex, which is one that doesn't
|
2004-12-13 14:21:39 +01:00
|
|
|
* have the top byte set. Doesn't validate whether IfIndex is a valid
|
|
|
|
* adapter index.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* IfIndex [In] interface index to get the friendly one for
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* A friendly version of IfIndex.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
|
|
|
|
{
|
|
|
|
/* windows doesn't validate these, either, just makes sure the top byte is
|
2003-09-08 21:00:25 +02:00
|
|
|
cleared. I assume my ifenum module never gives an index with the top
|
2003-05-13 05:32:20 +02:00
|
|
|
byte set. */
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", IfIndex);
|
2003-05-13 05:32:20 +02:00
|
|
|
return IfIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetIfEntry (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get information about an interface.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* PARAMS
|
|
|
|
* pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
|
|
|
|
* Out: interface information
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
2006-01-27 19:19:32 +01:00
|
|
|
char nameBuf[MAX_ADAPTER_NAME];
|
|
|
|
char *name;
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2004-01-02 04:55:05 +01:00
|
|
|
TRACE("pIfRow %p\n", pIfRow);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (!pIfRow)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2006-01-27 19:19:32 +01:00
|
|
|
name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (name) {
|
|
|
|
ret = getInterfaceEntryByName(name, pIfRow);
|
|
|
|
if (ret == NO_ERROR)
|
|
|
|
ret = getInterfaceStatsByName(name, pIfRow);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = ERROR_INVALID_DATA;
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-07-22 14:28:05 +02:00
|
|
|
/******************************************************************
|
|
|
|
* GetIfEntry2 (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetIfEntry2( MIB_IF_ROW2 *row2 )
|
|
|
|
{
|
2018-07-24 00:01:20 +02:00
|
|
|
DWORD ret, len = ARRAY_SIZE(row2->Description);
|
2015-07-22 14:28:05 +02:00
|
|
|
char buf[MAX_ADAPTER_NAME], *name;
|
|
|
|
MIB_IFROW row;
|
|
|
|
|
|
|
|
TRACE("%p\n", row2);
|
|
|
|
|
|
|
|
if (!row2 || (!(name = getInterfaceNameByIndex( row2->InterfaceIndex, buf )) &&
|
|
|
|
!(name = getInterfaceNameByIndex( row2->InterfaceLuid.Info.NetLuidIndex, buf ))))
|
|
|
|
{
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
if ((ret = getInterfaceEntryByName( name, &row ))) return ret;
|
|
|
|
if ((ret = getInterfaceStatsByName( name, &row ))) return ret;
|
|
|
|
|
|
|
|
memset( row2, 0, sizeof(*row2) );
|
|
|
|
row2->InterfaceLuid.Info.Reserved = 0;
|
|
|
|
row2->InterfaceLuid.Info.NetLuidIndex = row.dwIndex;
|
|
|
|
row2->InterfaceLuid.Info.IfType = row.dwType;
|
|
|
|
row2->InterfaceIndex = row.dwIndex;
|
2020-09-01 13:41:14 +02:00
|
|
|
ConvertInterfaceLuidToGuid( &row2->InterfaceLuid, &row2->InterfaceGuid );
|
2015-07-22 14:28:05 +02:00
|
|
|
row2->Type = row.dwType;
|
|
|
|
row2->Mtu = row.dwMtu;
|
|
|
|
MultiByteToWideChar( CP_UNIXCP, 0, (const char *)row.bDescr, -1, row2->Description, len );
|
|
|
|
row2->PhysicalAddressLength = row.dwPhysAddrLen;
|
|
|
|
memcpy( &row2->PhysicalAddress, &row.bPhysAddr, row.dwPhysAddrLen );
|
|
|
|
memcpy( &row2->PermanentPhysicalAddress, &row.bPhysAddr, row.dwPhysAddrLen );
|
|
|
|
row2->OperStatus = IfOperStatusUp;
|
|
|
|
row2->AdminStatus = NET_IF_ADMIN_STATUS_UP;
|
|
|
|
row2->MediaConnectState = MediaConnectStateConnected;
|
|
|
|
row2->ConnectionType = NET_IF_CONNECTION_DEDICATED;
|
|
|
|
|
|
|
|
/* stats */
|
|
|
|
row2->InOctets = row.dwInOctets;
|
|
|
|
row2->InUcastPkts = row.dwInUcastPkts;
|
|
|
|
row2->InNUcastPkts = row.dwInNUcastPkts;
|
|
|
|
row2->InDiscards = row.dwInDiscards;
|
|
|
|
row2->InErrors = row.dwInErrors;
|
|
|
|
row2->InUnknownProtos = row.dwInUnknownProtos;
|
|
|
|
row2->OutOctets = row.dwOutOctets;
|
|
|
|
row2->OutUcastPkts = row.dwOutUcastPkts;
|
|
|
|
row2->OutNUcastPkts = row.dwOutNUcastPkts;
|
|
|
|
row2->OutDiscards = row.dwOutDiscards;
|
|
|
|
row2->OutErrors = row.dwOutErrors;
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2003-09-08 21:00:25 +02:00
|
|
|
static int IfTableSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (a && b)
|
2005-06-27 11:53:46 +02:00
|
|
|
ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
|
2003-09-08 21:00:25 +02:00
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
/******************************************************************
|
|
|
|
* GetIfTable (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get a table of local interfaces.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pIfTable [Out] buffer for local interfaces table
|
|
|
|
* pdwSize [In/Out] length of output buffer
|
|
|
|
* bOrder [In] whether to sort the table
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* NOTES
|
|
|
|
* If pdwSize is less than required, the function will return
|
|
|
|
* ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
|
|
|
|
* size.
|
|
|
|
* If bOrder is true, the returned table will be sorted by interface index.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
2017-07-03 14:01:19 +02:00
|
|
|
TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pIfTable, pdwSize, bOrder);
|
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
if (!pdwSize)
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
else {
|
2013-09-19 16:39:20 +02:00
|
|
|
DWORD numInterfaces = get_interface_indices( FALSE, NULL );
|
2007-11-15 20:05:10 +01:00
|
|
|
ULONG size = sizeof(MIB_IFTABLE);
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2007-11-15 20:05:10 +01:00
|
|
|
if (numInterfaces > 1)
|
|
|
|
size += (numInterfaces - 1) * sizeof(MIB_IFROW);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (!pIfTable || *pdwSize < size) {
|
|
|
|
*pdwSize = size;
|
|
|
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
else {
|
2013-09-19 16:39:20 +02:00
|
|
|
InterfaceIndexTable *table;
|
|
|
|
get_interface_indices( FALSE, &table );
|
2003-05-13 05:32:20 +02:00
|
|
|
|
|
|
|
if (table) {
|
2007-11-15 20:05:10 +01:00
|
|
|
size = sizeof(MIB_IFTABLE);
|
|
|
|
if (table->numIndexes > 1)
|
|
|
|
size += (table->numIndexes - 1) * sizeof(MIB_IFROW);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (*pdwSize < size) {
|
|
|
|
*pdwSize = size;
|
|
|
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DWORD ndx;
|
|
|
|
|
2006-01-24 12:18:50 +01:00
|
|
|
*pdwSize = size;
|
2003-05-13 05:32:20 +02:00
|
|
|
pIfTable->dwNumEntries = 0;
|
|
|
|
for (ndx = 0; ndx < table->numIndexes; ndx++) {
|
|
|
|
pIfTable->table[ndx].dwIndex = table->indexes[ndx];
|
|
|
|
GetIfEntry(&pIfTable->table[ndx]);
|
|
|
|
pIfTable->dwNumEntries++;
|
|
|
|
}
|
2003-09-08 21:00:25 +02:00
|
|
|
if (bOrder)
|
|
|
|
qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
|
|
|
|
IfTableSorter);
|
2003-05-13 05:32:20 +02:00
|
|
|
ret = NO_ERROR;
|
|
|
|
}
|
2004-12-13 14:21:39 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-18 09:41:23 +02:00
|
|
|
/******************************************************************
|
2017-05-25 16:15:21 +02:00
|
|
|
* GetIfTable2Ex (IPHLPAPI.@)
|
2015-08-18 09:41:23 +02:00
|
|
|
*/
|
2017-05-25 16:15:21 +02:00
|
|
|
DWORD WINAPI GetIfTable2Ex( MIB_IF_TABLE_LEVEL level, MIB_IF_TABLE2 **table )
|
2015-08-18 09:41:23 +02:00
|
|
|
{
|
|
|
|
DWORD i, nb_interfaces, size = sizeof(MIB_IF_TABLE2);
|
|
|
|
InterfaceIndexTable *index_table;
|
|
|
|
MIB_IF_TABLE2 *ret;
|
|
|
|
|
2017-05-25 16:15:21 +02:00
|
|
|
TRACE( "level %u, table %p\n", level, table );
|
2015-08-18 09:41:23 +02:00
|
|
|
|
2018-03-23 16:01:02 +01:00
|
|
|
if (!table || level > MibIfTableNormalWithoutStatistics)
|
2017-05-25 16:15:21 +02:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (level != MibIfTableNormal)
|
|
|
|
FIXME("level %u not fully supported\n", level);
|
2015-08-18 09:41:23 +02:00
|
|
|
|
|
|
|
if ((nb_interfaces = get_interface_indices( FALSE, NULL )) > 1)
|
|
|
|
size += (nb_interfaces - 1) * sizeof(MIB_IF_ROW2);
|
|
|
|
|
|
|
|
if (!(ret = HeapAlloc( GetProcessHeap(), 0, size ))) return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
get_interface_indices( FALSE, &index_table );
|
|
|
|
if (!index_table)
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, ret );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret->NumEntries = 0;
|
|
|
|
for (i = 0; i < index_table->numIndexes; i++)
|
|
|
|
{
|
|
|
|
ret->Table[i].InterfaceIndex = index_table->indexes[i];
|
|
|
|
GetIfEntry2( &ret->Table[i] );
|
|
|
|
ret->NumEntries++;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, index_table );
|
|
|
|
*table = ret;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2017-05-25 16:15:21 +02:00
|
|
|
/******************************************************************
|
|
|
|
* GetIfTable2 (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetIfTable2( MIB_IF_TABLE2 **table )
|
|
|
|
{
|
|
|
|
TRACE( "table %p\n", table );
|
|
|
|
return GetIfTable2Ex(MibIfTableNormal, table);
|
|
|
|
}
|
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
/******************************************************************
|
|
|
|
* GetInterfaceInfo (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get a list of network interface adapters.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* PARAMS
|
2006-01-20 16:16:56 +01:00
|
|
|
* pIfTable [Out] buffer for interface adapters
|
2005-11-14 12:24:37 +01:00
|
|
|
* dwOutBufLen [Out] if buffer is too small, returns required size
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2006-01-27 19:19:32 +01:00
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* MSDN states this should return non-loopback interfaces only.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
2004-01-02 04:55:05 +01:00
|
|
|
TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (!dwOutBufLen)
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
else {
|
2013-09-19 16:39:20 +02:00
|
|
|
DWORD numInterfaces = get_interface_indices( FALSE, NULL );
|
2007-11-15 20:05:10 +01:00
|
|
|
ULONG size = sizeof(IP_INTERFACE_INFO);
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2007-11-15 20:05:10 +01:00
|
|
|
if (numInterfaces > 1)
|
|
|
|
size += (numInterfaces - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (!pIfTable || *dwOutBufLen < size) {
|
|
|
|
*dwOutBufLen = size;
|
|
|
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
else {
|
2013-09-19 16:39:20 +02:00
|
|
|
InterfaceIndexTable *table;
|
|
|
|
get_interface_indices( FALSE, &table );
|
2003-05-13 05:32:20 +02:00
|
|
|
|
|
|
|
if (table) {
|
2007-11-15 20:05:10 +01:00
|
|
|
size = sizeof(IP_INTERFACE_INFO);
|
|
|
|
if (table->numIndexes > 1)
|
|
|
|
size += (table->numIndexes - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (*dwOutBufLen < size) {
|
|
|
|
*dwOutBufLen = size;
|
|
|
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DWORD ndx;
|
2006-01-27 19:19:32 +01:00
|
|
|
char nameBuf[MAX_ADAPTER_NAME];
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2006-01-25 13:14:12 +01:00
|
|
|
*dwOutBufLen = size;
|
2003-05-13 05:32:20 +02:00
|
|
|
pIfTable->NumAdapters = 0;
|
|
|
|
for (ndx = 0; ndx < table->numIndexes; ndx++) {
|
|
|
|
const char *walker, *name;
|
|
|
|
WCHAR *assigner;
|
|
|
|
|
|
|
|
pIfTable->Adapter[ndx].Index = table->indexes[ndx];
|
2006-01-27 19:19:32 +01:00
|
|
|
name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
|
2003-05-13 05:32:20 +02:00
|
|
|
for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
|
|
|
|
walker && *walker &&
|
|
|
|
assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
|
|
|
|
walker++, assigner++)
|
|
|
|
*assigner = *walker;
|
|
|
|
*assigner = 0;
|
|
|
|
pIfTable->NumAdapters++;
|
|
|
|
}
|
|
|
|
ret = NO_ERROR;
|
|
|
|
}
|
2004-12-13 14:21:39 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetIpAddrTable (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get interface-to-IP address mapping table.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pIpAddrTable [Out] buffer for mapping table
|
|
|
|
* pdwSize [In/Out] length of output buffer
|
|
|
|
* bOrder [In] whether to sort the table
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* NOTES
|
|
|
|
* If pdwSize is less than required, the function will return
|
|
|
|
* ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
|
|
|
|
* size.
|
|
|
|
* If bOrder is true, the returned table will be sorted by the next hop and
|
|
|
|
* an assortment of arbitrary parameters.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable, pdwSize,
|
2004-01-02 04:55:05 +01:00
|
|
|
(DWORD)bOrder);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (!pdwSize)
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
else {
|
2006-01-24 12:18:50 +01:00
|
|
|
PMIB_IPADDRTABLE table;
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2006-01-24 12:18:50 +01:00
|
|
|
ret = getIPAddrTable(&table, GetProcessHeap(), 0);
|
|
|
|
if (ret == NO_ERROR)
|
|
|
|
{
|
2012-12-10 10:22:25 +01:00
|
|
|
ULONG size = FIELD_OFFSET(MIB_IPADDRTABLE, table[table->dwNumEntries]);
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2006-01-24 12:18:50 +01:00
|
|
|
if (!pIpAddrTable || *pdwSize < size) {
|
|
|
|
*pdwSize = size;
|
|
|
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
2006-01-24 12:18:50 +01:00
|
|
|
else {
|
|
|
|
*pdwSize = size;
|
2007-11-15 20:06:07 +01:00
|
|
|
memcpy(pIpAddrTable, table, size);
|
2016-12-01 13:23:36 +01:00
|
|
|
/* sort by numeric IP value */
|
2006-01-24 12:18:50 +01:00
|
|
|
if (bOrder)
|
|
|
|
qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
|
2016-12-01 13:23:36 +01:00
|
|
|
sizeof(MIB_IPADDRROW), IpAddrTableNumericSorter);
|
|
|
|
/* sort ensuring loopback interfaces are in the end */
|
|
|
|
else
|
|
|
|
qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
|
|
|
|
sizeof(MIB_IPADDRROW), IpAddrTableLoopbackSorter);
|
2006-01-24 12:18:50 +01:00
|
|
|
ret = NO_ERROR;
|
2003-09-08 21:00:25 +02:00
|
|
|
}
|
2006-01-24 12:18:50 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
2003-09-08 21:00:25 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2003-09-08 21:00:25 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
/******************************************************************
|
|
|
|
* GetIpForwardTable (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get the route table.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pIpForwardTable [Out] buffer for route table
|
|
|
|
* pdwSize [In/Out] length of output buffer
|
|
|
|
* bOrder [In] whether to sort the table
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* NOTES
|
|
|
|
* If pdwSize is less than required, the function will return
|
|
|
|
* ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
|
|
|
|
* size.
|
|
|
|
* If bOrder is true, the returned table will be sorted by the next hop and
|
|
|
|
* an assortment of arbitrary parameters.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
|
|
|
|
{
|
2009-03-02 12:49:09 +01:00
|
|
|
DWORD ret;
|
|
|
|
PMIB_IPFORWARDTABLE table;
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2009-03-02 12:49:09 +01:00
|
|
|
TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable, pdwSize, bOrder);
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2009-03-02 12:49:09 +01:00
|
|
|
if (!pdwSize) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2009-03-02 12:52:45 +01:00
|
|
|
ret = AllocateAndGetIpForwardTableFromStack(&table, bOrder, GetProcessHeap(), 0);
|
2009-03-02 12:49:09 +01:00
|
|
|
if (!ret) {
|
|
|
|
DWORD size = FIELD_OFFSET( MIB_IPFORWARDTABLE, table[table->dwNumEntries] );
|
|
|
|
if (!pIpForwardTable || *pdwSize < size) {
|
|
|
|
*pdwSize = size;
|
2003-05-13 05:32:20 +02:00
|
|
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
else {
|
2009-03-02 12:49:09 +01:00
|
|
|
*pdwSize = size;
|
|
|
|
memcpy(pIpForwardTable, table, size);
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
2004-12-13 14:21:39 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
2009-03-02 12:49:09 +01:00
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetIpNetTable (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get the IP-to-physical address mapping table.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pIpNetTable [Out] buffer for mapping table
|
|
|
|
* pdwSize [In/Out] length of output buffer
|
|
|
|
* bOrder [In] whether to sort the table
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* NOTES
|
|
|
|
* If pdwSize is less than required, the function will return
|
|
|
|
* ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
|
|
|
|
* size.
|
|
|
|
* If bOrder is true, the returned table will be sorted by IP address.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
|
|
|
|
{
|
2009-03-02 12:45:58 +01:00
|
|
|
DWORD ret;
|
|
|
|
PMIB_IPNETTABLE table;
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2009-03-02 12:45:58 +01:00
|
|
|
TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable, pdwSize, bOrder);
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2009-03-02 12:45:58 +01:00
|
|
|
if (!pdwSize) return ERROR_INVALID_PARAMETER;
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2009-03-02 12:51:48 +01:00
|
|
|
ret = AllocateAndGetIpNetTableFromStack( &table, bOrder, GetProcessHeap(), 0 );
|
2009-03-02 12:45:58 +01:00
|
|
|
if (!ret) {
|
|
|
|
DWORD size = FIELD_OFFSET( MIB_IPNETTABLE, table[table->dwNumEntries] );
|
|
|
|
if (!pIpNetTable || *pdwSize < size) {
|
2003-05-13 05:32:20 +02:00
|
|
|
*pdwSize = size;
|
|
|
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
else {
|
2006-01-24 12:18:50 +01:00
|
|
|
*pdwSize = size;
|
2003-05-13 05:32:20 +02:00
|
|
|
memcpy(pIpNetTable, table, size);
|
|
|
|
}
|
2004-12-13 14:21:39 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
2009-03-02 12:45:58 +01:00
|
|
|
TRACE("returning %d\n", ret);
|
|
|
|
return ret;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
2010-10-11 18:12:45 +02:00
|
|
|
/* Gets the DNS server list into the list beginning at list. Assumes that
|
|
|
|
* a single server address may be placed at list if *len is at least
|
|
|
|
* sizeof(IP_ADDR_STRING) long. Otherwise, list->Next is set to firstDynamic,
|
|
|
|
* and assumes that all remaining DNS servers are contiguously located
|
|
|
|
* beginning at firstDynamic. On input, *len is assumed to be the total number
|
|
|
|
* of bytes available for all DNS servers, and is ignored if list is NULL.
|
|
|
|
* On return, *len is set to the total number of bytes required for all DNS
|
|
|
|
* servers.
|
|
|
|
* Returns ERROR_BUFFER_OVERFLOW if *len is insufficient,
|
|
|
|
* ERROR_SUCCESS otherwise.
|
|
|
|
*/
|
|
|
|
static DWORD get_dns_server_list(PIP_ADDR_STRING list,
|
|
|
|
PIP_ADDR_STRING firstDynamic, DWORD *len)
|
|
|
|
{
|
|
|
|
DWORD size;
|
2013-09-13 13:52:54 +02:00
|
|
|
int num = get_dns_servers( NULL, 0, TRUE );
|
2010-10-11 18:12:45 +02:00
|
|
|
|
2013-09-13 13:52:53 +02:00
|
|
|
size = num * sizeof(IP_ADDR_STRING);
|
2010-10-11 18:12:45 +02:00
|
|
|
if (!list || *len < size) {
|
|
|
|
*len = size;
|
|
|
|
return ERROR_BUFFER_OVERFLOW;
|
|
|
|
}
|
|
|
|
*len = size;
|
2013-09-13 13:52:53 +02:00
|
|
|
if (num > 0) {
|
2010-10-11 18:12:45 +02:00
|
|
|
PIP_ADDR_STRING ptr;
|
|
|
|
int i;
|
2013-09-13 13:52:53 +02:00
|
|
|
SOCKADDR_STORAGE *addr = HeapAlloc( GetProcessHeap(), 0, num * sizeof(SOCKADDR_STORAGE) );
|
|
|
|
|
2013-09-13 13:52:54 +02:00
|
|
|
get_dns_servers( addr, num, TRUE );
|
2010-10-11 18:12:45 +02:00
|
|
|
|
2013-09-13 13:52:53 +02:00
|
|
|
for (i = 0, ptr = list; i < num; i++, ptr = ptr->Next) {
|
|
|
|
toIPAddressString(((struct sockaddr_in *)(addr + i))->sin_addr.s_addr,
|
2010-10-11 18:12:45 +02:00
|
|
|
ptr->IpAddress.String);
|
2013-09-13 13:52:53 +02:00
|
|
|
if (i == num - 1)
|
2010-10-11 18:12:45 +02:00
|
|
|
ptr->Next = NULL;
|
|
|
|
else if (i == 0)
|
|
|
|
ptr->Next = firstDynamic;
|
|
|
|
else
|
|
|
|
ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
|
|
|
|
}
|
2013-09-13 13:52:53 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, addr );
|
2010-10-11 18:12:45 +02:00
|
|
|
}
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2003-05-13 05:32:20 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetNetworkParams (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get the network parameters for the local computer.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* PARAMS
|
|
|
|
* pFixedInfo [Out] buffer for network parameters
|
2005-11-23 20:14:43 +01:00
|
|
|
* pOutBufLen [In/Out] length of output buffer
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* NOTES
|
|
|
|
* If pOutBufLen is less than required, the function will return
|
|
|
|
* ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
|
|
|
|
* size.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
|
|
|
|
{
|
2010-10-11 18:12:45 +02:00
|
|
|
DWORD ret, size, serverListSize;
|
2004-01-02 04:55:05 +01:00
|
|
|
LONG regReturn;
|
2003-09-08 21:00:25 +02:00
|
|
|
HKEY hKey;
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2004-01-02 04:55:05 +01:00
|
|
|
TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (!pOutBufLen)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2010-10-11 18:12:45 +02:00
|
|
|
get_dns_server_list(NULL, NULL, &serverListSize);
|
|
|
|
size = sizeof(FIXED_INFO) + serverListSize - sizeof(IP_ADDR_STRING);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (!pFixedInfo || *pOutBufLen < size) {
|
|
|
|
*pOutBufLen = size;
|
|
|
|
return ERROR_BUFFER_OVERFLOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(pFixedInfo, 0, size);
|
|
|
|
size = sizeof(pFixedInfo->HostName);
|
|
|
|
GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
|
|
|
|
size = sizeof(pFixedInfo->DomainName);
|
|
|
|
GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
|
2010-10-11 18:12:45 +02:00
|
|
|
get_dns_server_list(&pFixedInfo->DnsServerList,
|
|
|
|
(PIP_ADDR_STRING)((BYTE *)pFixedInfo + sizeof(FIXED_INFO)),
|
|
|
|
&serverListSize);
|
|
|
|
/* Assume the first DNS server in the list is the "current" DNS server: */
|
|
|
|
pFixedInfo->CurrentDnsServer = &pFixedInfo->DnsServerList;
|
2003-09-08 21:00:25 +02:00
|
|
|
pFixedInfo->NodeType = HYBRID_NODETYPE;
|
2004-01-02 04:55:05 +01:00
|
|
|
regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
|
|
|
|
"SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
|
|
|
|
if (regReturn != ERROR_SUCCESS)
|
|
|
|
regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
|
|
|
|
"SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
|
|
|
|
&hKey);
|
|
|
|
if (regReturn == ERROR_SUCCESS)
|
2003-09-08 21:00:25 +02:00
|
|
|
{
|
|
|
|
DWORD size = sizeof(pFixedInfo->ScopeId);
|
|
|
|
|
2005-07-07 14:08:42 +02:00
|
|
|
RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
|
2003-09-08 21:00:25 +02:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
/* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
|
|
|
|
I suppose could also check for a listener on port 53 to set EnableDns */
|
2004-01-02 04:55:05 +01:00
|
|
|
ret = NO_ERROR;
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2004-01-02 04:55:05 +01:00
|
|
|
return ret;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetNumberOfInterfaces (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get the number of interfaces.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pdwNumIf [Out] number of interfaces
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
2004-01-02 04:55:05 +01:00
|
|
|
TRACE("pdwNumIf %p\n", pdwNumIf);
|
2003-05-13 05:32:20 +02:00
|
|
|
if (!pdwNumIf)
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
else {
|
2013-09-19 16:39:20 +02:00
|
|
|
*pdwNumIf = get_interface_indices( FALSE, NULL );
|
2003-05-13 05:32:20 +02:00
|
|
|
ret = NO_ERROR;
|
|
|
|
}
|
2006-10-07 20:18:10 +02:00
|
|
|
TRACE("returning %d\n", ret);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetPerAdapterInfo (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get information about an adapter corresponding to an interface.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* IfIndex [In] interface info
|
|
|
|
* pPerAdapterInfo [Out] buffer for per adapter info
|
|
|
|
* pOutBufLen [In/Out] length of output buffer
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
|
|
|
|
{
|
2010-03-23 22:56:34 +01:00
|
|
|
ULONG bytesNeeded = sizeof(IP_PER_ADAPTER_INFO), serverListSize = 0;
|
|
|
|
DWORD ret = NO_ERROR;
|
2007-10-13 01:16:35 +02:00
|
|
|
|
2008-07-02 17:27:37 +02:00
|
|
|
TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex, pPerAdapterInfo, pOutBufLen);
|
|
|
|
|
|
|
|
if (!pOutBufLen) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2010-03-23 22:56:34 +01:00
|
|
|
if (!isIfIndexLoopback(IfIndex)) {
|
|
|
|
get_dns_server_list(NULL, NULL, &serverListSize);
|
|
|
|
if (serverListSize > sizeof(IP_ADDR_STRING))
|
|
|
|
bytesNeeded += serverListSize - sizeof(IP_ADDR_STRING);
|
|
|
|
}
|
2008-07-02 17:27:37 +02:00
|
|
|
if (!pPerAdapterInfo || *pOutBufLen < bytesNeeded)
|
2007-10-13 01:16:35 +02:00
|
|
|
{
|
|
|
|
*pOutBufLen = bytesNeeded;
|
2008-07-02 17:27:37 +02:00
|
|
|
return ERROR_BUFFER_OVERFLOW;
|
2007-10-13 01:16:35 +02:00
|
|
|
}
|
2008-07-02 17:27:37 +02:00
|
|
|
|
|
|
|
memset(pPerAdapterInfo, 0, bytesNeeded);
|
2010-03-23 22:56:34 +01:00
|
|
|
if (!isIfIndexLoopback(IfIndex)) {
|
|
|
|
ret = get_dns_server_list(&pPerAdapterInfo->DnsServerList,
|
|
|
|
(PIP_ADDR_STRING)((PBYTE)pPerAdapterInfo + sizeof(IP_PER_ADAPTER_INFO)),
|
|
|
|
&serverListSize);
|
|
|
|
/* Assume the first DNS server in the list is the "current" DNS server: */
|
|
|
|
pPerAdapterInfo->CurrentDnsServer = &pPerAdapterInfo->DnsServerList;
|
|
|
|
}
|
|
|
|
return ret;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetRTTAndHopCount (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get round-trip time (RTT) and hop count.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* DestIpAddress [In] destination address to get the info for
|
|
|
|
* HopCount [Out] retrieved hop count
|
|
|
|
* MaxHops [In] maximum hops to search for the destination
|
|
|
|
* RTT [Out] RTT in milliseconds
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns FALSE.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
|
|
|
|
{
|
2009-01-06 00:05:25 +01:00
|
|
|
FIXME("(DestIpAddress 0x%08x, HopCount %p, MaxHops %d, RTT %p): stub\n",
|
2004-01-02 04:55:05 +01:00
|
|
|
DestIpAddress, HopCount, MaxHops, RTT);
|
2004-12-13 14:21:39 +01:00
|
|
|
return FALSE;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetTcpTable (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get the table of active TCP connections.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pTcpTable [Out] buffer for TCP connections table
|
|
|
|
* pdwSize [In/Out] length of output buffer
|
|
|
|
* bOrder [In] whether to order the table
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* NOTES
|
|
|
|
* If pdwSize is less than required, the function will return
|
|
|
|
* ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
|
|
|
|
* the required byte size.
|
|
|
|
* If bOrder is true, the returned table will be sorted, first by
|
|
|
|
* local address and port number, then by remote address and port
|
|
|
|
* number.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
|
|
|
|
{
|
2009-03-02 12:45:12 +01:00
|
|
|
TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize, bOrder);
|
2015-08-18 09:40:58 +02:00
|
|
|
return GetExtendedTcpTable(pTcpTable, pdwSize, bOrder, WS_AF_INET, TCP_TABLE_BASIC_ALL, 0);
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
2011-12-19 15:41:48 +01:00
|
|
|
/******************************************************************
|
|
|
|
* GetExtendedTcpTable (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetExtendedTcpTable(PVOID pTcpTable, PDWORD pdwSize, BOOL bOrder,
|
|
|
|
ULONG ulAf, TCP_TABLE_CLASS TableClass, ULONG Reserved)
|
|
|
|
{
|
2012-04-16 12:35:32 +02:00
|
|
|
DWORD ret, size;
|
|
|
|
void *table;
|
|
|
|
|
2011-12-19 15:41:48 +01:00
|
|
|
TRACE("pTcpTable %p, pdwSize %p, bOrder %d, ulAf %u, TableClass %u, Reserved %u\n",
|
|
|
|
pTcpTable, pdwSize, bOrder, ulAf, TableClass, Reserved);
|
|
|
|
|
2012-04-16 12:35:32 +02:00
|
|
|
if (!pdwSize) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2013-07-30 12:57:50 +02:00
|
|
|
if (TableClass >= TCP_TABLE_OWNER_MODULE_LISTENER)
|
|
|
|
FIXME("module classes not fully supported\n");
|
|
|
|
|
2020-02-14 07:51:51 +01:00
|
|
|
switch (ulAf)
|
|
|
|
{
|
|
|
|
case WS_AF_INET:
|
|
|
|
ret = build_tcp_table(TableClass, &table, bOrder, GetProcessHeap(), 0, &size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_AF_INET6:
|
|
|
|
ret = build_tcp6_table(TableClass, &table, bOrder, GetProcessHeap(), 0, &size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("ulAf = %u not supported\n", ulAf);
|
|
|
|
ret = ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
2012-04-16 12:35:32 +02:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!pTcpTable || *pdwSize < size)
|
|
|
|
{
|
|
|
|
*pdwSize = size;
|
|
|
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pdwSize = size;
|
|
|
|
memcpy(pTcpTable, table, size);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
|
|
|
return ret;
|
2011-12-19 15:41:48 +01:00
|
|
|
}
|
2003-05-13 05:32:20 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetUdpTable (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Get a table of active UDP connections.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pUdpTable [Out] buffer for UDP connections table
|
|
|
|
* pdwSize [In/Out] length of output buffer
|
|
|
|
* bOrder [In] whether to order the table
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* NOTES
|
|
|
|
* If pdwSize is less than required, the function will return
|
|
|
|
* ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
|
|
|
|
* required byte size.
|
|
|
|
* If bOrder is true, the returned table will be sorted, first by
|
|
|
|
* local address, then by local port number.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
|
|
|
|
{
|
2015-08-18 09:40:58 +02:00
|
|
|
return GetExtendedUdpTable(pUdpTable, pdwSize, bOrder, WS_AF_INET, UDP_TABLE_BASIC, 0);
|
2012-09-07 13:35:36 +02:00
|
|
|
}
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2018-08-27 11:08:37 +02:00
|
|
|
/******************************************************************
|
|
|
|
* GetUdp6Table (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetUdp6Table(PMIB_UDP6TABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
|
|
|
|
{
|
|
|
|
return GetExtendedUdpTable(pUdpTable, pdwSize, bOrder, WS_AF_INET6, UDP_TABLE_BASIC, 0);
|
|
|
|
}
|
|
|
|
|
2012-09-07 13:35:36 +02:00
|
|
|
/******************************************************************
|
|
|
|
* GetExtendedUdpTable (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetExtendedUdpTable(PVOID pUdpTable, PDWORD pdwSize, BOOL bOrder,
|
|
|
|
ULONG ulAf, UDP_TABLE_CLASS TableClass, ULONG Reserved)
|
|
|
|
{
|
|
|
|
DWORD ret, size;
|
|
|
|
void *table;
|
|
|
|
|
|
|
|
TRACE("pUdpTable %p, pdwSize %p, bOrder %d, ulAf %u, TableClass %u, Reserved %u\n",
|
|
|
|
pUdpTable, pdwSize, bOrder, ulAf, TableClass, Reserved);
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2009-03-02 12:43:33 +01:00
|
|
|
if (!pdwSize) return ERROR_INVALID_PARAMETER;
|
2003-05-13 05:32:20 +02:00
|
|
|
|
2012-09-07 13:35:48 +02:00
|
|
|
if (TableClass == UDP_TABLE_OWNER_MODULE)
|
|
|
|
FIXME("UDP_TABLE_OWNER_MODULE not fully supported\n");
|
|
|
|
|
2018-08-27 11:08:37 +02:00
|
|
|
switch (ulAf)
|
|
|
|
{
|
|
|
|
case WS_AF_INET:
|
|
|
|
ret = build_udp_table(TableClass, &table, bOrder, GetProcessHeap(), 0, &size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WS_AF_INET6:
|
|
|
|
ret = build_udp6_table(TableClass, &table, bOrder, GetProcessHeap(), 0, &size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("ulAf = %u not supported\n", ulAf);
|
|
|
|
ret = ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
2012-09-07 13:35:36 +02:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!pUdpTable || *pdwSize < size)
|
|
|
|
{
|
|
|
|
*pdwSize = size;
|
|
|
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pdwSize = size;
|
|
|
|
memcpy(pUdpTable, table, size);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
2009-03-02 12:43:33 +01:00
|
|
|
return ret;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
2017-02-10 18:30:13 +01:00
|
|
|
DWORD WINAPI GetUnicastIpAddressEntry(MIB_UNICASTIPADDRESS_ROW *row)
|
|
|
|
{
|
|
|
|
IP_ADAPTER_ADDRESSES *aa, *ptr;
|
|
|
|
ULONG size = 0;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
TRACE("%p\n", row);
|
|
|
|
|
|
|
|
if (!row)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
ret = GetAdaptersAddresses(row->Address.si_family, 0, NULL, NULL, &size);
|
|
|
|
if (ret != ERROR_BUFFER_OVERFLOW)
|
|
|
|
return ret;
|
|
|
|
if (!(ptr = HeapAlloc(GetProcessHeap(), 0, size)))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
if ((ret = GetAdaptersAddresses(row->Address.si_family, 0, NULL, ptr, &size)))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ERROR_FILE_NOT_FOUND;
|
|
|
|
for (aa = ptr; aa; aa = aa->Next)
|
|
|
|
{
|
|
|
|
IP_ADAPTER_UNICAST_ADDRESS *ua;
|
|
|
|
|
|
|
|
if (aa->u.s.IfIndex != row->InterfaceIndex &&
|
|
|
|
memcmp(&aa->Luid, &row->InterfaceLuid, sizeof(row->InterfaceLuid)))
|
|
|
|
continue;
|
|
|
|
ret = ERROR_NOT_FOUND;
|
|
|
|
|
|
|
|
ua = aa->FirstUnicastAddress;
|
|
|
|
while (ua)
|
|
|
|
{
|
|
|
|
SOCKADDR_INET *uaaddr = (SOCKADDR_INET *)ua->Address.lpSockaddr;
|
|
|
|
|
|
|
|
if ((row->Address.si_family == WS_AF_INET6 &&
|
|
|
|
!memcmp(&row->Address.Ipv6.sin6_addr, &uaaddr->Ipv6.sin6_addr, sizeof(uaaddr->Ipv6.sin6_addr))) ||
|
|
|
|
(row->Address.si_family == WS_AF_INET &&
|
|
|
|
row->Address.Ipv4.sin_addr.S_un.S_addr == uaaddr->Ipv4.sin_addr.S_un.S_addr))
|
|
|
|
{
|
|
|
|
memcpy(&row->InterfaceLuid, &aa->Luid, sizeof(aa->Luid));
|
|
|
|
row->InterfaceIndex = aa->u.s.IfIndex;
|
|
|
|
row->PrefixOrigin = ua->PrefixOrigin;
|
|
|
|
row->SuffixOrigin = ua->SuffixOrigin;
|
|
|
|
row->ValidLifetime = ua->ValidLifetime;
|
|
|
|
row->PreferredLifetime = ua->PreferredLifetime;
|
|
|
|
row->OnLinkPrefixLength = ua->OnLinkPrefixLength;
|
|
|
|
row->SkipAsSource = 0;
|
|
|
|
row->DadState = ua->DadState;
|
|
|
|
if (row->Address.si_family == WS_AF_INET6)
|
|
|
|
row->ScopeId.u.Value = row->Address.Ipv6.sin6_scope_id;
|
|
|
|
else
|
|
|
|
row->ScopeId.u.Value = 0;
|
|
|
|
NtQuerySystemTime(&row->CreationTimeStamp);
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
ua = ua->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-27 22:48:00 +02:00
|
|
|
DWORD WINAPI GetUnicastIpAddressTable(ADDRESS_FAMILY family, MIB_UNICASTIPADDRESS_TABLE **table)
|
|
|
|
{
|
|
|
|
IP_ADAPTER_ADDRESSES *aa, *ptr;
|
|
|
|
MIB_UNICASTIPADDRESS_TABLE *data;
|
|
|
|
DWORD ret, count = 0;
|
|
|
|
ULONG size, flags;
|
|
|
|
|
|
|
|
TRACE("%u, %p\n", family, table);
|
|
|
|
|
|
|
|
if (!table || (family != WS_AF_INET && family != WS_AF_INET6 && family != WS_AF_UNSPEC))
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
flags = GAA_FLAG_SKIP_ANYCAST |
|
|
|
|
GAA_FLAG_SKIP_MULTICAST |
|
|
|
|
GAA_FLAG_SKIP_DNS_SERVER |
|
|
|
|
GAA_FLAG_SKIP_FRIENDLY_NAME;
|
|
|
|
|
|
|
|
ret = GetAdaptersAddresses(family, flags, NULL, NULL, &size);
|
|
|
|
if (ret != ERROR_BUFFER_OVERFLOW)
|
|
|
|
return ret;
|
|
|
|
if (!(ptr = HeapAlloc(GetProcessHeap(), 0, size)))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
if ((ret = GetAdaptersAddresses(family, flags, NULL, ptr, &size)))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (aa = ptr; aa; aa = aa->Next)
|
|
|
|
{
|
|
|
|
IP_ADAPTER_UNICAST_ADDRESS *ua = aa->FirstUnicastAddress;
|
|
|
|
while (ua)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
ua = ua->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data) + (count - 1) * sizeof(data->Table[0]))))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->NumEntries = 0;
|
|
|
|
for (aa = ptr; aa; aa = aa->Next)
|
|
|
|
{
|
|
|
|
IP_ADAPTER_UNICAST_ADDRESS *ua = aa->FirstUnicastAddress;
|
|
|
|
while (ua)
|
|
|
|
{
|
|
|
|
MIB_UNICASTIPADDRESS_ROW *row = &data->Table[data->NumEntries];
|
|
|
|
memcpy(&row->Address, ua->Address.lpSockaddr, ua->Address.iSockaddrLength);
|
|
|
|
memcpy(&row->InterfaceLuid, &aa->Luid, sizeof(aa->Luid));
|
|
|
|
row->InterfaceIndex = aa->u.s.IfIndex;
|
|
|
|
row->PrefixOrigin = ua->PrefixOrigin;
|
|
|
|
row->SuffixOrigin = ua->SuffixOrigin;
|
|
|
|
row->ValidLifetime = ua->ValidLifetime;
|
|
|
|
row->PreferredLifetime = ua->PreferredLifetime;
|
|
|
|
row->OnLinkPrefixLength = ua->OnLinkPrefixLength;
|
|
|
|
row->SkipAsSource = 0;
|
|
|
|
row->DadState = ua->DadState;
|
|
|
|
if (row->Address.si_family == WS_AF_INET6)
|
|
|
|
row->ScopeId.u.Value = row->Address.Ipv6.sin6_scope_id;
|
|
|
|
else
|
|
|
|
row->ScopeId.u.Value = 0;
|
|
|
|
NtQuerySystemTime(&row->CreationTimeStamp);
|
|
|
|
|
|
|
|
data->NumEntries++;
|
|
|
|
ua = ua->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
|
|
|
|
*table = data;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
/******************************************************************
|
|
|
|
* GetUniDirectionalAdapterInfo (IPHLPAPI.@)
|
|
|
|
*
|
2004-12-13 14:21:39 +01:00
|
|
|
* This is a Win98-only function to get information on "unidirectional"
|
|
|
|
* adapters. Since this is pretty nonsensical in other contexts, it
|
|
|
|
* never returns anything.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pIPIfInfo [Out] buffer for adapter infos
|
|
|
|
* dwOutBufLen [Out] length of the output buffer
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
|
|
|
|
{
|
2004-01-02 04:55:05 +01:00
|
|
|
TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
|
2003-05-13 05:32:20 +02:00
|
|
|
/* a unidirectional adapter?? not bloody likely! */
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* IpReleaseAddress (IPHLPAPI.@)
|
|
|
|
*
|
2008-04-03 19:10:30 +02:00
|
|
|
* Release an IP obtained through DHCP,
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* AdapterInfo [In] adapter to release IP address
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* NOTES
|
|
|
|
* Since GetAdaptersInfo never returns adapters that have DHCP enabled,
|
|
|
|
* this function does nothing.
|
|
|
|
*
|
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
|
|
|
|
{
|
2012-09-27 17:14:32 +02:00
|
|
|
FIXME("Stub AdapterInfo %p\n", AdapterInfo);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* IpRenewAddress (IPHLPAPI.@)
|
|
|
|
*
|
2008-04-04 21:23:01 +02:00
|
|
|
* Renew an IP obtained through DHCP.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* AdapterInfo [In] adapter to renew IP address
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Since GetAdaptersInfo never returns adapters that have DHCP enabled,
|
|
|
|
* this function does nothing.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
|
|
|
|
{
|
2012-09-27 17:14:32 +02:00
|
|
|
FIXME("Stub AdapterInfo %p\n", AdapterInfo);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* NotifyAddrChange (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Notify caller whenever the ip-interface map is changed.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2008-04-03 19:10:30 +02:00
|
|
|
* Handle [Out] handle usable in asynchronous notification
|
2005-11-14 12:24:37 +01:00
|
|
|
* overlapped [In] overlapped structure that notifies the caller
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
|
2011-02-08 19:43:59 +01:00
|
|
|
if (Handle) *Handle = INVALID_HANDLE_VALUE;
|
2011-05-22 09:22:45 +02:00
|
|
|
if (overlapped) ((IO_STATUS_BLOCK *) overlapped)->u.Status = STATUS_PENDING;
|
2011-02-08 19:43:59 +01:00
|
|
|
return ERROR_IO_PENDING;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-27 02:50:05 +01:00
|
|
|
/******************************************************************
|
|
|
|
* NotifyIpInterfaceChange (IPHLPAPI.@)
|
|
|
|
*/
|
2017-03-11 15:05:08 +01:00
|
|
|
DWORD WINAPI NotifyIpInterfaceChange(ADDRESS_FAMILY family, PIPINTERFACE_CHANGE_CALLBACK callback,
|
|
|
|
PVOID context, BOOLEAN init_notify, PHANDLE handle)
|
2014-10-27 02:50:05 +01:00
|
|
|
{
|
|
|
|
FIXME("(family %d, callback %p, context %p, init_notify %d, handle %p): stub\n",
|
|
|
|
family, callback, context, init_notify, handle);
|
|
|
|
if (handle) *handle = NULL;
|
2019-10-15 04:25:39 +02:00
|
|
|
return NO_ERROR;
|
2014-10-27 02:50:05 +01:00
|
|
|
}
|
|
|
|
|
2020-05-08 17:59:23 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NotifyRouteChange2 (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI NotifyRouteChange2(ADDRESS_FAMILY family, PIPFORWARD_CHANGE_CALLBACK callback, VOID* context,
|
|
|
|
BOOLEAN init_notify, HANDLE* handle)
|
|
|
|
{
|
|
|
|
FIXME("(family %d, callback %p, context %p, init_notify %d, handle %p): stub\n",
|
|
|
|
family, callback, context, init_notify, handle);
|
|
|
|
if (handle) *handle = NULL;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2014-10-27 02:50:05 +01:00
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NotifyRouteChange (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Notify caller whenever the ip routing table is changed.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2008-04-04 21:23:01 +02:00
|
|
|
* Handle [Out] handle usable in asynchronous notification
|
2005-11-14 12:24:37 +01:00
|
|
|
* overlapped [In] overlapped structure that notifies the caller
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-08 21:22:22 +01:00
|
|
|
/******************************************************************
|
|
|
|
* NotifyUnicastIpAddressChange (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI NotifyUnicastIpAddressChange(ADDRESS_FAMILY family, PUNICAST_IPADDRESS_CHANGE_CALLBACK callback,
|
|
|
|
PVOID context, BOOLEAN init_notify, PHANDLE handle)
|
|
|
|
{
|
2020-02-27 12:10:32 +01:00
|
|
|
FIXME("(family %d, callback %p, context %p, init_notify %d, handle %p): semi-stub\n",
|
2017-03-08 21:22:22 +01:00
|
|
|
family, callback, context, init_notify, handle);
|
|
|
|
if (handle) *handle = NULL;
|
2020-02-27 12:10:32 +01:00
|
|
|
|
|
|
|
if (init_notify)
|
|
|
|
callback(context, NULL, MibInitialNotification);
|
|
|
|
|
2020-02-27 12:10:33 +01:00
|
|
|
return NO_ERROR;
|
2017-03-08 21:22:22 +01:00
|
|
|
}
|
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SendARP (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Send an ARP request.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2006-01-24 12:18:50 +01:00
|
|
|
* DestIP [In] attempt to obtain this IP
|
2005-11-14 12:24:37 +01:00
|
|
|
* SrcIP [In] optional sender IP address
|
|
|
|
* pMacAddr [Out] buffer for the mac address
|
|
|
|
* PhyAddrLen [In/Out] length of the output buffer
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
|
|
|
|
{
|
2009-01-06 00:05:25 +01:00
|
|
|
FIXME("(DestIP 0x%08x, SrcIP 0x%08x, pMacAddr %p, PhyAddrLen %p): stub\n",
|
2004-12-13 14:21:39 +01:00
|
|
|
DestIP, SrcIP, pMacAddr, PhyAddrLen);
|
2003-05-13 05:32:20 +02:00
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SetIfEntry (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Set the administrative status of an interface.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pIfRow [In] dwAdminStatus member specifies the new status.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(pIfRow %p): stub\n", pIfRow);
|
2006-01-25 13:14:12 +01:00
|
|
|
/* this is supposed to set an interface administratively up or down.
|
2003-05-13 05:32:20 +02:00
|
|
|
Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
|
|
|
|
this sort of down is indistinguishable from other sorts of down (e.g. no
|
|
|
|
link). */
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SetIpForwardEntry (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Modify an existing route.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pRoute [In] route with the new information
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns NO_ERROR.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(pRoute %p): stub\n", pRoute);
|
2003-05-13 05:32:20 +02:00
|
|
|
/* this is to add a route entry, how's it distinguishable from
|
|
|
|
CreateIpForwardEntry?
|
|
|
|
could use SIOCADDRT, not sure I want to */
|
2008-11-03 22:34:55 +01:00
|
|
|
return 0;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SetIpNetEntry (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Modify an existing ARP entry.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pArpEntry [In] ARP entry with the new information
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns NO_ERROR.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(pArpEntry %p): stub\n", pArpEntry);
|
2003-05-13 05:32:20 +02:00
|
|
|
/* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
|
2008-11-03 22:34:55 +01:00
|
|
|
return 0;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SetIpStatistics (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Toggle IP forwarding and det the default TTL value.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pIpStats [In] IP statistics with the new information
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns NO_ERROR.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(pIpStats %p): stub\n", pIpStats);
|
2008-11-03 22:34:55 +01:00
|
|
|
return 0;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SetIpTTL (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Set the default TTL value.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* nTTL [In] new TTL value
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns NO_ERROR.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI SetIpTTL(UINT nTTL)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(nTTL %d): stub\n", nTTL);
|
2003-05-13 05:32:20 +02:00
|
|
|
/* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
|
|
|
|
want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
|
2008-11-03 22:34:55 +01:00
|
|
|
return 0;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SetTcpEntry (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Set the state of a TCP connection.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pTcpRow [In] specifies connection with new state
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns NO_ERROR.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(pTcpRow %p): stub\n", pTcpRow);
|
2008-11-03 22:34:55 +01:00
|
|
|
return 0;
|
2003-05-13 05:32:20 +02:00
|
|
|
}
|
|
|
|
|
2015-08-08 18:11:35 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SetPerTcpConnectionEStats (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SetPerTcpConnectionEStats(PMIB_TCPROW row, TCP_ESTATS_TYPE state, PBYTE rw,
|
|
|
|
ULONG version, ULONG size, ULONG offset)
|
|
|
|
{
|
|
|
|
FIXME("(row %p, state %d, rw %p, version %u, size %u, offset %u): stub\n",
|
|
|
|
row, state, rw, version, size, offset);
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2003-05-13 05:32:20 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* UnenableRouter (IPHLPAPI.@)
|
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* Decrement the IP-forwarding reference count. Turn off IP-forwarding
|
|
|
|
* if it reaches zero.
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-11-14 12:24:37 +01:00
|
|
|
* pOverlapped [In/Out] should be the same as in EnableRouter()
|
|
|
|
* lpdwEnableCount [Out] optional, receives reference count
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-11-14 12:24:37 +01:00
|
|
|
* Success: NO_ERROR
|
|
|
|
* Failure: error code from winerror.h
|
2003-05-13 05:32:20 +02:00
|
|
|
*
|
2005-11-14 12:24:37 +01:00
|
|
|
* FIXME
|
|
|
|
* Stub, returns ERROR_NOT_SUPPORTED.
|
2003-05-13 05:32:20 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
|
|
|
|
{
|
2004-12-13 14:21:39 +01:00
|
|
|
FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
|
|
|
|
lpdwEnableCount);
|
2003-05-13 05:32:20 +02:00
|
|
|
/* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
|
|
|
|
could map EACCESS to ERROR_ACCESS_DENIED, I suppose
|
2006-01-20 16:16:56 +01:00
|
|
|
*/
|
2003-05-13 05:32:20 +02:00
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2011-06-07 13:10:57 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* PfCreateInterface (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI PfCreateInterface(DWORD dwName, PFFORWARD_ACTION inAction, PFFORWARD_ACTION outAction,
|
|
|
|
BOOL bUseLog, BOOL bMustBeUnique, INTERFACE_HANDLE *ppInterface)
|
|
|
|
{
|
|
|
|
FIXME("(%d %d %d %x %x %p) stub\n", dwName, inAction, outAction, bUseLog, bMustBeUnique, ppInterface);
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
2012-01-25 01:02:50 +01:00
|
|
|
|
2014-07-31 09:28:04 +02:00
|
|
|
/******************************************************************
|
|
|
|
* PfUnBindInterface (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI PfUnBindInterface(INTERFACE_HANDLE interface)
|
|
|
|
{
|
|
|
|
FIXME("(%p) stub\n", interface);
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2014-07-31 09:27:47 +02:00
|
|
|
/******************************************************************
|
|
|
|
* PfDeleteInterface(IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI PfDeleteInterface(INTERFACE_HANDLE interface)
|
|
|
|
{
|
|
|
|
FIXME("(%p) stub\n", interface);
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2014-07-31 09:26:58 +02:00
|
|
|
/******************************************************************
|
|
|
|
* PfBindInterfaceToIPAddress(IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI PfBindInterfaceToIPAddress(INTERFACE_HANDLE interface, PFADDRESSTYPE type, PBYTE ip)
|
|
|
|
{
|
|
|
|
FIXME("(%p %d %p) stub\n", interface, type, ip);
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-01-25 01:02:50 +01:00
|
|
|
/******************************************************************
|
|
|
|
* GetTcpTable2 (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
ULONG WINAPI GetTcpTable2(PMIB_TCPTABLE2 table, PULONG size, BOOL order)
|
|
|
|
{
|
|
|
|
FIXME("pTcpTable2 %p, pdwSize %p, bOrder %d: stub\n", table, size, order);
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2012-01-25 23:29:48 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetTcp6Table (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
ULONG WINAPI GetTcp6Table(PMIB_TCP6TABLE table, PULONG size, BOOL order)
|
|
|
|
{
|
2020-02-14 07:51:51 +01:00
|
|
|
TRACE("(table %p, size %p, order %d)\n", table, size, order);
|
|
|
|
return GetExtendedTcpTable(table, size, order, WS_AF_INET6, TCP_TABLE_BASIC_ALL, 0);
|
2012-01-25 23:29:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetTcp6Table2 (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
ULONG WINAPI GetTcp6Table2(PMIB_TCP6TABLE2 table, PULONG size, BOOL order)
|
|
|
|
{
|
|
|
|
FIXME("pTcp6Table2 %p, size %p, order %d: stub\n", table, size, order);
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2015-06-05 10:48:57 +02:00
|
|
|
|
2015-07-22 14:26:59 +02:00
|
|
|
/******************************************************************
|
|
|
|
* ConvertInterfaceGuidToLuid (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI ConvertInterfaceGuidToLuid(const GUID *guid, NET_LUID *luid)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
MIB_IFROW row;
|
|
|
|
|
|
|
|
TRACE("(%s %p)\n", debugstr_guid(guid), luid);
|
|
|
|
|
|
|
|
if (!guid || !luid) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
row.dwIndex = guid->Data1;
|
|
|
|
if ((ret = GetIfEntry( &row ))) return ret;
|
|
|
|
|
|
|
|
luid->Info.Reserved = 0;
|
|
|
|
luid->Info.NetLuidIndex = guid->Data1;
|
|
|
|
luid->Info.IfType = row.dwType;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* ConvertInterfaceIndexToLuid (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI ConvertInterfaceIndexToLuid(NET_IFINDEX index, NET_LUID *luid)
|
|
|
|
{
|
|
|
|
MIB_IFROW row;
|
|
|
|
|
|
|
|
TRACE("(%u %p)\n", index, luid);
|
|
|
|
|
|
|
|
if (!luid) return ERROR_INVALID_PARAMETER;
|
|
|
|
memset( luid, 0, sizeof(*luid) );
|
|
|
|
|
|
|
|
row.dwIndex = index;
|
|
|
|
if (GetIfEntry( &row )) return ERROR_FILE_NOT_FOUND;
|
|
|
|
|
|
|
|
luid->Info.Reserved = 0;
|
|
|
|
luid->Info.NetLuidIndex = index;
|
|
|
|
luid->Info.IfType = row.dwType;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2015-06-05 10:48:57 +02:00
|
|
|
/******************************************************************
|
|
|
|
* ConvertInterfaceLuidToGuid (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI ConvertInterfaceLuidToGuid(const NET_LUID *luid, GUID *guid)
|
|
|
|
{
|
2015-07-22 14:26:59 +02:00
|
|
|
DWORD ret;
|
|
|
|
MIB_IFROW row;
|
|
|
|
|
|
|
|
TRACE("(%p %p)\n", luid, guid);
|
|
|
|
|
|
|
|
if (!luid || !guid) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
row.dwIndex = luid->Info.NetLuidIndex;
|
|
|
|
if ((ret = GetIfEntry( &row ))) return ret;
|
|
|
|
|
2017-05-10 14:27:35 +02:00
|
|
|
memset( guid, 0, sizeof(*guid) );
|
2015-07-22 14:26:59 +02:00
|
|
|
guid->Data1 = luid->Info.NetLuidIndex;
|
2020-09-01 13:41:15 +02:00
|
|
|
memcpy( guid->Data4+2, "NetDev", 6 );
|
2015-07-22 14:26:59 +02:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* ConvertInterfaceLuidToIndex (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI ConvertInterfaceLuidToIndex(const NET_LUID *luid, NET_IFINDEX *index)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
MIB_IFROW row;
|
|
|
|
|
|
|
|
TRACE("(%p %p)\n", luid, index);
|
|
|
|
|
|
|
|
if (!luid || !index) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
row.dwIndex = luid->Info.NetLuidIndex;
|
|
|
|
if ((ret = GetIfEntry( &row ))) return ret;
|
|
|
|
|
|
|
|
*index = luid->Info.NetLuidIndex;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* ConvertInterfaceLuidToNameA (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI ConvertInterfaceLuidToNameA(const NET_LUID *luid, char *name, SIZE_T len)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
MIB_IFROW row;
|
|
|
|
|
|
|
|
TRACE("(%p %p %u)\n", luid, name, (DWORD)len);
|
|
|
|
|
|
|
|
if (!luid) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
row.dwIndex = luid->Info.NetLuidIndex;
|
|
|
|
if ((ret = GetIfEntry( &row ))) return ret;
|
|
|
|
|
|
|
|
if (!name || len < WideCharToMultiByte( CP_UNIXCP, 0, row.wszName, -1, NULL, 0, NULL, NULL ))
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, row.wszName, -1, name, len, NULL, NULL );
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* ConvertInterfaceLuidToNameW (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI ConvertInterfaceLuidToNameW(const NET_LUID *luid, WCHAR *name, SIZE_T len)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
MIB_IFROW row;
|
|
|
|
|
|
|
|
TRACE("(%p %p %u)\n", luid, name, (DWORD)len);
|
|
|
|
|
|
|
|
if (!luid || !name) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
row.dwIndex = luid->Info.NetLuidIndex;
|
|
|
|
if ((ret = GetIfEntry( &row ))) return ret;
|
|
|
|
|
|
|
|
if (len < strlenW( row.wszName ) + 1) return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
strcpyW( name, row.wszName );
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* ConvertInterfaceNameToLuidA (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI ConvertInterfaceNameToLuidA(const char *name, NET_LUID *luid)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
IF_INDEX index;
|
|
|
|
MIB_IFROW row;
|
|
|
|
|
|
|
|
TRACE("(%s %p)\n", debugstr_a(name), luid);
|
|
|
|
|
|
|
|
if ((ret = getInterfaceIndexByName( name, &index ))) return ERROR_INVALID_NAME;
|
|
|
|
if (!luid) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
row.dwIndex = index;
|
|
|
|
if ((ret = GetIfEntry( &row ))) return ret;
|
|
|
|
|
|
|
|
luid->Info.Reserved = 0;
|
|
|
|
luid->Info.NetLuidIndex = index;
|
|
|
|
luid->Info.IfType = row.dwType;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* ConvertInterfaceNameToLuidW (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI ConvertInterfaceNameToLuidW(const WCHAR *name, NET_LUID *luid)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
IF_INDEX index;
|
|
|
|
MIB_IFROW row;
|
|
|
|
char nameA[IF_MAX_STRING_SIZE + 1];
|
|
|
|
|
|
|
|
TRACE("(%s %p)\n", debugstr_w(name), luid);
|
|
|
|
|
|
|
|
if (!luid) return ERROR_INVALID_PARAMETER;
|
|
|
|
memset( luid, 0, sizeof(*luid) );
|
|
|
|
|
|
|
|
if (!WideCharToMultiByte( CP_UNIXCP, 0, name, -1, nameA, sizeof(nameA), NULL, NULL ))
|
|
|
|
return ERROR_INVALID_NAME;
|
|
|
|
|
|
|
|
if ((ret = getInterfaceIndexByName( nameA, &index ))) return ret;
|
|
|
|
|
|
|
|
row.dwIndex = index;
|
|
|
|
if ((ret = GetIfEntry( &row ))) return ret;
|
|
|
|
|
|
|
|
luid->Info.Reserved = 0;
|
|
|
|
luid->Info.NetLuidIndex = index;
|
|
|
|
luid->Info.IfType = row.dwType;
|
|
|
|
return NO_ERROR;
|
2015-06-05 10:48:57 +02:00
|
|
|
}
|
2017-05-24 19:09:53 +02:00
|
|
|
|
2018-03-20 18:27:04 +01:00
|
|
|
/******************************************************************
|
|
|
|
* ConvertLengthToIpv4Mask (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI ConvertLengthToIpv4Mask(ULONG mask_len, ULONG *mask)
|
|
|
|
{
|
|
|
|
if (mask_len > 32)
|
|
|
|
{
|
|
|
|
*mask = INADDR_NONE;
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask_len == 0)
|
|
|
|
*mask = 0;
|
|
|
|
else
|
|
|
|
*mask = htonl(~0u << (32 - mask_len));
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-05-24 19:09:53 +02:00
|
|
|
/******************************************************************
|
|
|
|
* if_nametoindex (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
IF_INDEX WINAPI IPHLP_if_nametoindex(const char *name)
|
|
|
|
{
|
|
|
|
IF_INDEX idx;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", name);
|
|
|
|
if (getInterfaceIndexByName(name, &idx) == NO_ERROR)
|
|
|
|
return idx;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-01-23 09:43:50 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* if_indextoname (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
PCHAR WINAPI IPHLP_if_indextoname(NET_IFINDEX index, PCHAR name)
|
|
|
|
{
|
|
|
|
TRACE("(%u, %p)\n", index, name);
|
|
|
|
|
|
|
|
return getInterfaceNameByIndex(index, name);
|
|
|
|
}
|
2018-04-13 23:11:15 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetIpForwardTable2 (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetIpForwardTable2(ADDRESS_FAMILY family, PMIB_IPFORWARD_TABLE2 *table)
|
|
|
|
{
|
|
|
|
static int once;
|
|
|
|
|
|
|
|
if (!once++) FIXME("(%u %p): stub\n", family, table);
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2018-09-25 22:59:20 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetIpNetTable2 (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetIpNetTable2(ADDRESS_FAMILY family, PMIB_IPNET_TABLE2 *table)
|
|
|
|
{
|
|
|
|
static int once;
|
|
|
|
|
|
|
|
if (!once++) FIXME("(%u %p): stub\n", family, table);
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2018-10-28 18:58:03 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetIpInterfaceTable (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetIpInterfaceTable(ADDRESS_FAMILY family, PMIB_IPINTERFACE_TABLE *table)
|
|
|
|
{
|
|
|
|
FIXME("(%u %p): stub\n", family, table);
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2019-04-28 08:13:27 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetBestRoute2 (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetBestRoute2(NET_LUID *luid, NET_IFINDEX index,
|
|
|
|
const SOCKADDR_INET *source, const SOCKADDR_INET *destination,
|
|
|
|
ULONG options, PMIB_IPFORWARD_ROW2 bestroute,
|
|
|
|
SOCKADDR_INET *bestaddress)
|
|
|
|
{
|
|
|
|
static int once;
|
|
|
|
|
|
|
|
if (!once++)
|
|
|
|
FIXME("(%p, %d, %p, %p, 0x%08x, %p, %p): stub\n", luid, index, source,
|
|
|
|
destination, options, bestroute, bestaddress);
|
|
|
|
|
|
|
|
if (!destination || !bestroute || !bestaddress)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2019-09-05 07:14:15 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* ParseNetworkString (IPHLPAPI.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI ParseNetworkString(const WCHAR *str, DWORD type,
|
|
|
|
NET_ADDRESS_INFO *info, USHORT *port, BYTE *prefix_len)
|
|
|
|
{
|
|
|
|
IN_ADDR temp_addr4;
|
2020-05-13 16:52:54 +02:00
|
|
|
IN6_ADDR temp_addr6;
|
|
|
|
ULONG temp_scope;
|
2019-09-05 07:14:15 +02:00
|
|
|
USHORT temp_port = 0;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("(%s, %d, %p, %p, %p)\n", debugstr_w(str), type, info, port, prefix_len);
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (type & NET_STRING_IPV4_ADDRESS)
|
|
|
|
{
|
|
|
|
status = RtlIpv4StringToAddressExW(str, TRUE, &temp_addr4, &temp_port);
|
|
|
|
if (SUCCEEDED(status) && !temp_port)
|
|
|
|
{
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
info->Format = NET_ADDRESS_IPV4;
|
|
|
|
info->u.Ipv4Address.sin_addr = temp_addr4;
|
|
|
|
info->u.Ipv4Address.sin_port = 0;
|
|
|
|
}
|
|
|
|
if (port) *port = 0;
|
|
|
|
if (prefix_len) *prefix_len = 255;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type & NET_STRING_IPV4_SERVICE)
|
|
|
|
{
|
|
|
|
status = RtlIpv4StringToAddressExW(str, TRUE, &temp_addr4, &temp_port);
|
|
|
|
if (SUCCEEDED(status) && temp_port)
|
|
|
|
{
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
info->Format = NET_ADDRESS_IPV4;
|
|
|
|
info->u.Ipv4Address.sin_addr = temp_addr4;
|
|
|
|
info->u.Ipv4Address.sin_port = temp_port;
|
|
|
|
}
|
|
|
|
if (port) *port = ntohs(temp_port);
|
|
|
|
if (prefix_len) *prefix_len = 255;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2020-05-13 16:52:54 +02:00
|
|
|
if (type & NET_STRING_IPV6_ADDRESS)
|
|
|
|
{
|
|
|
|
status = RtlIpv6StringToAddressExW(str, &temp_addr6, &temp_scope, &temp_port);
|
|
|
|
if (SUCCEEDED(status) && !temp_port)
|
|
|
|
{
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
info->Format = NET_ADDRESS_IPV6;
|
|
|
|
info->u.Ipv6Address.sin6_addr = temp_addr6;
|
|
|
|
info->u.Ipv6Address.sin6_scope_id = temp_scope;
|
|
|
|
info->u.Ipv6Address.sin6_port = 0;
|
|
|
|
}
|
|
|
|
if (port) *port = 0;
|
|
|
|
if (prefix_len) *prefix_len = 255;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type & NET_STRING_IPV6_SERVICE)
|
|
|
|
{
|
|
|
|
status = RtlIpv6StringToAddressExW(str, &temp_addr6, &temp_scope, &temp_port);
|
|
|
|
if (SUCCEEDED(status) && temp_port)
|
|
|
|
{
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
info->Format = NET_ADDRESS_IPV6;
|
|
|
|
info->u.Ipv6Address.sin6_addr = temp_addr6;
|
|
|
|
info->u.Ipv6Address.sin6_scope_id = temp_scope;
|
|
|
|
info->u.Ipv6Address.sin6_port = temp_port;
|
|
|
|
}
|
|
|
|
if (port) *port = ntohs(temp_port);
|
|
|
|
if (prefix_len) *prefix_len = 255;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2019-09-05 07:14:15 +02:00
|
|
|
|
|
|
|
if (info) info->Format = NET_ADDRESS_FORMAT_UNSPECIFIED;
|
|
|
|
|
2020-05-13 16:52:54 +02:00
|
|
|
if (type & ~(NET_STRING_IPV4_ADDRESS|NET_STRING_IPV4_SERVICE|NET_STRING_IPV6_ADDRESS|NET_STRING_IPV6_SERVICE))
|
2019-09-05 07:14:15 +02:00
|
|
|
{
|
|
|
|
FIXME("Unimplemented type 0x%x\n", type);
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|