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
) {
877 if (matchedNdx
< table
->dwNumEntries
) {
878 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
882 /* No route matches, which can happen if there's no default route. */
883 ret
= ERROR_HOST_UNREACHABLE
;
885 HeapFree(GetProcessHeap(), 0, table
);
887 TRACE("returning %d\n", ret
);
892 /******************************************************************
893 * GetFriendlyIfIndex (IPHLPAPI.@)
895 * Get a "friendly" version of IfIndex, which is one that doesn't
896 * have the top byte set. Doesn't validate whether IfIndex is a valid
900 * IfIndex [In] interface index to get the friendly one for
903 * A friendly version of IfIndex.
905 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
907 /* windows doesn't validate these, either, just makes sure the top byte is
908 cleared. I assume my ifenum module never gives an index with the top
910 TRACE("returning %d\n", IfIndex
);
915 /******************************************************************
916 * GetIfEntry (IPHLPAPI.@)
918 * Get information about an interface.
921 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
922 * Out: interface information
926 * Failure: error code from winerror.h
928 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
931 char nameBuf
[MAX_ADAPTER_NAME
];
934 TRACE("pIfRow %p\n", pIfRow
);
936 return ERROR_INVALID_PARAMETER
;
938 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
, nameBuf
);
940 ret
= getInterfaceEntryByName(name
, pIfRow
);
942 ret
= getInterfaceStatsByName(name
, pIfRow
);
945 ret
= ERROR_INVALID_DATA
;
946 TRACE("returning %d\n", ret
);
951 static int IfTableSorter(const void *a
, const void *b
)
956 ret
= ((const MIB_IFROW
*)a
)->dwIndex
- ((const MIB_IFROW
*)b
)->dwIndex
;
963 /******************************************************************
964 * GetIfTable (IPHLPAPI.@)
966 * Get a table of local interfaces.
969 * pIfTable [Out] buffer for local interfaces table
970 * pdwSize [In/Out] length of output buffer
971 * bOrder [In] whether to sort the table
975 * Failure: error code from winerror.h
978 * If pdwSize is less than required, the function will return
979 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
981 * If bOrder is true, the returned table will be sorted by interface index.
983 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
987 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize
, pdwSize
,
990 ret
= ERROR_INVALID_PARAMETER
;
992 DWORD numInterfaces
= getNumInterfaces();
993 ULONG size
= sizeof(MIB_IFTABLE
);
995 if (numInterfaces
> 1)
996 size
+= (numInterfaces
- 1) * sizeof(MIB_IFROW
);
997 if (!pIfTable
|| *pdwSize
< size
) {
999 ret
= ERROR_INSUFFICIENT_BUFFER
;
1002 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1005 size
= sizeof(MIB_IFTABLE
);
1006 if (table
->numIndexes
> 1)
1007 size
+= (table
->numIndexes
- 1) * sizeof(MIB_IFROW
);
1008 if (*pdwSize
< size
) {
1010 ret
= ERROR_INSUFFICIENT_BUFFER
;
1016 pIfTable
->dwNumEntries
= 0;
1017 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1018 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1019 GetIfEntry(&pIfTable
->table
[ndx
]);
1020 pIfTable
->dwNumEntries
++;
1023 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
1027 HeapFree(GetProcessHeap(), 0, table
);
1030 ret
= ERROR_OUTOFMEMORY
;
1033 TRACE("returning %d\n", ret
);
1038 /******************************************************************
1039 * GetInterfaceInfo (IPHLPAPI.@)
1041 * Get a list of network interface adapters.
1044 * pIfTable [Out] buffer for interface adapters
1045 * dwOutBufLen [Out] if buffer is too small, returns required size
1049 * Failure: error code from winerror.h
1052 * MSDN states this should return non-loopback interfaces only.
1054 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1058 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1060 ret
= ERROR_INVALID_PARAMETER
;
1062 DWORD numInterfaces
= getNumInterfaces();
1063 ULONG size
= sizeof(IP_INTERFACE_INFO
);
1065 if (numInterfaces
> 1)
1066 size
+= (numInterfaces
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
1067 if (!pIfTable
|| *dwOutBufLen
< size
) {
1068 *dwOutBufLen
= size
;
1069 ret
= ERROR_INSUFFICIENT_BUFFER
;
1072 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1075 size
= sizeof(IP_INTERFACE_INFO
);
1076 if (table
->numIndexes
> 1)
1077 size
+= (table
->numIndexes
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
1078 if (*dwOutBufLen
< size
) {
1079 *dwOutBufLen
= size
;
1080 ret
= ERROR_INSUFFICIENT_BUFFER
;
1084 char nameBuf
[MAX_ADAPTER_NAME
];
1086 *dwOutBufLen
= size
;
1087 pIfTable
->NumAdapters
= 0;
1088 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1089 const char *walker
, *name
;
1092 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1093 name
= getInterfaceNameByIndex(table
->indexes
[ndx
], nameBuf
);
1094 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1095 walker
&& *walker
&&
1096 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1097 walker
++, assigner
++)
1098 *assigner
= *walker
;
1100 pIfTable
->NumAdapters
++;
1104 HeapFree(GetProcessHeap(), 0, table
);
1107 ret
= ERROR_OUTOFMEMORY
;
1110 TRACE("returning %d\n", ret
);
1115 /******************************************************************
1116 * GetIpAddrTable (IPHLPAPI.@)
1118 * Get interface-to-IP address mapping table.
1121 * pIpAddrTable [Out] buffer for mapping table
1122 * pdwSize [In/Out] length of output buffer
1123 * bOrder [In] whether to sort the table
1127 * Failure: error code from winerror.h
1130 * If pdwSize is less than required, the function will return
1131 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1133 * If bOrder is true, the returned table will be sorted by the next hop and
1134 * an assortment of arbitrary parameters.
1136 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1140 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable
, pdwSize
,
1143 ret
= ERROR_INVALID_PARAMETER
;
1145 PMIB_IPADDRTABLE table
;
1147 ret
= getIPAddrTable(&table
, GetProcessHeap(), 0);
1148 if (ret
== NO_ERROR
)
1150 ULONG size
= sizeof(MIB_IPADDRTABLE
);
1152 if (table
->dwNumEntries
> 1)
1153 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPADDRROW
);
1154 if (!pIpAddrTable
|| *pdwSize
< size
) {
1156 ret
= ERROR_INSUFFICIENT_BUFFER
;
1160 memcpy(pIpAddrTable
, table
, size
);
1162 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1163 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1166 HeapFree(GetProcessHeap(), 0, table
);
1169 TRACE("returning %d\n", ret
);
1174 /******************************************************************
1175 * GetIpForwardTable (IPHLPAPI.@)
1177 * Get the route table.
1180 * pIpForwardTable [Out] buffer for route table
1181 * pdwSize [In/Out] length of output buffer
1182 * bOrder [In] whether to sort the table
1186 * Failure: error code from winerror.h
1189 * If pdwSize is less than required, the function will return
1190 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1192 * If bOrder is true, the returned table will be sorted by the next hop and
1193 * an assortment of arbitrary parameters.
1195 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1198 PMIB_IPFORWARDTABLE table
;
1200 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable
, pdwSize
, bOrder
);
1202 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1204 ret
= AllocateAndGetIpForwardTableFromStack(&table
, bOrder
, GetProcessHeap(), 0);
1206 DWORD size
= FIELD_OFFSET( MIB_IPFORWARDTABLE
, table
[table
->dwNumEntries
] );
1207 if (!pIpForwardTable
|| *pdwSize
< size
) {
1209 ret
= ERROR_INSUFFICIENT_BUFFER
;
1213 memcpy(pIpForwardTable
, table
, size
);
1215 HeapFree(GetProcessHeap(), 0, table
);
1217 TRACE("returning %d\n", ret
);
1222 /******************************************************************
1223 * GetIpNetTable (IPHLPAPI.@)
1225 * Get the IP-to-physical address mapping table.
1228 * pIpNetTable [Out] buffer for mapping table
1229 * pdwSize [In/Out] length of output buffer
1230 * bOrder [In] whether to sort the table
1234 * Failure: error code from winerror.h
1237 * If pdwSize is less than required, the function will return
1238 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1240 * If bOrder is true, the returned table will be sorted by IP address.
1242 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
1245 PMIB_IPNETTABLE table
;
1247 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
, bOrder
);
1249 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1251 ret
= AllocateAndGetIpNetTableFromStack( &table
, bOrder
, GetProcessHeap(), 0 );
1253 DWORD size
= FIELD_OFFSET( MIB_IPNETTABLE
, table
[table
->dwNumEntries
] );
1254 if (!pIpNetTable
|| *pdwSize
< size
) {
1256 ret
= ERROR_INSUFFICIENT_BUFFER
;
1260 memcpy(pIpNetTable
, table
, size
);
1262 HeapFree(GetProcessHeap(), 0, table
);
1264 TRACE("returning %d\n", ret
);
1269 /******************************************************************
1270 * GetNetworkParams (IPHLPAPI.@)
1272 * Get the network parameters for the local computer.
1275 * pFixedInfo [Out] buffer for network parameters
1276 * pOutBufLen [In/Out] length of output buffer
1280 * Failure: error code from winerror.h
1283 * If pOutBufLen is less than required, the function will return
1284 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1287 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
1293 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
1295 return ERROR_INVALID_PARAMETER
;
1297 initialise_resolver();
1298 size
= sizeof(FIXED_INFO
) + (_res
.nscount
> 0 ? (_res
.nscount
- 1) *
1299 sizeof(IP_ADDR_STRING
) : 0);
1300 if (!pFixedInfo
|| *pOutBufLen
< size
) {
1302 return ERROR_BUFFER_OVERFLOW
;
1305 memset(pFixedInfo
, 0, size
);
1306 size
= sizeof(pFixedInfo
->HostName
);
1307 GetComputerNameExA(ComputerNameDnsHostname
, pFixedInfo
->HostName
, &size
);
1308 size
= sizeof(pFixedInfo
->DomainName
);
1309 GetComputerNameExA(ComputerNameDnsDomain
, pFixedInfo
->DomainName
, &size
);
1310 if (_res
.nscount
> 0) {
1311 PIP_ADDR_STRING ptr
;
1314 for (i
= 0, ptr
= &pFixedInfo
->DnsServerList
; i
< _res
.nscount
&& ptr
;
1315 i
++, ptr
= ptr
->Next
) {
1316 toIPAddressString(_res
.nsaddr_list
[i
].sin_addr
.s_addr
,
1317 ptr
->IpAddress
.String
);
1318 if (i
== _res
.nscount
- 1)
1321 ptr
->Next
= (PIP_ADDR_STRING
)((LPBYTE
)pFixedInfo
+ sizeof(FIXED_INFO
));
1323 ptr
->Next
= (PIP_ADDR_STRING
)((PBYTE
)ptr
+ sizeof(IP_ADDR_STRING
));
1326 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
1327 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1328 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
1329 if (regReturn
!= ERROR_SUCCESS
)
1330 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1331 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
1333 if (regReturn
== ERROR_SUCCESS
)
1335 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
1337 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (LPBYTE
)pFixedInfo
->ScopeId
, &size
);
1341 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1342 I suppose could also check for a listener on port 53 to set EnableDns */
1344 TRACE("returning %d\n", ret
);
1349 /******************************************************************
1350 * GetNumberOfInterfaces (IPHLPAPI.@)
1352 * Get the number of interfaces.
1355 * pdwNumIf [Out] number of interfaces
1358 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1360 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
1364 TRACE("pdwNumIf %p\n", pdwNumIf
);
1366 ret
= ERROR_INVALID_PARAMETER
;
1368 *pdwNumIf
= getNumInterfaces();
1371 TRACE("returning %d\n", ret
);
1376 /******************************************************************
1377 * GetPerAdapterInfo (IPHLPAPI.@)
1379 * Get information about an adapter corresponding to an interface.
1382 * IfIndex [In] interface info
1383 * pPerAdapterInfo [Out] buffer for per adapter info
1384 * pOutBufLen [In/Out] length of output buffer
1388 * Failure: error code from winerror.h
1391 * Stub, returns empty IP_PER_ADAPTER_INFO in every case.
1393 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
1395 ULONG bytesNeeded
= sizeof(IP_PER_ADAPTER_INFO
);
1397 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex
, pPerAdapterInfo
, pOutBufLen
);
1399 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
1401 if (!pPerAdapterInfo
|| *pOutBufLen
< bytesNeeded
)
1403 *pOutBufLen
= bytesNeeded
;
1404 return ERROR_BUFFER_OVERFLOW
;
1407 memset(pPerAdapterInfo
, 0, bytesNeeded
);
1412 /******************************************************************
1413 * GetRTTAndHopCount (IPHLPAPI.@)
1415 * Get round-trip time (RTT) and hop count.
1419 * DestIpAddress [In] destination address to get the info for
1420 * HopCount [Out] retrieved hop count
1421 * MaxHops [In] maximum hops to search for the destination
1422 * RTT [Out] RTT in milliseconds
1429 * Stub, returns FALSE.
1431 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
1433 FIXME("(DestIpAddress 0x%08x, HopCount %p, MaxHops %d, RTT %p): stub\n",
1434 DestIpAddress
, HopCount
, MaxHops
, RTT
);
1439 /******************************************************************
1440 * GetTcpTable (IPHLPAPI.@)
1442 * Get the table of active TCP connections.
1445 * pTcpTable [Out] buffer for TCP connections table
1446 * pdwSize [In/Out] length of output buffer
1447 * bOrder [In] whether to order the table
1451 * Failure: error code from winerror.h
1454 * If pdwSize is less than required, the function will return
1455 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1456 * the required byte size.
1457 * If bOrder is true, the returned table will be sorted, first by
1458 * local address and port number, then by remote address and port
1461 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
1464 PMIB_TCPTABLE table
;
1466 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable
, pdwSize
, bOrder
);
1468 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1470 ret
= AllocateAndGetTcpTableFromStack(&table
, bOrder
, GetProcessHeap(), 0);
1472 DWORD size
= FIELD_OFFSET( MIB_TCPTABLE
, table
[table
->dwNumEntries
] );
1473 if (!pTcpTable
|| *pdwSize
< size
) {
1475 ret
= ERROR_INSUFFICIENT_BUFFER
;
1479 memcpy(pTcpTable
, table
, size
);
1481 HeapFree(GetProcessHeap(), 0, table
);
1483 TRACE("returning %d\n", ret
);
1488 /******************************************************************
1489 * GetUdpTable (IPHLPAPI.@)
1491 * Get a table of active UDP connections.
1494 * pUdpTable [Out] buffer for UDP connections table
1495 * pdwSize [In/Out] length of output buffer
1496 * bOrder [In] whether to order the table
1500 * Failure: error code from winerror.h
1503 * If pdwSize is less than required, the function will return
1504 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1505 * required byte size.
1506 * If bOrder is true, the returned table will be sorted, first by
1507 * local address, then by local port number.
1509 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
1512 PMIB_UDPTABLE table
;
1514 TRACE("pUdpTable %p, pdwSize %p, bOrder %d\n", pUdpTable
, pdwSize
, bOrder
);
1516 if (!pdwSize
) return ERROR_INVALID_PARAMETER
;
1518 ret
= AllocateAndGetUdpTableFromStack( &table
, bOrder
, GetProcessHeap(), 0 );
1520 DWORD size
= FIELD_OFFSET( MIB_UDPTABLE
, table
[table
->dwNumEntries
] );
1521 if (!pUdpTable
|| *pdwSize
< size
) {
1523 ret
= ERROR_INSUFFICIENT_BUFFER
;
1527 memcpy(pUdpTable
, table
, size
);
1529 HeapFree(GetProcessHeap(), 0, table
);
1531 TRACE("returning %d\n", ret
);
1536 /******************************************************************
1537 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1539 * This is a Win98-only function to get information on "unidirectional"
1540 * adapters. Since this is pretty nonsensical in other contexts, it
1541 * never returns anything.
1544 * pIPIfInfo [Out] buffer for adapter infos
1545 * dwOutBufLen [Out] length of the output buffer
1549 * Failure: error code from winerror.h
1552 * Stub, returns ERROR_NOT_SUPPORTED.
1554 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
1556 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
1557 /* a unidirectional adapter?? not bloody likely! */
1558 return ERROR_NOT_SUPPORTED
;
1562 /******************************************************************
1563 * IpReleaseAddress (IPHLPAPI.@)
1565 * Release an IP obtained through DHCP,
1568 * AdapterInfo [In] adapter to release IP address
1572 * Failure: error code from winerror.h
1575 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1576 * this function does nothing.
1579 * Stub, returns ERROR_NOT_SUPPORTED.
1581 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1583 TRACE("AdapterInfo %p\n", AdapterInfo
);
1584 /* not a stub, never going to support this (and I never mark an adapter as
1585 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1586 return ERROR_NOT_SUPPORTED
;
1590 /******************************************************************
1591 * IpRenewAddress (IPHLPAPI.@)
1593 * Renew an IP obtained through DHCP.
1596 * AdapterInfo [In] adapter to renew IP address
1600 * Failure: error code from winerror.h
1603 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1604 * this function does nothing.
1607 * Stub, returns ERROR_NOT_SUPPORTED.
1609 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1611 TRACE("AdapterInfo %p\n", AdapterInfo
);
1612 /* not a stub, never going to support this (and I never mark an adapter as
1613 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1614 return ERROR_NOT_SUPPORTED
;
1618 /******************************************************************
1619 * NotifyAddrChange (IPHLPAPI.@)
1621 * Notify caller whenever the ip-interface map is changed.
1624 * Handle [Out] handle usable in asynchronous notification
1625 * overlapped [In] overlapped structure that notifies the caller
1629 * Failure: error code from winerror.h
1632 * Stub, returns ERROR_NOT_SUPPORTED.
1634 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
1636 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
1637 return ERROR_NOT_SUPPORTED
;
1641 /******************************************************************
1642 * NotifyRouteChange (IPHLPAPI.@)
1644 * Notify caller whenever the ip routing table is changed.
1647 * Handle [Out] handle usable in asynchronous notification
1648 * overlapped [In] overlapped structure that notifies the caller
1652 * Failure: error code from winerror.h
1655 * Stub, returns ERROR_NOT_SUPPORTED.
1657 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
1659 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
1660 return ERROR_NOT_SUPPORTED
;
1664 /******************************************************************
1665 * SendARP (IPHLPAPI.@)
1667 * Send an ARP request.
1670 * DestIP [In] attempt to obtain this IP
1671 * SrcIP [In] optional sender IP address
1672 * pMacAddr [Out] buffer for the mac address
1673 * PhyAddrLen [In/Out] length of the output buffer
1677 * Failure: error code from winerror.h
1680 * Stub, returns ERROR_NOT_SUPPORTED.
1682 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
1684 FIXME("(DestIP 0x%08x, SrcIP 0x%08x, pMacAddr %p, PhyAddrLen %p): stub\n",
1685 DestIP
, SrcIP
, pMacAddr
, PhyAddrLen
);
1686 return ERROR_NOT_SUPPORTED
;
1690 /******************************************************************
1691 * SetIfEntry (IPHLPAPI.@)
1693 * Set the administrative status of an interface.
1696 * pIfRow [In] dwAdminStatus member specifies the new status.
1700 * Failure: error code from winerror.h
1703 * Stub, returns ERROR_NOT_SUPPORTED.
1705 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
1707 FIXME("(pIfRow %p): stub\n", pIfRow
);
1708 /* this is supposed to set an interface administratively up or down.
1709 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1710 this sort of down is indistinguishable from other sorts of down (e.g. no
1712 return ERROR_NOT_SUPPORTED
;
1716 /******************************************************************
1717 * SetIpForwardEntry (IPHLPAPI.@)
1719 * Modify an existing route.
1722 * pRoute [In] route with the new information
1726 * Failure: error code from winerror.h
1729 * Stub, returns NO_ERROR.
1731 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
1733 FIXME("(pRoute %p): stub\n", pRoute
);
1734 /* this is to add a route entry, how's it distinguishable from
1735 CreateIpForwardEntry?
1736 could use SIOCADDRT, not sure I want to */
1741 /******************************************************************
1742 * SetIpNetEntry (IPHLPAPI.@)
1744 * Modify an existing ARP entry.
1747 * pArpEntry [In] ARP entry with the new information
1751 * Failure: error code from winerror.h
1754 * Stub, returns NO_ERROR.
1756 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
1758 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
1759 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1764 /******************************************************************
1765 * SetIpStatistics (IPHLPAPI.@)
1767 * Toggle IP forwarding and det the default TTL value.
1770 * pIpStats [In] IP statistics with the new information
1774 * Failure: error code from winerror.h
1777 * Stub, returns NO_ERROR.
1779 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
1781 FIXME("(pIpStats %p): stub\n", pIpStats
);
1786 /******************************************************************
1787 * SetIpTTL (IPHLPAPI.@)
1789 * Set the default TTL value.
1792 * nTTL [In] new TTL value
1796 * Failure: error code from winerror.h
1799 * Stub, returns NO_ERROR.
1801 DWORD WINAPI
SetIpTTL(UINT nTTL
)
1803 FIXME("(nTTL %d): stub\n", nTTL
);
1804 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1805 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1810 /******************************************************************
1811 * SetTcpEntry (IPHLPAPI.@)
1813 * Set the state of a TCP connection.
1816 * pTcpRow [In] specifies connection with new state
1820 * Failure: error code from winerror.h
1823 * Stub, returns NO_ERROR.
1825 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
1827 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
1832 /******************************************************************
1833 * UnenableRouter (IPHLPAPI.@)
1835 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
1836 * if it reaches zero.
1839 * pOverlapped [In/Out] should be the same as in EnableRouter()
1840 * lpdwEnableCount [Out] optional, receives reference count
1844 * Failure: error code from winerror.h
1847 * Stub, returns ERROR_NOT_SUPPORTED.
1849 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
1851 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
1853 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
1854 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
1856 return ERROR_NOT_SUPPORTED
;