2 * iphlpapi dll implementation
4 * Copyright (C) 2003 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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>
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
50 #define INADDR_NONE ~0UL
53 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
56 case DLL_PROCESS_ATTACH
:
57 DisableThreadLibraryCalls( hinstDLL
);
61 case DLL_PROCESS_DETACH
:
68 /******************************************************************
69 * AddIPAddress (IPHLPAPI.@)
71 * Add an IP address to an adapter.
74 * Address [In] IP address to add to the adapter
75 * IpMask [In] subnet mask for the IP address
76 * IfIndex [In] adapter index to add the address
77 * NTEContext [Out] Net Table Entry (NTE) context for the IP address
78 * NTEInstance [Out] NTE instance for the IP address
82 * Failure: error code from winerror.h
85 * Stub. Currently returns ERROR_NOT_SUPPORTED.
87 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask IpMask
, DWORD IfIndex
, PULONG NTEContext
, PULONG NTEInstance
)
90 /* marking Win2K+ functions not supported */
91 return ERROR_NOT_SUPPORTED
;
95 /******************************************************************
96 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
98 * Get table of local interfaces.
99 * Like GetIfTable(), but allocate the returned table from heap.
102 * ppIfTable [Out] pointer into which the MIB_IFTABLE is
103 * allocated and returned.
104 * bOrder [In] passed to GetIfTable() to order the table
105 * heap [In] heap from which the table is allocated
106 * flags [In] flags to HeapAlloc
109 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
110 * GetIfTable() returns otherwise.
112 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
113 BOOL bOrder
, HANDLE heap
, DWORD flags
)
117 TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08lx\n", ppIfTable
,
118 bOrder
, heap
, flags
);
120 ret
= ERROR_INVALID_PARAMETER
;
124 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
125 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
126 *ppIfTable
= HeapAlloc(heap
, flags
, dwSize
);
127 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
130 TRACE("returning %ld\n", ret
);
135 /******************************************************************
136 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
138 * Get interface-to-IP address mapping table.
139 * Like GetIpAddrTable(), but allocate the returned table from heap.
142 * ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
143 * allocated and returned.
144 * bOrder [In] passed to GetIpAddrTable to order the table
145 * heap [In] heap from which the table is allocated
146 * flags [In] flags to HeapAlloc
149 * ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, whatever GetIpAddrTable()
152 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
153 BOOL bOrder
, HANDLE heap
, DWORD flags
)
157 TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
158 ppIpAddrTable
, bOrder
, heap
, flags
);
160 ret
= ERROR_INVALID_PARAMETER
;
164 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
165 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
166 *ppIpAddrTable
= HeapAlloc(heap
, flags
, dwSize
);
167 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
170 TRACE("returning %ld\n", ret
);
175 /******************************************************************
176 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
178 * Get the route table.
179 * Like GetIpForwardTable(), but allocate the returned table from heap.
182 * ppIpForwardTable [Out] pointer into which the MIB_IPFORWARDTABLE is
183 * allocated and returned.
184 * bOrder [In] passed to GetIfTable to order the table
185 * heap [In] heap from which the table is allocated
186 * flags [In] flags to HeapAlloc
189 * ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
190 * GetIpForwardTable() returns otherwise.
192 DWORD WINAPI
AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE
*
193 ppIpForwardTable
, BOOL bOrder
, HANDLE heap
, DWORD flags
)
197 TRACE("ppIpForwardTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
198 ppIpForwardTable
, bOrder
, heap
, flags
);
199 if (!ppIpForwardTable
)
200 ret
= ERROR_INVALID_PARAMETER
;
204 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
205 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
206 *ppIpForwardTable
= HeapAlloc(heap
, flags
, dwSize
);
207 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
210 TRACE("returning %ld\n", ret
);
215 /******************************************************************
216 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
218 * Get the IP-to-physical address mapping table.
219 * Like GetIpNetTable(), but allocate the returned table from heap.
222 * ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE is
223 * allocated and returned.
224 * bOrder [In] passed to GetIpNetTable to order the table
225 * heap [In] heap from which the table is allocated
226 * flags [In] flags to HeapAlloc
229 * ERROR_INVALID_PARAMETER if ppIpNetTable is NULL, whatever GetIpNetTable()
232 DWORD WINAPI
AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE
*ppIpNetTable
,
233 BOOL bOrder
, HANDLE heap
, DWORD flags
)
237 TRACE("ppIpNetTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
238 ppIpNetTable
, bOrder
, heap
, flags
);
240 ret
= ERROR_INVALID_PARAMETER
;
244 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
245 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
246 *ppIpNetTable
= HeapAlloc(heap
, flags
, dwSize
);
247 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
250 TRACE("returning %ld\n", ret
);
255 /******************************************************************
256 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
258 * Get the TCP connection table.
259 * Like GetTcpTable(), but allocate the returned table from heap.
262 * ppTcpTable [Out] pointer into which the MIB_TCPTABLE is
263 * allocated and returned.
264 * bOrder [In] passed to GetTcpTable to order the table
265 * heap [In] heap from which the table is allocated
266 * flags [In] flags to HeapAlloc
269 * ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable()
272 DWORD WINAPI
AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE
*ppTcpTable
,
273 BOOL bOrder
, HANDLE heap
, DWORD flags
)
277 TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
278 ppTcpTable
, bOrder
, heap
, flags
);
280 ret
= ERROR_INVALID_PARAMETER
;
284 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
285 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
286 *ppTcpTable
= HeapAlloc(heap
, flags
, dwSize
);
287 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
290 TRACE("returning %ld\n", ret
);
295 /******************************************************************
296 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
298 * Get the UDP listener table.
299 * Like GetUdpTable(), but allocate the returned table from heap.
302 * ppUdpTable [Out] pointer into which the MIB_UDPTABLE is
303 * allocated and returned.
304 * bOrder [In] passed to GetUdpTable to order the table
305 * heap [In] heap from which the table is allocated
306 * flags [In] flags to HeapAlloc
309 * ERROR_INVALID_PARAMETER if ppUdpTable is NULL, whatever GetUdpTable()
312 DWORD WINAPI
AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE
*ppUdpTable
,
313 BOOL bOrder
, HANDLE heap
, DWORD flags
)
317 TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
318 ppUdpTable
, bOrder
, heap
, flags
);
320 ret
= ERROR_INVALID_PARAMETER
;
324 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
325 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
326 *ppUdpTable
= HeapAlloc(heap
, flags
, dwSize
);
327 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
330 TRACE("returning %ld\n", ret
);
335 /******************************************************************
336 * CreateIpForwardEntry (IPHLPAPI.@)
338 * Create a route in the local computer's IP table.
341 * pRoute [In] new route information
345 * Failure: error code from winerror.h
348 * Stub, always returns NO_ERROR.
350 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
352 FIXME("(pRoute %p): stub\n", pRoute
);
353 /* could use SIOCADDRT, not sure I want to */
358 /******************************************************************
359 * CreateIpNetEntry (IPHLPAPI.@)
361 * Create entry in the ARP table.
364 * pArpEntry [In] new ARP entry
368 * Failure: error code from winerror.h
371 * Stub, always returns NO_ERROR.
373 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
375 FIXME("(pArpEntry %p)\n", pArpEntry
);
376 /* could use SIOCSARP on systems that support it, not sure I want to */
381 /******************************************************************
382 * CreateProxyArpEntry (IPHLPAPI.@)
384 * Create a Proxy ARP (PARP) entry for an IP address.
387 * dwAddress [In] IP address for which this computer acts as a proxy.
388 * dwMask [In] subnet mask for dwAddress
389 * dwIfIndex [In] interface index
393 * Failure: error code from winerror.h
396 * Stub, returns ERROR_NOT_SUPPORTED.
398 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
400 FIXME("(dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx): stub\n",
401 dwAddress
, dwMask
, dwIfIndex
);
402 /* marking Win2K+ functions not supported */
403 return ERROR_NOT_SUPPORTED
;
407 /******************************************************************
408 * DeleteIPAddress (IPHLPAPI.@)
410 * Delete an IP address added with AddIPAddress().
413 * NTEContext [In] NTE context from AddIPAddress();
417 * Failure: error code from winerror.h
420 * Stub, returns ERROR_NOT_SUPPORTED.
422 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
424 FIXME("(NTEContext %ld): stub\n", NTEContext
);
425 /* marking Win2K+ functions not supported */
426 return ERROR_NOT_SUPPORTED
;
430 /******************************************************************
431 * DeleteIpForwardEntry (IPHLPAPI.@)
436 * pRoute [In] route to delete
440 * Failure: error code from winerror.h
443 * Stub, returns NO_ERROR.
445 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
447 FIXME("(pRoute %p): stub\n", pRoute
);
448 /* could use SIOCDELRT, not sure I want to */
453 /******************************************************************
454 * DeleteIpNetEntry (IPHLPAPI.@)
456 * Delete an ARP entry.
459 * pArpEntry [In] ARP entry to delete
463 * Failure: error code from winerror.h
466 * Stub, returns NO_ERROR.
468 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
470 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
471 /* could use SIOCDARP on systems that support it, not sure I want to */
476 /******************************************************************
477 * DeleteProxyArpEntry (IPHLPAPI.@)
479 * Delete a Proxy ARP entry.
482 * dwAddress [In] IP address for which this computer acts as a proxy.
483 * dwMask [In] subnet mask for dwAddress
484 * dwIfIndex [In] interface index
488 * Failure: error code from winerror.h
491 * Stub, returns ERROR_NOT_SUPPORTED.
493 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
495 FIXME("(dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx): stub\n",
496 dwAddress
, dwMask
, dwIfIndex
);
497 /* marking Win2K+ functions not supported */
498 return ERROR_NOT_SUPPORTED
;
502 /******************************************************************
503 * EnableRouter (IPHLPAPI.@)
505 * Turn on ip forwarding.
509 * pOverlapped [In/Out] hEvent member should contain a valid handle.
512 * Success: ERROR_IO_PENDING
513 * Failure: error code from winerror.h
516 * Stub, returns ERROR_NOT_SUPPORTED.
518 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
520 FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle
, pOverlapped
);
521 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
522 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
523 marking Win2K+ functions not supported */
524 return ERROR_NOT_SUPPORTED
;
528 /******************************************************************
529 * FlushIpNetTable (IPHLPAPI.@)
531 * Delete all ARP entries of an interface
534 * dwIfIndex [In] interface index
538 * Failure: error code from winerror.h
541 * Stub, returns ERROR_NOT_SUPPORTED.
543 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
545 FIXME("(dwIfIndex 0x%08lx): stub\n", dwIfIndex
);
546 /* this flushes the arp cache of the given index
547 marking Win2K+ functions not supported */
548 return ERROR_NOT_SUPPORTED
;
552 /******************************************************************
553 * GetAdapterIndex (IPHLPAPI.@)
555 * Get interface index from its name.
558 * AdapterName [In] unicode string with the adapter name
559 * IfIndex [Out] returns found interface index
563 * Failure: error code from winerror.h
566 * Stub, returns ERROR_NOT_SUPPORTED.
568 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
570 FIXME("(AdapterName %p, IfIndex %p): stub\n", AdapterName
, IfIndex
);
571 /* marking Win2K+ functions not supported */
572 return ERROR_NOT_SUPPORTED
;
576 /******************************************************************
577 * GetAdaptersInfo (IPHLPAPI.@)
579 * Get information about adapters.
582 * pAdapterInfo [Out] buffer for adapter infos
583 * pOutBufLen [In] length of output buffer
587 * Failure: error code from winerror.h
589 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
593 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
595 ret
= ERROR_INVALID_PARAMETER
;
597 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
599 if (numNonLoopbackInterfaces
> 0) {
600 /* this calculation assumes only one address in the IP_ADDR_STRING lists.
601 that's okay, because:
602 - we don't get multiple addresses per adapter anyway
603 - we don't know about per-adapter gateways
604 - DHCP and WINS servers can have max one entry per list */
605 ULONG size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
607 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
609 ret
= ERROR_BUFFER_OVERFLOW
;
612 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
615 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
616 if (*pOutBufLen
< size
) {
618 ret
= ERROR_INSUFFICIENT_BUFFER
;
623 BOOL winsEnabled
= FALSE
;
624 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
626 memset(pAdapterInfo
, 0, size
);
627 /* @@ Wine registry key: HKCU\Software\Wine\Network */
628 if (RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Network", &hKey
) == ERROR_SUCCESS
) {
629 DWORD size
= sizeof(primaryWINS
.String
);
632 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
633 (LPBYTE
)primaryWINS
.String
, &size
);
634 addr
= inet_addr(primaryWINS
.String
);
635 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
637 size
= sizeof(secondaryWINS
.String
);
638 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
639 (LPBYTE
)secondaryWINS
.String
, &size
);
640 addr
= inet_addr(secondaryWINS
.String
);
641 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
645 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
646 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
647 DWORD addrLen
= sizeof(ptr
->Address
), type
;
649 /* on Win98 this is left empty, but whatever */
650 lstrcpynA(ptr
->AdapterName
,
651 getInterfaceNameByIndex(table
->indexes
[ndx
]),
652 MAX_ADAPTER_NAME_LENGTH
+1);
653 getInterfacePhysicalByIndex(table
->indexes
[ndx
], &addrLen
,
654 ptr
->Address
, &type
);
655 /* MS defines address length and type as UINT in some places and
656 DWORD in others, **sigh**. Don't want to assume that PUINT and
657 PDWORD are equiv (64-bit?) */
658 ptr
->AddressLength
= addrLen
;
660 ptr
->Index
= table
->indexes
[ndx
];
661 toIPAddressString(getInterfaceIPAddrByIndex(table
->indexes
[ndx
]),
662 ptr
->IpAddressList
.IpAddress
.String
);
663 toIPAddressString(getInterfaceMaskByIndex(table
->indexes
[ndx
]),
664 ptr
->IpAddressList
.IpMask
.String
);
666 ptr
->HaveWins
= TRUE
;
667 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
668 primaryWINS
.String
, sizeof(primaryWINS
.String
));
669 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
670 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
672 if (ndx
< table
->numIndexes
- 1)
673 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
679 HeapFree(GetProcessHeap(), 0, table
);
682 ret
= ERROR_OUTOFMEMORY
;
688 TRACE("returning %ld\n", ret
);
693 /******************************************************************
694 * GetBestInterface (IPHLPAPI.@)
696 * Get the interface, with the best route for the given IP address.
699 * dwDestAddr [In] IP address to search the interface for
700 * pdwBestIfIndex [Out] found best interface
704 * Failure: error code from winerror.h
706 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
710 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr
, pdwBestIfIndex
);
712 ret
= ERROR_INVALID_PARAMETER
;
714 MIB_IPFORWARDROW ipRow
;
716 ret
= GetBestRoute(dwDestAddr
, 0, &ipRow
);
717 if (ret
== ERROR_SUCCESS
)
718 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
720 TRACE("returning %ld\n", ret
);
725 /******************************************************************
726 * GetBestRoute (IPHLPAPI.@)
728 * Get the best route for the given IP address.
731 * dwDestAddr [In] IP address to search the best route for
732 * dwSourceAddr [In] optional source IP address
733 * pBestRoute [Out] found best route
737 * Failure: error code from winerror.h
739 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
741 PMIB_IPFORWARDTABLE table
;
744 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr
,
745 dwSourceAddr
, pBestRoute
);
747 return ERROR_INVALID_PARAMETER
;
749 AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
751 DWORD ndx
, matchedBits
, matchedNdx
= 0;
753 for (ndx
= 0, matchedBits
= 0; ndx
< table
->dwNumEntries
; ndx
++) {
754 if ((dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
755 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
756 DWORD numShifts
, mask
;
758 for (numShifts
= 0, mask
= table
->table
[ndx
].dwForwardMask
;
759 mask
&& !(mask
& 1); mask
>>= 1, numShifts
++)
761 if (numShifts
> matchedBits
) {
762 matchedBits
= numShifts
;
767 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
768 HeapFree(GetProcessHeap(), 0, table
);
772 ret
= ERROR_OUTOFMEMORY
;
773 TRACE("returning %ld\n", ret
);
778 /******************************************************************
779 * GetFriendlyIfIndex (IPHLPAPI.@)
781 * Get a "friendly" version of IfIndex, which is one that doesn't
782 * have the top byte set. Doesn't validate whether IfIndex is a valid
786 * IfIndex [In] interface index to get the friendly one for
789 * A friendly version of IfIndex.
791 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
793 /* windows doesn't validate these, either, just makes sure the top byte is
794 cleared. I assume my ifenum module never gives an index with the top
796 TRACE("returning %ld\n", IfIndex
);
801 /******************************************************************
802 * GetIcmpStatistics (IPHLPAPI.@)
804 * Get the ICMP statistics for the local computer.
807 * pStats [Out] buffer for ICMP statistics
811 * Failure: error code from winerror.h
813 DWORD WINAPI
GetIcmpStatistics(PMIB_ICMP pStats
)
817 TRACE("pStats %p\n", pStats
);
818 ret
= getICMPStats(pStats
);
819 TRACE("returning %ld\n", ret
);
824 /******************************************************************
825 * GetIfEntry (IPHLPAPI.@)
827 * Get information about an interface.
830 * pIfRow [In/Out] In: dwIndex of MIB_IFROW selects the interface.
831 * Out: interface information
835 * Failure: error code from winerror.h
837 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
842 TRACE("pIfRow %p\n", pIfRow
);
844 return ERROR_INVALID_PARAMETER
;
846 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
);
848 ret
= getInterfaceEntryByName(name
, pIfRow
);
850 ret
= getInterfaceStatsByName(name
, pIfRow
);
853 ret
= ERROR_INVALID_DATA
;
854 TRACE("returning %ld\n", ret
);
859 static int IfTableSorter(const void *a
, const void *b
)
864 ret
= ((const MIB_IFROW
*)a
)->dwIndex
- ((const MIB_IFROW
*)b
)->dwIndex
;
871 /******************************************************************
872 * GetIfTable (IPHLPAPI.@)
874 * Get a table of local interfaces.
877 * pIfTable [Out] buffer for local interfaces table
878 * pdwSize [In/Out] length of output buffer
879 * bOrder [In] whether to sort the table
883 * Failure: error code from winerror.h
886 * If pdwSize is less than required, the function will return
887 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
889 * If bOrder is true, the returned table will be sorted by interface index.
891 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
895 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize
, pdwSize
,
898 ret
= ERROR_INVALID_PARAMETER
;
900 DWORD numInterfaces
= getNumInterfaces();
901 ULONG size
= sizeof(MIB_IFTABLE
) + (numInterfaces
- 1) * sizeof(MIB_IFROW
);
903 if (!pIfTable
|| *pdwSize
< size
) {
905 ret
= ERROR_INSUFFICIENT_BUFFER
;
908 InterfaceIndexTable
*table
= getInterfaceIndexTable();
911 size
= sizeof(MIB_IFTABLE
) + (table
->numIndexes
- 1) *
913 if (*pdwSize
< size
) {
915 ret
= ERROR_INSUFFICIENT_BUFFER
;
920 pIfTable
->dwNumEntries
= 0;
921 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
922 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
923 GetIfEntry(&pIfTable
->table
[ndx
]);
924 pIfTable
->dwNumEntries
++;
927 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
931 HeapFree(GetProcessHeap(), 0, table
);
934 ret
= ERROR_OUTOFMEMORY
;
937 TRACE("returning %ld\n", ret
);
942 /******************************************************************
943 * GetInterfaceInfo (IPHLPAPI.@)
945 * Get a list of network interface adapters.
948 * pIfTable [Out] buffer for intertace adapters
949 * dwOutBufLen [Out] if buffer is too small, returns required size
953 * Failure: error code from winerror.h
955 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
959 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
961 ret
= ERROR_INVALID_PARAMETER
;
963 DWORD numInterfaces
= getNumInterfaces();
964 ULONG size
= sizeof(IP_INTERFACE_INFO
) + (numInterfaces
- 1) *
965 sizeof(IP_ADAPTER_INDEX_MAP
);
967 if (!pIfTable
|| *dwOutBufLen
< size
) {
969 ret
= ERROR_INSUFFICIENT_BUFFER
;
972 InterfaceIndexTable
*table
= getInterfaceIndexTable();
975 size
= sizeof(IP_INTERFACE_INFO
) + (table
->numIndexes
- 1) *
976 sizeof(IP_ADAPTER_INDEX_MAP
);
977 if (*dwOutBufLen
< size
) {
979 ret
= ERROR_INSUFFICIENT_BUFFER
;
984 pIfTable
->NumAdapters
= 0;
985 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
986 const char *walker
, *name
;
989 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
990 name
= getInterfaceNameByIndex(table
->indexes
[ndx
]);
991 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
993 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
994 walker
++, assigner
++)
997 pIfTable
->NumAdapters
++;
1001 HeapFree(GetProcessHeap(), 0, table
);
1004 ret
= ERROR_OUTOFMEMORY
;
1007 TRACE("returning %ld\n", ret
);
1012 static int IpAddrTableSorter(const void *a
, const void *b
)
1017 ret
= ((const MIB_IPADDRROW
*)a
)->dwAddr
- ((const MIB_IPADDRROW
*)b
)->dwAddr
;
1024 /******************************************************************
1025 * GetIpAddrTable (IPHLPAPI.@)
1027 * Get interface-to-IP address mapping table.
1030 * pIpAddrTable [Out] buffer for mapping table
1031 * pdwSize [In/Out] length of output buffer
1032 * bOrder [In] whether to sort the table
1036 * Failure: error code from winerror.h
1039 * If pdwSize is less than required, the function will return
1040 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1042 * If bOrder is true, the returned table will be sorted by the next hop and
1043 * an assortment of arbitrary parameters.
1045 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1049 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable
, pdwSize
,
1052 ret
= ERROR_INVALID_PARAMETER
;
1054 DWORD numInterfaces
= getNumInterfaces();
1055 ULONG size
= sizeof(MIB_IPADDRTABLE
) + (numInterfaces
- 1) *
1056 sizeof(MIB_IPADDRROW
);
1058 if (!pIpAddrTable
|| *pdwSize
< size
) {
1060 ret
= ERROR_INSUFFICIENT_BUFFER
;
1063 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1066 size
= sizeof(MIB_IPADDRTABLE
) + (table
->numIndexes
- 1) *
1067 sizeof(MIB_IPADDRROW
);
1068 if (*pdwSize
< size
) {
1070 ret
= ERROR_INSUFFICIENT_BUFFER
;
1075 pIpAddrTable
->dwNumEntries
= 0;
1076 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1077 pIpAddrTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1078 pIpAddrTable
->table
[ndx
].dwAddr
=
1079 getInterfaceIPAddrByIndex(table
->indexes
[ndx
]);
1080 pIpAddrTable
->table
[ndx
].dwMask
=
1081 getInterfaceMaskByIndex(table
->indexes
[ndx
]);
1082 /* the dwBCastAddr member isn't the broadcast address, it indicates
1083 * whether the interface uses the 1's broadcast address (1) or the
1084 * 0's broadcast address (0).
1086 bcast
= getInterfaceBCastAddrByIndex(table
->indexes
[ndx
]);
1087 pIpAddrTable
->table
[ndx
].dwBCastAddr
=
1088 (bcast
& pIpAddrTable
->table
[ndx
].dwMask
) ? 1 : 0;
1089 /* FIXME: hardcoded reasm size, not sure where to get it */
1090 pIpAddrTable
->table
[ndx
].dwReasmSize
= 65535;
1091 pIpAddrTable
->table
[ndx
].unused1
= 0;
1092 pIpAddrTable
->table
[ndx
].wType
= 0; /* aka unused2 */
1093 pIpAddrTable
->dwNumEntries
++;
1096 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1097 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1100 HeapFree(GetProcessHeap(), 0, table
);
1103 ret
= ERROR_OUTOFMEMORY
;
1106 TRACE("returning %ld\n", ret
);
1111 static int IpForwardTableSorter(const void *a
, const void *b
)
1116 const MIB_IPFORWARDROW
* rowA
= (const MIB_IPFORWARDROW
*)a
;
1117 const MIB_IPFORWARDROW
* rowB
= (const MIB_IPFORWARDROW
*)b
;
1119 ret
= rowA
->dwForwardDest
- rowB
->dwForwardDest
;
1121 ret
= rowA
->dwForwardProto
- rowB
->dwForwardProto
;
1123 ret
= rowA
->dwForwardPolicy
- rowB
->dwForwardPolicy
;
1125 ret
= rowA
->dwForwardNextHop
- rowB
->dwForwardNextHop
;
1135 /******************************************************************
1136 * GetIpForwardTable (IPHLPAPI.@)
1138 * Get the route table.
1141 * pIpForwardTable [Out] buffer for route table
1142 * pdwSize [In/Out] length of output buffer
1143 * bOrder [In] whether to sort the table
1147 * Failure: error code from winerror.h
1150 * If pdwSize is less than required, the function will return
1151 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1153 * If bOrder is true, the returned table will be sorted by the next hop and
1154 * an assortment of arbitrary parameters.
1156 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1160 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable
,
1161 pdwSize
, (DWORD
)bOrder
);
1163 ret
= ERROR_INVALID_PARAMETER
;
1165 DWORD numRoutes
= getNumRoutes();
1166 ULONG sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (numRoutes
- 1) *
1167 sizeof(MIB_IPFORWARDROW
);
1169 if (!pIpForwardTable
|| *pdwSize
< sizeNeeded
) {
1170 *pdwSize
= sizeNeeded
;
1171 ret
= ERROR_INSUFFICIENT_BUFFER
;
1174 RouteTable
*table
= getRouteTable();
1176 sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (table
->numRoutes
- 1) *
1177 sizeof(MIB_IPFORWARDROW
);
1178 if (*pdwSize
< sizeNeeded
) {
1179 *pdwSize
= sizeNeeded
;
1180 ret
= ERROR_INSUFFICIENT_BUFFER
;
1185 pIpForwardTable
->dwNumEntries
= table
->numRoutes
;
1186 for (ndx
= 0; ndx
< numRoutes
; ndx
++) {
1187 pIpForwardTable
->table
[ndx
].dwForwardIfIndex
=
1188 table
->routes
[ndx
].ifIndex
;
1189 pIpForwardTable
->table
[ndx
].dwForwardDest
=
1190 table
->routes
[ndx
].dest
;
1191 pIpForwardTable
->table
[ndx
].dwForwardMask
=
1192 table
->routes
[ndx
].mask
;
1193 pIpForwardTable
->table
[ndx
].dwForwardPolicy
= 0;
1194 pIpForwardTable
->table
[ndx
].dwForwardNextHop
=
1195 table
->routes
[ndx
].gateway
;
1196 /* FIXME: this type is appropriate for local interfaces; may not
1197 always be appropriate */
1198 pIpForwardTable
->table
[ndx
].dwForwardType
= MIB_IPROUTE_TYPE_DIRECT
;
1199 /* FIXME: other protos might be appropriate, e.g. the default route
1200 is typically set with MIB_IPPROTO_NETMGMT instead */
1201 pIpForwardTable
->table
[ndx
].dwForwardProto
= MIB_IPPROTO_LOCAL
;
1202 /* punt on age and AS */
1203 pIpForwardTable
->table
[ndx
].dwForwardAge
= 0;
1204 pIpForwardTable
->table
[ndx
].dwForwardNextHopAS
= 0;
1205 pIpForwardTable
->table
[ndx
].dwForwardMetric1
=
1206 table
->routes
[ndx
].metric
;
1207 /* rest of the metrics are 0.. */
1208 pIpForwardTable
->table
[ndx
].dwForwardMetric2
= 0;
1209 pIpForwardTable
->table
[ndx
].dwForwardMetric3
= 0;
1210 pIpForwardTable
->table
[ndx
].dwForwardMetric4
= 0;
1211 pIpForwardTable
->table
[ndx
].dwForwardMetric5
= 0;
1214 qsort(pIpForwardTable
->table
, pIpForwardTable
->dwNumEntries
,
1215 sizeof(MIB_IPFORWARDROW
), IpForwardTableSorter
);
1218 HeapFree(GetProcessHeap(), 0, table
);
1221 ret
= ERROR_OUTOFMEMORY
;
1224 TRACE("returning %ld\n", ret
);
1229 static int IpNetTableSorter(const void *a
, const void *b
)
1234 ret
= ((const MIB_IPNETROW
*)a
)->dwAddr
- ((const MIB_IPNETROW
*)b
)->dwAddr
;
1241 /******************************************************************
1242 * GetIpNetTable (IPHLPAPI.@)
1244 * Get the IP-to-physical address mapping table.
1247 * pIpNetTable [Out] buffer for mapping table
1248 * pdwSize [In/Out] length of output buffer
1249 * bOrder [In] whether to sort the table
1253 * Failure: error code from winerror.h
1256 * If pdwSize is less than required, the function will return
1257 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1259 * If bOrder is true, the returned table will be sorted by IP address.
1261 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
1265 TRACE("pIpNetTable %p, pdwSize %p, bOrder %ld\n", pIpNetTable
, pdwSize
,
1268 ret
= ERROR_INVALID_PARAMETER
;
1270 DWORD numEntries
= getNumArpEntries();
1271 ULONG size
= sizeof(MIB_IPNETTABLE
) + (numEntries
- 1) *
1272 sizeof(MIB_IPNETROW
);
1274 if (!pIpNetTable
|| *pdwSize
< size
) {
1276 ret
= ERROR_INSUFFICIENT_BUFFER
;
1279 PMIB_IPNETTABLE table
= getArpTable();
1282 size
= sizeof(MIB_IPNETTABLE
) + (table
->dwNumEntries
- 1) *
1283 sizeof(MIB_IPNETROW
);
1284 if (*pdwSize
< size
) {
1286 ret
= ERROR_INSUFFICIENT_BUFFER
;
1289 memcpy(pIpNetTable
, table
, size
);
1291 qsort(pIpNetTable
->table
, pIpNetTable
->dwNumEntries
,
1292 sizeof(MIB_IPNETROW
), IpNetTableSorter
);
1295 HeapFree(GetProcessHeap(), 0, table
);
1298 ret
= ERROR_OUTOFMEMORY
;
1301 TRACE("returning %ld\n", ret
);
1306 /******************************************************************
1307 * GetIpStatistics (IPHLPAPI.@)
1309 * Get the IP statistics for the local computer.
1312 * pStats [Out] buffer for IP statistics
1316 * Failure: error code from winerror.h
1318 DWORD WINAPI
GetIpStatistics(PMIB_IPSTATS pStats
)
1322 TRACE("pStats %p\n", pStats
);
1323 ret
= getIPStats(pStats
);
1324 TRACE("returning %ld\n", ret
);
1329 /******************************************************************
1330 * GetNetworkParams (IPHLPAPI.@)
1332 * Get the network parameters for the local computer.
1335 * pFixedInfo [Out] buffer for network parameters
1336 * pOutBufLen [In/Out] length of output buffer
1340 * Failure: error code from winerror.h
1343 * If pOutBufLen is less than required, the function will return
1344 * ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1347 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
1353 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
1355 return ERROR_INVALID_PARAMETER
;
1358 size
= sizeof(FIXED_INFO
) + (_res
.nscount
> 0 ? (_res
.nscount
- 1) *
1359 sizeof(IP_ADDR_STRING
) : 0);
1360 if (!pFixedInfo
|| *pOutBufLen
< size
) {
1362 return ERROR_BUFFER_OVERFLOW
;
1365 memset(pFixedInfo
, 0, size
);
1366 size
= sizeof(pFixedInfo
->HostName
);
1367 GetComputerNameExA(ComputerNameDnsHostname
, pFixedInfo
->HostName
, &size
);
1368 size
= sizeof(pFixedInfo
->DomainName
);
1369 GetComputerNameExA(ComputerNameDnsDomain
, pFixedInfo
->DomainName
, &size
);
1370 if (_res
.nscount
> 0) {
1371 PIP_ADDR_STRING ptr
;
1374 for (i
= 0, ptr
= &pFixedInfo
->DnsServerList
; i
< _res
.nscount
&& ptr
;
1375 i
++, ptr
= ptr
->Next
) {
1376 toIPAddressString(_res
.nsaddr_list
[i
].sin_addr
.s_addr
,
1377 ptr
->IpAddress
.String
);
1378 if (i
== _res
.nscount
- 1)
1381 ptr
->Next
= (PIP_ADDR_STRING
)((LPBYTE
)pFixedInfo
+ sizeof(FIXED_INFO
));
1383 ptr
->Next
= (PIP_ADDR_STRING
)((PBYTE
)ptr
+ sizeof(IP_ADDR_STRING
));
1386 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
1387 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1388 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
1389 if (regReturn
!= ERROR_SUCCESS
)
1390 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1391 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
1393 if (regReturn
== ERROR_SUCCESS
)
1395 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
1397 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (LPBYTE
)pFixedInfo
->ScopeId
, &size
);
1401 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1402 I suppose could also check for a listener on port 53 to set EnableDns */
1404 TRACE("returning %ld\n", ret
);
1409 /******************************************************************
1410 * GetNumberOfInterfaces (IPHLPAPI.@)
1412 * Get the number of interfaces.
1415 * pdwNumIf [Out] number of interfaces
1418 * NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1420 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
1424 TRACE("pdwNumIf %p\n", pdwNumIf
);
1426 ret
= ERROR_INVALID_PARAMETER
;
1428 *pdwNumIf
= getNumInterfaces();
1431 TRACE("returning %ld\n", ret
);
1436 /******************************************************************
1437 * GetPerAdapterInfo (IPHLPAPI.@)
1439 * Get information about an adapter corresponding to an interface.
1442 * IfIndex [In] interface info
1443 * pPerAdapterInfo [Out] buffer for per adapter info
1444 * pOutBufLen [In/Out] length of output buffer
1448 * Failure: error code from winerror.h
1451 * Stub, returns ERROR_NOT_SUPPORTED.
1453 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
1455 TRACE("(IfIndex %ld, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex
,
1456 pPerAdapterInfo
, pOutBufLen
);
1457 /* marking Win2K+ functions not supported */
1458 return ERROR_NOT_SUPPORTED
;
1462 /******************************************************************
1463 * GetRTTAndHopCount (IPHLPAPI.@)
1465 * Get round-trip time (RTT) and hop count.
1469 * DestIpAddress [In] destination address to get the info for
1470 * HopCount [Out] retrieved hop count
1471 * MaxHops [In] maximum hops to search for the destination
1472 * RTT [Out] RTT in milliseconds
1479 * Stub, returns FALSE.
1481 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
1483 FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p): stub\n",
1484 DestIpAddress
, HopCount
, MaxHops
, RTT
);
1489 /******************************************************************
1490 * GetTcpStatistics (IPHLPAPI.@)
1492 * Get the TCP statistics for the local computer.
1495 * pStats [Out] buffer for TCP statistics
1499 * Failure: error code from winerror.h
1501 DWORD WINAPI
GetTcpStatistics(PMIB_TCPSTATS pStats
)
1505 TRACE("pStats %p\n", pStats
);
1506 ret
= getTCPStats(pStats
);
1507 TRACE("returning %ld\n", ret
);
1512 static int TcpTableSorter(const void *a
, const void *b
)
1517 const MIB_TCPROW
* rowA
= a
;
1518 const MIB_TCPROW
* rowB
= b
;
1520 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1522 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1524 ret
= rowA
->dwRemoteAddr
- rowB
->dwRemoteAddr
;
1526 ret
= rowA
->dwRemotePort
- rowB
->dwRemotePort
;
1536 /******************************************************************
1537 * GetTcpTable (IPHLPAPI.@)
1539 * Get the table of active TCP connections.
1542 * pTcpTable [Out] buffer for TCP connections table
1543 * pdwSize [In/Out] length of output buffer
1544 * bOrder [In] whether to order the table
1548 * Failure: error code from winerror.h
1551 * If pdwSize is less than required, the function will return
1552 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1553 * the required byte size.
1554 * If bOrder is true, the returned table will be sorted, first by
1555 * local address and port number, then by remote address and port
1558 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
1562 TRACE("pTcpTable %p, pdwSize %p, bOrder %ld\n", pTcpTable
, pdwSize
,
1565 ret
= ERROR_INVALID_PARAMETER
;
1567 DWORD numEntries
= getNumTcpEntries();
1568 ULONG size
= sizeof(MIB_TCPTABLE
) + (numEntries
- 1) * sizeof(MIB_TCPROW
);
1570 if (!pTcpTable
|| *pdwSize
< size
) {
1572 ret
= ERROR_INSUFFICIENT_BUFFER
;
1575 PMIB_TCPTABLE table
= getTcpTable();
1578 size
= sizeof(MIB_TCPTABLE
) + (table
->dwNumEntries
- 1) *
1580 if (*pdwSize
< size
) {
1582 ret
= ERROR_INSUFFICIENT_BUFFER
;
1585 memcpy(pTcpTable
, table
, size
);
1587 qsort(pTcpTable
->table
, pTcpTable
->dwNumEntries
,
1588 sizeof(MIB_TCPROW
), TcpTableSorter
);
1591 HeapFree(GetProcessHeap(), 0, table
);
1594 ret
= ERROR_OUTOFMEMORY
;
1597 TRACE("returning %ld\n", ret
);
1602 /******************************************************************
1603 * GetUdpStatistics (IPHLPAPI.@)
1605 * Get the UDP statistics for the local computer.
1608 * pStats [Out] buffer for UDP statistics
1612 * Failure: error code from winerror.h
1614 DWORD WINAPI
GetUdpStatistics(PMIB_UDPSTATS pStats
)
1618 TRACE("pStats %p\n", pStats
);
1619 ret
= getUDPStats(pStats
);
1620 TRACE("returning %ld\n", ret
);
1625 static int UdpTableSorter(const void *a
, const void *b
)
1630 const MIB_UDPROW
* rowA
= (const MIB_UDPROW
*)a
;
1631 const MIB_UDPROW
* rowB
= (const MIB_UDPROW
*)b
;
1633 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1635 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1643 /******************************************************************
1644 * GetUdpTable (IPHLPAPI.@)
1646 * Get a table of active UDP connections.
1649 * pUdpTable [Out] buffer for UDP connections table
1650 * pdwSize [In/Out] length of output buffer
1651 * bOrder [In] whether to order the table
1655 * Failure: error code from winerror.h
1658 * If pdwSize is less than required, the function will return
1659 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1660 * required byte size.
1661 * If bOrder is true, the returned table will be sorted, first by
1662 * local address, then by local port number.
1664 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
1668 TRACE("pUdpTable %p, pdwSize %p, bOrder %ld\n", pUdpTable
, pdwSize
,
1671 ret
= ERROR_INVALID_PARAMETER
;
1673 DWORD numEntries
= getNumUdpEntries();
1674 ULONG size
= sizeof(MIB_UDPTABLE
) + (numEntries
- 1) * sizeof(MIB_UDPROW
);
1676 if (!pUdpTable
|| *pdwSize
< size
) {
1678 ret
= ERROR_INSUFFICIENT_BUFFER
;
1681 PMIB_UDPTABLE table
= getUdpTable();
1684 size
= sizeof(MIB_UDPTABLE
) + (table
->dwNumEntries
- 1) *
1686 if (*pdwSize
< size
) {
1688 ret
= ERROR_INSUFFICIENT_BUFFER
;
1691 memcpy(pUdpTable
, table
, size
);
1693 qsort(pUdpTable
->table
, pUdpTable
->dwNumEntries
,
1694 sizeof(MIB_UDPROW
), UdpTableSorter
);
1697 HeapFree(GetProcessHeap(), 0, table
);
1700 ret
= ERROR_OUTOFMEMORY
;
1703 TRACE("returning %ld\n", ret
);
1708 /******************************************************************
1709 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1711 * This is a Win98-only function to get information on "unidirectional"
1712 * adapters. Since this is pretty nonsensical in other contexts, it
1713 * never returns anything.
1716 * pIPIfInfo [Out] buffer for adapter infos
1717 * dwOutBufLen [Out] length of the output buffer
1721 * Failure: error code from winerror.h
1724 * Stub, returns ERROR_NOT_SUPPORTED.
1726 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
1728 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
1729 /* a unidirectional adapter?? not bloody likely! */
1730 return ERROR_NOT_SUPPORTED
;
1734 /******************************************************************
1735 * IpReleaseAddress (IPHLPAPI.@)
1737 * Release an IP optained through DHCP,
1740 * AdapterInfo [In] adapter to release IP address
1744 * Failure: error code from winerror.h
1747 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1748 * this function does nothing.
1751 * Stub, returns ERROR_NOT_SUPPORTED.
1753 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1755 TRACE("AdapterInfo %p\n", AdapterInfo
);
1756 /* not a stub, never going to support this (and I never mark an adapter as
1757 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1758 return ERROR_NOT_SUPPORTED
;
1762 /******************************************************************
1763 * IpRenewAddress (IPHLPAPI.@)
1765 * Renew an IP optained through DHCP.
1768 * AdapterInfo [In] adapter to renew IP address
1772 * Failure: error code from winerror.h
1775 * Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1776 * this function does nothing.
1779 * Stub, returns ERROR_NOT_SUPPORTED.
1781 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
1783 TRACE("AdapterInfo %p\n", AdapterInfo
);
1784 /* not a stub, never going to support this (and I never mark an adapter as
1785 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1786 return ERROR_NOT_SUPPORTED
;
1790 /******************************************************************
1791 * NotifyAddrChange (IPHLPAPI.@)
1793 * Notify caller whenever the ip-interface map is changed.
1796 * Handle [Out] handle useable in asynchronus notification
1797 * overlapped [In] overlapped structure that notifies the caller
1801 * Failure: error code from winerror.h
1804 * Stub, returns ERROR_NOT_SUPPORTED.
1806 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
1808 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
1809 /* marking Win2K+ functions not supported */
1810 return ERROR_NOT_SUPPORTED
;
1814 /******************************************************************
1815 * NotifyRouteChange (IPHLPAPI.@)
1817 * Notify caller whenever the ip routing table is changed.
1820 * Handle [Out] handle useable in asynchronus notification
1821 * overlapped [In] overlapped structure that notifies the caller
1825 * Failure: error code from winerror.h
1828 * Stub, returns ERROR_NOT_SUPPORTED.
1830 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
1832 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
1833 /* marking Win2K+ functions not supported */
1834 return ERROR_NOT_SUPPORTED
;
1838 /******************************************************************
1839 * SendARP (IPHLPAPI.@)
1841 * Send an ARP request.
1844 * DestIP [In] attemp to obtain this IP
1845 * SrcIP [In] optional sender IP address
1846 * pMacAddr [Out] buffer for the mac address
1847 * PhyAddrLen [In/Out] length of the output buffer
1851 * Failure: error code from winerror.h
1854 * Stub, returns ERROR_NOT_SUPPORTED.
1856 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
1858 FIXME("(DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p): stub\n",
1859 DestIP
, SrcIP
, pMacAddr
, PhyAddrLen
);
1860 /* marking Win2K+ functions not supported */
1861 return ERROR_NOT_SUPPORTED
;
1865 /******************************************************************
1866 * SetIfEntry (IPHLPAPI.@)
1868 * Set the administrative status of an interface.
1871 * pIfRow [In] dwAdminStatus member specifies the new status.
1875 * Failure: error code from winerror.h
1878 * Stub, returns ERROR_NOT_SUPPORTED.
1880 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
1882 FIXME("(pIfRow %p): stub\n", pIfRow
);
1883 /* this is supposed to set an administratively interface up or down.
1884 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1885 this sort of down is indistinguishable from other sorts of down (e.g. no
1887 return ERROR_NOT_SUPPORTED
;
1891 /******************************************************************
1892 * SetIpForwardEntry (IPHLPAPI.@)
1894 * Modify an existing route.
1897 * pRoute [In] route with the new information
1901 * Failure: error code from winerror.h
1904 * Stub, returns NO_ERROR.
1906 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
1908 FIXME("(pRoute %p): stub\n", pRoute
);
1909 /* this is to add a route entry, how's it distinguishable from
1910 CreateIpForwardEntry?
1911 could use SIOCADDRT, not sure I want to */
1916 /******************************************************************
1917 * SetIpNetEntry (IPHLPAPI.@)
1919 * Modify an existing ARP entry.
1922 * pArpEntry [In] ARP entry with the new information
1926 * Failure: error code from winerror.h
1929 * Stub, returns NO_ERROR.
1931 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
1933 FIXME("(pArpEntry %p): stub\n", pArpEntry
);
1934 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1939 /******************************************************************
1940 * SetIpStatistics (IPHLPAPI.@)
1942 * Toggle IP forwarding and det the default TTL value.
1945 * pIpStats [In] IP statistics with the new information
1949 * Failure: error code from winerror.h
1952 * Stub, returns NO_ERROR.
1954 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
1956 FIXME("(pIpStats %p): stub\n", pIpStats
);
1961 /******************************************************************
1962 * SetIpTTL (IPHLPAPI.@)
1964 * Set the default TTL value.
1967 * nTTL [In] new TTL value
1971 * Failure: error code from winerror.h
1974 * Stub, returns NO_ERROR.
1976 DWORD WINAPI
SetIpTTL(UINT nTTL
)
1978 FIXME("(nTTL %d): stub\n", nTTL
);
1979 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1980 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1985 /******************************************************************
1986 * SetTcpEntry (IPHLPAPI.@)
1988 * Set the state of a TCP connection.
1991 * pTcpRow [In] specifies connection with new state
1995 * Failure: error code from winerror.h
1998 * Stub, returns NO_ERROR.
2000 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
2002 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
2007 /******************************************************************
2008 * UnenableRouter (IPHLPAPI.@)
2010 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2011 * if it reaches zero.
2014 * pOverlapped [In/Out] should be the same as in EnableRouter()
2015 * lpdwEnableCount [Out] optional, receives reference count
2019 * Failure: error code from winerror.h
2022 * Stub, returns ERROR_NOT_SUPPORTED.
2024 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
2026 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
2028 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
2029 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
2030 marking Win2K+ functions not supported */
2031 return ERROR_NOT_SUPPORTED
;