2 * iphlpapi dll implementation
4 * Copyright (C) 2003,2006 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <sys/types.h>
26 #ifdef HAVE_NETINET_IN_H
27 # include <netinet/in.h>
29 #ifdef HAVE_ARPA_INET_H
30 # include <arpa/inet.h>
32 #ifdef HAVE_ARPA_NAMESER_H
33 # include <arpa/nameser.h>
39 #define NONAMELESSUNION
40 #define NONAMELESSSTRUCT
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
59 #define IF_NAMESIZE 16
63 #define INADDR_NONE ~0UL
66 /* call res_init() just once because of a bug in Mac OS X 10.4 */
67 /* Call once per thread on systems that have per-thread _res. */
68 static void initialise_resolver(void)
70 if ((_res
.options
& RES_INIT
) == 0)
74 /******************************************************************
75 * AddIPAddress (IPHLPAPI.@)
77 * Add an IP address to an adapter.
80 * Address [In] IP address to add to the adapter
81 * IpMask [In] subnet mask for the IP address
82 * IfIndex [In] adapter index to add the address
83 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
84 * NTEInstance [Out] NTE instance for the IP address
88 * Failure: error code from winerror.h
91 * Stub. Currently returns ERROR_NOT_SUPPORTED.
93 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask IpMask
, DWORD IfIndex
, PULONG NTEContext
, PULONG NTEInstance
)
96 return ERROR_NOT_SUPPORTED
;
100 /******************************************************************
101 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
103 * Get table of local interfaces.
104 * Like GetIfTable(), but allocate the returned table from heap.
107 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
108 * allocated and returned.
109 * bOrder [In] whether to sort the table
110 * heap [In] heap from which the table is allocated
111 * flags [In] flags to HeapAlloc
114 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
115 * GetIfTable() returns otherwise.
117 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
118 BOOL bOrder
, HANDLE heap
, DWORD flags
)
122 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable
,
123 bOrder
, heap
, flags
);
125 ret
= ERROR_INVALID_PARAMETER
;
129 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
130 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
131 *ppIfTable
= HeapAlloc(heap
, flags
, dwSize
);
132 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
135 TRACE("returning %d\n", ret
);
140 static int IpAddrTableSorter(const void *a
, const void *b
)
145 ret
= ((const MIB_IPADDRROW
*)a
)->dwAddr
- ((const MIB_IPADDRROW
*)b
)->dwAddr
;
152 /******************************************************************
153 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
155 * Get interface-to-IP address mapping table.
156 * Like GetIpAddrTable(), but allocate the returned table from heap.
159 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
160 * allocated and returned.
161 * bOrder [In] whether to sort the table
162 * heap [In] heap from which the table is allocated
163 * flags [In] flags to HeapAlloc
166 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
167 * failure, NO_ERROR on success.
169 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
170 BOOL bOrder
, HANDLE heap
, DWORD flags
)
174 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
175 ppIpAddrTable
, bOrder
, heap
, flags
);
176 ret
= getIPAddrTable(ppIpAddrTable
, heap
, flags
);
178 qsort((*ppIpAddrTable
)->table
, (*ppIpAddrTable
)->dwNumEntries
,
179 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
180 TRACE("returning %d\n", ret
);
185 /******************************************************************
186 * CancelIPChangeNotify (IPHLPAPI.@)
188 * Cancel a previous notification created by NotifyAddrChange or
192 * overlapped [In] overlapped structure that notifies the caller
199 * Stub, returns FALSE.
201 BOOL WINAPI
CancelIPChangeNotify(LPOVERLAPPED overlapped
)
203 FIXME("(overlapped %p): stub\n", overlapped
);
209 /******************************************************************
210 * CreateIpForwardEntry (IPHLPAPI.@)
212 * Create a route in the local computer's IP table.
215 * pRoute [In] new route information
219 * Failure: error code from winerror.h
222 * Stub, always returns NO_ERROR.
224 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
226 FIXME("(pRoute %p): stub\n", pRoute
);
227 /* could use SIOCADDRT, not sure I want to */
232 /******************************************************************
233 * CreateIpNetEntry (IPHLPAPI.@)
235 * Create entry in the ARP table.
238 * pArpEntry [In] new ARP entry
242 * Failure: error code from winerror.h
245 * Stub, always returns NO_ERROR.
247 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
249 FIXME("(pArpEntry %p)\n", pArpEntry
);
250 /* could use SIOCSARP on systems that support it, not sure I want to */
255 /******************************************************************
256 * CreateProxyArpEntry (IPHLPAPI.@)
258 * Create a Proxy ARP (PARP) entry for an IP address.
261 * dwAddress [In] IP address for which this computer acts as a proxy.
262 * dwMask [In] subnet mask for dwAddress
263 * dwIfIndex [In] interface index
267 * Failure: error code from winerror.h
270 * Stub, returns ERROR_NOT_SUPPORTED.
272 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
274 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
275 dwAddress
, dwMask
, dwIfIndex
);
276 return ERROR_NOT_SUPPORTED
;
280 /******************************************************************
281 * DeleteIPAddress (IPHLPAPI.@)
283 * Delete an IP address added with AddIPAddress().
286 * NTEContext [In] NTE context from AddIPAddress();
290 * Failure: error code from winerror.h
293 * Stub, returns ERROR_NOT_SUPPORTED.
295 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
297 FIXME("(NTEContext %d): stub\n", NTEContext
);
298 return ERROR_NOT_SUPPORTED
;
302 /******************************************************************
303 * DeleteIpForwardEntry (IPHLPAPI.@)
308 * pRoute [In] route to delete
312 * Failure: error code from winerror.h
315 * Stub, returns NO_ERROR.
317 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
319 FIXME("(pRoute %p): stub\n", pRoute
);
320 /* could use SIOCDELRT, not sure I want to */
325 /******************************************************************
326 * DeleteIpNetEntry (IPHLPAPI.@)
328 * Delete an ARP entry.
331 * pArpEntry [In] ARP entry to delete
335 * Failure: error code from winerror.h
338 * Stub, returns NO_ERROR.
340 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
342 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
343 /* could use SIOCDARP on systems that support it, not sure I want to */
348 /******************************************************************
349 * DeleteProxyArpEntry (IPHLPAPI.@)
351 * Delete a Proxy ARP entry.
354 * dwAddress [In] IP address for which this computer acts as a proxy.
355 * dwMask [In] subnet mask for dwAddress
356 * dwIfIndex [In] interface index
360 * Failure: error code from winerror.h
363 * Stub, returns ERROR_NOT_SUPPORTED.
365 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
367 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
368 dwAddress
, dwMask
, dwIfIndex
);
369 return ERROR_NOT_SUPPORTED
;
373 /******************************************************************
374 * EnableRouter (IPHLPAPI.@)
376 * Turn on ip forwarding.
380 * pOverlapped [In/Out] hEvent member should contain a valid handle.
383 * Success: ERROR_IO_PENDING
384 * Failure: error code from winerror.h
387 * Stub, returns ERROR_NOT_SUPPORTED.
389 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
391 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle
, pOverlapped
);
392 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
393 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
395 return ERROR_NOT_SUPPORTED
;
399 /******************************************************************
400 * FlushIpNetTable (IPHLPAPI.@)
402 * Delete all ARP entries of an interface
405 * dwIfIndex [In] interface index
409 * Failure: error code from winerror.h
412 * Stub, returns ERROR_NOT_SUPPORTED.
414 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
416 FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex
);
417 /* this flushes the arp cache of the given index */
418 return ERROR_NOT_SUPPORTED
;
422 /******************************************************************
423 * GetAdapterIndex (IPHLPAPI.@)
425 * Get interface index from its name.
428 * AdapterName [In] unicode string with the adapter name
429 * IfIndex [Out] returns found interface index
433 * Failure: error code from winerror.h
435 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
437 char adapterName
[MAX_ADAPTER_NAME
];
441 TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName
, IfIndex
);
442 /* The adapter name is guaranteed not to have any unicode characters, so
443 * this translation is never lossy */
444 for (i
= 0; i
< sizeof(adapterName
) - 1 && AdapterName
[i
]; i
++)
445 adapterName
[i
] = (char)AdapterName
[i
];
446 adapterName
[i
] = '\0';
447 ret
= getInterfaceIndexByName(adapterName
, IfIndex
);
448 TRACE("returning %d\n", ret
);
453 /******************************************************************
454 * GetAdaptersInfo (IPHLPAPI.@)
456 * Get information about adapters.
459 * pAdapterInfo [Out] buffer for adapter infos
460 * pOutBufLen [In] length of output buffer
464 * Failure: error code from winerror.h
466 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
470 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
472 ret
= ERROR_INVALID_PARAMETER
;
474 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
476 if (numNonLoopbackInterfaces
> 0) {
477 DWORD numIPAddresses
= getNumIPAddresses();
480 /* This may slightly overestimate the amount of space needed, because
481 * the IP addresses include the loopback address, but it's easier
482 * to make sure there's more than enough space than to make sure there's
483 * precisely enough space.
485 size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
486 size
+= numIPAddresses
* sizeof(IP_ADDR_STRING
);
487 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
489 ret
= ERROR_BUFFER_OVERFLOW
;
492 InterfaceIndexTable
*table
= NULL
;
493 PMIB_IPADDRTABLE ipAddrTable
= NULL
;
494 PMIB_IPFORWARDTABLE routeTable
= NULL
;
496 ret
= getIPAddrTable(&ipAddrTable
, GetProcessHeap(), 0);
498 ret
= AllocateAndGetIpForwardTableFromStack(&routeTable
, FALSE
, GetProcessHeap(), 0);
500 table
= getNonLoopbackInterfaceIndexTable();
502 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
503 size
+= ipAddrTable
->dwNumEntries
* sizeof(IP_ADDR_STRING
);
504 if (*pOutBufLen
< size
) {
506 ret
= ERROR_INSUFFICIENT_BUFFER
;
511 BOOL winsEnabled
= FALSE
;
512 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
513 PIP_ADDR_STRING nextIPAddr
= (PIP_ADDR_STRING
)((LPBYTE
)pAdapterInfo
514 + numNonLoopbackInterfaces
* sizeof(IP_ADAPTER_INFO
));
516 memset(pAdapterInfo
, 0, size
);
517 /* @@ Wine registry key: HKCU\Software\Wine\Network */
518 if (RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Network",
519 &hKey
) == ERROR_SUCCESS
) {
520 DWORD size
= sizeof(primaryWINS
.String
);
523 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
524 (LPBYTE
)primaryWINS
.String
, &size
);
525 addr
= inet_addr(primaryWINS
.String
);
526 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
528 size
= sizeof(secondaryWINS
.String
);
529 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
530 (LPBYTE
)secondaryWINS
.String
, &size
);
531 addr
= inet_addr(secondaryWINS
.String
);
532 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
536 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
537 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
539 PIP_ADDR_STRING currentIPAddr
= &ptr
->IpAddressList
;
540 BOOL firstIPAddr
= TRUE
;
542 /* on Win98 this is left empty, but whatever */
543 getInterfaceNameByIndex(table
->indexes
[ndx
], ptr
->AdapterName
);
544 getInterfaceNameByIndex(table
->indexes
[ndx
], ptr
->Description
);
545 ptr
->AddressLength
= sizeof(ptr
->Address
);
546 getInterfacePhysicalByIndex(table
->indexes
[ndx
],
547 &ptr
->AddressLength
, ptr
->Address
, &ptr
->Type
);
548 ptr
->Index
= table
->indexes
[ndx
];
549 for (i
= 0; i
< ipAddrTable
->dwNumEntries
; i
++) {
550 if (ipAddrTable
->table
[i
].dwIndex
== ptr
->Index
) {
552 toIPAddressString(ipAddrTable
->table
[i
].dwAddr
,
553 ptr
->IpAddressList
.IpAddress
.String
);
554 toIPAddressString(ipAddrTable
->table
[i
].dwMask
,
555 ptr
->IpAddressList
.IpMask
.String
);
559 currentIPAddr
->Next
= nextIPAddr
;
560 currentIPAddr
= nextIPAddr
;
561 toIPAddressString(ipAddrTable
->table
[i
].dwAddr
,
562 currentIPAddr
->IpAddress
.String
);
563 toIPAddressString(ipAddrTable
->table
[i
].dwMask
,
564 currentIPAddr
->IpMask
.String
);
569 /* Find first router through this interface, which we'll assume
570 * is the default gateway for this adapter */
571 for (i
= 0; i
< routeTable
->dwNumEntries
; i
++)
572 if (routeTable
->table
[i
].dwForwardIfIndex
== ptr
->Index
573 && routeTable
->table
[i
].u1
.ForwardType
==
574 MIB_IPROUTE_TYPE_INDIRECT
)
575 toIPAddressString(routeTable
->table
[i
].dwForwardNextHop
,
576 ptr
->GatewayList
.IpAddress
.String
);
578 ptr
->HaveWins
= TRUE
;
579 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
580 primaryWINS
.String
, sizeof(primaryWINS
.String
));
581 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
582 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
584 if (ndx
< table
->numIndexes
- 1)
585 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
589 ptr
->DhcpEnabled
= TRUE
;
593 HeapFree(GetProcessHeap(), 0, table
);
596 ret
= ERROR_OUTOFMEMORY
;
597 HeapFree(GetProcessHeap(), 0, routeTable
);
598 HeapFree(GetProcessHeap(), 0, ipAddrTable
);
604 TRACE("returning %d\n", ret
);
608 static DWORD
typeFromMibType(DWORD mib_type
)
612 case MIB_IF_TYPE_ETHERNET
: return IF_TYPE_ETHERNET_CSMACD
;
613 case MIB_IF_TYPE_TOKENRING
: return IF_TYPE_ISO88025_TOKENRING
;
614 case MIB_IF_TYPE_PPP
: return IF_TYPE_PPP
;
615 case MIB_IF_TYPE_LOOPBACK
: return IF_TYPE_SOFTWARE_LOOPBACK
;
616 default: return IF_TYPE_OTHER
;
620 static NET_IF_CONNECTION_TYPE
connectionTypeFromMibType(DWORD mib_type
)
624 case MIB_IF_TYPE_PPP
: return NET_IF_CONNECTION_DEMAND
;
625 case MIB_IF_TYPE_SLIP
: return NET_IF_CONNECTION_DEMAND
;
626 default: return NET_IF_CONNECTION_DEDICATED
;
630 static ULONG
v4addressesFromIndex(IF_INDEX index
, DWORD
**addrs
, ULONG
*num_addrs
)
636 if ((ret
= getIPAddrTable(&at
, GetProcessHeap(), 0))) return ret
;
637 for (i
= 0; i
< at
->dwNumEntries
; i
++)
639 if (at
->table
[i
].dwIndex
== index
) (*num_addrs
)++;
641 if (!(*addrs
= HeapAlloc(GetProcessHeap(), 0, *num_addrs
* sizeof(DWORD
))))
643 HeapFree(GetProcessHeap(), 0, at
);
644 return ERROR_OUTOFMEMORY
;
646 for (i
= 0, j
= 0; i
< at
->dwNumEntries
; i
++)
648 if (at
->table
[i
].dwIndex
== index
) (*addrs
)[j
++] = at
->table
[i
].dwAddr
;
650 HeapFree(GetProcessHeap(), 0, at
);
651 return ERROR_SUCCESS
;
654 static char *debugstr_ipv4(const in_addr_t
*in_addr
, char *buf
)
659 for (addrp
= (const BYTE
*)in_addr
;
660 addrp
- (const BYTE
*)in_addr
< sizeof(*in_addr
);
663 if (addrp
== (const BYTE
*)in_addr
+ sizeof(*in_addr
) - 1)
664 sprintf(p
, "%d", *addrp
);
666 p
+= sprintf(p
, "%d.", *addrp
);
671 static char *debugstr_ipv6(const struct WS_sockaddr_in6
*sin
, char *buf
)
673 const IN6_ADDR
*addr
= &sin
->sin6_addr
;
676 BOOL in_zero
= FALSE
;
678 for (i
= 0; i
< 7; i
++)
680 if (!addr
->u
.Word
[i
])
692 p
+= sprintf(p
, "%x:", ntohs(addr
->u
.Word
[i
]));
696 sprintf(p
, "%x", ntohs(addr
->u
.Word
[7]));
700 static ULONG
count_v4_gateways(DWORD index
, PMIB_IPFORWARDTABLE routeTable
)
702 DWORD i
, num_gateways
= 0;
704 for (i
= 0; i
< routeTable
->dwNumEntries
; i
++)
706 if (routeTable
->table
[i
].dwForwardIfIndex
== index
&&
707 routeTable
->table
[i
].u1
.ForwardType
== MIB_IPROUTE_TYPE_INDIRECT
)
713 static PMIB_IPFORWARDROW
findIPv4Gateway(DWORD index
,
714 PMIB_IPFORWARDTABLE routeTable
)
717 PMIB_IPFORWARDROW row
= NULL
;
719 for (i
= 0; !row
&& i
< routeTable
->dwNumEntries
; i
++)
721 if (routeTable
->table
[i
].dwForwardIfIndex
== index
&&
722 routeTable
->table
[i
].u1
.ForwardType
== MIB_IPROUTE_TYPE_INDIRECT
)
723 row
= &routeTable
->table
[i
];
728 static ULONG
adapterAddressesFromIndex(ULONG family
, ULONG flags
, IF_INDEX index
,
729 IP_ADAPTER_ADDRESSES
*aa
, ULONG
*size
)
731 ULONG ret
= ERROR_SUCCESS
, i
, num_v4addrs
= 0, num_v4_gateways
= 0, num_v6addrs
= 0, total_size
;
732 DWORD
*v4addrs
= NULL
;
733 SOCKET_ADDRESS
*v6addrs
= NULL
;
734 PMIB_IPFORWARDTABLE routeTable
= NULL
;
736 if (family
== WS_AF_INET
)
738 if (!(flags
& GAA_FLAG_SKIP_UNICAST
))
739 ret
= v4addressesFromIndex(index
, &v4addrs
, &num_v4addrs
);
740 if (!ret
&& flags
& GAA_FLAG_INCLUDE_ALL_GATEWAYS
)
742 ret
= AllocateAndGetIpForwardTableFromStack(&routeTable
, FALSE
,
743 GetProcessHeap(), 0);
745 num_v4_gateways
= count_v4_gateways(index
, routeTable
);
748 else if (family
== WS_AF_INET6
)
750 if (!(flags
& GAA_FLAG_SKIP_UNICAST
))
751 ret
= v6addressesFromIndex(index
, &v6addrs
, &num_v6addrs
);
753 else if (family
== WS_AF_UNSPEC
)
755 if (!(flags
& GAA_FLAG_SKIP_UNICAST
))
756 ret
= v4addressesFromIndex(index
, &v4addrs
, &num_v4addrs
);
757 if (!ret
&& flags
& GAA_FLAG_INCLUDE_ALL_GATEWAYS
)
759 ret
= AllocateAndGetIpForwardTableFromStack(&routeTable
, FALSE
,
760 GetProcessHeap(), 0);
762 num_v4_gateways
= count_v4_gateways(index
, routeTable
);
764 if (!ret
&& !(flags
& GAA_FLAG_SKIP_UNICAST
))
765 ret
= v6addressesFromIndex(index
, &v6addrs
, &num_v6addrs
);
769 FIXME("address family %u unsupported\n", family
);
774 HeapFree(GetProcessHeap(), 0, v4addrs
);
775 HeapFree(GetProcessHeap(), 0, routeTable
);
779 total_size
= sizeof(IP_ADAPTER_ADDRESSES
);
780 total_size
+= IF_NAMESIZE
;
781 total_size
+= IF_NAMESIZE
* sizeof(WCHAR
);
782 if (!(flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
783 total_size
+= IF_NAMESIZE
* sizeof(WCHAR
);
784 total_size
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
) * num_v4addrs
;
785 total_size
+= sizeof(struct sockaddr_in
) * num_v4addrs
;
786 total_size
+= (sizeof(IP_ADAPTER_GATEWAY_ADDRESS
) + sizeof(SOCKADDR_IN
)) * num_v4_gateways
;
787 total_size
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
) * num_v6addrs
;
788 total_size
+= sizeof(SOCKET_ADDRESS
) * num_v6addrs
;
789 for (i
= 0; i
< num_v6addrs
; i
++)
790 total_size
+= v6addrs
[i
].iSockaddrLength
;
792 if (aa
&& *size
>= total_size
)
794 char name
[IF_NAMESIZE
], *ptr
= (char *)aa
+ sizeof(IP_ADAPTER_ADDRESSES
), *src
;
797 INTERNAL_IF_OPER_STATUS status
;
799 memset(aa
, 0, sizeof(IP_ADAPTER_ADDRESSES
));
800 aa
->u
.s
.Length
= sizeof(IP_ADAPTER_ADDRESSES
);
801 aa
->u
.s
.IfIndex
= index
;
803 getInterfaceNameByIndex(index
, name
);
804 memcpy(ptr
, name
, IF_NAMESIZE
);
805 aa
->AdapterName
= ptr
;
807 if (!(flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
809 aa
->FriendlyName
= (WCHAR
*)ptr
;
810 for (src
= name
, dst
= (WCHAR
*)ptr
; *src
; src
++, dst
++)
815 aa
->Description
= (WCHAR
*)ptr
;
816 for (src
= name
, dst
= (WCHAR
*)ptr
; *src
; src
++, dst
++)
821 TRACE("%s: %d IPv4 addresses, %d IPv6 addresses:\n", name
, num_v4addrs
,
825 PMIB_IPFORWARDROW adapterRow
;
827 if ((adapterRow
= findIPv4Gateway(index
, routeTable
)))
829 PIP_ADAPTER_GATEWAY_ADDRESS gw
;
832 gw
= (PIP_ADAPTER_GATEWAY_ADDRESS
)ptr
;
833 aa
->FirstGatewayAddress
= gw
;
835 gw
->u
.s
.Length
= sizeof(IP_ADAPTER_GATEWAY_ADDRESS
);
836 ptr
+= sizeof(IP_ADAPTER_GATEWAY_ADDRESS
);
837 sin
= (PSOCKADDR_IN
)ptr
;
838 sin
->sin_family
= AF_INET
;
840 memcpy(&sin
->sin_addr
, &adapterRow
->dwForwardNextHop
,
842 gw
->Address
.lpSockaddr
= (LPSOCKADDR
)sin
;
843 gw
->Address
.iSockaddrLength
= sizeof(SOCKADDR_IN
);
845 ptr
+= sizeof(SOCKADDR_IN
);
850 IP_ADAPTER_UNICAST_ADDRESS
*ua
;
851 struct WS_sockaddr_in
*sa
;
852 aa
->Flags
|= IP_ADAPTER_IPV4_ENABLED
;
853 ua
= aa
->FirstUnicastAddress
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
854 for (i
= 0; i
< num_v4addrs
; i
++)
858 memset(ua
, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS
));
859 ua
->u
.s
.Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
860 ua
->Address
.iSockaddrLength
= sizeof(struct sockaddr_in
);
861 ua
->Address
.lpSockaddr
= (SOCKADDR
*)((char *)ua
+ ua
->u
.s
.Length
);
863 sa
= (struct WS_sockaddr_in
*)ua
->Address
.lpSockaddr
;
864 sa
->sin_family
= WS_AF_INET
;
865 sa
->sin_addr
.S_un
.S_addr
= v4addrs
[i
];
867 TRACE("IPv4 %d/%d: %s\n", i
+ 1, num_v4addrs
,
868 debugstr_ipv4(&sa
->sin_addr
.S_un
.S_addr
, addr_buf
));
870 ptr
+= ua
->u
.s
.Length
+ ua
->Address
.iSockaddrLength
;
871 if (i
< num_v4addrs
- 1)
873 ua
->Next
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
880 IP_ADAPTER_UNICAST_ADDRESS
*ua
;
881 struct WS_sockaddr_in6
*sa
;
883 aa
->Flags
|= IP_ADAPTER_IPV6_ENABLED
;
884 if (aa
->FirstUnicastAddress
)
886 for (ua
= aa
->FirstUnicastAddress
; ua
->Next
; ua
= ua
->Next
)
888 ua
->Next
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
889 ua
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
892 ua
= aa
->FirstUnicastAddress
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
893 for (i
= 0; i
< num_v6addrs
; i
++)
897 memset(ua
, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS
));
898 ua
->u
.s
.Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
899 ua
->Address
.iSockaddrLength
= v6addrs
[i
].iSockaddrLength
;
900 ua
->Address
.lpSockaddr
= (SOCKADDR
*)((char *)ua
+ ua
->u
.s
.Length
);
902 sa
= (struct WS_sockaddr_in6
*)ua
->Address
.lpSockaddr
;
903 memcpy(sa
, v6addrs
[i
].lpSockaddr
, sizeof(*sa
));
904 TRACE("IPv6 %d/%d: %s\n", i
+ 1, num_v6addrs
,
905 debugstr_ipv6(sa
, addr_buf
));
907 ptr
+= ua
->u
.s
.Length
+ ua
->Address
.iSockaddrLength
;
908 if (i
< num_v6addrs
- 1)
910 ua
->Next
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
916 buflen
= MAX_INTERFACE_PHYSADDR
;
917 getInterfacePhysicalByIndex(index
, &buflen
, aa
->PhysicalAddress
, &type
);
918 aa
->PhysicalAddressLength
= buflen
;
919 aa
->IfType
= typeFromMibType(type
);
920 aa
->ConnectionType
= connectionTypeFromMibType(type
);
922 getInterfaceMtuByName(name
, &aa
->Mtu
);
924 getInterfaceStatusByName(name
, &status
);
925 if (status
== MIB_IF_OPER_STATUS_OPERATIONAL
) aa
->OperStatus
= IfOperStatusUp
;
926 else if (status
== MIB_IF_OPER_STATUS_NON_OPERATIONAL
) aa
->OperStatus
= IfOperStatusDown
;
927 else aa
->OperStatus
= IfOperStatusUnknown
;
930 HeapFree(GetProcessHeap(), 0, routeTable
);
931 HeapFree(GetProcessHeap(), 0, v6addrs
);
932 HeapFree(GetProcessHeap(), 0, v4addrs
);
933 return ERROR_SUCCESS
;
936 static ULONG
get_dns_server_addresses(PIP_ADAPTER_DNS_SERVER_ADDRESS address
, ULONG
*len
)
940 initialise_resolver();
941 /* FIXME: no support for IPv6 DNS server addresses. Doing so requires
942 * sizeof SOCKADDR_STORAGE instead, and using _res._u._ext.nsaddrs when
945 size
= _res
.nscount
* (sizeof(IP_ADAPTER_DNS_SERVER_ADDRESS
) + sizeof(SOCKADDR
));
946 if (!address
|| *len
< size
)
949 return ERROR_BUFFER_OVERFLOW
;
952 if (_res
.nscount
> 0)
954 PIP_ADAPTER_DNS_SERVER_ADDRESS addr
;
957 for (i
= 0, addr
= address
; i
< _res
.nscount
&& addr
;
958 i
++, addr
= addr
->Next
)
962 addr
->Address
.iSockaddrLength
= sizeof(SOCKADDR
);
963 addr
->Address
.lpSockaddr
=
964 (LPSOCKADDR
)((PBYTE
)addr
+ sizeof(IP_ADAPTER_DNS_SERVER_ADDRESS
));
965 sin
= (SOCKADDR_IN
*)addr
->Address
.lpSockaddr
;
966 sin
->sin_family
= WS_AF_INET
;
967 sin
->sin_port
= _res
.nsaddr_list
[i
].sin_port
;
968 memcpy(&sin
->sin_addr
, &_res
.nsaddr_list
[i
].sin_addr
, sizeof(sin
->sin_addr
));
969 if (i
== _res
.nscount
- 1)
973 (PIP_ADAPTER_DNS_SERVER_ADDRESS
)((PBYTE
)addr
+
974 sizeof(IP_ADAPTER_DNS_SERVER_ADDRESS
) + sizeof(SOCKADDR
));
977 return ERROR_SUCCESS
;
980 static BOOL
is_ip_address_string(const char *str
)
985 ret
= inet_aton(str
, &in
);
989 static ULONG
get_dns_suffix(WCHAR
*suffix
, ULONG
*len
)
992 char *found_suffix
= NULL
;
994 initialise_resolver();
995 /* Always return a NULL-terminated string, even if it's empty. */
996 size
= sizeof(WCHAR
);
997 for (i
= 0, found_suffix
= NULL
;
998 !found_suffix
&& i
< MAXDNSRCH
+ 1 && _res
.dnsrch
[i
]; i
++)
1000 /* This uses a heuristic to select a DNS suffix:
1001 * the first, non-IP address string is selected.
1003 if (!is_ip_address_string(_res
.dnsrch
[i
]))
1004 found_suffix
= _res
.dnsrch
[i
];
1007 size
+= strlen(found_suffix
) * sizeof(WCHAR
);
1008 if (!suffix
|| *len
< size
)
1011 return ERROR_BUFFER_OVERFLOW
;
1018 for (p
= found_suffix
; *p
; p
++)
1022 return ERROR_SUCCESS
;
1025 ULONG WINAPI DECLSPEC_HOTPATCH
GetAdaptersAddresses(ULONG family
, ULONG flags
, PVOID reserved
,
1026 PIP_ADAPTER_ADDRESSES aa
, PULONG buflen
)
1028 InterfaceIndexTable
*table
;
1029 ULONG i
, size
, dns_server_size
, dns_suffix_size
, total_size
, ret
= ERROR_NO_DATA
;
1031 TRACE("(%d, %08x, %p, %p, %p)\n", family
, flags
, reserved
, aa
, buflen
);
1033 if (!buflen
) return ERROR_INVALID_PARAMETER
;
1035 table
= getInterfaceIndexTable();
1036 if (!table
|| !table
->numIndexes
)
1038 HeapFree(GetProcessHeap(), 0, table
);
1039 return ERROR_NO_DATA
;
1042 for (i
= 0; i
< table
->numIndexes
; i
++)
1045 if ((ret
= adapterAddressesFromIndex(family
, flags
, table
->indexes
[i
], NULL
, &size
)))
1047 HeapFree(GetProcessHeap(), 0, table
);
1052 if (!(flags
& GAA_FLAG_SKIP_DNS_SERVER
))
1054 /* Since DNS servers aren't really per adapter, get enough space for a
1055 * single copy of them.
1057 get_dns_server_addresses(NULL
, &dns_server_size
);
1058 total_size
+= dns_server_size
;
1060 /* Since DNS suffix also isn't really per adapter, get enough space for a
1061 * single copy of it.
1063 get_dns_suffix(NULL
, &dns_suffix_size
);
1064 total_size
+= dns_suffix_size
;
1065 if (aa
&& *buflen
>= total_size
)
1067 ULONG bytes_left
= size
= total_size
;
1068 PIP_ADAPTER_ADDRESSES first_aa
= aa
;
1069 PIP_ADAPTER_DNS_SERVER_ADDRESS firstDns
;
1072 for (i
= 0; i
< table
->numIndexes
; i
++)
1074 if ((ret
= adapterAddressesFromIndex(family
, flags
, table
->indexes
[i
], aa
, &size
)))
1076 HeapFree(GetProcessHeap(), 0, table
);
1079 if (i
< table
->numIndexes
- 1)
1081 aa
->Next
= (IP_ADAPTER_ADDRESSES
*)((char *)aa
+ size
);
1083 size
= bytes_left
-= size
;
1086 if (!(flags
& GAA_FLAG_SKIP_DNS_SERVER
))
1088 firstDns
= (PIP_ADAPTER_DNS_SERVER_ADDRESS
)((BYTE
*)first_aa
+ total_size
- dns_server_size
- dns_suffix_size
);
1089 get_dns_server_addresses(firstDns
, &dns_server_size
);
1090 for (aa
= first_aa
; aa
; aa
= aa
->Next
)
1092 if (aa
->IfType
!= IF_TYPE_SOFTWARE_LOOPBACK
&& aa
->OperStatus
== IfOperStatusUp
)
1093 aa
->FirstDnsServerAddress
= firstDns
;
1097 dnsSuffix
= (WCHAR
*)((BYTE
*)aa
+ total_size
- dns_suffix_size
);
1098 get_dns_suffix(dnsSuffix
, &dns_suffix_size
);
1099 for (; aa
; aa
= aa
->Next
)
1101 if (aa
->IfType
!= IF_TYPE_SOFTWARE_LOOPBACK
&& aa
->OperStatus
== IfOperStatusUp
)
1102 aa
->DnsSuffix
= dnsSuffix
;
1104 aa
->DnsSuffix
= (WCHAR
*)((BYTE
*)dnsSuffix
+ dns_suffix_size
- 2);
1106 ret
= ERROR_SUCCESS
;
1109 ret
= ERROR_BUFFER_OVERFLOW
;
1110 *buflen
= total_size
;
1112 TRACE("num adapters %u\n", table
->numIndexes
);
1113 HeapFree(GetProcessHeap(), 0, table
);
1117 /******************************************************************
1118 * GetBestInterface (IPHLPAPI.@)
1120 * Get the interface, with the best route for the given IP address.
1123 * dwDestAddr [In] IP address to search the interface for
1124 * pdwBestIfIndex [Out] found best interface
1128 * Failure: error code from winerror.h
1130 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
1132 struct WS_sockaddr_in sa_in
;
1133 memset(&sa_in
, 0, sizeof(sa_in
));
1134 sa_in
.sin_family
= AF_INET
;
1135 sa_in
.sin_addr
.S_un
.S_addr
= dwDestAddr
;
1136 return GetBestInterfaceEx((struct WS_sockaddr
*)&sa_in
, pdwBestIfIndex
);
1139 /******************************************************************
1140 * GetBestInterfaceEx (IPHLPAPI.@)
1142 * Get the interface, with the best route for the given IP address.
1145 * dwDestAddr [In] IP address to search the interface for
1146 * pdwBestIfIndex [Out] found best interface
1150 * Failure: error code from winerror.h
1152 DWORD WINAPI
GetBestInterfaceEx(struct WS_sockaddr
*pDestAddr
, PDWORD pdwBestIfIndex
)
1156 TRACE("pDestAddr %p, pdwBestIfIndex %p\n", pDestAddr
, pdwBestIfIndex
);
1157 if (!pDestAddr
|| !pdwBestIfIndex
)
1158 ret
= ERROR_INVALID_PARAMETER
;
1160 MIB_IPFORWARDROW ipRow
;
1162 if (pDestAddr
->sa_family
== AF_INET
) {
1163 ret
= GetBestRoute(((struct WS_sockaddr_in
*)pDestAddr
)->sin_addr
.S_un
.S_addr
, 0, &ipRow
);
1164 if (ret
== ERROR_SUCCESS
)
1165 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
1167 FIXME("address family %d not supported\n", pDestAddr
->sa_family
);
1168 ret
= ERROR_NOT_SUPPORTED
;
1171 TRACE("returning %d\n", ret
);
1176 /******************************************************************
1177 * GetBestRoute (IPHLPAPI.@)
1179 * Get the best route for the given IP address.
1182 * dwDestAddr [In] IP address to search the best route for
1183 * dwSourceAddr [In] optional source IP address
1184 * pBestRoute [Out] found best route
1188 * Failure: error code from winerror.h
1190 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
1192 PMIB_IPFORWARDTABLE table
;
1195 TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr
,
1196 dwSourceAddr
, pBestRoute
);
1198 return ERROR_INVALID_PARAMETER
;
1200 ret
= AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
1202 DWORD ndx
, matchedBits
, matchedNdx
= table
->dwNumEntries
;
1204 for (ndx
= 0, matchedBits
= 0; ndx
< table
->dwNumEntries
; ndx
++) {
1205 if (table
->table
[ndx
].u1
.ForwardType
!= MIB_IPROUTE_TYPE_INVALID
&&
1206 (dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
1207 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
1208 DWORD numShifts
, mask
;
1210 for (numShifts
= 0, mask
= table
->table
[ndx
].dwForwardMask
;
1211 mask
&& mask
& 1; mask
>>= 1, numShifts
++)
1213 if (numShifts
> matchedBits
) {
1214 matchedBits
= numShifts
;
1217 else if (!matchedBits
) {
1222 if (matchedNdx
< table
->dwNumEntries
) {
1223 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
1224 ret
= ERROR_SUCCESS
;
1227 /* No route matches, which can happen if there's no default route. */
1228 ret
= ERROR_HOST_UNREACHABLE
;
1230 HeapFree(GetProcessHeap(), 0, table
);
1232 TRACE("returning %d\n", ret
);
1237 /******************************************************************
1238 * GetFriendlyIfIndex (IPHLPAPI.@)
1240 * Get a "friendly" version of IfIndex, which is one that doesn't
1241 * have the top byte set. Doesn't validate whether IfIndex is a valid
1245 * IfIndex [In] interface index to get the friendly one for
1248 * A friendly version of IfIndex.
1250 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
1252 /* windows doesn't validate these, either, just makes sure the top byte is
1253 cleared. I assume my ifenum module never gives an index with the top
1255 TRACE("returning %d\n", IfIndex
);
1260 /******************************************************************
1261 * GetIfEntry (IPHLPAPI.@)
1263 * Get information about an interface.
1266 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
1267 * Out: interface information
1271 * Failure: error code from winerror.h
1273 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
1276 char nameBuf
[MAX_ADAPTER_NAME
];
1279 TRACE("pIfRow %p\n", pIfRow
);
1281 return ERROR_INVALID_PARAMETER
;
1283 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
, nameBuf
);
1285 ret
= getInterfaceEntryByName(name
, pIfRow
);
1286 if (ret
== NO_ERROR
)
1287 ret
= getInterfaceStatsByName(name
, pIfRow
);
1290 ret
= ERROR_INVALID_DATA
;
1291 TRACE("returning %d\n", ret
);
1296 static int IfTableSorter(const void *a
, const void *b
)
1301 ret
= ((const MIB_IFROW
*)a
)->dwIndex
- ((const MIB_IFROW
*)b
)->dwIndex
;
1308 /******************************************************************
1309 * GetIfTable (IPHLPAPI.@)
1311 * Get a table of local interfaces.
1314 * pIfTable [Out] buffer for local interfaces table
1315 * pdwSize [In/Out] length of output buffer
1316 * bOrder [In] whether to sort the table
1320 * Failure: error code from winerror.h
1323 * If pdwSize is less than required, the function will return
1324 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1326 * If bOrder is true, the returned table will be sorted by interface index.
1328 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
1332 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize
, pdwSize
,
1335 ret
= ERROR_INVALID_PARAMETER
;
1337 DWORD numInterfaces
= getNumInterfaces();
1338 ULONG size
= sizeof(MIB_IFTABLE
);
1340 if (numInterfaces
> 1)
1341 size
+= (numInterfaces
- 1) * sizeof(MIB_IFROW
);
1342 if (!pIfTable
|| *pdwSize
< size
) {
1344 ret
= ERROR_INSUFFICIENT_BUFFER
;
1347 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1350 size
= sizeof(MIB_IFTABLE
);
1351 if (table
->numIndexes
> 1)
1352 size
+= (table
->numIndexes
- 1) * sizeof(MIB_IFROW
);
1353 if (*pdwSize
< size
) {
1355 ret
= ERROR_INSUFFICIENT_BUFFER
;
1361 pIfTable
->dwNumEntries
= 0;
1362 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1363 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1364 GetIfEntry(&pIfTable
->table
[ndx
]);
1365 pIfTable
->dwNumEntries
++;
1368 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
1372 HeapFree(GetProcessHeap(), 0, table
);
1375 ret
= ERROR_OUTOFMEMORY
;
1378 TRACE("returning %d\n", ret
);
1383 /******************************************************************
1384 * GetInterfaceInfo (IPHLPAPI.@)
1386 * Get a list of network interface adapters.
1389 * pIfTable [Out] buffer for interface adapters
1390 * dwOutBufLen [Out] if buffer is too small, returns required size
1394 * Failure: error code from winerror.h
1397 * MSDN states this should return non-loopback interfaces only.
1399 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1403 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1405 ret
= ERROR_INVALID_PARAMETER
;
1407 DWORD numInterfaces
= getNumInterfaces();
1408 ULONG size
= sizeof(IP_INTERFACE_INFO
);
1410 if (numInterfaces
> 1)
1411 size
+= (numInterfaces
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
1412 if (!pIfTable
|| *dwOutBufLen
< size
) {
1413 *dwOutBufLen
= size
;
1414 ret
= ERROR_INSUFFICIENT_BUFFER
;
1417 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1420 size
= sizeof(IP_INTERFACE_INFO
);
1421 if (table
->numIndexes
> 1)
1422 size
+= (table
->numIndexes
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
1423 if (*dwOutBufLen
< size
) {
1424 *dwOutBufLen
= size
;
1425 ret
= ERROR_INSUFFICIENT_BUFFER
;
1429 char nameBuf
[MAX_ADAPTER_NAME
];
1431 *dwOutBufLen
= size
;
1432 pIfTable
->NumAdapters
= 0;
1433 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1434 const char *walker
, *name
;
1437 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1438 name
= getInterfaceNameByIndex(table
->indexes
[ndx
], nameBuf
);
1439 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1440 walker
&& *walker
&&
1441 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1442 walker
++, assigner
++)
1443 *assigner
= *walker
;
1445 pIfTable
->NumAdapters
++;
1449 HeapFree(GetProcessHeap(), 0, table
);
1452 ret
= ERROR_OUTOFMEMORY
;
1455 TRACE("returning %d\n", ret
);
1460 /******************************************************************
1461 * GetIpAddrTable (IPHLPAPI.@)
1463 * Get interface-to-IP address mapping table.
1466 * pIpAddrTable [Out] buffer for mapping table
1467 * pdwSize [In/Out] length of output buffer
1468 * bOrder [In] whether to sort the table
1472 * Failure: error code from winerror.h
1475 * If pdwSize is less than required, the function will return
1476 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1478 * If bOrder is true, the returned table will be sorted by the next hop and
1479 * an assortment of arbitrary parameters.
1481 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1485 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable
, pdwSize
,
1488 ret
= ERROR_INVALID_PARAMETER
;
1490 PMIB_IPADDRTABLE table
;
1492 ret
= getIPAddrTable(&table
, GetProcessHeap(), 0);
1493 if (ret
== NO_ERROR
)
1495 ULONG size
= FIELD_OFFSET(MIB_IPADDRTABLE
, table
[table
->dwNumEntries
]);
1497 if (!pIpAddrTable
|| *pdwSize
< size
) {
1499 ret
= ERROR_INSUFFICIENT_BUFFER
;
1503 memcpy(pIpAddrTable
, table
, size
);
1505 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1506 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1509 HeapFree(GetProcessHeap(), 0, table
);
1512 TRACE("returning %d\n", ret
);
1517 /******************************************************************
1518 * GetIpForwardTable (IPHLPAPI.@)
1520 * Get the route table.
1523 * pIpForwardTable [Out] buffer for route table
1524 * pdwSize [In/Out] length of output buffer
1525 * bOrder [In] whether to sort the table
1529 * Failure: error code from winerror.h
1532 * If pdwSize is less than required, the function will return
1533 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1535 * If bOrder is true, the returned table will be sorted by the next hop and
1536 * an assortment of arbitrary parameters.
1538 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1541 PMIB_IPFORWARDTABLE table
;
1543 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable
, pdwSize
, bOrder
);
1545 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1547 ret
= AllocateAndGetIpForwardTableFromStack(&table
, bOrder
, GetProcessHeap(), 0);
1549 DWORD size
= FIELD_OFFSET( MIB_IPFORWARDTABLE
, table
[table
->dwNumEntries
] );
1550 if (!pIpForwardTable
|| *pdwSize
< size
) {
1552 ret
= ERROR_INSUFFICIENT_BUFFER
;
1556 memcpy(pIpForwardTable
, table
, size
);
1558 HeapFree(GetProcessHeap(), 0, table
);
1560 TRACE("returning %d\n", ret
);
1565 /******************************************************************
1566 * GetIpNetTable (IPHLPAPI.@)
1568 * Get the IP-to-physical address mapping table.
1571 * pIpNetTable [Out] buffer for mapping table
1572 * pdwSize [In/Out] length of output buffer
1573 * bOrder [In] whether to sort the table
1577 * Failure: error code from winerror.h
1580 * If pdwSize is less than required, the function will return
1581 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1583 * If bOrder is true, the returned table will be sorted by IP address.
1585 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
1588 PMIB_IPNETTABLE table
;
1590 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
, bOrder
);
1592 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1594 ret
= AllocateAndGetIpNetTableFromStack( &table
, bOrder
, GetProcessHeap(), 0 );
1596 DWORD size
= FIELD_OFFSET( MIB_IPNETTABLE
, table
[table
->dwNumEntries
] );
1597 if (!pIpNetTable
|| *pdwSize
< size
) {
1599 ret
= ERROR_INSUFFICIENT_BUFFER
;
1603 memcpy(pIpNetTable
, table
, size
);
1605 HeapFree(GetProcessHeap(), 0, table
);
1607 TRACE("returning %d\n", ret
);
1611 /* Gets the DNS server list into the list beginning at list. Assumes that
1612 * a single server address may be placed at list if *len is at least
1613 * sizeof(IP_ADDR_STRING) long. Otherwise, list->Next is set to firstDynamic,
1614 * and assumes that all remaining DNS servers are contiguously located
1615 * beginning at firstDynamic. On input, *len is assumed to be the total number
1616 * of bytes available for all DNS servers, and is ignored if list is NULL.
1617 * On return, *len is set to the total number of bytes required for all DNS
1619 * Returns ERROR_BUFFER_OVERFLOW if *len is insufficient,
1620 * ERROR_SUCCESS otherwise.
1622 static DWORD
get_dns_server_list(PIP_ADDR_STRING list
,
1623 PIP_ADDR_STRING firstDynamic
, DWORD
*len
)
1627 initialise_resolver();
1628 size
= _res
.nscount
* sizeof(IP_ADDR_STRING
);
1629 if (!list
|| *len
< size
) {
1631 return ERROR_BUFFER_OVERFLOW
;
1634 if (_res
.nscount
> 0) {
1635 PIP_ADDR_STRING ptr
;
1638 for (i
= 0, ptr
= list
; i
< _res
.nscount
&& ptr
; i
++, ptr
= ptr
->Next
) {
1639 toIPAddressString(_res
.nsaddr_list
[i
].sin_addr
.s_addr
,
1640 ptr
->IpAddress
.String
);
1641 if (i
== _res
.nscount
- 1)
1644 ptr
->Next
= firstDynamic
;
1646 ptr
->Next
= (PIP_ADDR_STRING
)((PBYTE
)ptr
+ sizeof(IP_ADDR_STRING
));
1649 return ERROR_SUCCESS
;
1652 /******************************************************************
1653 * GetNetworkParams (IPHLPAPI.@)
1655 * Get the network parameters for the local computer.
1658 * pFixedInfo [Out] buffer for network parameters
1659 * pOutBufLen [In/Out] length of output buffer
1663 * Failure: error code from winerror.h
1666 * If pOutBufLen is less than required, the function will return
1667 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1670 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
1672 DWORD ret
, size
, serverListSize
;
1676 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
1678 return ERROR_INVALID_PARAMETER
;
1680 get_dns_server_list(NULL
, NULL
, &serverListSize
);
1681 size
= sizeof(FIXED_INFO
) + serverListSize
- sizeof(IP_ADDR_STRING
);
1682 if (!pFixedInfo
|| *pOutBufLen
< size
) {
1684 return ERROR_BUFFER_OVERFLOW
;
1687 memset(pFixedInfo
, 0, size
);
1688 size
= sizeof(pFixedInfo
->HostName
);
1689 GetComputerNameExA(ComputerNameDnsHostname
, pFixedInfo
->HostName
, &size
);
1690 size
= sizeof(pFixedInfo
->DomainName
);
1691 GetComputerNameExA(ComputerNameDnsDomain
, pFixedInfo
->DomainName
, &size
);
1692 get_dns_server_list(&pFixedInfo
->DnsServerList
,
1693 (PIP_ADDR_STRING
)((BYTE
*)pFixedInfo
+ sizeof(FIXED_INFO
)),
1695 /* Assume the first DNS server in the list is the "current" DNS server: */
1696 pFixedInfo
->CurrentDnsServer
= &pFixedInfo
->DnsServerList
;
1697 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
1698 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1699 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
1700 if (regReturn
!= ERROR_SUCCESS
)
1701 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1702 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
1704 if (regReturn
== ERROR_SUCCESS
)
1706 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
1708 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (LPBYTE
)pFixedInfo
->ScopeId
, &size
);
1712 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1713 I suppose could also check for a listener on port 53 to set EnableDns */
1715 TRACE("returning %d\n", ret
);
1720 /******************************************************************
1721 * GetNumberOfInterfaces (IPHLPAPI.@)
1723 * Get the number of interfaces.
1726 * pdwNumIf [Out] number of interfaces
1729 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1731 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
1735 TRACE("pdwNumIf %p\n", pdwNumIf
);
1737 ret
= ERROR_INVALID_PARAMETER
;
1739 *pdwNumIf
= getNumInterfaces();
1742 TRACE("returning %d\n", ret
);
1747 /******************************************************************
1748 * GetPerAdapterInfo (IPHLPAPI.@)
1750 * Get information about an adapter corresponding to an interface.
1753 * IfIndex [In] interface info
1754 * pPerAdapterInfo [Out] buffer for per adapter info
1755 * pOutBufLen [In/Out] length of output buffer
1759 * Failure: error code from winerror.h
1761 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
1763 ULONG bytesNeeded
= sizeof(IP_PER_ADAPTER_INFO
), serverListSize
= 0;
1764 DWORD ret
= NO_ERROR
;
1766 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex
, pPerAdapterInfo
, pOutBufLen
);
1768 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
1770 if (!isIfIndexLoopback(IfIndex
)) {
1771 get_dns_server_list(NULL
, NULL
, &serverListSize
);
1772 if (serverListSize
> sizeof(IP_ADDR_STRING
))
1773 bytesNeeded
+= serverListSize
- sizeof(IP_ADDR_STRING
);
1775 if (!pPerAdapterInfo
|| *pOutBufLen
< bytesNeeded
)
1777 *pOutBufLen
= bytesNeeded
;
1778 return ERROR_BUFFER_OVERFLOW
;
1781 memset(pPerAdapterInfo
, 0, bytesNeeded
);
1782 if (!isIfIndexLoopback(IfIndex
)) {
1783 ret
= get_dns_server_list(&pPerAdapterInfo
->DnsServerList
,
1784 (PIP_ADDR_STRING
)((PBYTE
)pPerAdapterInfo
+ sizeof(IP_PER_ADAPTER_INFO
)),
1786 /* Assume the first DNS server in the list is the "current" DNS server: */
1787 pPerAdapterInfo
->CurrentDnsServer
= &pPerAdapterInfo
->DnsServerList
;
1793 /******************************************************************
1794 * GetRTTAndHopCount (IPHLPAPI.@)
1796 * Get round-trip time (RTT) and hop count.
1800 * DestIpAddress [In] destination address to get the info for
1801 * HopCount [Out] retrieved hop count
1802 * MaxHops [In] maximum hops to search for the destination
1803 * RTT [Out] RTT in milliseconds
1810 * Stub, returns FALSE.
1812 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
1814 FIXME("(DestIpAddress 0x%08x, HopCount %p, MaxHops %d, RTT %p): stub\n",
1815 DestIpAddress
, HopCount
, MaxHops
, RTT
);
1820 /******************************************************************
1821 * GetTcpTable (IPHLPAPI.@)
1823 * Get the table of active TCP connections.
1826 * pTcpTable [Out] buffer for TCP connections table
1827 * pdwSize [In/Out] length of output buffer
1828 * bOrder [In] whether to order the table
1832 * Failure: error code from winerror.h
1835 * If pdwSize is less than required, the function will return
1836 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1837 * the required byte size.
1838 * If bOrder is true, the returned table will be sorted, first by
1839 * local address and port number, then by remote address and port
1842 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
1844 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable
, pdwSize
, bOrder
);
1845 return GetExtendedTcpTable(pTcpTable
, pdwSize
, bOrder
, AF_INET
, TCP_TABLE_BASIC_ALL
, 0);
1848 /******************************************************************
1849 * GetExtendedTcpTable (IPHLPAPI.@)
1851 DWORD WINAPI
GetExtendedTcpTable(PVOID pTcpTable
, PDWORD pdwSize
, BOOL bOrder
,
1852 ULONG ulAf
, TCP_TABLE_CLASS TableClass
, ULONG Reserved
)
1857 TRACE("pTcpTable %p, pdwSize %p, bOrder %d, ulAf %u, TableClass %u, Reserved %u\n",
1858 pTcpTable
, pdwSize
, bOrder
, ulAf
, TableClass
, Reserved
);
1860 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1862 if (ulAf
!= AF_INET
||
1863 (TableClass
!= TCP_TABLE_BASIC_ALL
&& TableClass
!= TCP_TABLE_OWNER_PID_ALL
))
1865 FIXME("ulAf = %u, TableClass = %u not supported\n", ulAf
, TableClass
);
1866 return ERROR_NOT_SUPPORTED
;
1868 if ((ret
= build_tcp_table(TableClass
, &table
, bOrder
, GetProcessHeap(), 0, &size
)))
1871 if (!pTcpTable
|| *pdwSize
< size
)
1874 ret
= ERROR_INSUFFICIENT_BUFFER
;
1879 memcpy(pTcpTable
, table
, size
);
1881 HeapFree(GetProcessHeap(), 0, table
);
1885 /******************************************************************
1886 * GetUdpTable (IPHLPAPI.@)
1888 * Get a table of active UDP connections.
1891 * pUdpTable [Out] buffer for UDP connections table
1892 * pdwSize [In/Out] length of output buffer
1893 * bOrder [In] whether to order the table
1897 * Failure: error code from winerror.h
1900 * If pdwSize is less than required, the function will return
1901 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1902 * required byte size.
1903 * If bOrder is true, the returned table will be sorted, first by
1904 * local address, then by local port number.
1906 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
1908 return GetExtendedUdpTable(pUdpTable
, pdwSize
, bOrder
, AF_INET
, UDP_TABLE_BASIC
, 0);
1911 /******************************************************************
1912 * GetExtendedUdpTable (IPHLPAPI.@)
1914 DWORD WINAPI
GetExtendedUdpTable(PVOID pUdpTable
, PDWORD pdwSize
, BOOL bOrder
,
1915 ULONG ulAf
, UDP_TABLE_CLASS TableClass
, ULONG Reserved
)
1920 TRACE("pUdpTable %p, pdwSize %p, bOrder %d, ulAf %u, TableClass %u, Reserved %u\n",
1921 pUdpTable
, pdwSize
, bOrder
, ulAf
, TableClass
, Reserved
);
1923 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1925 if (ulAf
!= AF_INET
||
1926 (TableClass
!= UDP_TABLE_BASIC
&& TableClass
!= UDP_TABLE_OWNER_PID
&&
1927 TableClass
!= UDP_TABLE_OWNER_MODULE
))
1929 FIXME("ulAf = %u, TableClass = %u not supported\n", ulAf
, TableClass
);
1930 return ERROR_NOT_SUPPORTED
;
1932 if (TableClass
== UDP_TABLE_OWNER_MODULE
)
1933 FIXME("UDP_TABLE_OWNER_MODULE not fully supported\n");
1935 if ((ret
= build_udp_table(TableClass
, &table
, bOrder
, GetProcessHeap(), 0, &size
)))
1938 if (!pUdpTable
|| *pdwSize
< size
)
1941 ret
= ERROR_INSUFFICIENT_BUFFER
;
1946 memcpy(pUdpTable
, table
, size
);
1948 HeapFree(GetProcessHeap(), 0, table
);
1952 /******************************************************************
1953 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1955 * This is a Win98-only function to get information on "unidirectional"
1956 * adapters. Since this is pretty nonsensical in other contexts, it
1957 * never returns anything.
1960 * pIPIfInfo [Out] buffer for adapter infos
1961 * dwOutBufLen [Out] length of the output buffer
1965 * Failure: error code from winerror.h
1968 * Stub, returns ERROR_NOT_SUPPORTED.
1970 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
1972 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
1973 /* a unidirectional adapter?? not bloody likely! */
1974 return ERROR_NOT_SUPPORTED
;
1978 /******************************************************************
1979 * IpReleaseAddress (IPHLPAPI.@)
1981 * Release an IP obtained through DHCP,
1984 * AdapterInfo [In] adapter to release IP address
1988 * Failure: error code from winerror.h
1991 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1992 * this function does nothing.
1995 * Stub, returns ERROR_NOT_SUPPORTED.
1997 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1999 FIXME("Stub AdapterInfo %p\n", AdapterInfo
);
2000 return ERROR_NOT_SUPPORTED
;
2004 /******************************************************************
2005 * IpRenewAddress (IPHLPAPI.@)
2007 * Renew an IP obtained through DHCP.
2010 * AdapterInfo [In] adapter to renew IP address
2014 * Failure: error code from winerror.h
2017 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
2018 * this function does nothing.
2021 * Stub, returns ERROR_NOT_SUPPORTED.
2023 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2025 FIXME("Stub AdapterInfo %p\n", AdapterInfo
);
2026 return ERROR_NOT_SUPPORTED
;
2030 /******************************************************************
2031 * NotifyAddrChange (IPHLPAPI.@)
2033 * Notify caller whenever the ip-interface map is changed.
2036 * Handle [Out] handle usable in asynchronous notification
2037 * overlapped [In] overlapped structure that notifies the caller
2041 * Failure: error code from winerror.h
2044 * Stub, returns ERROR_NOT_SUPPORTED.
2046 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2048 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2049 if (Handle
) *Handle
= INVALID_HANDLE_VALUE
;
2050 if (overlapped
) ((IO_STATUS_BLOCK
*) overlapped
)->u
.Status
= STATUS_PENDING
;
2051 return ERROR_IO_PENDING
;
2055 /******************************************************************
2056 * NotifyRouteChange (IPHLPAPI.@)
2058 * Notify caller whenever the ip routing table is changed.
2061 * Handle [Out] handle usable in asynchronous notification
2062 * overlapped [In] overlapped structure that notifies the caller
2066 * Failure: error code from winerror.h
2069 * Stub, returns ERROR_NOT_SUPPORTED.
2071 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2073 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2074 return ERROR_NOT_SUPPORTED
;
2078 /******************************************************************
2079 * SendARP (IPHLPAPI.@)
2081 * Send an ARP request.
2084 * DestIP [In] attempt to obtain this IP
2085 * SrcIP [In] optional sender IP address
2086 * pMacAddr [Out] buffer for the mac address
2087 * PhyAddrLen [In/Out] length of the output buffer
2091 * Failure: error code from winerror.h
2094 * Stub, returns ERROR_NOT_SUPPORTED.
2096 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
2098 FIXME("(DestIP 0x%08x, SrcIP 0x%08x, pMacAddr %p, PhyAddrLen %p): stub\n",
2099 DestIP
, SrcIP
, pMacAddr
, PhyAddrLen
);
2100 return ERROR_NOT_SUPPORTED
;
2104 /******************************************************************
2105 * SetIfEntry (IPHLPAPI.@)
2107 * Set the administrative status of an interface.
2110 * pIfRow [In] dwAdminStatus member specifies the new status.
2114 * Failure: error code from winerror.h
2117 * Stub, returns ERROR_NOT_SUPPORTED.
2119 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
2121 FIXME("(pIfRow %p): stub\n", pIfRow
);
2122 /* this is supposed to set an interface administratively up or down.
2123 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2124 this sort of down is indistinguishable from other sorts of down (e.g. no
2126 return ERROR_NOT_SUPPORTED
;
2130 /******************************************************************
2131 * SetIpForwardEntry (IPHLPAPI.@)
2133 * Modify an existing route.
2136 * pRoute [In] route with the new information
2140 * Failure: error code from winerror.h
2143 * Stub, returns NO_ERROR.
2145 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
2147 FIXME("(pRoute %p): stub\n", pRoute
);
2148 /* this is to add a route entry, how's it distinguishable from
2149 CreateIpForwardEntry?
2150 could use SIOCADDRT, not sure I want to */
2155 /******************************************************************
2156 * SetIpNetEntry (IPHLPAPI.@)
2158 * Modify an existing ARP entry.
2161 * pArpEntry [In] ARP entry with the new information
2165 * Failure: error code from winerror.h
2168 * Stub, returns NO_ERROR.
2170 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
2172 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
2173 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
2178 /******************************************************************
2179 * SetIpStatistics (IPHLPAPI.@)
2181 * Toggle IP forwarding and det the default TTL value.
2184 * pIpStats [In] IP statistics with the new information
2188 * Failure: error code from winerror.h
2191 * Stub, returns NO_ERROR.
2193 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
2195 FIXME("(pIpStats %p): stub\n", pIpStats
);
2200 /******************************************************************
2201 * SetIpTTL (IPHLPAPI.@)
2203 * Set the default TTL value.
2206 * nTTL [In] new TTL value
2210 * Failure: error code from winerror.h
2213 * Stub, returns NO_ERROR.
2215 DWORD WINAPI
SetIpTTL(UINT nTTL
)
2217 FIXME("(nTTL %d): stub\n", nTTL
);
2218 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
2219 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
2224 /******************************************************************
2225 * SetTcpEntry (IPHLPAPI.@)
2227 * Set the state of a TCP connection.
2230 * pTcpRow [In] specifies connection with new state
2234 * Failure: error code from winerror.h
2237 * Stub, returns NO_ERROR.
2239 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
2241 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
2246 /******************************************************************
2247 * UnenableRouter (IPHLPAPI.@)
2249 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2250 * if it reaches zero.
2253 * pOverlapped [In/Out] should be the same as in EnableRouter()
2254 * lpdwEnableCount [Out] optional, receives reference count
2258 * Failure: error code from winerror.h
2261 * Stub, returns ERROR_NOT_SUPPORTED.
2263 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
2265 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
2267 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
2268 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
2270 return ERROR_NOT_SUPPORTED
;
2273 /******************************************************************
2274 * PfCreateInterface (IPHLPAPI.@)
2276 DWORD WINAPI
PfCreateInterface(DWORD dwName
, PFFORWARD_ACTION inAction
, PFFORWARD_ACTION outAction
,
2277 BOOL bUseLog
, BOOL bMustBeUnique
, INTERFACE_HANDLE
*ppInterface
)
2279 FIXME("(%d %d %d %x %x %p) stub\n", dwName
, inAction
, outAction
, bUseLog
, bMustBeUnique
, ppInterface
);
2280 return ERROR_CALL_NOT_IMPLEMENTED
;
2283 /******************************************************************
2284 * GetTcpTable2 (IPHLPAPI.@)
2286 ULONG WINAPI
GetTcpTable2(PMIB_TCPTABLE2 table
, PULONG size
, BOOL order
)
2288 FIXME("pTcpTable2 %p, pdwSize %p, bOrder %d: stub\n", table
, size
, order
);
2289 return ERROR_NOT_SUPPORTED
;
2292 /******************************************************************
2293 * GetTcp6Table (IPHLPAPI.@)
2295 ULONG WINAPI
GetTcp6Table(PMIB_TCP6TABLE table
, PULONG size
, BOOL order
)
2297 FIXME("pTcp6Table %p, size %p, order %d: stub\n", table
, size
, order
);
2298 return ERROR_NOT_SUPPORTED
;
2301 /******************************************************************
2302 * GetTcp6Table2 (IPHLPAPI.@)
2304 ULONG WINAPI
GetTcp6Table2(PMIB_TCP6TABLE2 table
, PULONG size
, BOOL order
)
2306 FIXME("pTcp6Table2 %p, size %p, order %d: stub\n", table
, size
, order
);
2307 return ERROR_NOT_SUPPORTED
;