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>
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
53 #define INADDR_NONE ~0UL
56 static int resolver_initialised
;
58 /* call res_init() just once because of a bug in Mac OS X 10.4 */
59 static void initialise_resolver(void)
61 if (!resolver_initialised
)
64 resolver_initialised
= 1;
68 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
71 case DLL_PROCESS_ATTACH
:
72 DisableThreadLibraryCalls( hinstDLL
);
75 case DLL_PROCESS_DETACH
:
81 /******************************************************************
82 * AddIPAddress (IPHLPAPI.@)
84 * Add an IP address to an adapter.
87 * Address [In] IP address to add to the adapter
88 * IpMask [In] subnet mask for the IP address
89 * IfIndex [In] adapter index to add the address
90 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
91 * NTEInstance [Out] NTE instance for the IP address
95 * Failure: error code from winerror.h
98 * Stub. Currently returns ERROR_NOT_SUPPORTED.
100 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask IpMask
, DWORD IfIndex
, PULONG NTEContext
, PULONG NTEInstance
)
103 return ERROR_NOT_SUPPORTED
;
107 /******************************************************************
108 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
110 * Get table of local interfaces.
111 * Like GetIfTable(), but allocate the returned table from heap.
114 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
115 * allocated and returned.
116 * bOrder [In] whether to sort the table
117 * heap [In] heap from which the table is allocated
118 * flags [In] flags to HeapAlloc
121 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
122 * GetIfTable() returns otherwise.
124 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
125 BOOL bOrder
, HANDLE heap
, DWORD flags
)
129 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable
,
130 bOrder
, heap
, flags
);
132 ret
= ERROR_INVALID_PARAMETER
;
136 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
137 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
138 *ppIfTable
= HeapAlloc(heap
, flags
, dwSize
);
139 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
142 TRACE("returning %d\n", ret
);
147 static int IpAddrTableSorter(const void *a
, const void *b
)
152 ret
= ((const MIB_IPADDRROW
*)a
)->dwAddr
- ((const MIB_IPADDRROW
*)b
)->dwAddr
;
159 /******************************************************************
160 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
162 * Get interface-to-IP address mapping table.
163 * Like GetIpAddrTable(), but allocate the returned table from heap.
166 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
167 * allocated and returned.
168 * bOrder [In] whether to sort the table
169 * heap [In] heap from which the table is allocated
170 * flags [In] flags to HeapAlloc
173 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
174 * failure, NO_ERROR on success.
176 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
177 BOOL bOrder
, HANDLE heap
, DWORD flags
)
181 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
182 ppIpAddrTable
, bOrder
, heap
, flags
);
183 ret
= getIPAddrTable(ppIpAddrTable
, heap
, flags
);
185 qsort((*ppIpAddrTable
)->table
, (*ppIpAddrTable
)->dwNumEntries
,
186 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
187 TRACE("returning %d\n", ret
);
192 static int IpForwardTableSorter(const void *a
, const void *b
)
197 const MIB_IPFORWARDROW
* rowA
= (const MIB_IPFORWARDROW
*)a
;
198 const MIB_IPFORWARDROW
* rowB
= (const MIB_IPFORWARDROW
*)b
;
200 ret
= rowA
->dwForwardDest
- rowB
->dwForwardDest
;
202 ret
= rowA
->dwForwardProto
- rowB
->dwForwardProto
;
204 ret
= rowA
->dwForwardPolicy
- rowB
->dwForwardPolicy
;
206 ret
= rowA
->dwForwardNextHop
- rowB
->dwForwardNextHop
;
216 /******************************************************************
217 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
219 * Get the route table.
220 * Like GetIpForwardTable(), but allocate the returned table from heap.
223 * ppIpForwardTable [Out] pointer into which the MIB_IPFORWARDTABLE is
224 * allocated and returned.
225 * bOrder [In] whether to sort the table
226 * heap [In] heap from which the table is allocated
227 * flags [In] flags to HeapAlloc
230 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, other error codes
231 * on failure, NO_ERROR on success.
233 DWORD WINAPI
AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE
*
234 ppIpForwardTable
, BOOL bOrder
, HANDLE heap
, DWORD flags
)
238 TRACE("ppIpForwardTable %p, bOrder %d, heap %p, flags 0x%08x\n",
239 ppIpForwardTable
, bOrder
, heap
, flags
);
240 ret
= getRouteTable(ppIpForwardTable
, heap
, flags
);
242 qsort((*ppIpForwardTable
)->table
, (*ppIpForwardTable
)->dwNumEntries
,
243 sizeof(MIB_IPFORWARDROW
), IpForwardTableSorter
);
244 TRACE("returning %d\n", ret
);
249 static int IpNetTableSorter(const void *a
, const void *b
)
254 ret
= ((const MIB_IPNETROW
*)a
)->dwAddr
- ((const MIB_IPNETROW
*)b
)->dwAddr
;
261 /******************************************************************
262 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
264 * Get the IP-to-physical address mapping table.
265 * Like GetIpNetTable(), but allocate the returned table from heap.
268 * ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE is
269 * allocated and returned.
270 * bOrder [In] whether to sort the table
271 * heap [In] heap from which the table is allocated
272 * flags [In] flags to HeapAlloc
275 * ERROR_INVALID_PARAMETER if ppIpNetTable is NULL, other error codes
276 * on failure, NO_ERROR on success.
278 DWORD WINAPI
AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE
*ppIpNetTable
,
279 BOOL bOrder
, HANDLE heap
, DWORD flags
)
283 TRACE("ppIpNetTable %p, bOrder %d, heap %p, flags 0x%08x\n",
284 ppIpNetTable
, bOrder
, heap
, flags
);
285 ret
= getArpTable(ppIpNetTable
, heap
, flags
);
287 qsort((*ppIpNetTable
)->table
, (*ppIpNetTable
)->dwNumEntries
,
288 sizeof(MIB_IPADDRROW
), IpNetTableSorter
);
289 TRACE("returning %d\n", ret
);
294 static int TcpTableSorter(const void *a
, const void *b
)
299 const MIB_TCPROW
* rowA
= a
;
300 const MIB_TCPROW
* rowB
= b
;
302 ret
= ntohl (rowA
->dwLocalAddr
) - ntohl (rowB
->dwLocalAddr
);
304 ret
= ntohs ((unsigned short)rowA
->dwLocalPort
) -
305 ntohs ((unsigned short)rowB
->dwLocalPort
);
307 ret
= ntohl (rowA
->dwRemoteAddr
) - ntohl (rowB
->dwRemoteAddr
);
309 ret
= ntohs ((unsigned short)rowA
->dwRemotePort
) -
310 ntohs ((unsigned short)rowB
->dwRemotePort
);
320 /******************************************************************
321 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
323 * Get the TCP connection table.
324 * Like GetTcpTable(), but allocate the returned table from heap.
327 * ppTcpTable [Out] pointer into which the MIB_TCPTABLE is
328 * allocated and returned.
329 * bOrder [In] whether to sort the table
330 * heap [In] heap from which the table is allocated
331 * flags [In] flags to HeapAlloc
334 * ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable()
337 DWORD WINAPI
AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE
*ppTcpTable
,
338 BOOL bOrder
, HANDLE heap
, DWORD flags
)
342 TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
343 ppTcpTable
, bOrder
, heap
, flags
);
346 ret
= getTcpTable(ppTcpTable
, 0, heap
, flags
);
348 qsort((*ppTcpTable
)->table
, (*ppTcpTable
)->dwNumEntries
,
349 sizeof(MIB_TCPROW
), TcpTableSorter
);
350 TRACE("returning %d\n", ret
);
355 static int UdpTableSorter(const void *a
, const void *b
)
360 const MIB_UDPROW
* rowA
= (const MIB_UDPROW
*)a
;
361 const MIB_UDPROW
* rowB
= (const MIB_UDPROW
*)b
;
363 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
365 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
373 /******************************************************************
374 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
376 * Get the UDP listener table.
377 * Like GetUdpTable(), but allocate the returned table from heap.
380 * ppUdpTable [Out] pointer into which the MIB_UDPTABLE is
381 * allocated and returned.
382 * bOrder [In] whether to sort the table
383 * heap [In] heap from which the table is allocated
384 * flags [In] flags to HeapAlloc
387 * ERROR_INVALID_PARAMETER if ppUdpTable is NULL, whatever GetUdpTable()
390 DWORD WINAPI
AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE
*ppUdpTable
,
391 BOOL bOrder
, HANDLE heap
, DWORD flags
)
395 TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
396 ppUdpTable
, bOrder
, heap
, flags
);
397 ret
= getUdpTable(ppUdpTable
, heap
, flags
);
399 qsort((*ppUdpTable
)->table
, (*ppUdpTable
)->dwNumEntries
,
400 sizeof(MIB_UDPROW
), UdpTableSorter
);
401 TRACE("returning %d\n", ret
);
406 /******************************************************************
407 * CreateIpForwardEntry (IPHLPAPI.@)
409 * Create a route in the local computer's IP table.
412 * pRoute [In] new route information
416 * Failure: error code from winerror.h
419 * Stub, always returns NO_ERROR.
421 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
423 FIXME("(pRoute %p): stub\n", pRoute
);
424 /* could use SIOCADDRT, not sure I want to */
429 /******************************************************************
430 * CreateIpNetEntry (IPHLPAPI.@)
432 * Create entry in the ARP table.
435 * pArpEntry [In] new ARP entry
439 * Failure: error code from winerror.h
442 * Stub, always returns NO_ERROR.
444 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
446 FIXME("(pArpEntry %p)\n", pArpEntry
);
447 /* could use SIOCSARP on systems that support it, not sure I want to */
452 /******************************************************************
453 * CreateProxyArpEntry (IPHLPAPI.@)
455 * Create a Proxy ARP (PARP) entry for an IP address.
458 * dwAddress [In] IP address for which this computer acts as a proxy.
459 * dwMask [In] subnet mask for dwAddress
460 * dwIfIndex [In] interface index
464 * Failure: error code from winerror.h
467 * Stub, returns ERROR_NOT_SUPPORTED.
469 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
471 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
472 dwAddress
, dwMask
, dwIfIndex
);
473 return ERROR_NOT_SUPPORTED
;
477 /******************************************************************
478 * DeleteIPAddress (IPHLPAPI.@)
480 * Delete an IP address added with AddIPAddress().
483 * NTEContext [In] NTE context from AddIPAddress();
487 * Failure: error code from winerror.h
490 * Stub, returns ERROR_NOT_SUPPORTED.
492 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
494 FIXME("(NTEContext %d): stub\n", NTEContext
);
495 return ERROR_NOT_SUPPORTED
;
499 /******************************************************************
500 * DeleteIpForwardEntry (IPHLPAPI.@)
505 * pRoute [In] route to delete
509 * Failure: error code from winerror.h
512 * Stub, returns NO_ERROR.
514 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
516 FIXME("(pRoute %p): stub\n", pRoute
);
517 /* could use SIOCDELRT, not sure I want to */
522 /******************************************************************
523 * DeleteIpNetEntry (IPHLPAPI.@)
525 * Delete an ARP entry.
528 * pArpEntry [In] ARP entry to delete
532 * Failure: error code from winerror.h
535 * Stub, returns NO_ERROR.
537 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
539 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
540 /* could use SIOCDARP on systems that support it, not sure I want to */
545 /******************************************************************
546 * DeleteProxyArpEntry (IPHLPAPI.@)
548 * Delete a Proxy ARP entry.
551 * dwAddress [In] IP address for which this computer acts as a proxy.
552 * dwMask [In] subnet mask for dwAddress
553 * dwIfIndex [In] interface index
557 * Failure: error code from winerror.h
560 * Stub, returns ERROR_NOT_SUPPORTED.
562 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
564 FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
565 dwAddress
, dwMask
, dwIfIndex
);
566 return ERROR_NOT_SUPPORTED
;
570 /******************************************************************
571 * EnableRouter (IPHLPAPI.@)
573 * Turn on ip forwarding.
577 * pOverlapped [In/Out] hEvent member should contain a valid handle.
580 * Success: ERROR_IO_PENDING
581 * Failure: error code from winerror.h
584 * Stub, returns ERROR_NOT_SUPPORTED.
586 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
588 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle
, pOverlapped
);
589 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
590 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
592 return ERROR_NOT_SUPPORTED
;
596 /******************************************************************
597 * FlushIpNetTable (IPHLPAPI.@)
599 * Delete all ARP entries of an interface
602 * dwIfIndex [In] interface index
606 * Failure: error code from winerror.h
609 * Stub, returns ERROR_NOT_SUPPORTED.
611 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
613 FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex
);
614 /* this flushes the arp cache of the given index */
615 return ERROR_NOT_SUPPORTED
;
619 /******************************************************************
620 * GetAdapterIndex (IPHLPAPI.@)
622 * Get interface index from its name.
625 * AdapterName [In] unicode string with the adapter name
626 * IfIndex [Out] returns found interface index
630 * Failure: error code from winerror.h
632 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
634 char adapterName
[MAX_ADAPTER_NAME
];
638 TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName
, IfIndex
);
639 /* The adapter name is guaranteed not to have any unicode characters, so
640 * this translation is never lossy */
641 for (i
= 0; i
< sizeof(adapterName
) - 1 && AdapterName
[i
]; i
++)
642 adapterName
[i
] = (char)AdapterName
[i
];
643 adapterName
[i
] = '\0';
644 ret
= getInterfaceIndexByName(adapterName
, IfIndex
);
645 TRACE("returning %d\n", ret
);
650 /******************************************************************
651 * GetAdaptersInfo (IPHLPAPI.@)
653 * Get information about adapters.
656 * pAdapterInfo [Out] buffer for adapter infos
657 * pOutBufLen [In] length of output buffer
661 * Failure: error code from winerror.h
663 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
667 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
669 ret
= ERROR_INVALID_PARAMETER
;
671 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
673 if (numNonLoopbackInterfaces
> 0) {
674 DWORD numIPAddresses
= getNumIPAddresses();
677 /* This may slightly overestimate the amount of space needed, because
678 * the IP addresses include the loopback address, but it's easier
679 * to make sure there's more than enough space than to make sure there's
680 * precisely enough space.
682 size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
683 size
+= numIPAddresses
* sizeof(IP_ADDR_STRING
);
684 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
686 ret
= ERROR_BUFFER_OVERFLOW
;
689 InterfaceIndexTable
*table
= NULL
;
690 PMIB_IPADDRTABLE ipAddrTable
= NULL
;
691 PMIB_IPFORWARDTABLE routeTable
= NULL
;
693 ret
= getIPAddrTable(&ipAddrTable
, GetProcessHeap(), 0);
695 ret
= getRouteTable(&routeTable
, GetProcessHeap(), 0);
697 table
= getNonLoopbackInterfaceIndexTable();
699 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
700 size
+= ipAddrTable
->dwNumEntries
* sizeof(IP_ADDR_STRING
);
701 if (*pOutBufLen
< size
) {
703 ret
= ERROR_INSUFFICIENT_BUFFER
;
708 BOOL winsEnabled
= FALSE
;
709 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
710 PIP_ADDR_STRING nextIPAddr
= (PIP_ADDR_STRING
)((LPBYTE
)pAdapterInfo
711 + numNonLoopbackInterfaces
* sizeof(IP_ADAPTER_INFO
));
713 memset(pAdapterInfo
, 0, size
);
714 /* @@ Wine registry key: HKCU\Software\Wine\Network */
715 if (RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Network",
716 &hKey
) == ERROR_SUCCESS
) {
717 DWORD size
= sizeof(primaryWINS
.String
);
720 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
721 (LPBYTE
)primaryWINS
.String
, &size
);
722 addr
= inet_addr(primaryWINS
.String
);
723 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
725 size
= sizeof(secondaryWINS
.String
);
726 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
727 (LPBYTE
)secondaryWINS
.String
, &size
);
728 addr
= inet_addr(secondaryWINS
.String
);
729 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
733 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
734 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
736 PIP_ADDR_STRING currentIPAddr
= &ptr
->IpAddressList
;
737 BOOL firstIPAddr
= TRUE
;
739 /* on Win98 this is left empty, but whatever */
740 getInterfaceNameByIndex(table
->indexes
[ndx
], ptr
->AdapterName
);
741 ptr
->AddressLength
= sizeof(ptr
->Address
);
742 getInterfacePhysicalByIndex(table
->indexes
[ndx
],
743 &ptr
->AddressLength
, ptr
->Address
, &ptr
->Type
);
744 ptr
->Index
= table
->indexes
[ndx
];
745 for (i
= 0; i
< ipAddrTable
->dwNumEntries
; i
++) {
746 if (ipAddrTable
->table
[i
].dwIndex
== ptr
->Index
) {
748 toIPAddressString(ipAddrTable
->table
[i
].dwAddr
,
749 ptr
->IpAddressList
.IpAddress
.String
);
750 toIPAddressString(ipAddrTable
->table
[i
].dwMask
,
751 ptr
->IpAddressList
.IpMask
.String
);
755 currentIPAddr
->Next
= nextIPAddr
;
756 currentIPAddr
= nextIPAddr
;
757 toIPAddressString(ipAddrTable
->table
[i
].dwAddr
,
758 currentIPAddr
->IpAddress
.String
);
759 toIPAddressString(ipAddrTable
->table
[i
].dwMask
,
760 currentIPAddr
->IpMask
.String
);
765 /* Find first router through this interface, which we'll assume
766 * is the default gateway for this adapter */
767 for (i
= 0; i
< routeTable
->dwNumEntries
; i
++)
768 if (routeTable
->table
[i
].dwForwardIfIndex
== ptr
->Index
769 && routeTable
->table
[i
].dwForwardType
==
770 MIB_IPROUTE_TYPE_INDIRECT
)
771 toIPAddressString(routeTable
->table
[i
].dwForwardNextHop
,
772 ptr
->GatewayList
.IpAddress
.String
);
774 ptr
->HaveWins
= TRUE
;
775 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
776 primaryWINS
.String
, sizeof(primaryWINS
.String
));
777 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
778 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
780 if (ndx
< table
->numIndexes
- 1)
781 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
787 HeapFree(GetProcessHeap(), 0, table
);
790 ret
= ERROR_OUTOFMEMORY
;
791 HeapFree(GetProcessHeap(), 0, routeTable
);
792 HeapFree(GetProcessHeap(), 0, ipAddrTable
);
798 TRACE("returning %d\n", ret
);
803 /******************************************************************
804 * GetBestInterface (IPHLPAPI.@)
806 * Get the interface, with the best route for the given IP address.
809 * dwDestAddr [In] IP address to search the interface for
810 * pdwBestIfIndex [Out] found best interface
814 * Failure: error code from winerror.h
816 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
818 struct WS_sockaddr_in sa_in
;
819 memset(&sa_in
, 0, sizeof(sa_in
));
820 sa_in
.sin_family
= AF_INET
;
821 sa_in
.sin_addr
.S_un
.S_addr
= dwDestAddr
;
822 return GetBestInterfaceEx((struct WS_sockaddr
*)&sa_in
, pdwBestIfIndex
);
825 /******************************************************************
826 * GetBestInterfaceEx (IPHLPAPI.@)
828 * Get the interface, with the best route for the given IP address.
831 * dwDestAddr [In] IP address to search the interface for
832 * pdwBestIfIndex [Out] found best interface
836 * Failure: error code from winerror.h
838 DWORD WINAPI
GetBestInterfaceEx(struct WS_sockaddr
*pDestAddr
, PDWORD pdwBestIfIndex
)
842 TRACE("pDestAddr %p, pdwBestIfIndex %p\n", pDestAddr
, pdwBestIfIndex
);
843 if (!pDestAddr
|| !pdwBestIfIndex
)
844 ret
= ERROR_INVALID_PARAMETER
;
846 MIB_IPFORWARDROW ipRow
;
848 if (pDestAddr
->sa_family
== AF_INET
) {
849 ret
= GetBestRoute(((struct WS_sockaddr_in
*)pDestAddr
)->sin_addr
.S_un
.S_addr
, 0, &ipRow
);
850 if (ret
== ERROR_SUCCESS
)
851 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
853 FIXME("address family %d not supported\n", pDestAddr
->sa_family
);
854 ret
= ERROR_NOT_SUPPORTED
;
857 TRACE("returning %d\n", ret
);
862 /******************************************************************
863 * GetBestRoute (IPHLPAPI.@)
865 * Get the best route for the given IP address.
868 * dwDestAddr [In] IP address to search the best route for
869 * dwSourceAddr [In] optional source IP address
870 * pBestRoute [Out] found best route
874 * Failure: error code from winerror.h
876 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
878 PMIB_IPFORWARDTABLE table
;
881 TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr
,
882 dwSourceAddr
, pBestRoute
);
884 return ERROR_INVALID_PARAMETER
;
886 ret
= AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
888 DWORD ndx
, matchedBits
, matchedNdx
= table
->dwNumEntries
;
890 for (ndx
= 0, matchedBits
= 0; ndx
< table
->dwNumEntries
; ndx
++) {
891 if (table
->table
[ndx
].dwForwardType
!= MIB_IPROUTE_TYPE_INVALID
&&
892 (dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
893 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
894 DWORD numShifts
, mask
;
896 for (numShifts
= 0, mask
= table
->table
[ndx
].dwForwardMask
;
897 mask
&& !(mask
& 1); mask
>>= 1, numShifts
++)
899 if (numShifts
> matchedBits
) {
900 matchedBits
= numShifts
;
903 else if (!matchedBits
&& table
->table
[ndx
].dwForwardType
==
904 MIB_IPROUTE_TYPE_INDIRECT
) {
905 /* default to a default gateway */
910 if (matchedNdx
< table
->dwNumEntries
) {
911 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
915 /* No route matches, which can happen if there's no default route. */
916 ret
= ERROR_HOST_UNREACHABLE
;
918 HeapFree(GetProcessHeap(), 0, table
);
920 TRACE("returning %d\n", ret
);
925 /******************************************************************
926 * GetFriendlyIfIndex (IPHLPAPI.@)
928 * Get a "friendly" version of IfIndex, which is one that doesn't
929 * have the top byte set. Doesn't validate whether IfIndex is a valid
933 * IfIndex [In] interface index to get the friendly one for
936 * A friendly version of IfIndex.
938 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
940 /* windows doesn't validate these, either, just makes sure the top byte is
941 cleared. I assume my ifenum module never gives an index with the top
943 TRACE("returning %d\n", IfIndex
);
948 /******************************************************************
949 * GetIcmpStatistics (IPHLPAPI.@)
951 * Get the ICMP statistics for the local computer.
954 * pStats [Out] buffer for ICMP statistics
958 * Failure: error code from winerror.h
960 DWORD WINAPI
GetIcmpStatistics(PMIB_ICMP pStats
)
964 TRACE("pStats %p\n", pStats
);
965 ret
= getICMPStats(pStats
);
966 TRACE("returning %d\n", ret
);
971 /******************************************************************
972 * GetIfEntry (IPHLPAPI.@)
974 * Get information about an interface.
977 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
978 * Out: interface information
982 * Failure: error code from winerror.h
984 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
987 char nameBuf
[MAX_ADAPTER_NAME
];
990 TRACE("pIfRow %p\n", pIfRow
);
992 return ERROR_INVALID_PARAMETER
;
994 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
, nameBuf
);
996 ret
= getInterfaceEntryByName(name
, pIfRow
);
998 ret
= getInterfaceStatsByName(name
, pIfRow
);
1001 ret
= ERROR_INVALID_DATA
;
1002 TRACE("returning %d\n", ret
);
1007 static int IfTableSorter(const void *a
, const void *b
)
1012 ret
= ((const MIB_IFROW
*)a
)->dwIndex
- ((const MIB_IFROW
*)b
)->dwIndex
;
1019 /******************************************************************
1020 * GetIfTable (IPHLPAPI.@)
1022 * Get a table of local interfaces.
1025 * pIfTable [Out] buffer for local interfaces table
1026 * pdwSize [In/Out] length of output buffer
1027 * bOrder [In] whether to sort the table
1031 * Failure: error code from winerror.h
1034 * If pdwSize is less than required, the function will return
1035 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1037 * If bOrder is true, the returned table will be sorted by interface index.
1039 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
1043 TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize
, pdwSize
,
1046 ret
= ERROR_INVALID_PARAMETER
;
1048 DWORD numInterfaces
= getNumInterfaces();
1049 ULONG size
= sizeof(MIB_IFTABLE
);
1051 if (numInterfaces
> 1)
1052 size
+= (numInterfaces
- 1) * sizeof(MIB_IFROW
);
1053 if (!pIfTable
|| *pdwSize
< size
) {
1055 ret
= ERROR_INSUFFICIENT_BUFFER
;
1058 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1061 size
= sizeof(MIB_IFTABLE
);
1062 if (table
->numIndexes
> 1)
1063 size
+= (table
->numIndexes
- 1) * sizeof(MIB_IFROW
);
1064 if (*pdwSize
< size
) {
1066 ret
= ERROR_INSUFFICIENT_BUFFER
;
1072 pIfTable
->dwNumEntries
= 0;
1073 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1074 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1075 GetIfEntry(&pIfTable
->table
[ndx
]);
1076 pIfTable
->dwNumEntries
++;
1079 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
1083 HeapFree(GetProcessHeap(), 0, table
);
1086 ret
= ERROR_OUTOFMEMORY
;
1089 TRACE("returning %d\n", ret
);
1094 /******************************************************************
1095 * GetInterfaceInfo (IPHLPAPI.@)
1097 * Get a list of network interface adapters.
1100 * pIfTable [Out] buffer for interface adapters
1101 * dwOutBufLen [Out] if buffer is too small, returns required size
1105 * Failure: error code from winerror.h
1108 * MSDN states this should return non-loopback interfaces only.
1110 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1114 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1116 ret
= ERROR_INVALID_PARAMETER
;
1118 DWORD numInterfaces
= getNumInterfaces();
1119 ULONG size
= sizeof(IP_INTERFACE_INFO
);
1121 if (numInterfaces
> 1)
1122 size
+= (numInterfaces
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
1123 if (!pIfTable
|| *dwOutBufLen
< size
) {
1124 *dwOutBufLen
= size
;
1125 ret
= ERROR_INSUFFICIENT_BUFFER
;
1128 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1131 size
= sizeof(IP_INTERFACE_INFO
);
1132 if (table
->numIndexes
> 1)
1133 size
+= (table
->numIndexes
- 1) * sizeof(IP_ADAPTER_INDEX_MAP
);
1134 if (*dwOutBufLen
< size
) {
1135 *dwOutBufLen
= size
;
1136 ret
= ERROR_INSUFFICIENT_BUFFER
;
1140 char nameBuf
[MAX_ADAPTER_NAME
];
1142 *dwOutBufLen
= size
;
1143 pIfTable
->NumAdapters
= 0;
1144 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1145 const char *walker
, *name
;
1148 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1149 name
= getInterfaceNameByIndex(table
->indexes
[ndx
], nameBuf
);
1150 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1151 walker
&& *walker
&&
1152 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1153 walker
++, assigner
++)
1154 *assigner
= *walker
;
1156 pIfTable
->NumAdapters
++;
1160 HeapFree(GetProcessHeap(), 0, table
);
1163 ret
= ERROR_OUTOFMEMORY
;
1166 TRACE("returning %d\n", ret
);
1171 /******************************************************************
1172 * GetIpAddrTable (IPHLPAPI.@)
1174 * Get interface-to-IP address mapping table.
1177 * pIpAddrTable [Out] buffer for mapping table
1178 * pdwSize [In/Out] length of output buffer
1179 * bOrder [In] whether to sort the table
1183 * Failure: error code from winerror.h
1186 * If pdwSize is less than required, the function will return
1187 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1189 * If bOrder is true, the returned table will be sorted by the next hop and
1190 * an assortment of arbitrary parameters.
1192 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1196 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable
, pdwSize
,
1199 ret
= ERROR_INVALID_PARAMETER
;
1201 PMIB_IPADDRTABLE table
;
1203 ret
= getIPAddrTable(&table
, GetProcessHeap(), 0);
1204 if (ret
== NO_ERROR
)
1206 ULONG size
= sizeof(MIB_IPADDRTABLE
);
1208 if (table
->dwNumEntries
> 1)
1209 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPADDRROW
);
1210 if (!pIpAddrTable
|| *pdwSize
< size
) {
1212 ret
= ERROR_INSUFFICIENT_BUFFER
;
1216 memcpy(pIpAddrTable
, table
, size
);
1218 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1219 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1222 HeapFree(GetProcessHeap(), 0, table
);
1225 TRACE("returning %d\n", ret
);
1230 /******************************************************************
1231 * GetIpForwardTable (IPHLPAPI.@)
1233 * Get the route table.
1236 * pIpForwardTable [Out] buffer for route table
1237 * pdwSize [In/Out] length of output buffer
1238 * bOrder [In] whether to sort the table
1242 * Failure: error code from winerror.h
1245 * If pdwSize is less than required, the function will return
1246 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1248 * If bOrder is true, the returned table will be sorted by the next hop and
1249 * an assortment of arbitrary parameters.
1251 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1255 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable
,
1256 pdwSize
, (DWORD
)bOrder
);
1258 ret
= ERROR_INVALID_PARAMETER
;
1260 DWORD numRoutes
= getNumRoutes();
1261 ULONG sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
);
1264 sizeNeeded
+= (numRoutes
- 1) * sizeof(MIB_IPFORWARDROW
);
1265 if (!pIpForwardTable
|| *pdwSize
< sizeNeeded
) {
1266 *pdwSize
= sizeNeeded
;
1267 ret
= ERROR_INSUFFICIENT_BUFFER
;
1270 PMIB_IPFORWARDTABLE table
;
1272 ret
= getRouteTable(&table
, GetProcessHeap(), 0);
1274 sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
);
1275 if (table
->dwNumEntries
> 1)
1276 sizeNeeded
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPFORWARDROW
);
1277 if (*pdwSize
< sizeNeeded
) {
1278 *pdwSize
= sizeNeeded
;
1279 ret
= ERROR_INSUFFICIENT_BUFFER
;
1282 *pdwSize
= sizeNeeded
;
1283 memcpy(pIpForwardTable
, table
, sizeNeeded
);
1285 qsort(pIpForwardTable
->table
, pIpForwardTable
->dwNumEntries
,
1286 sizeof(MIB_IPFORWARDROW
), IpForwardTableSorter
);
1289 HeapFree(GetProcessHeap(), 0, table
);
1293 TRACE("returning %d\n", ret
);
1298 /******************************************************************
1299 * GetIpNetTable (IPHLPAPI.@)
1301 * Get the IP-to-physical address mapping table.
1304 * pIpNetTable [Out] buffer for mapping table
1305 * pdwSize [In/Out] length of output buffer
1306 * bOrder [In] whether to sort the table
1310 * Failure: error code from winerror.h
1313 * If pdwSize is less than required, the function will return
1314 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1316 * If bOrder is true, the returned table will be sorted by IP address.
1318 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
1322 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
,
1325 ret
= ERROR_INVALID_PARAMETER
;
1327 DWORD numEntries
= getNumArpEntries();
1328 ULONG size
= sizeof(MIB_IPNETTABLE
);
1331 size
+= (numEntries
- 1) * sizeof(MIB_IPNETROW
);
1332 if (!pIpNetTable
|| *pdwSize
< size
) {
1334 ret
= ERROR_INSUFFICIENT_BUFFER
;
1337 PMIB_IPNETTABLE table
;
1339 ret
= getArpTable(&table
, GetProcessHeap(), 0);
1341 size
= sizeof(MIB_IPNETTABLE
);
1342 if (table
->dwNumEntries
> 1)
1343 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPNETROW
);
1344 if (*pdwSize
< size
) {
1346 ret
= ERROR_INSUFFICIENT_BUFFER
;
1350 memcpy(pIpNetTable
, table
, size
);
1352 qsort(pIpNetTable
->table
, pIpNetTable
->dwNumEntries
,
1353 sizeof(MIB_IPNETROW
), IpNetTableSorter
);
1356 HeapFree(GetProcessHeap(), 0, table
);
1360 TRACE("returning %d\n", ret
);
1365 /******************************************************************
1366 * GetIpStatistics (IPHLPAPI.@)
1368 * Get the IP statistics for the local computer.
1371 * pStats [Out] buffer for IP statistics
1375 * Failure: error code from winerror.h
1377 DWORD WINAPI
GetIpStatistics(PMIB_IPSTATS pStats
)
1381 TRACE("pStats %p\n", pStats
);
1382 ret
= getIPStats(pStats
);
1383 TRACE("returning %d\n", ret
);
1388 /******************************************************************
1389 * GetNetworkParams (IPHLPAPI.@)
1391 * Get the network parameters for the local computer.
1394 * pFixedInfo [Out] buffer for network parameters
1395 * pOutBufLen [In/Out] length of output buffer
1399 * Failure: error code from winerror.h
1402 * If pOutBufLen is less than required, the function will return
1403 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1406 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
1412 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
1414 return ERROR_INVALID_PARAMETER
;
1416 initialise_resolver();
1417 size
= sizeof(FIXED_INFO
) + (_res
.nscount
> 0 ? (_res
.nscount
- 1) *
1418 sizeof(IP_ADDR_STRING
) : 0);
1419 if (!pFixedInfo
|| *pOutBufLen
< size
) {
1421 return ERROR_BUFFER_OVERFLOW
;
1424 memset(pFixedInfo
, 0, size
);
1425 size
= sizeof(pFixedInfo
->HostName
);
1426 GetComputerNameExA(ComputerNameDnsHostname
, pFixedInfo
->HostName
, &size
);
1427 size
= sizeof(pFixedInfo
->DomainName
);
1428 GetComputerNameExA(ComputerNameDnsDomain
, pFixedInfo
->DomainName
, &size
);
1429 if (_res
.nscount
> 0) {
1430 PIP_ADDR_STRING ptr
;
1433 for (i
= 0, ptr
= &pFixedInfo
->DnsServerList
; i
< _res
.nscount
&& ptr
;
1434 i
++, ptr
= ptr
->Next
) {
1435 toIPAddressString(_res
.nsaddr_list
[i
].sin_addr
.s_addr
,
1436 ptr
->IpAddress
.String
);
1437 if (i
== _res
.nscount
- 1)
1440 ptr
->Next
= (PIP_ADDR_STRING
)((LPBYTE
)pFixedInfo
+ sizeof(FIXED_INFO
));
1442 ptr
->Next
= (PIP_ADDR_STRING
)((PBYTE
)ptr
+ sizeof(IP_ADDR_STRING
));
1445 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
1446 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1447 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
1448 if (regReturn
!= ERROR_SUCCESS
)
1449 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1450 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
1452 if (regReturn
== ERROR_SUCCESS
)
1454 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
1456 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (LPBYTE
)pFixedInfo
->ScopeId
, &size
);
1460 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1461 I suppose could also check for a listener on port 53 to set EnableDns */
1463 TRACE("returning %d\n", ret
);
1468 /******************************************************************
1469 * GetNumberOfInterfaces (IPHLPAPI.@)
1471 * Get the number of interfaces.
1474 * pdwNumIf [Out] number of interfaces
1477 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1479 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
1483 TRACE("pdwNumIf %p\n", pdwNumIf
);
1485 ret
= ERROR_INVALID_PARAMETER
;
1487 *pdwNumIf
= getNumInterfaces();
1490 TRACE("returning %d\n", ret
);
1495 /******************************************************************
1496 * GetPerAdapterInfo (IPHLPAPI.@)
1498 * Get information about an adapter corresponding to an interface.
1501 * IfIndex [In] interface info
1502 * pPerAdapterInfo [Out] buffer for per adapter info
1503 * pOutBufLen [In/Out] length of output buffer
1507 * Failure: error code from winerror.h
1510 * Stub, returns empty IP_PER_ADAPTER_INFO in every case.
1512 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
1514 ULONG bytesNeeded
= sizeof(IP_PER_ADAPTER_INFO
);
1517 TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex
,
1518 pPerAdapterInfo
, pOutBufLen
);
1520 ret
= ERROR_INVALID_PARAMETER
;
1521 else if (!pPerAdapterInfo
)
1523 *pOutBufLen
= bytesNeeded
;
1526 else if (*pOutBufLen
< bytesNeeded
)
1528 *pOutBufLen
= bytesNeeded
;
1529 ret
= ERROR_BUFFER_OVERFLOW
;
1533 memset(pPerAdapterInfo
, 0, bytesNeeded
);
1540 /******************************************************************
1541 * GetRTTAndHopCount (IPHLPAPI.@)
1543 * Get round-trip time (RTT) and hop count.
1547 * DestIpAddress [In] destination address to get the info for
1548 * HopCount [Out] retrieved hop count
1549 * MaxHops [In] maximum hops to search for the destination
1550 * RTT [Out] RTT in milliseconds
1557 * Stub, returns FALSE.
1559 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
1561 FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %d, RTT %p): stub\n",
1562 DestIpAddress
, HopCount
, MaxHops
, RTT
);
1567 /******************************************************************
1568 * GetTcpStatistics (IPHLPAPI.@)
1570 * Get the TCP statistics for the local computer.
1573 * pStats [Out] buffer for TCP statistics
1577 * Failure: error code from winerror.h
1579 DWORD WINAPI
GetTcpStatistics(PMIB_TCPSTATS pStats
)
1583 TRACE("pStats %p\n", pStats
);
1584 ret
= getTCPStats(pStats
);
1585 TRACE("returning %d\n", ret
);
1590 /******************************************************************
1591 * GetTcpTable (IPHLPAPI.@)
1593 * Get the table of active TCP connections.
1596 * pTcpTable [Out] buffer for TCP connections table
1597 * pdwSize [In/Out] length of output buffer
1598 * bOrder [In] whether to order the table
1602 * Failure: error code from winerror.h
1605 * If pdwSize is less than required, the function will return
1606 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1607 * the required byte size.
1608 * If bOrder is true, the returned table will be sorted, first by
1609 * local address and port number, then by remote address and port
1612 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
1616 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable
, pdwSize
,
1619 ret
= ERROR_INVALID_PARAMETER
;
1621 DWORD numEntries
= getNumTcpEntries();
1622 DWORD size
= sizeof(MIB_TCPTABLE
);
1625 size
+= (numEntries
- 1) * sizeof(MIB_TCPROW
);
1626 if (!pTcpTable
|| *pdwSize
< size
) {
1628 ret
= ERROR_INSUFFICIENT_BUFFER
;
1631 ret
= getTcpTable(&pTcpTable
, numEntries
, 0, 0);
1633 size
= sizeof(MIB_TCPTABLE
);
1634 if (pTcpTable
->dwNumEntries
> 1)
1635 size
+= (pTcpTable
->dwNumEntries
- 1) * sizeof(MIB_TCPROW
);
1639 qsort(pTcpTable
->table
, pTcpTable
->dwNumEntries
,
1640 sizeof(MIB_TCPROW
), TcpTableSorter
);
1645 TRACE("returning %d\n", ret
);
1650 /******************************************************************
1651 * GetUdpStatistics (IPHLPAPI.@)
1653 * Get the UDP statistics for the local computer.
1656 * pStats [Out] buffer for UDP statistics
1660 * Failure: error code from winerror.h
1662 DWORD WINAPI
GetUdpStatistics(PMIB_UDPSTATS pStats
)
1666 TRACE("pStats %p\n", pStats
);
1667 ret
= getUDPStats(pStats
);
1668 TRACE("returning %d\n", ret
);
1673 /******************************************************************
1674 * GetUdpTable (IPHLPAPI.@)
1676 * Get a table of active UDP connections.
1679 * pUdpTable [Out] buffer for UDP connections table
1680 * pdwSize [In/Out] length of output buffer
1681 * bOrder [In] whether to order the table
1685 * Failure: error code from winerror.h
1688 * If pdwSize is less than required, the function will return
1689 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1690 * required byte size.
1691 * If bOrder is true, the returned table will be sorted, first by
1692 * local address, then by local port number.
1694 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
1698 TRACE("pUdpTable %p, pdwSize %p, bOrder %d\n", pUdpTable
, pdwSize
,
1701 ret
= ERROR_INVALID_PARAMETER
;
1703 DWORD numEntries
= getNumUdpEntries();
1704 DWORD size
= sizeof(MIB_UDPTABLE
);
1707 size
+= (numEntries
- 1) * sizeof(MIB_UDPROW
);
1708 if (!pUdpTable
|| *pdwSize
< size
) {
1710 ret
= ERROR_INSUFFICIENT_BUFFER
;
1713 PMIB_UDPTABLE table
;
1715 ret
= getUdpTable(&table
, GetProcessHeap(), 0);
1717 size
= sizeof(MIB_UDPTABLE
);
1718 if (table
->dwNumEntries
> 1)
1719 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_UDPROW
);
1720 if (*pdwSize
< size
) {
1722 ret
= ERROR_INSUFFICIENT_BUFFER
;
1726 memcpy(pUdpTable
, table
, size
);
1728 qsort(pUdpTable
->table
, pUdpTable
->dwNumEntries
,
1729 sizeof(MIB_UDPROW
), UdpTableSorter
);
1732 HeapFree(GetProcessHeap(), 0, table
);
1735 ret
= ERROR_OUTOFMEMORY
;
1738 TRACE("returning %d\n", ret
);
1743 /******************************************************************
1744 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1746 * This is a Win98-only function to get information on "unidirectional"
1747 * adapters. Since this is pretty nonsensical in other contexts, it
1748 * never returns anything.
1751 * pIPIfInfo [Out] buffer for adapter infos
1752 * dwOutBufLen [Out] length of the output buffer
1756 * Failure: error code from winerror.h
1759 * Stub, returns ERROR_NOT_SUPPORTED.
1761 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
1763 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
1764 /* a unidirectional adapter?? not bloody likely! */
1765 return ERROR_NOT_SUPPORTED
;
1769 /******************************************************************
1770 * IpReleaseAddress (IPHLPAPI.@)
1772 * Release an IP obtained through DHCP,
1775 * AdapterInfo [In] adapter to release IP address
1779 * Failure: error code from winerror.h
1782 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1783 * this function does nothing.
1786 * Stub, returns ERROR_NOT_SUPPORTED.
1788 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1790 TRACE("AdapterInfo %p\n", AdapterInfo
);
1791 /* not a stub, never going to support this (and I never mark an adapter as
1792 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1793 return ERROR_NOT_SUPPORTED
;
1797 /******************************************************************
1798 * IpRenewAddress (IPHLPAPI.@)
1800 * Renew an IP obtained through DHCP.
1803 * AdapterInfo [In] adapter to renew IP address
1807 * Failure: error code from winerror.h
1810 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1811 * this function does nothing.
1814 * Stub, returns ERROR_NOT_SUPPORTED.
1816 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1818 TRACE("AdapterInfo %p\n", AdapterInfo
);
1819 /* not a stub, never going to support this (and I never mark an adapter as
1820 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1821 return ERROR_NOT_SUPPORTED
;
1825 /******************************************************************
1826 * NotifyAddrChange (IPHLPAPI.@)
1828 * Notify caller whenever the ip-interface map is changed.
1831 * Handle [Out] handle usable in asynchronous notification
1832 * overlapped [In] overlapped structure that notifies the caller
1836 * Failure: error code from winerror.h
1839 * Stub, returns ERROR_NOT_SUPPORTED.
1841 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
1843 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
1844 return ERROR_NOT_SUPPORTED
;
1848 /******************************************************************
1849 * NotifyRouteChange (IPHLPAPI.@)
1851 * Notify caller whenever the ip routing table is changed.
1854 * Handle [Out] handle usable in asynchronous notification
1855 * overlapped [In] overlapped structure that notifies the caller
1859 * Failure: error code from winerror.h
1862 * Stub, returns ERROR_NOT_SUPPORTED.
1864 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
1866 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
1867 return ERROR_NOT_SUPPORTED
;
1871 /******************************************************************
1872 * SendARP (IPHLPAPI.@)
1874 * Send an ARP request.
1877 * DestIP [In] attempt to obtain this IP
1878 * SrcIP [In] optional sender IP address
1879 * pMacAddr [Out] buffer for the mac address
1880 * PhyAddrLen [In/Out] length of the output buffer
1884 * Failure: error code from winerror.h
1887 * Stub, returns ERROR_NOT_SUPPORTED.
1889 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
1891 FIXME("(DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p): stub\n",
1892 DestIP
, SrcIP
, pMacAddr
, PhyAddrLen
);
1893 return ERROR_NOT_SUPPORTED
;
1897 /******************************************************************
1898 * SetIfEntry (IPHLPAPI.@)
1900 * Set the administrative status of an interface.
1903 * pIfRow [In] dwAdminStatus member specifies the new status.
1907 * Failure: error code from winerror.h
1910 * Stub, returns ERROR_NOT_SUPPORTED.
1912 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
1914 FIXME("(pIfRow %p): stub\n", pIfRow
);
1915 /* this is supposed to set an interface administratively up or down.
1916 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1917 this sort of down is indistinguishable from other sorts of down (e.g. no
1919 return ERROR_NOT_SUPPORTED
;
1923 /******************************************************************
1924 * SetIpForwardEntry (IPHLPAPI.@)
1926 * Modify an existing route.
1929 * pRoute [In] route with the new information
1933 * Failure: error code from winerror.h
1936 * Stub, returns NO_ERROR.
1938 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
1940 FIXME("(pRoute %p): stub\n", pRoute
);
1941 /* this is to add a route entry, how's it distinguishable from
1942 CreateIpForwardEntry?
1943 could use SIOCADDRT, not sure I want to */
1948 /******************************************************************
1949 * SetIpNetEntry (IPHLPAPI.@)
1951 * Modify an existing ARP entry.
1954 * pArpEntry [In] ARP entry with the new information
1958 * Failure: error code from winerror.h
1961 * Stub, returns NO_ERROR.
1963 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
1965 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
1966 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1971 /******************************************************************
1972 * SetIpStatistics (IPHLPAPI.@)
1974 * Toggle IP forwarding and det the default TTL value.
1977 * pIpStats [In] IP statistics with the new information
1981 * Failure: error code from winerror.h
1984 * Stub, returns NO_ERROR.
1986 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
1988 FIXME("(pIpStats %p): stub\n", pIpStats
);
1993 /******************************************************************
1994 * SetIpTTL (IPHLPAPI.@)
1996 * Set the default TTL value.
1999 * nTTL [In] new TTL value
2003 * Failure: error code from winerror.h
2006 * Stub, returns NO_ERROR.
2008 DWORD WINAPI
SetIpTTL(UINT nTTL
)
2010 FIXME("(nTTL %d): stub\n", nTTL
);
2011 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
2012 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
2017 /******************************************************************
2018 * SetTcpEntry (IPHLPAPI.@)
2020 * Set the state of a TCP connection.
2023 * pTcpRow [In] specifies connection with new state
2027 * Failure: error code from winerror.h
2030 * Stub, returns NO_ERROR.
2032 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
2034 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
2039 /******************************************************************
2040 * UnenableRouter (IPHLPAPI.@)
2042 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2043 * if it reaches zero.
2046 * pOverlapped [In/Out] should be the same as in EnableRouter()
2047 * lpdwEnableCount [Out] optional, receives reference count
2051 * Failure: error code from winerror.h
2054 * Stub, returns ERROR_NOT_SUPPORTED.
2056 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
2058 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
2060 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
2061 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
2063 return ERROR_NOT_SUPPORTED
;