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_SYS_SOCKET_H
27 #include <sys/socket.h>
32 #ifdef HAVE_NETINET_IN_H
33 # include <netinet/in.h>
35 #ifdef HAVE_ARPA_INET_H
36 # include <arpa/inet.h>
38 #ifdef HAVE_ARPA_NAMESER_H
39 # include <arpa/nameser.h>
45 #define NONAMELESSUNION
46 #define NONAMELESSSTRUCT
57 #include "wine/debug.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
62 #define IF_NAMESIZE 16
66 #define INADDR_NONE ~0UL
69 static int resolver_initialised
;
71 /* call res_init() just once because of a bug in Mac OS X 10.4 */
72 static void initialise_resolver(void)
74 if (!resolver_initialised
)
77 resolver_initialised
= 1;
81 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
84 case DLL_PROCESS_ATTACH
:
85 DisableThreadLibraryCalls( hinstDLL
);
88 case DLL_PROCESS_DETACH
:
94 /******************************************************************
95 * AddIPAddress (IPHLPAPI.@)
97 * Add an IP address to an adapter.
100 * Address [In] IP address to add to the adapter
101 * IpMask [In] subnet mask for the IP address
102 * IfIndex [In] adapter index to add the address
103 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
104 * NTEInstance [Out] NTE instance for the IP address
108 * Failure: error code from winerror.h
111 * Stub. Currently returns ERROR_NOT_SUPPORTED.
113 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask IpMask
, DWORD IfIndex
, PULONG NTEContext
, PULONG NTEInstance
)
116 return ERROR_NOT_SUPPORTED
;
120 /******************************************************************
121 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
123 * Get table of local interfaces.
124 * Like GetIfTable(), but allocate the returned table from heap.
127 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
128 * allocated and returned.
129 * bOrder [In] whether to sort the table
130 * heap [In] heap from which the table is allocated
131 * flags [In] flags to HeapAlloc
134 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
135 * GetIfTable() returns otherwise.
137 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
138 BOOL bOrder
, HANDLE heap
, DWORD flags
)
142 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable
,
143 bOrder
, heap
, flags
);
145 ret
= ERROR_INVALID_PARAMETER
;
149 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
150 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
151 *ppIfTable
= HeapAlloc(heap
, flags
, dwSize
);
152 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
155 TRACE("returning %d\n", ret
);
160 static int IpAddrTableSorter(const void *a
, const void *b
)
165 ret
= ((const MIB_IPADDRROW
*)a
)->dwAddr
- ((const MIB_IPADDRROW
*)b
)->dwAddr
;
172 /******************************************************************
173 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
175 * Get interface-to-IP address mapping table.
176 * Like GetIpAddrTable(), but allocate the returned table from heap.
179 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
180 * allocated and returned.
181 * bOrder [In] whether to sort the table
182 * heap [In] heap from which the table is allocated
183 * flags [In] flags to HeapAlloc
186 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
187 * failure, NO_ERROR on success.
189 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
190 BOOL bOrder
, HANDLE heap
, DWORD flags
)
194 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
195 ppIpAddrTable
, bOrder
, heap
, flags
);
196 ret
= getIPAddrTable(ppIpAddrTable
, heap
, flags
);
198 qsort((*ppIpAddrTable
)->table
, (*ppIpAddrTable
)->dwNumEntries
,
199 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
200 TRACE("returning %d\n", ret
);
205 /******************************************************************
206 * CreateIpForwardEntry (IPHLPAPI.@)
208 * Create a route in the local computer's IP table.
211 * pRoute [In] new route information
215 * Failure: error code from winerror.h
218 * Stub, always returns NO_ERROR.
220 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
222 FIXME("(pRoute %p): stub\n", pRoute
);
223 /* could use SIOCADDRT, not sure I want to */
228 /******************************************************************
229 * CreateIpNetEntry (IPHLPAPI.@)
231 * Create entry in the ARP table.
234 * pArpEntry [In] new ARP entry
238 * Failure: error code from winerror.h
241 * Stub, always returns NO_ERROR.
243 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
245 FIXME("(pArpEntry %p)\n", pArpEntry
);
246 /* could use SIOCSARP on systems that support it, not sure I want to */
251 /******************************************************************
252 * CreateProxyArpEntry (IPHLPAPI.@)
254 * Create a Proxy ARP (PARP) entry for an IP address.
257 * dwAddress [In] IP address for which this computer acts as a proxy.
258 * dwMask [In] subnet mask for dwAddress
259 * dwIfIndex [In] interface index
263 * Failure: error code from winerror.h
266 * Stub, returns ERROR_NOT_SUPPORTED.
268 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
270 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
271 dwAddress
, dwMask
, dwIfIndex
);
272 return ERROR_NOT_SUPPORTED
;
276 /******************************************************************
277 * DeleteIPAddress (IPHLPAPI.@)
279 * Delete an IP address added with AddIPAddress().
282 * NTEContext [In] NTE context from AddIPAddress();
286 * Failure: error code from winerror.h
289 * Stub, returns ERROR_NOT_SUPPORTED.
291 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
293 FIXME("(NTEContext %d): stub\n", NTEContext
);
294 return ERROR_NOT_SUPPORTED
;
298 /******************************************************************
299 * DeleteIpForwardEntry (IPHLPAPI.@)
304 * pRoute [In] route to delete
308 * Failure: error code from winerror.h
311 * Stub, returns NO_ERROR.
313 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
315 FIXME("(pRoute %p): stub\n", pRoute
);
316 /* could use SIOCDELRT, not sure I want to */
321 /******************************************************************
322 * DeleteIpNetEntry (IPHLPAPI.@)
324 * Delete an ARP entry.
327 * pArpEntry [In] ARP entry to delete
331 * Failure: error code from winerror.h
334 * Stub, returns NO_ERROR.
336 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
338 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
339 /* could use SIOCDARP on systems that support it, not sure I want to */
344 /******************************************************************
345 * DeleteProxyArpEntry (IPHLPAPI.@)
347 * Delete a Proxy ARP entry.
350 * dwAddress [In] IP address for which this computer acts as a proxy.
351 * dwMask [In] subnet mask for dwAddress
352 * dwIfIndex [In] interface index
356 * Failure: error code from winerror.h
359 * Stub, returns ERROR_NOT_SUPPORTED.
361 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
363 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
364 dwAddress
, dwMask
, dwIfIndex
);
365 return ERROR_NOT_SUPPORTED
;
369 /******************************************************************
370 * EnableRouter (IPHLPAPI.@)
372 * Turn on ip forwarding.
376 * pOverlapped [In/Out] hEvent member should contain a valid handle.
379 * Success: ERROR_IO_PENDING
380 * Failure: error code from winerror.h
383 * Stub, returns ERROR_NOT_SUPPORTED.
385 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
387 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle
, pOverlapped
);
388 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
389 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
391 return ERROR_NOT_SUPPORTED
;
395 /******************************************************************
396 * FlushIpNetTable (IPHLPAPI.@)
398 * Delete all ARP entries of an interface
401 * dwIfIndex [In] interface index
405 * Failure: error code from winerror.h
408 * Stub, returns ERROR_NOT_SUPPORTED.
410 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
412 FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex
);
413 /* this flushes the arp cache of the given index */
414 return ERROR_NOT_SUPPORTED
;
418 /******************************************************************
419 * GetAdapterIndex (IPHLPAPI.@)
421 * Get interface index from its name.
424 * AdapterName [In] unicode string with the adapter name
425 * IfIndex [Out] returns found interface index
429 * Failure: error code from winerror.h
431 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
433 char adapterName
[MAX_ADAPTER_NAME
];
437 TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName
, IfIndex
);
438 /* The adapter name is guaranteed not to have any unicode characters, so
439 * this translation is never lossy */
440 for (i
= 0; i
< sizeof(adapterName
) - 1 && AdapterName
[i
]; i
++)
441 adapterName
[i
] = (char)AdapterName
[i
];
442 adapterName
[i
] = '\0';
443 ret
= getInterfaceIndexByName(adapterName
, IfIndex
);
444 TRACE("returning %d\n", ret
);
449 /******************************************************************
450 * GetAdaptersInfo (IPHLPAPI.@)
452 * Get information about adapters.
455 * pAdapterInfo [Out] buffer for adapter infos
456 * pOutBufLen [In] length of output buffer
460 * Failure: error code from winerror.h
462 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
466 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
468 ret
= ERROR_INVALID_PARAMETER
;
470 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
472 if (numNonLoopbackInterfaces
> 0) {
473 DWORD numIPAddresses
= getNumIPAddresses();
476 /* This may slightly overestimate the amount of space needed, because
477 * the IP addresses include the loopback address, but it's easier
478 * to make sure there's more than enough space than to make sure there's
479 * precisely enough space.
481 size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
482 size
+= numIPAddresses
* sizeof(IP_ADDR_STRING
);
483 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
485 ret
= ERROR_BUFFER_OVERFLOW
;
488 InterfaceIndexTable
*table
= NULL
;
489 PMIB_IPADDRTABLE ipAddrTable
= NULL
;
490 PMIB_IPFORWARDTABLE routeTable
= NULL
;
492 ret
= getIPAddrTable(&ipAddrTable
, GetProcessHeap(), 0);
494 ret
= AllocateAndGetIpForwardTableFromStack(&routeTable
, FALSE
, GetProcessHeap(), 0);
496 table
= getNonLoopbackInterfaceIndexTable();
498 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
499 size
+= ipAddrTable
->dwNumEntries
* sizeof(IP_ADDR_STRING
);
500 if (*pOutBufLen
< size
) {
502 ret
= ERROR_INSUFFICIENT_BUFFER
;
507 BOOL winsEnabled
= FALSE
;
508 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
509 PIP_ADDR_STRING nextIPAddr
= (PIP_ADDR_STRING
)((LPBYTE
)pAdapterInfo
510 + numNonLoopbackInterfaces
* sizeof(IP_ADAPTER_INFO
));
512 memset(pAdapterInfo
, 0, size
);
513 /* @@ Wine registry key: HKCU\Software\Wine\Network */
514 if (RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Network",
515 &hKey
) == ERROR_SUCCESS
) {
516 DWORD size
= sizeof(primaryWINS
.String
);
519 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
520 (LPBYTE
)primaryWINS
.String
, &size
);
521 addr
= inet_addr(primaryWINS
.String
);
522 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
524 size
= sizeof(secondaryWINS
.String
);
525 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
526 (LPBYTE
)secondaryWINS
.String
, &size
);
527 addr
= inet_addr(secondaryWINS
.String
);
528 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
532 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
533 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
535 PIP_ADDR_STRING currentIPAddr
= &ptr
->IpAddressList
;
536 BOOL firstIPAddr
= TRUE
;
538 /* on Win98 this is left empty, but whatever */
539 getInterfaceNameByIndex(table
->indexes
[ndx
], ptr
->AdapterName
);
540 getInterfaceNameByIndex(table
->indexes
[ndx
], ptr
->Description
);
541 ptr
->AddressLength
= sizeof(ptr
->Address
);
542 getInterfacePhysicalByIndex(table
->indexes
[ndx
],
543 &ptr
->AddressLength
, ptr
->Address
, &ptr
->Type
);
544 ptr
->Index
= table
->indexes
[ndx
];
545 for (i
= 0; i
< ipAddrTable
->dwNumEntries
; i
++) {
546 if (ipAddrTable
->table
[i
].dwIndex
== ptr
->Index
) {
548 toIPAddressString(ipAddrTable
->table
[i
].dwAddr
,
549 ptr
->IpAddressList
.IpAddress
.String
);
550 toIPAddressString(ipAddrTable
->table
[i
].dwMask
,
551 ptr
->IpAddressList
.IpMask
.String
);
555 currentIPAddr
->Next
= nextIPAddr
;
556 currentIPAddr
= nextIPAddr
;
557 toIPAddressString(ipAddrTable
->table
[i
].dwAddr
,
558 currentIPAddr
->IpAddress
.String
);
559 toIPAddressString(ipAddrTable
->table
[i
].dwMask
,
560 currentIPAddr
->IpMask
.String
);
565 /* Find first router through this interface, which we'll assume
566 * is the default gateway for this adapter */
567 for (i
= 0; i
< routeTable
->dwNumEntries
; i
++)
568 if (routeTable
->table
[i
].dwForwardIfIndex
== ptr
->Index
569 && routeTable
->table
[i
].dwForwardType
==
570 MIB_IPROUTE_TYPE_INDIRECT
)
571 toIPAddressString(routeTable
->table
[i
].dwForwardNextHop
,
572 ptr
->GatewayList
.IpAddress
.String
);
574 ptr
->HaveWins
= TRUE
;
575 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
576 primaryWINS
.String
, sizeof(primaryWINS
.String
));
577 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
578 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
580 if (ndx
< table
->numIndexes
- 1)
581 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
587 HeapFree(GetProcessHeap(), 0, table
);
590 ret
= ERROR_OUTOFMEMORY
;
591 HeapFree(GetProcessHeap(), 0, routeTable
);
592 HeapFree(GetProcessHeap(), 0, ipAddrTable
);
598 TRACE("returning %d\n", ret
);
602 static DWORD
typeFromMibType(DWORD mib_type
)
606 case MIB_IF_TYPE_ETHERNET
: return IF_TYPE_ETHERNET_CSMACD
;
607 case MIB_IF_TYPE_TOKENRING
: return IF_TYPE_ISO88025_TOKENRING
;
608 case MIB_IF_TYPE_PPP
: return IF_TYPE_PPP
;
609 case MIB_IF_TYPE_LOOPBACK
: return IF_TYPE_SOFTWARE_LOOPBACK
;
610 default: return IF_TYPE_OTHER
;
614 static ULONG
addressesFromIndex(DWORD index
, DWORD
**addrs
, ULONG
*num_addrs
)
620 if ((ret
= getIPAddrTable(&at
, GetProcessHeap(), 0))) return ret
;
621 for (i
= 0; i
< at
->dwNumEntries
; i
++)
623 if (at
->table
[i
].dwIndex
== index
) (*num_addrs
)++;
625 if (!(*addrs
= HeapAlloc(GetProcessHeap(), 0, *num_addrs
* sizeof(DWORD
))))
627 HeapFree(GetProcessHeap(), 0, at
);
628 return ERROR_OUTOFMEMORY
;
630 for (i
= 0, j
= 0; i
< at
->dwNumEntries
; i
++)
632 if (at
->table
[i
].dwIndex
== index
) (*addrs
)[j
++] = at
->table
[i
].dwAddr
;
634 HeapFree(GetProcessHeap(), 0, at
);
635 return ERROR_SUCCESS
;
638 static ULONG
adapterAddressesFromIndex(DWORD index
, IP_ADAPTER_ADDRESSES
*aa
, ULONG
*size
)
640 ULONG ret
, i
, num_addrs
, total_size
;
643 if ((ret
= addressesFromIndex(index
, &addrs
, &num_addrs
))) return ret
;
645 total_size
= sizeof(IP_ADAPTER_ADDRESSES
);
646 total_size
+= IF_NAMESIZE
;
647 total_size
+= IF_NAMESIZE
* sizeof(WCHAR
);
648 total_size
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
) * num_addrs
;
649 total_size
+= sizeof(struct sockaddr_in
) * num_addrs
;
651 if (aa
&& *size
>= total_size
)
653 char name
[IF_NAMESIZE
], *ptr
= (char *)aa
+ sizeof(IP_ADAPTER_ADDRESSES
), *src
;
655 DWORD buflen
, type
, status
;
657 memset(aa
, 0, sizeof(IP_ADAPTER_ADDRESSES
));
658 aa
->u
.s
.Length
= sizeof(IP_ADAPTER_ADDRESSES
);
659 aa
->u
.s
.IfIndex
= index
;
661 getInterfaceNameByIndex(index
, name
);
662 memcpy(ptr
, name
, IF_NAMESIZE
);
663 aa
->AdapterName
= ptr
;
665 aa
->FriendlyName
= (WCHAR
*)ptr
;
666 for (src
= name
, dst
= (WCHAR
*)ptr
; *src
; src
++, dst
++)
673 IP_ADAPTER_UNICAST_ADDRESS
*ua
;
674 struct sockaddr_in
*sa
;
676 ua
= aa
->FirstUnicastAddress
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
677 for (i
= 0; i
< num_addrs
; i
++)
679 memset(ua
, 0, sizeof(IP_ADAPTER_UNICAST_ADDRESS
));
680 ua
->u
.s
.Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
681 ua
->Address
.iSockaddrLength
= sizeof(struct sockaddr_in
);
682 ua
->Address
.lpSockaddr
= (SOCKADDR
*)((char *)ua
+ ua
->u
.s
.Length
);
684 sa
= (struct sockaddr_in
*)ua
->Address
.lpSockaddr
;
685 sa
->sin_family
= AF_INET
;
686 sa
->sin_addr
.s_addr
= addrs
[i
];
689 ptr
+= ua
->u
.s
.Length
+ ua
->Address
.iSockaddrLength
;
690 if (i
< num_addrs
- 1)
692 ua
->Next
= (IP_ADAPTER_UNICAST_ADDRESS
*)ptr
;
698 buflen
= MAX_INTERFACE_PHYSADDR
;
699 getInterfacePhysicalByIndex(index
, &buflen
, aa
->PhysicalAddress
, &type
);
700 aa
->PhysicalAddressLength
= buflen
;
701 aa
->IfType
= typeFromMibType(type
);
703 getInterfaceMtuByName(name
, &aa
->Mtu
);
705 getInterfaceStatusByName(name
, &status
);
706 if (status
== MIB_IF_OPER_STATUS_OPERATIONAL
) aa
->OperStatus
= IfOperStatusUp
;
707 else if (status
== MIB_IF_OPER_STATUS_NON_OPERATIONAL
) aa
->OperStatus
= IfOperStatusDown
;
708 else aa
->OperStatus
= IfOperStatusUnknown
;
711 HeapFree(GetProcessHeap(), 0, addrs
);
712 return ERROR_SUCCESS
;
715 ULONG WINAPI
GetAdaptersAddresses(ULONG family
, ULONG flags
, PVOID reserved
,
716 PIP_ADAPTER_ADDRESSES aa
, PULONG buflen
)
718 InterfaceIndexTable
*table
;
719 ULONG i
, size
, total_size
, ret
= ERROR_NO_DATA
;
721 if (!buflen
) return ERROR_INVALID_PARAMETER
;
723 if (family
== AF_INET6
|| family
== AF_UNSPEC
)
724 FIXME("no support for IPv6 addresses\n");
726 if (family
!= AF_INET
&& family
!= AF_UNSPEC
) return ERROR_NO_DATA
;
728 table
= getInterfaceIndexTable();
729 if (!table
|| !table
->numIndexes
)
731 HeapFree(GetProcessHeap(), 0, table
);
732 return ERROR_NO_DATA
;
735 for (i
= 0; i
< table
->numIndexes
; i
++)
738 if ((ret
= adapterAddressesFromIndex(table
->indexes
[i
], NULL
, &size
)))
740 HeapFree(GetProcessHeap(), 0, table
);
745 if (aa
&& *buflen
>= total_size
)
747 ULONG bytes_left
= size
= total_size
;
748 for (i
= 0; i
< table
->numIndexes
; i
++)
750 if ((ret
= adapterAddressesFromIndex(table
->indexes
[i
], aa
, &size
)))
752 HeapFree(GetProcessHeap(), 0, table
);
755 if (i
< table
->numIndexes
- 1)
757 aa
->Next
= (IP_ADAPTER_ADDRESSES
*)((char *)aa
+ size
);
759 size
= bytes_left
-= size
;
764 if (*buflen
< total_size
) ret
= ERROR_BUFFER_OVERFLOW
;
765 *buflen
= total_size
;
767 TRACE("num adapters %u\n", table
->numIndexes
);
768 HeapFree(GetProcessHeap(), 0, table
);
772 /******************************************************************
773 * GetBestInterface (IPHLPAPI.@)
775 * Get the interface, with the best route for the given IP address.
778 * dwDestAddr [In] IP address to search the interface for
779 * pdwBestIfIndex [Out] found best interface
783 * Failure: error code from winerror.h
785 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
787 struct WS_sockaddr_in sa_in
;
788 memset(&sa_in
, 0, sizeof(sa_in
));
789 sa_in
.sin_family
= AF_INET
;
790 sa_in
.sin_addr
.S_un
.S_addr
= dwDestAddr
;
791 return GetBestInterfaceEx((struct WS_sockaddr
*)&sa_in
, pdwBestIfIndex
);
794 /******************************************************************
795 * GetBestInterfaceEx (IPHLPAPI.@)
797 * Get the interface, with the best route for the given IP address.
800 * dwDestAddr [In] IP address to search the interface for
801 * pdwBestIfIndex [Out] found best interface
805 * Failure: error code from winerror.h
807 DWORD WINAPI
GetBestInterfaceEx(struct WS_sockaddr
*pDestAddr
, PDWORD pdwBestIfIndex
)
811 TRACE("pDestAddr %p, pdwBestIfIndex %p\n", pDestAddr
, pdwBestIfIndex
);
812 if (!pDestAddr
|| !pdwBestIfIndex
)
813 ret
= ERROR_INVALID_PARAMETER
;
815 MIB_IPFORWARDROW ipRow
;
817 if (pDestAddr
->sa_family
== AF_INET
) {
818 ret
= GetBestRoute(((struct WS_sockaddr_in
*)pDestAddr
)->sin_addr
.S_un
.S_addr
, 0, &ipRow
);
819 if (ret
== ERROR_SUCCESS
)
820 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
822 FIXME("address family %d not supported\n", pDestAddr
->sa_family
);
823 ret
= ERROR_NOT_SUPPORTED
;
826 TRACE("returning %d\n", ret
);
831 /******************************************************************
832 * GetBestRoute (IPHLPAPI.@)
834 * Get the best route for the given IP address.
837 * dwDestAddr [In] IP address to search the best route for
838 * dwSourceAddr [In] optional source IP address
839 * pBestRoute [Out] found best route
843 * Failure: error code from winerror.h
845 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
847 PMIB_IPFORWARDTABLE table
;
850 TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr
,
851 dwSourceAddr
, pBestRoute
);
853 return ERROR_INVALID_PARAMETER
;
855 ret
= AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
857 DWORD ndx
, matchedBits
, matchedNdx
= table
->dwNumEntries
;
859 for (ndx
= 0, matchedBits
= 0; ndx
< table
->dwNumEntries
; ndx
++) {
860 if (table
->table
[ndx
].dwForwardType
!= MIB_IPROUTE_TYPE_INVALID
&&
861 (dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
862 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
863 DWORD numShifts
, mask
;
865 for (numShifts
= 0, mask
= table
->table
[ndx
].dwForwardMask
;
866 mask
&& !(mask
& 1); mask
>>= 1, numShifts
++)
868 if (numShifts
> matchedBits
) {
869 matchedBits
= numShifts
;
872 else if (!matchedBits
&& table
->table
[ndx
].dwForwardType
==
873 MIB_IPROUTE_TYPE_INDIRECT
) {
874 /* default to a default gateway */
879 if (matchedNdx
< table
->dwNumEntries
) {
880 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
884 /* No route matches, which can happen if there's no default route. */
885 ret
= ERROR_HOST_UNREACHABLE
;
887 HeapFree(GetProcessHeap(), 0, table
);
889 TRACE("returning %d\n", ret
);
894 /******************************************************************
895 * GetFriendlyIfIndex (IPHLPAPI.@)
897 * Get a "friendly" version of IfIndex, which is one that doesn't
898 * have the top byte set. Doesn't validate whether IfIndex is a valid
902 * IfIndex [In] interface index to get the friendly one for
905 * A friendly version of IfIndex.
907 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
909 /* windows doesn't validate these, either, just makes sure the top byte is
910 cleared. I assume my ifenum module never gives an index with the top
912 TRACE("returning %d\n", IfIndex
);
917 /******************************************************************
918 * GetIfEntry (IPHLPAPI.@)
920 * Get information about an interface.
923 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
924 * Out: interface information
928 * Failure: error code from winerror.h
930 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
933 char nameBuf
[MAX_ADAPTER_NAME
];
936 TRACE("pIfRow %p\n", pIfRow
);
938 return ERROR_INVALID_PARAMETER
;
940 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
, nameBuf
);
942 ret
= getInterfaceEntryByName(name
, pIfRow
);
944 ret
= getInterfaceStatsByName(name
, pIfRow
);
947 ret
= ERROR_INVALID_DATA
;
948 TRACE("returning %d\n", ret
);
953 static int IfTableSorter(const void *a
, const void *b
)
958 ret
= ((const MIB_IFROW
*)a
)->dwIndex
- ((const MIB_IFROW
*)b
)->dwIndex
;
965 /******************************************************************
966 * GetIfTable (IPHLPAPI.@)
968 * Get a table of local interfaces.
971 * pIfTable [Out] buffer for local interfaces table
972 * pdwSize [In/Out] length of output buffer
973 * bOrder [In] whether to sort the table
977 * Failure: error code from winerror.h
980 * If pdwSize is less than required, the function will return
981 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
983 * If bOrder is true, the returned table will be sorted by interface index.
985 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
989 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize
, pdwSize
,
992 ret
= ERROR_INVALID_PARAMETER
;
994 DWORD numInterfaces
= getNumInterfaces();
995 ULONG size
= sizeof(MIB_IFTABLE
);
997 if (numInterfaces
> 1)
998 size
+= (numInterfaces
- 1) * sizeof(MIB_IFROW
);
999 if (!pIfTable
|| *pdwSize
< size
) {
1001 ret
= ERROR_INSUFFICIENT_BUFFER
;
1004 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1007 size
= sizeof(MIB_IFTABLE
);
1008 if (table
->numIndexes
> 1)
1009 size
+= (table
->numIndexes
- 1) * sizeof(MIB_IFROW
);
1010 if (*pdwSize
< size
) {
1012 ret
= ERROR_INSUFFICIENT_BUFFER
;
1018 pIfTable
->dwNumEntries
= 0;
1019 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1020 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1021 GetIfEntry(&pIfTable
->table
[ndx
]);
1022 pIfTable
->dwNumEntries
++;
1025 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
1029 HeapFree(GetProcessHeap(), 0, table
);
1032 ret
= ERROR_OUTOFMEMORY
;
1035 TRACE("returning %d\n", ret
);
1040 /******************************************************************
1041 * GetInterfaceInfo (IPHLPAPI.@)
1043 * Get a list of network interface adapters.
1046 * pIfTable [Out] buffer for interface adapters
1047 * dwOutBufLen [Out] if buffer is too small, returns required size
1051 * Failure: error code from winerror.h
1054 * MSDN states this should return non-loopback interfaces only.
1056 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1060 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1062 ret
= ERROR_INVALID_PARAMETER
;
1064 DWORD numInterfaces
= getNumInterfaces();
1065 ULONG size
= sizeof(IP_INTERFACE_INFO
);
1067 if (numInterfaces
> 1)
1068 size
+= (numInterfaces
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
1069 if (!pIfTable
|| *dwOutBufLen
< size
) {
1070 *dwOutBufLen
= size
;
1071 ret
= ERROR_INSUFFICIENT_BUFFER
;
1074 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1077 size
= sizeof(IP_INTERFACE_INFO
);
1078 if (table
->numIndexes
> 1)
1079 size
+= (table
->numIndexes
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
1080 if (*dwOutBufLen
< size
) {
1081 *dwOutBufLen
= size
;
1082 ret
= ERROR_INSUFFICIENT_BUFFER
;
1086 char nameBuf
[MAX_ADAPTER_NAME
];
1088 *dwOutBufLen
= size
;
1089 pIfTable
->NumAdapters
= 0;
1090 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1091 const char *walker
, *name
;
1094 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1095 name
= getInterfaceNameByIndex(table
->indexes
[ndx
], nameBuf
);
1096 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1097 walker
&& *walker
&&
1098 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1099 walker
++, assigner
++)
1100 *assigner
= *walker
;
1102 pIfTable
->NumAdapters
++;
1106 HeapFree(GetProcessHeap(), 0, table
);
1109 ret
= ERROR_OUTOFMEMORY
;
1112 TRACE("returning %d\n", ret
);
1117 /******************************************************************
1118 * GetIpAddrTable (IPHLPAPI.@)
1120 * Get interface-to-IP address mapping table.
1123 * pIpAddrTable [Out] buffer for mapping table
1124 * pdwSize [In/Out] length of output buffer
1125 * bOrder [In] whether to sort the table
1129 * Failure: error code from winerror.h
1132 * If pdwSize is less than required, the function will return
1133 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1135 * If bOrder is true, the returned table will be sorted by the next hop and
1136 * an assortment of arbitrary parameters.
1138 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1142 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable
, pdwSize
,
1145 ret
= ERROR_INVALID_PARAMETER
;
1147 PMIB_IPADDRTABLE table
;
1149 ret
= getIPAddrTable(&table
, GetProcessHeap(), 0);
1150 if (ret
== NO_ERROR
)
1152 ULONG size
= sizeof(MIB_IPADDRTABLE
);
1154 if (table
->dwNumEntries
> 1)
1155 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPADDRROW
);
1156 if (!pIpAddrTable
|| *pdwSize
< size
) {
1158 ret
= ERROR_INSUFFICIENT_BUFFER
;
1162 memcpy(pIpAddrTable
, table
, size
);
1164 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1165 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1168 HeapFree(GetProcessHeap(), 0, table
);
1171 TRACE("returning %d\n", ret
);
1176 /******************************************************************
1177 * GetIpForwardTable (IPHLPAPI.@)
1179 * Get the route table.
1182 * pIpForwardTable [Out] buffer for route table
1183 * pdwSize [In/Out] length of output buffer
1184 * bOrder [In] whether to sort the table
1188 * Failure: error code from winerror.h
1191 * If pdwSize is less than required, the function will return
1192 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1194 * If bOrder is true, the returned table will be sorted by the next hop and
1195 * an assortment of arbitrary parameters.
1197 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1200 PMIB_IPFORWARDTABLE table
;
1202 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable
, pdwSize
, bOrder
);
1204 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1206 ret
= AllocateAndGetIpForwardTableFromStack(&table
, bOrder
, GetProcessHeap(), 0);
1208 DWORD size
= FIELD_OFFSET( MIB_IPFORWARDTABLE
, table
[table
->dwNumEntries
] );
1209 if (!pIpForwardTable
|| *pdwSize
< size
) {
1211 ret
= ERROR_INSUFFICIENT_BUFFER
;
1215 memcpy(pIpForwardTable
, table
, size
);
1217 HeapFree(GetProcessHeap(), 0, table
);
1219 TRACE("returning %d\n", ret
);
1224 /******************************************************************
1225 * GetIpNetTable (IPHLPAPI.@)
1227 * Get the IP-to-physical address mapping table.
1230 * pIpNetTable [Out] buffer for mapping table
1231 * pdwSize [In/Out] length of output buffer
1232 * bOrder [In] whether to sort the table
1236 * Failure: error code from winerror.h
1239 * If pdwSize is less than required, the function will return
1240 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1242 * If bOrder is true, the returned table will be sorted by IP address.
1244 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
1247 PMIB_IPNETTABLE table
;
1249 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
, bOrder
);
1251 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1253 ret
= AllocateAndGetIpNetTableFromStack( &table
, bOrder
, GetProcessHeap(), 0 );
1255 DWORD size
= FIELD_OFFSET( MIB_IPNETTABLE
, table
[table
->dwNumEntries
] );
1256 if (!pIpNetTable
|| *pdwSize
< size
) {
1258 ret
= ERROR_INSUFFICIENT_BUFFER
;
1262 memcpy(pIpNetTable
, table
, size
);
1264 HeapFree(GetProcessHeap(), 0, table
);
1266 TRACE("returning %d\n", ret
);
1271 /******************************************************************
1272 * GetNetworkParams (IPHLPAPI.@)
1274 * Get the network parameters for the local computer.
1277 * pFixedInfo [Out] buffer for network parameters
1278 * pOutBufLen [In/Out] length of output buffer
1282 * Failure: error code from winerror.h
1285 * If pOutBufLen is less than required, the function will return
1286 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1289 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
1295 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
1297 return ERROR_INVALID_PARAMETER
;
1299 initialise_resolver();
1300 size
= sizeof(FIXED_INFO
) + (_res
.nscount
> 0 ? (_res
.nscount
- 1) *
1301 sizeof(IP_ADDR_STRING
) : 0);
1302 if (!pFixedInfo
|| *pOutBufLen
< size
) {
1304 return ERROR_BUFFER_OVERFLOW
;
1307 memset(pFixedInfo
, 0, size
);
1308 size
= sizeof(pFixedInfo
->HostName
);
1309 GetComputerNameExA(ComputerNameDnsHostname
, pFixedInfo
->HostName
, &size
);
1310 size
= sizeof(pFixedInfo
->DomainName
);
1311 GetComputerNameExA(ComputerNameDnsDomain
, pFixedInfo
->DomainName
, &size
);
1312 if (_res
.nscount
> 0) {
1313 PIP_ADDR_STRING ptr
;
1316 for (i
= 0, ptr
= &pFixedInfo
->DnsServerList
; i
< _res
.nscount
&& ptr
;
1317 i
++, ptr
= ptr
->Next
) {
1318 toIPAddressString(_res
.nsaddr_list
[i
].sin_addr
.s_addr
,
1319 ptr
->IpAddress
.String
);
1320 if (i
== _res
.nscount
- 1)
1323 ptr
->Next
= (PIP_ADDR_STRING
)((LPBYTE
)pFixedInfo
+ sizeof(FIXED_INFO
));
1325 ptr
->Next
= (PIP_ADDR_STRING
)((PBYTE
)ptr
+ sizeof(IP_ADDR_STRING
));
1328 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
1329 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1330 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
1331 if (regReturn
!= ERROR_SUCCESS
)
1332 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1333 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
1335 if (regReturn
== ERROR_SUCCESS
)
1337 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
1339 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (LPBYTE
)pFixedInfo
->ScopeId
, &size
);
1343 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1344 I suppose could also check for a listener on port 53 to set EnableDns */
1346 TRACE("returning %d\n", ret
);
1351 /******************************************************************
1352 * GetNumberOfInterfaces (IPHLPAPI.@)
1354 * Get the number of interfaces.
1357 * pdwNumIf [Out] number of interfaces
1360 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1362 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
1366 TRACE("pdwNumIf %p\n", pdwNumIf
);
1368 ret
= ERROR_INVALID_PARAMETER
;
1370 *pdwNumIf
= getNumInterfaces();
1373 TRACE("returning %d\n", ret
);
1378 /******************************************************************
1379 * GetPerAdapterInfo (IPHLPAPI.@)
1381 * Get information about an adapter corresponding to an interface.
1384 * IfIndex [In] interface info
1385 * pPerAdapterInfo [Out] buffer for per adapter info
1386 * pOutBufLen [In/Out] length of output buffer
1390 * Failure: error code from winerror.h
1393 * Stub, returns empty IP_PER_ADAPTER_INFO in every case.
1395 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
1397 ULONG bytesNeeded
= sizeof(IP_PER_ADAPTER_INFO
);
1399 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex
, pPerAdapterInfo
, pOutBufLen
);
1401 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
1403 if (!pPerAdapterInfo
|| *pOutBufLen
< bytesNeeded
)
1405 *pOutBufLen
= bytesNeeded
;
1406 return ERROR_BUFFER_OVERFLOW
;
1409 memset(pPerAdapterInfo
, 0, bytesNeeded
);
1414 /******************************************************************
1415 * GetRTTAndHopCount (IPHLPAPI.@)
1417 * Get round-trip time (RTT) and hop count.
1421 * DestIpAddress [In] destination address to get the info for
1422 * HopCount [Out] retrieved hop count
1423 * MaxHops [In] maximum hops to search for the destination
1424 * RTT [Out] RTT in milliseconds
1431 * Stub, returns FALSE.
1433 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
1435 FIXME("(DestIpAddress 0x%08x, HopCount %p, MaxHops %d, RTT %p): stub\n",
1436 DestIpAddress
, HopCount
, MaxHops
, RTT
);
1441 /******************************************************************
1442 * GetTcpTable (IPHLPAPI.@)
1444 * Get the table of active TCP connections.
1447 * pTcpTable [Out] buffer for TCP connections table
1448 * pdwSize [In/Out] length of output buffer
1449 * bOrder [In] whether to order the table
1453 * Failure: error code from winerror.h
1456 * If pdwSize is less than required, the function will return
1457 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1458 * the required byte size.
1459 * If bOrder is true, the returned table will be sorted, first by
1460 * local address and port number, then by remote address and port
1463 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
1466 PMIB_TCPTABLE table
;
1468 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable
, pdwSize
, bOrder
);
1470 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1472 ret
= AllocateAndGetTcpTableFromStack(&table
, bOrder
, GetProcessHeap(), 0);
1474 DWORD size
= FIELD_OFFSET( MIB_TCPTABLE
, table
[table
->dwNumEntries
] );
1475 if (!pTcpTable
|| *pdwSize
< size
) {
1477 ret
= ERROR_INSUFFICIENT_BUFFER
;
1481 memcpy(pTcpTable
, table
, size
);
1483 HeapFree(GetProcessHeap(), 0, table
);
1485 TRACE("returning %d\n", ret
);
1490 /******************************************************************
1491 * GetUdpTable (IPHLPAPI.@)
1493 * Get a table of active UDP connections.
1496 * pUdpTable [Out] buffer for UDP connections table
1497 * pdwSize [In/Out] length of output buffer
1498 * bOrder [In] whether to order the table
1502 * Failure: error code from winerror.h
1505 * If pdwSize is less than required, the function will return
1506 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1507 * required byte size.
1508 * If bOrder is true, the returned table will be sorted, first by
1509 * local address, then by local port number.
1511 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
1514 PMIB_UDPTABLE table
;
1516 TRACE("pUdpTable %p, pdwSize %p, bOrder %d\n", pUdpTable
, pdwSize
, bOrder
);
1518 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1520 ret
= AllocateAndGetUdpTableFromStack( &table
, bOrder
, GetProcessHeap(), 0 );
1522 DWORD size
= FIELD_OFFSET( MIB_UDPTABLE
, table
[table
->dwNumEntries
] );
1523 if (!pUdpTable
|| *pdwSize
< size
) {
1525 ret
= ERROR_INSUFFICIENT_BUFFER
;
1529 memcpy(pUdpTable
, table
, size
);
1531 HeapFree(GetProcessHeap(), 0, table
);
1533 TRACE("returning %d\n", ret
);
1538 /******************************************************************
1539 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1541 * This is a Win98-only function to get information on "unidirectional"
1542 * adapters. Since this is pretty nonsensical in other contexts, it
1543 * never returns anything.
1546 * pIPIfInfo [Out] buffer for adapter infos
1547 * dwOutBufLen [Out] length of the output buffer
1551 * Failure: error code from winerror.h
1554 * Stub, returns ERROR_NOT_SUPPORTED.
1556 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
1558 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
1559 /* a unidirectional adapter?? not bloody likely! */
1560 return ERROR_NOT_SUPPORTED
;
1564 /******************************************************************
1565 * IpReleaseAddress (IPHLPAPI.@)
1567 * Release an IP obtained through DHCP,
1570 * AdapterInfo [In] adapter to release IP address
1574 * Failure: error code from winerror.h
1577 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1578 * this function does nothing.
1581 * Stub, returns ERROR_NOT_SUPPORTED.
1583 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1585 TRACE("AdapterInfo %p\n", AdapterInfo
);
1586 /* not a stub, never going to support this (and I never mark an adapter as
1587 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1588 return ERROR_NOT_SUPPORTED
;
1592 /******************************************************************
1593 * IpRenewAddress (IPHLPAPI.@)
1595 * Renew an IP obtained through DHCP.
1598 * AdapterInfo [In] adapter to renew IP address
1602 * Failure: error code from winerror.h
1605 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1606 * this function does nothing.
1609 * Stub, returns ERROR_NOT_SUPPORTED.
1611 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1613 TRACE("AdapterInfo %p\n", AdapterInfo
);
1614 /* not a stub, never going to support this (and I never mark an adapter as
1615 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1616 return ERROR_NOT_SUPPORTED
;
1620 /******************************************************************
1621 * NotifyAddrChange (IPHLPAPI.@)
1623 * Notify caller whenever the ip-interface map is changed.
1626 * Handle [Out] handle usable in asynchronous notification
1627 * overlapped [In] overlapped structure that notifies the caller
1631 * Failure: error code from winerror.h
1634 * Stub, returns ERROR_NOT_SUPPORTED.
1636 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
1638 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
1639 return ERROR_NOT_SUPPORTED
;
1643 /******************************************************************
1644 * NotifyRouteChange (IPHLPAPI.@)
1646 * Notify caller whenever the ip routing table is changed.
1649 * Handle [Out] handle usable in asynchronous notification
1650 * overlapped [In] overlapped structure that notifies the caller
1654 * Failure: error code from winerror.h
1657 * Stub, returns ERROR_NOT_SUPPORTED.
1659 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
1661 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
1662 return ERROR_NOT_SUPPORTED
;
1666 /******************************************************************
1667 * SendARP (IPHLPAPI.@)
1669 * Send an ARP request.
1672 * DestIP [In] attempt to obtain this IP
1673 * SrcIP [In] optional sender IP address
1674 * pMacAddr [Out] buffer for the mac address
1675 * PhyAddrLen [In/Out] length of the output buffer
1679 * Failure: error code from winerror.h
1682 * Stub, returns ERROR_NOT_SUPPORTED.
1684 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
1686 FIXME("(DestIP 0x%08x, SrcIP 0x%08x, pMacAddr %p, PhyAddrLen %p): stub\n",
1687 DestIP
, SrcIP
, pMacAddr
, PhyAddrLen
);
1688 return ERROR_NOT_SUPPORTED
;
1692 /******************************************************************
1693 * SetIfEntry (IPHLPAPI.@)
1695 * Set the administrative status of an interface.
1698 * pIfRow [In] dwAdminStatus member specifies the new status.
1702 * Failure: error code from winerror.h
1705 * Stub, returns ERROR_NOT_SUPPORTED.
1707 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
1709 FIXME("(pIfRow %p): stub\n", pIfRow
);
1710 /* this is supposed to set an interface administratively up or down.
1711 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1712 this sort of down is indistinguishable from other sorts of down (e.g. no
1714 return ERROR_NOT_SUPPORTED
;
1718 /******************************************************************
1719 * SetIpForwardEntry (IPHLPAPI.@)
1721 * Modify an existing route.
1724 * pRoute [In] route with the new information
1728 * Failure: error code from winerror.h
1731 * Stub, returns NO_ERROR.
1733 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
1735 FIXME("(pRoute %p): stub\n", pRoute
);
1736 /* this is to add a route entry, how's it distinguishable from
1737 CreateIpForwardEntry?
1738 could use SIOCADDRT, not sure I want to */
1743 /******************************************************************
1744 * SetIpNetEntry (IPHLPAPI.@)
1746 * Modify an existing ARP entry.
1749 * pArpEntry [In] ARP entry with the new information
1753 * Failure: error code from winerror.h
1756 * Stub, returns NO_ERROR.
1758 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
1760 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
1761 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1766 /******************************************************************
1767 * SetIpStatistics (IPHLPAPI.@)
1769 * Toggle IP forwarding and det the default TTL value.
1772 * pIpStats [In] IP statistics with the new information
1776 * Failure: error code from winerror.h
1779 * Stub, returns NO_ERROR.
1781 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
1783 FIXME("(pIpStats %p): stub\n", pIpStats
);
1788 /******************************************************************
1789 * SetIpTTL (IPHLPAPI.@)
1791 * Set the default TTL value.
1794 * nTTL [In] new TTL value
1798 * Failure: error code from winerror.h
1801 * Stub, returns NO_ERROR.
1803 DWORD WINAPI
SetIpTTL(UINT nTTL
)
1805 FIXME("(nTTL %d): stub\n", nTTL
);
1806 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1807 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1812 /******************************************************************
1813 * SetTcpEntry (IPHLPAPI.@)
1815 * Set the state of a TCP connection.
1818 * pTcpRow [In] specifies connection with new state
1822 * Failure: error code from winerror.h
1825 * Stub, returns NO_ERROR.
1827 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
1829 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
1834 /******************************************************************
1835 * UnenableRouter (IPHLPAPI.@)
1837 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
1838 * if it reaches zero.
1841 * pOverlapped [In/Out] should be the same as in EnableRouter()
1842 * lpdwEnableCount [Out] optional, receives reference count
1846 * Failure: error code from winerror.h
1849 * Stub, returns ERROR_NOT_SUPPORTED.
1851 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
1853 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
1855 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
1856 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
1858 return ERROR_NOT_SUPPORTED
;