Don't use DSBCAPS_{CTRLDEFAULT,CTRLALL} in capability-dumping
[wine/wine-kai.git] / dlls / iphlpapi / iphlpapi_main.c
blob717608dc75c5c9734cad43a80a3bf52c13105851
1 /*
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
21 #include "config.h"
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <sys/types.h>
26 #ifdef HAVE_NETINET_IN_H
27 # include <netinet/in.h>
28 #endif
29 #ifdef HAVE_ARPA_INET_H
30 # include <arpa/inet.h>
31 #endif
32 #ifdef HAVE_ARPA_NAMESER_H
33 # include <arpa/nameser.h>
34 #endif
35 #ifdef HAVE_RESOLV_H
36 # include <resolv.h>
37 #endif
39 #include "windef.h"
40 #include "winbase.h"
41 #include "winreg.h"
42 #include "iphlpapi.h"
43 #include "ifenum.h"
44 #include "ipstats.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
49 #ifndef INADDR_NONE
50 #define INADDR_NONE ~0UL
51 #endif
53 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
55 switch (fdwReason) {
56 case DLL_PROCESS_ATTACH:
57 DisableThreadLibraryCalls( hinstDLL );
58 interfaceMapInit();
59 break;
61 case DLL_PROCESS_DETACH:
62 interfaceMapFree();
63 break;
65 return TRUE;
68 /******************************************************************
69 * AddIPAddress (IPHLPAPI.@)
72 * PARAMS
74 * Address [In]
75 * IpMask [In]
76 * IfIndex [In]
77 * NTEContext [In/Out]
78 * NTEInstance [In/Out]
80 * RETURNS
82 * DWORD
85 DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
87 FIXME(":stub\n");
88 /* marking Win2K+ functions not supported */
89 return ERROR_NOT_SUPPORTED;
93 /******************************************************************
94 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
97 * PARAMS
99 * ppIfTable [Out] -- pointer into which the MIB_IFTABLE is
100 * allocated and returned.
101 * bOrder [In] -- passed to GetIfTable to order the table
102 * heap [In] -- heap from which the table is allocated
103 * flags [In] -- flags to HeapAlloc
105 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
106 * GetIfTable returns otherwise
109 DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
110 BOOL bOrder, HANDLE heap, DWORD flags)
112 DWORD ret;
114 TRACE("ppIfTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n", ppIfTable,
115 (DWORD)bOrder, (DWORD)heap, flags);
116 if (!ppIfTable)
117 ret = ERROR_INVALID_PARAMETER;
118 else {
119 DWORD dwSize = 0;
121 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
122 if (ret == ERROR_INSUFFICIENT_BUFFER) {
123 *ppIfTable = (PMIB_IFTABLE)HeapAlloc(heap, flags, dwSize);
124 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
127 TRACE("returning %ld\n", ret);
128 return ret;
132 /******************************************************************
133 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
136 * PARAMS
138 * ppIpAddrTable [Out]
139 * bOrder [In] -- passed to GetIpAddrTable to order the table
140 * heap [In] -- heap from which the table is allocated
141 * flags [In] -- flags to HeapAlloc
143 * RETURNS
145 * DWORD
148 DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
149 BOOL bOrder, HANDLE heap, DWORD flags)
151 DWORD ret;
153 TRACE("ppIpAddrTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
154 ppIpAddrTable, (DWORD)bOrder, (DWORD)heap, flags);
155 if (!ppIpAddrTable)
156 ret = ERROR_INVALID_PARAMETER;
157 else {
158 DWORD dwSize = 0;
160 ret = GetIpAddrTable(*ppIpAddrTable, &dwSize, bOrder);
161 if (ret == ERROR_INSUFFICIENT_BUFFER) {
162 *ppIpAddrTable = (PMIB_IPADDRTABLE)HeapAlloc(heap, flags, dwSize);
163 ret = GetIpAddrTable(*ppIpAddrTable, &dwSize, bOrder);
166 TRACE("returning %ld\n", ret);
167 return ret;
171 /******************************************************************
172 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
175 * ppIpForwardTable [Out] -- pointer into which the MIB_IPFORWARDTABLE is
176 * allocated and returned.
177 * bOrder [In] -- passed to GetIfTable to order the table
178 * heap [In] -- heap from which the table is allocated
179 * flags [In] -- flags to HeapAlloc
181 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
182 * GetIpForwardTable returns otherwise
185 DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
186 ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags)
188 DWORD ret;
190 TRACE("ppIpForwardTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
191 ppIpForwardTable, (DWORD)bOrder, (DWORD)heap, flags);
192 if (!ppIpForwardTable)
193 ret = ERROR_INVALID_PARAMETER;
194 else {
195 DWORD dwSize = 0;
197 ret = GetIpForwardTable(*ppIpForwardTable, &dwSize, bOrder);
198 if (ret == ERROR_INSUFFICIENT_BUFFER) {
199 *ppIpForwardTable = (PMIB_IPFORWARDTABLE)HeapAlloc(heap, flags, dwSize);
200 ret = GetIpForwardTable(*ppIpForwardTable, &dwSize, bOrder);
203 TRACE("returning %ld\n", ret);
204 return ret;
208 /******************************************************************
209 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
212 * PARAMS
214 * ppIpNetTable [Out]
215 * bOrder [In] -- passed to GetIpNetTable to order the table
216 * heap [In] -- heap from which the table is allocated
217 * flags [In] -- flags to HeapAlloc
219 * RETURNS
221 * DWORD
224 DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable,
225 BOOL bOrder, HANDLE heap, DWORD flags)
227 DWORD ret;
229 TRACE("ppIpNetTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
230 ppIpNetTable, (DWORD)bOrder, (DWORD)heap, flags);
231 if (!ppIpNetTable)
232 ret = ERROR_INVALID_PARAMETER;
233 else {
234 DWORD dwSize = 0;
236 ret = GetIpNetTable(*ppIpNetTable, &dwSize, bOrder);
237 if (ret == ERROR_INSUFFICIENT_BUFFER) {
238 *ppIpNetTable = (PMIB_IPNETTABLE)HeapAlloc(heap, flags, dwSize);
239 ret = GetIpNetTable(*ppIpNetTable, &dwSize, bOrder);
242 TRACE("returning %ld\n", ret);
243 return ret;
247 /******************************************************************
248 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
251 * PARAMS
253 * ppTcpTable [Out]
254 * bOrder [In] -- passed to GetTcpTable to order the table
255 * heap [In] -- heap from which the table is allocated
256 * flags [In] -- flags to HeapAlloc
258 * RETURNS
260 * DWORD
263 DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
264 BOOL bOrder, HANDLE heap, DWORD flags)
266 DWORD ret;
268 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
269 ppTcpTable, (DWORD)bOrder, (DWORD)heap, flags);
270 if (!ppTcpTable)
271 ret = ERROR_INVALID_PARAMETER;
272 else {
273 DWORD dwSize = 0;
275 ret = GetTcpTable(*ppTcpTable, &dwSize, bOrder);
276 if (ret == ERROR_INSUFFICIENT_BUFFER) {
277 *ppTcpTable = (PMIB_TCPTABLE)HeapAlloc(heap, flags, dwSize);
278 ret = GetTcpTable(*ppTcpTable, &dwSize, bOrder);
281 TRACE("returning %ld\n", ret);
282 return ret;
286 /******************************************************************
287 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
290 * PARAMS
292 * ppUdpTable [Out]
293 * bOrder [In] -- passed to GetUdpTable to order the table
294 * heap [In] -- heap from which the table is allocated
295 * flags [In] -- flags to HeapAlloc
297 * RETURNS
299 * DWORD
302 DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
303 BOOL bOrder, HANDLE heap, DWORD flags)
305 DWORD ret;
307 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
308 ppUdpTable, (DWORD)bOrder, (DWORD)heap, flags);
309 if (!ppUdpTable)
310 ret = ERROR_INVALID_PARAMETER;
311 else {
312 DWORD dwSize = 0;
314 ret = GetUdpTable(*ppUdpTable, &dwSize, bOrder);
315 if (ret == ERROR_INSUFFICIENT_BUFFER) {
316 *ppUdpTable = (PMIB_UDPTABLE)HeapAlloc(heap, flags, dwSize);
317 ret = GetUdpTable(*ppUdpTable, &dwSize, bOrder);
320 TRACE("returning %ld\n", ret);
321 return ret;
325 /******************************************************************
326 * CreateIpForwardEntry (IPHLPAPI.@)
329 * PARAMS
331 * pRoute [In/Out]
333 * RETURNS
335 * DWORD
338 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
340 TRACE("pRoute %p\n", pRoute);
341 /* could use SIOCADDRT, not sure I want to */
342 FIXME(":stub\n");
343 return (DWORD) 0;
347 /******************************************************************
348 * CreateIpNetEntry (IPHLPAPI.@)
351 * PARAMS
353 * pArpEntry [In/Out]
355 * RETURNS
357 * DWORD
360 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
362 TRACE("pArpEntry %p\n", pArpEntry);
363 /* could use SIOCSARP on systems that support it, not sure I want to */
364 FIXME(":stub\n");
365 return (DWORD) 0;
369 /******************************************************************
370 * CreateProxyArpEntry (IPHLPAPI.@)
373 * PARAMS
375 * dwAddress [In]
376 * dwMask [In]
377 * dwIfIndex [In]
379 * RETURNS
381 * DWORD
384 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
386 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress,
387 dwMask, dwIfIndex);
388 FIXME(":stub\n");
389 /* marking Win2K+ functions not supported */
390 return ERROR_NOT_SUPPORTED;
394 /******************************************************************
395 * DeleteIPAddress (IPHLPAPI.@)
398 * PARAMS
400 * NTEContext [In]
402 * RETURNS
404 * DWORD
407 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
409 TRACE("NTEContext %ld\n", NTEContext);
410 FIXME(":stub\n");
411 /* marking Win2K+ functions not supported */
412 return ERROR_NOT_SUPPORTED;
416 /******************************************************************
417 * DeleteIpForwardEntry (IPHLPAPI.@)
420 * PARAMS
422 * pRoute [In/Out]
424 * RETURNS
426 * DWORD
429 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
431 TRACE("pRoute %p\n", pRoute);
432 /* could use SIOCDELRT, not sure I want to */
433 FIXME(":stub\n");
434 return (DWORD) 0;
438 /******************************************************************
439 * DeleteIpNetEntry (IPHLPAPI.@)
442 * PARAMS
444 * pArpEntry [In/Out]
446 * RETURNS
448 * DWORD
451 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
453 TRACE("pArpEntry %p\n", pArpEntry);
454 /* could use SIOCDARP on systems that support it, not sure I want to */
455 FIXME(":stub\n");
456 return (DWORD) 0;
460 /******************************************************************
461 * DeleteProxyArpEntry (IPHLPAPI.@)
464 * PARAMS
466 * dwAddress [In]
467 * dwMask [In]
468 * dwIfIndex [In]
470 * RETURNS
472 * DWORD
475 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
477 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress,
478 dwMask, dwIfIndex);
479 FIXME(":stub\n");
480 /* marking Win2K+ functions not supported */
481 return ERROR_NOT_SUPPORTED;
485 /******************************************************************
486 * EnableRouter (IPHLPAPI.@)
489 * PARAMS
491 * pHandle [In/Out]
492 * pOverlapped [In/Out]
494 * RETURNS
496 * DWORD
499 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
501 TRACE("pHandle %p, pOverlapped %p\n", pHandle, pOverlapped);
502 FIXME(":stub\n");
503 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
504 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
505 marking Win2K+ functions not supported */
506 return ERROR_NOT_SUPPORTED;
510 /******************************************************************
511 * FlushIpNetTable (IPHLPAPI.@)
514 * PARAMS
516 * dwIfIndex [In]
518 * RETURNS
520 * DWORD
523 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
525 TRACE("dwIfIndex 0x%08lx\n", dwIfIndex);
526 FIXME(":stub\n");
527 /* this flushes the arp cache of the given index
528 marking Win2K+ functions not supported */
529 return ERROR_NOT_SUPPORTED;
533 /******************************************************************
534 * GetAdapterIndex (IPHLPAPI.@)
537 * PARAMS
539 * AdapterName [In/Out]
540 * IfIndex [In/Out]
542 * RETURNS
544 * DWORD
547 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
549 TRACE("AdapterName %p, IfIndex %p\n", AdapterName, IfIndex);
550 FIXME(":stub\n");
551 /* marking Win2K+ functions not supported */
552 return ERROR_NOT_SUPPORTED;
556 /******************************************************************
557 * GetAdaptersInfo (IPHLPAPI.@)
560 * PARAMS
562 * pAdapterInfo [In/Out]
563 * pOutBufLen [In/Out]
565 * RETURNS
567 * DWORD
570 DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
572 DWORD ret;
574 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
575 if (!pOutBufLen)
576 ret = ERROR_INVALID_PARAMETER;
577 else {
578 DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
580 if (numNonLoopbackInterfaces > 0) {
581 /* this calculation assumes only one address in the IP_ADDR_STRING lists.
582 that's okay, because:
583 - we don't get multiple addresses per adapter anyway
584 - we don't know about per-adapter gateways
585 - DHCP and WINS servers can have max one entry per list */
586 ULONG size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
588 if (!pAdapterInfo || *pOutBufLen < size) {
589 *pOutBufLen = size;
590 ret = ERROR_BUFFER_OVERFLOW;
592 else {
593 InterfaceIndexTable *table = getNonLoopbackInterfaceIndexTable();
595 if (table) {
596 size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
597 if (*pOutBufLen < size) {
598 *pOutBufLen = size;
599 ret = ERROR_INSUFFICIENT_BUFFER;
601 else {
602 DWORD ndx;
603 HKEY hKey;
604 BOOL winsEnabled = FALSE;
605 IP_ADDRESS_STRING primaryWINS, secondaryWINS;
607 memset(pAdapterInfo, 0, size);
608 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
609 "Software\\Wine\\Wine\\Config\\Network", 0, KEY_READ,
610 &hKey) == ERROR_SUCCESS) {
611 DWORD size = sizeof(primaryWINS.String);
612 unsigned long addr;
614 RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
615 primaryWINS.String, &size);
616 addr = inet_addr(primaryWINS.String);
617 if (addr != INADDR_NONE && addr != INADDR_ANY)
618 winsEnabled = TRUE;
619 size = sizeof(secondaryWINS.String);
620 RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
621 secondaryWINS.String, &size);
622 addr = inet_addr(secondaryWINS.String);
623 if (addr != INADDR_NONE && addr != INADDR_ANY)
624 winsEnabled = TRUE;
625 RegCloseKey(hKey);
627 for (ndx = 0; ndx < table->numIndexes; ndx++) {
628 PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
629 DWORD addrLen = sizeof(ptr->Address), type;
631 /* on Win98 this is left empty, but whatever */
632 strncpy(ptr->AdapterName,
633 getInterfaceNameByIndex(table->indexes[ndx]),
634 sizeof(ptr->AdapterName));
635 ptr->AdapterName[MAX_ADAPTER_NAME_LENGTH] = '\0';
636 getInterfacePhysicalByIndex(table->indexes[ndx], &addrLen,
637 ptr->Address, &type);
638 /* MS defines address length and type as UINT in some places and
639 DWORD in others, **sigh**. Don't want to assume that PUINT and
640 PDWORD are equiv (64-bit?) */
641 ptr->AddressLength = addrLen;
642 ptr->Type = type;
643 ptr->Index = table->indexes[ndx];
644 toIPAddressString(getInterfaceIPAddrByIndex(table->indexes[ndx]),
645 ptr->IpAddressList.IpAddress.String);
646 toIPAddressString(getInterfaceMaskByIndex(table->indexes[ndx]),
647 ptr->IpAddressList.IpMask.String);
648 if (winsEnabled) {
649 ptr->HaveWins = TRUE;
650 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
651 primaryWINS.String, sizeof(primaryWINS.String));
652 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
653 secondaryWINS.String, sizeof(secondaryWINS.String));
655 if (ndx < table->numIndexes - 1)
656 ptr->Next = &pAdapterInfo[ndx + 1];
657 else
658 ptr->Next = NULL;
660 ret = NO_ERROR;
662 free(table);
664 else
665 ret = ERROR_OUTOFMEMORY;
668 else
669 ret = ERROR_NO_DATA;
671 TRACE("returning %ld\n", ret);
672 return ret;
676 /******************************************************************
677 * GetBestInterface (IPHLPAPI.@)
680 * PARAMS
682 * dwDestAddr [In]
683 * pdwBestIfIndex [In/Out]
685 * RETURNS
687 * DWORD
690 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
692 DWORD ret;
694 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex);
695 if (!pdwBestIfIndex)
696 ret = ERROR_INVALID_PARAMETER;
697 else {
698 MIB_IPFORWARDROW ipRow;
700 ret = GetBestRoute(dwDestAddr, 0, &ipRow);
701 if (ret == ERROR_SUCCESS)
702 *pdwBestIfIndex = ipRow.dwForwardIfIndex;
704 TRACE("returning %ld\n", ret);
705 return ret;
709 /******************************************************************
710 * GetBestRoute (IPHLPAPI.@)
713 * PARAMS
715 * dwDestAddr [In]
716 * dwSourceAddr [In]
717 * OUT [In]
719 * RETURNS
721 * DWORD
724 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
726 PMIB_IPFORWARDTABLE table;
727 DWORD ret;
729 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr,
730 dwSourceAddr, pBestRoute);
731 if (!pBestRoute)
732 return ERROR_INVALID_PARAMETER;
734 AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
735 if (table) {
736 DWORD ndx, matchedBits, matchedNdx = 0;
738 for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
739 if ((dwDestAddr & table->table[ndx].dwForwardMask) ==
740 (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
741 DWORD numShifts, mask;
743 for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
744 mask && !(mask & 1); mask >>= 1, numShifts++)
746 if (numShifts > matchedBits) {
747 matchedBits = numShifts;
748 matchedNdx = ndx;
752 memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
753 HeapFree(GetProcessHeap(), 0, table);
754 ret = ERROR_SUCCESS;
756 else
757 ret = ERROR_OUTOFMEMORY;
758 TRACE("returning %ld\n", ret);
759 return ret;
763 /******************************************************************
764 * GetFriendlyIfIndex (IPHLPAPI.@)
767 * PARAMS
769 * IfIndex [In]
771 * RETURNS
773 * DWORD
776 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
778 /* windows doesn't validate these, either, just makes sure the top byte is
779 cleared. I assume my ifenum module never gives an index with the top
780 byte set. */
781 TRACE("returning %ld\n", IfIndex);
782 return IfIndex;
786 /******************************************************************
787 * GetIcmpStatistics (IPHLPAPI.@)
790 * PARAMS
792 * pStats [In/Out]
794 * RETURNS
796 * DWORD
799 DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
801 DWORD ret;
803 TRACE("pStats %p\n", pStats);
804 ret = getICMPStats(pStats);
805 TRACE("returning %ld\n", ret);
806 return ret;
810 /******************************************************************
811 * GetIfEntry (IPHLPAPI.@)
814 * PARAMS
816 * pIfRow [In/Out]
818 * RETURNS
820 * DWORD
823 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
825 DWORD ret;
826 const char *name;
828 TRACE("pIfRow %p\n", pIfRow);
829 if (!pIfRow)
830 return ERROR_INVALID_PARAMETER;
832 name = getInterfaceNameByIndex(pIfRow->dwIndex);
833 if (name) {
834 ret = getInterfaceEntryByName(name, pIfRow);
835 if (ret == NO_ERROR)
836 ret = getInterfaceStatsByName(name, pIfRow);
838 else
839 ret = ERROR_INVALID_DATA;
840 TRACE("returning %ld\n", ret);
841 return ret;
845 static int IfTableSorter(const void *a, const void *b)
847 int ret;
849 if (a && b)
850 ret = ((PMIB_IFROW)a)->dwIndex - ((PMIB_IFROW)b)->dwIndex;
851 else
852 ret = 0;
853 return ret;
857 /******************************************************************
858 * GetIfTable (IPHLPAPI.@)
861 * PARAMS
863 * pIfTable [In/Out]
864 * pdwSize [In/Out]
865 * bOrder [In]
867 * RETURNS
869 * DWORD
872 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
874 DWORD ret;
876 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize, pdwSize,
877 (DWORD)bOrder);
878 if (!pdwSize)
879 ret = ERROR_INVALID_PARAMETER;
880 else {
881 DWORD numInterfaces = getNumInterfaces();
882 ULONG size = sizeof(MIB_IFTABLE) + (numInterfaces - 1) * sizeof(MIB_IFROW);
884 if (!pIfTable || *pdwSize < size) {
885 *pdwSize = size;
886 ret = ERROR_INSUFFICIENT_BUFFER;
888 else {
889 InterfaceIndexTable *table = getInterfaceIndexTable();
891 if (table) {
892 size = sizeof(MIB_IFTABLE) + (table->numIndexes - 1) *
893 sizeof(MIB_IFROW);
894 if (*pdwSize < size) {
895 *pdwSize = size;
896 ret = ERROR_INSUFFICIENT_BUFFER;
898 else {
899 DWORD ndx;
901 pIfTable->dwNumEntries = 0;
902 for (ndx = 0; ndx < table->numIndexes; ndx++) {
903 pIfTable->table[ndx].dwIndex = table->indexes[ndx];
904 GetIfEntry(&pIfTable->table[ndx]);
905 pIfTable->dwNumEntries++;
907 if (bOrder)
908 qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
909 IfTableSorter);
910 ret = NO_ERROR;
912 free(table);
914 else
915 ret = ERROR_OUTOFMEMORY;
918 TRACE("returning %ld\n", ret);
919 return ret;
923 /******************************************************************
924 * GetInterfaceInfo (IPHLPAPI.@)
927 * PARAMS
929 * pIfTable [In/Out]
930 * dwOutBufLen [In/Out]
932 * RETURNS
934 * DWORD
937 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
939 DWORD ret;
941 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
942 if (!dwOutBufLen)
943 ret = ERROR_INVALID_PARAMETER;
944 else {
945 DWORD numInterfaces = getNumInterfaces();
946 ULONG size = sizeof(IP_INTERFACE_INFO) + (numInterfaces - 1) *
947 sizeof(IP_ADAPTER_INDEX_MAP);
949 if (!pIfTable || *dwOutBufLen < size) {
950 *dwOutBufLen = size;
951 ret = ERROR_INSUFFICIENT_BUFFER;
953 else {
954 InterfaceIndexTable *table = getInterfaceIndexTable();
956 if (table) {
957 size = sizeof(IP_INTERFACE_INFO) + (table->numIndexes - 1) *
958 sizeof(IP_ADAPTER_INDEX_MAP);
959 if (*dwOutBufLen < size) {
960 *dwOutBufLen = size;
961 ret = ERROR_INSUFFICIENT_BUFFER;
963 else {
964 DWORD ndx;
966 pIfTable->NumAdapters = 0;
967 for (ndx = 0; ndx < table->numIndexes; ndx++) {
968 const char *walker, *name;
969 WCHAR *assigner;
971 pIfTable->Adapter[ndx].Index = table->indexes[ndx];
972 name = getInterfaceNameByIndex(table->indexes[ndx]);
973 for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
974 walker && *walker &&
975 assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
976 walker++, assigner++)
977 *assigner = *walker;
978 *assigner = 0;
979 pIfTable->NumAdapters++;
981 ret = NO_ERROR;
983 free(table);
985 else
986 ret = ERROR_OUTOFMEMORY;
989 TRACE("returning %ld\n", ret);
990 return ret;
994 static int IpAddrTableSorter(const void *a, const void *b)
996 int ret;
998 if (a && b)
999 ret = ((PMIB_IPADDRROW)a)->dwAddr - ((PMIB_IPADDRROW)b)->dwAddr;
1000 else
1001 ret = 0;
1002 return ret;
1006 /******************************************************************
1007 * GetIpAddrTable (IPHLPAPI.@)
1010 * PARAMS
1012 * pIpAddrTable [In/Out]
1013 * pdwSize [In/Out]
1014 * bOrder [In]
1016 * RETURNS
1018 * DWORD
1021 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1023 DWORD ret;
1025 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable, pdwSize,
1026 (DWORD)bOrder);
1027 if (!pdwSize)
1028 ret = ERROR_INVALID_PARAMETER;
1029 else {
1030 DWORD numInterfaces = getNumInterfaces();
1031 ULONG size = sizeof(MIB_IPADDRTABLE) + (numInterfaces - 1) *
1032 sizeof(MIB_IPADDRROW);
1034 if (!pIpAddrTable || *pdwSize < size) {
1035 *pdwSize = size;
1036 ret = ERROR_INSUFFICIENT_BUFFER;
1038 else {
1039 InterfaceIndexTable *table = getInterfaceIndexTable();
1041 if (table) {
1042 size = sizeof(MIB_IPADDRTABLE) + (table->numIndexes - 1) *
1043 sizeof(MIB_IPADDRROW);
1044 if (*pdwSize < size) {
1045 *pdwSize = size;
1046 ret = ERROR_INSUFFICIENT_BUFFER;
1048 else {
1049 DWORD ndx, bcast;
1051 pIpAddrTable->dwNumEntries = 0;
1052 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1053 pIpAddrTable->table[ndx].dwIndex = table->indexes[ndx];
1054 pIpAddrTable->table[ndx].dwAddr =
1055 getInterfaceIPAddrByIndex(table->indexes[ndx]);
1056 pIpAddrTable->table[ndx].dwMask =
1057 getInterfaceMaskByIndex(table->indexes[ndx]);
1058 /* the dwBCastAddr member isn't the broadcast address, it indicates
1059 * whether the interface uses the 1's broadcast address (1) or the
1060 * 0's broadcast address (0).
1062 bcast = getInterfaceBCastAddrByIndex(table->indexes[ndx]);
1063 pIpAddrTable->table[ndx].dwBCastAddr =
1064 (bcast & pIpAddrTable->table[ndx].dwMask) ? 1 : 0;
1065 /* FIXME: hardcoded reasm size, not sure where to get it */
1066 pIpAddrTable->table[ndx].dwReasmSize = 65535;
1067 pIpAddrTable->table[ndx].unused1 = 0;
1068 pIpAddrTable->table[ndx].wType = 0; /* aka unused2 */
1069 pIpAddrTable->dwNumEntries++;
1071 if (bOrder)
1072 qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1073 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1074 ret = NO_ERROR;
1076 free(table);
1078 else
1079 ret = ERROR_OUTOFMEMORY;
1082 TRACE("returning %ld\n", ret);
1083 return ret;
1087 static int IpForwardTableSorter(const void *a, const void *b)
1089 int ret;
1091 if (a && b) {
1092 PMIB_IPFORWARDROW rowA = (PMIB_IPFORWARDROW)a, rowB = (PMIB_IPFORWARDROW)b;
1094 ret = rowA->dwForwardDest - rowB->dwForwardDest;
1095 if (ret == 0) {
1096 ret = rowA->dwForwardProto - rowB->dwForwardProto;
1097 if (ret == 0) {
1098 ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy;
1099 if (ret == 0)
1100 ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop;
1104 else
1105 ret = 0;
1106 return ret;
1110 /******************************************************************
1111 * GetIpForwardTable (IPHLPAPI.@)
1114 * PARAMS
1116 * pIpForwardTable [In/Out]
1117 * pdwSize [In/Out]
1118 * bOrder [In]
1120 * RETURNS
1122 * DWORD
1125 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1127 DWORD ret;
1129 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable,
1130 pdwSize, (DWORD)bOrder);
1131 if (!pdwSize)
1132 ret = ERROR_INVALID_PARAMETER;
1133 else {
1134 DWORD numRoutes = getNumRoutes();
1135 ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) *
1136 sizeof(MIB_IPFORWARDROW);
1138 if (!pIpForwardTable || *pdwSize < sizeNeeded) {
1139 *pdwSize = sizeNeeded;
1140 ret = ERROR_INSUFFICIENT_BUFFER;
1142 else {
1143 RouteTable *table = getRouteTable();
1144 if (table) {
1145 sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (table->numRoutes - 1) *
1146 sizeof(MIB_IPFORWARDROW);
1147 if (*pdwSize < sizeNeeded) {
1148 *pdwSize = sizeNeeded;
1149 ret = ERROR_INSUFFICIENT_BUFFER;
1151 else {
1152 DWORD ndx;
1154 pIpForwardTable->dwNumEntries = table->numRoutes;
1155 for (ndx = 0; ndx < numRoutes; ndx++) {
1156 pIpForwardTable->table[ndx].dwForwardIfIndex =
1157 table->routes[ndx].ifIndex;
1158 pIpForwardTable->table[ndx].dwForwardDest =
1159 table->routes[ndx].dest;
1160 pIpForwardTable->table[ndx].dwForwardMask =
1161 table->routes[ndx].mask;
1162 pIpForwardTable->table[ndx].dwForwardPolicy = 0;
1163 pIpForwardTable->table[ndx].dwForwardNextHop =
1164 table->routes[ndx].gateway;
1165 /* FIXME: this type is appropriate for local interfaces; may not
1166 always be appropriate */
1167 pIpForwardTable->table[ndx].dwForwardType = MIB_IPROUTE_TYPE_DIRECT;
1168 /* FIXME: other protos might be appropriate, e.g. the default route
1169 is typically set with MIB_IPPROTO_NETMGMT instead */
1170 pIpForwardTable->table[ndx].dwForwardProto = MIB_IPPROTO_LOCAL;
1171 /* punt on age and AS */
1172 pIpForwardTable->table[ndx].dwForwardAge = 0;
1173 pIpForwardTable->table[ndx].dwForwardNextHopAS = 0;
1174 pIpForwardTable->table[ndx].dwForwardMetric1 =
1175 table->routes[ndx].metric;
1176 /* rest of the metrics are 0.. */
1177 pIpForwardTable->table[ndx].dwForwardMetric2 = 0;
1178 pIpForwardTable->table[ndx].dwForwardMetric3 = 0;
1179 pIpForwardTable->table[ndx].dwForwardMetric4 = 0;
1180 pIpForwardTable->table[ndx].dwForwardMetric5 = 0;
1182 if (bOrder)
1183 qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
1184 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1185 ret = NO_ERROR;
1187 free(table);
1189 else
1190 ret = ERROR_OUTOFMEMORY;
1193 TRACE("returning %ld\n", ret);
1194 return ret;
1198 static int IpNetTableSorter(const void *a, const void *b)
1200 int ret;
1202 if (a && b)
1203 ret = ((PMIB_IPNETROW)a)->dwAddr - ((PMIB_IPNETROW)b)->dwAddr;
1204 else
1205 ret = 0;
1206 return ret;
1210 /******************************************************************
1211 * GetIpNetTable (IPHLPAPI.@)
1214 * PARAMS
1216 * pIpNetTable [In/Out]
1217 * pdwSize [In/Out]
1218 * bOrder [In]
1220 * RETURNS
1222 * DWORD
1225 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1227 DWORD ret;
1229 TRACE("pIpNetTable %p, pdwSize %p, bOrder %ld\n", pIpNetTable, pdwSize,
1230 (DWORD)bOrder);
1231 if (!pdwSize)
1232 ret = ERROR_INVALID_PARAMETER;
1233 else {
1234 DWORD numEntries = getNumArpEntries();
1235 ULONG size = sizeof(MIB_IPNETTABLE) + (numEntries - 1) *
1236 sizeof(MIB_IPNETROW);
1238 if (!pIpNetTable || *pdwSize < size) {
1239 *pdwSize = size;
1240 ret = ERROR_INSUFFICIENT_BUFFER;
1242 else {
1243 PMIB_IPNETTABLE table = getArpTable();
1245 if (table) {
1246 size = sizeof(MIB_IPNETTABLE) + (table->dwNumEntries - 1) *
1247 sizeof(MIB_IPNETROW);
1248 if (*pdwSize < size) {
1249 *pdwSize = size;
1250 ret = ERROR_INSUFFICIENT_BUFFER;
1252 else {
1253 memcpy(pIpNetTable, table, size);
1254 if (bOrder)
1255 qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
1256 sizeof(MIB_IPNETROW), IpNetTableSorter);
1257 ret = NO_ERROR;
1259 free(table);
1261 else
1262 ret = ERROR_OUTOFMEMORY;
1265 TRACE("returning %ld\n", ret);
1266 return ret;
1270 /******************************************************************
1271 * GetIpStatistics (IPHLPAPI.@)
1274 * PARAMS
1276 * pStats [In/Out]
1278 * RETURNS
1280 * DWORD
1283 DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
1285 DWORD ret;
1287 TRACE("pStats %p\n", pStats);
1288 ret = getIPStats(pStats);
1289 TRACE("returning %ld\n", ret);
1290 return ret;
1294 /******************************************************************
1295 * GetNetworkParams (IPHLPAPI.@)
1298 * PARAMS
1300 * pFixedInfo [In/Out]
1301 * pOutBufLen [In/Out]
1303 * RETURNS
1305 * DWORD
1308 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1310 DWORD ret, size;
1311 LONG regReturn;
1312 HKEY hKey;
1314 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1315 if (!pOutBufLen)
1316 return ERROR_INVALID_PARAMETER;
1318 res_init();
1319 size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount - 1) *
1320 sizeof(IP_ADDR_STRING) : 0);
1321 if (!pFixedInfo || *pOutBufLen < size) {
1322 *pOutBufLen = size;
1323 return ERROR_BUFFER_OVERFLOW;
1326 memset(pFixedInfo, 0, size);
1327 size = sizeof(pFixedInfo->HostName);
1328 GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1329 size = sizeof(pFixedInfo->DomainName);
1330 GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1331 if (_res.nscount > 0) {
1332 PIP_ADDR_STRING ptr;
1333 int i;
1335 for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1336 i++, ptr = ptr->Next) {
1337 toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
1338 ptr->IpAddress.String);
1339 if (i == _res.nscount - 1)
1340 ptr->Next = NULL;
1341 else if (i == 0)
1342 ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
1343 else
1344 ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1347 pFixedInfo->NodeType = HYBRID_NODETYPE;
1348 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1349 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1350 if (regReturn != ERROR_SUCCESS)
1351 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1352 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1353 &hKey);
1354 if (regReturn == ERROR_SUCCESS)
1356 DWORD size = sizeof(pFixedInfo->ScopeId);
1358 RegQueryValueExA(hKey, "ScopeID", NULL, NULL, pFixedInfo->ScopeId, &size);
1359 RegCloseKey(hKey);
1362 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1363 I suppose could also check for a listener on port 53 to set EnableDns */
1364 ret = NO_ERROR;
1365 TRACE("returning %ld\n", ret);
1366 return ret;
1370 /******************************************************************
1371 * GetNumberOfInterfaces (IPHLPAPI.@)
1374 * PARAMS
1376 * pdwNumIf [In/Out]
1378 * RETURNS
1380 * DWORD
1383 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
1385 DWORD ret;
1387 TRACE("pdwNumIf %p\n", pdwNumIf);
1388 if (!pdwNumIf)
1389 ret = ERROR_INVALID_PARAMETER;
1390 else {
1391 *pdwNumIf = getNumInterfaces();
1392 ret = NO_ERROR;
1394 TRACE("returning %ld\n", ret);
1395 return ret;
1399 /******************************************************************
1400 * GetPerAdapterInfo (IPHLPAPI.@)
1403 * PARAMS
1405 * IfIndex [In]
1406 * pPerAdapterInfo [In/Out]
1407 * pOutBufLen [In/Out]
1409 * RETURNS
1411 * DWORD
1414 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
1416 TRACE("IfIndex %ld, pPerAdapterInfo %p, pOutBufLen %p\n", IfIndex,
1417 pPerAdapterInfo, pOutBufLen);
1418 FIXME(":stub\n");
1419 /* marking Win2K+ functions not supported */
1420 return ERROR_NOT_SUPPORTED;
1424 /******************************************************************
1425 * GetRTTAndHopCount (IPHLPAPI.@)
1428 * PARAMS
1430 * DestIpAddress [In]
1431 * HopCount [In/Out]
1432 * MaxHops [In]
1433 * RTT [In/Out]
1435 * RETURNS
1437 * BOOL
1440 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
1442 TRACE("DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p\n",
1443 DestIpAddress, HopCount, MaxHops, RTT);
1444 FIXME(":stub\n");
1445 return (BOOL) 0;
1449 /******************************************************************
1450 * GetTcpStatistics (IPHLPAPI.@)
1453 * PARAMS
1455 * pStats [In/Out]
1457 * RETURNS
1459 * DWORD
1462 DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
1464 DWORD ret;
1466 TRACE("pStats %p\n", pStats);
1467 ret = getTCPStats(pStats);
1468 TRACE("returning %ld\n", ret);
1469 return ret;
1473 static int TcpTableSorter(const void *a, const void *b)
1475 int ret;
1477 if (a && b) {
1478 PMIB_TCPROW rowA = (PMIB_TCPROW)a, rowB = (PMIB_TCPROW)b;
1480 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
1481 if (ret == 0) {
1482 ret = rowA->dwLocalPort - rowB->dwLocalPort;
1483 if (ret == 0) {
1484 ret = rowA->dwRemoteAddr - rowB->dwRemoteAddr;
1485 if (ret == 0)
1486 ret = rowA->dwRemotePort - rowB->dwRemotePort;
1490 else
1491 ret = 0;
1492 return ret;
1496 /******************************************************************
1497 * GetTcpTable (IPHLPAPI.@)
1500 * PARAMS
1502 * pTcpTable [In/Out]
1503 * pdwSize [In/Out]
1504 * bOrder [In]
1506 * RETURNS
1508 * DWORD
1511 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
1513 DWORD ret;
1515 TRACE("pTcpTable %p, pdwSize %p, bOrder %ld\n", pTcpTable, pdwSize,
1516 (DWORD)bOrder);
1517 if (!pdwSize)
1518 ret = ERROR_INVALID_PARAMETER;
1519 else {
1520 DWORD numEntries = getNumTcpEntries();
1521 ULONG size = sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW);
1523 if (!pTcpTable || *pdwSize < size) {
1524 *pdwSize = size;
1525 ret = ERROR_INSUFFICIENT_BUFFER;
1527 else {
1528 PMIB_TCPTABLE table = getTcpTable();
1530 if (table) {
1531 size = sizeof(MIB_TCPTABLE) + (table->dwNumEntries - 1) *
1532 sizeof(MIB_TCPROW);
1533 if (*pdwSize < size) {
1534 *pdwSize = size;
1535 ret = ERROR_INSUFFICIENT_BUFFER;
1537 else {
1538 memcpy(pTcpTable, table, size);
1539 if (bOrder)
1540 qsort(pTcpTable->table, pTcpTable->dwNumEntries,
1541 sizeof(MIB_TCPROW), TcpTableSorter);
1542 ret = NO_ERROR;
1544 free(table);
1546 else
1547 ret = ERROR_OUTOFMEMORY;
1550 TRACE("returning %ld\n", ret);
1551 return ret;
1555 /******************************************************************
1556 * GetUdpStatistics (IPHLPAPI.@)
1559 * PARAMS
1561 * pStats [In/Out]
1563 * RETURNS
1565 * DWORD
1568 DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
1570 DWORD ret;
1572 TRACE("pStats %p\n", pStats);
1573 ret = getUDPStats(pStats);
1574 TRACE("returning %ld\n", ret);
1575 return ret;
1579 static int UdpTableSorter(const void *a, const void *b)
1581 int ret;
1583 if (a && b) {
1584 PMIB_UDPROW rowA = (PMIB_UDPROW)a, rowB = (PMIB_UDPROW)b;
1586 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
1587 if (ret == 0)
1588 ret = rowA->dwLocalPort - rowB->dwLocalPort;
1590 else
1591 ret = 0;
1592 return ret;
1596 /******************************************************************
1597 * GetUdpTable (IPHLPAPI.@)
1600 * PARAMS
1602 * pUdpTable [In/Out]
1603 * pdwSize [In/Out]
1604 * bOrder [In]
1606 * RETURNS
1608 * DWORD
1611 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
1613 DWORD ret;
1615 TRACE("pUdpTable %p, pdwSize %p, bOrder %ld\n", pUdpTable, pdwSize,
1616 (DWORD)bOrder);
1617 if (!pdwSize)
1618 ret = ERROR_INVALID_PARAMETER;
1619 else {
1620 DWORD numEntries = getNumUdpEntries();
1621 ULONG size = sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW);
1623 if (!pUdpTable || *pdwSize < size) {
1624 *pdwSize = size;
1625 ret = ERROR_INSUFFICIENT_BUFFER;
1627 else {
1628 PMIB_UDPTABLE table = getUdpTable();
1630 if (table) {
1631 size = sizeof(MIB_UDPTABLE) + (table->dwNumEntries - 1) *
1632 sizeof(MIB_UDPROW);
1633 if (*pdwSize < size) {
1634 *pdwSize = size;
1635 ret = ERROR_INSUFFICIENT_BUFFER;
1637 else {
1638 memcpy(pUdpTable, table, size);
1639 if (bOrder)
1640 qsort(pUdpTable->table, pUdpTable->dwNumEntries,
1641 sizeof(MIB_UDPROW), UdpTableSorter);
1642 ret = NO_ERROR;
1644 free(table);
1646 else
1647 ret = ERROR_OUTOFMEMORY;
1650 TRACE("returning %ld\n", ret);
1651 return ret;
1655 /******************************************************************
1656 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1659 * PARAMS
1661 * pIPIfInfo [In/Out]
1662 * dwOutBufLen [In/Out]
1664 * RETURNS
1666 * DWORD
1669 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
1671 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1672 /* a unidirectional adapter?? not bloody likely! */
1673 return ERROR_NOT_SUPPORTED;
1677 /******************************************************************
1678 * IpReleaseAddress (IPHLPAPI.@)
1681 * PARAMS
1683 * AdapterInfo [In/Out]
1685 * RETURNS
1687 * DWORD
1690 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1692 TRACE("AdapterInfo %p\n", AdapterInfo);
1693 /* not a stub, never going to support this (and I never mark an adapter as
1694 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1695 return ERROR_NOT_SUPPORTED;
1699 /******************************************************************
1700 * IpRenewAddress (IPHLPAPI.@)
1703 * PARAMS
1705 * AdapterInfo [In/Out]
1707 * RETURNS
1709 * DWORD
1712 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1714 TRACE("AdapterInfo %p\n", AdapterInfo);
1715 /* not a stub, never going to support this (and I never mark an adapter as
1716 DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1717 return ERROR_NOT_SUPPORTED;
1721 /******************************************************************
1722 * NotifyAddrChange (IPHLPAPI.@)
1725 * PARAMS
1727 * Handle [In/Out]
1728 * overlapped [In/Out]
1730 * RETURNS
1732 * DWORD
1735 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1737 TRACE("Handle %p, overlapped %p\n", Handle, overlapped);
1738 FIXME(":stub\n");
1739 /* marking Win2K+ functions not supported */
1740 return ERROR_NOT_SUPPORTED;
1744 /******************************************************************
1745 * NotifyRouteChange (IPHLPAPI.@)
1748 * PARAMS
1750 * Handle [In/Out]
1751 * overlapped [In/Out]
1753 * RETURNS
1755 * DWORD
1758 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1760 TRACE("Handle %p, overlapped %p\n", Handle, overlapped);
1761 FIXME(":stub\n");
1762 /* marking Win2K+ functions not supported */
1763 return ERROR_NOT_SUPPORTED;
1767 /******************************************************************
1768 * SendARP (IPHLPAPI.@)
1771 * PARAMS
1773 * DestIP [In]
1774 * SrcIP [In]
1775 * pMacAddr [In/Out]
1776 * PhyAddrLen [In/Out]
1778 * RETURNS
1780 * DWORD
1783 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
1785 TRACE("DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p\n", DestIP,
1786 SrcIP, pMacAddr, PhyAddrLen);
1787 FIXME(":stub\n");
1788 /* marking Win2K+ functions not supported */
1789 return ERROR_NOT_SUPPORTED;
1793 /******************************************************************
1794 * SetIfEntry (IPHLPAPI.@)
1797 * PARAMS
1799 * pIfRow [In/Out]
1801 * RETURNS
1803 * DWORD
1806 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
1808 TRACE("pIfRow %p\n", pIfRow);
1809 /* this is supposed to set an administratively interface up or down.
1810 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1811 this sort of down is indistinguishable from other sorts of down (e.g. no
1812 link). */
1813 FIXME(":stub\n");
1814 return ERROR_NOT_SUPPORTED;
1818 /******************************************************************
1819 * SetIpForwardEntry (IPHLPAPI.@)
1822 * PARAMS
1824 * pRoute [In/Out]
1826 * RETURNS
1828 * DWORD
1831 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
1833 TRACE("pRoute %p\n", pRoute);
1834 /* this is to add a route entry, how's it distinguishable from
1835 CreateIpForwardEntry?
1836 could use SIOCADDRT, not sure I want to */
1837 FIXME(":stub\n");
1838 return (DWORD) 0;
1842 /******************************************************************
1843 * SetIpNetEntry (IPHLPAPI.@)
1846 * PARAMS
1848 * pArpEntry [In/Out]
1850 * RETURNS
1852 * DWORD
1855 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
1857 TRACE("pArpEntry %p\n", pArpEntry);
1858 /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1859 FIXME(":stub\n");
1860 return (DWORD) 0;
1864 /******************************************************************
1865 * SetIpStatistics (IPHLPAPI.@)
1868 * PARAMS
1870 * pIpStats [In/Out]
1872 * RETURNS
1874 * DWORD
1877 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
1879 TRACE("pIpStats %p\n", pIpStats);
1880 FIXME(":stub\n");
1881 return (DWORD) 0;
1885 /******************************************************************
1886 * SetIpTTL (IPHLPAPI.@)
1889 * PARAMS
1891 * nTTL [In]
1893 * RETURNS
1895 * DWORD
1898 DWORD WINAPI SetIpTTL(UINT nTTL)
1900 TRACE("nTTL %d\n", nTTL);
1901 /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1902 want to. Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1903 FIXME(":stub\n");
1904 return (DWORD) 0;
1908 /******************************************************************
1909 * SetTcpEntry (IPHLPAPI.@)
1912 * PARAMS
1914 * pTcpRow [In/Out]
1916 * RETURNS
1918 * DWORD
1921 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
1923 TRACE("pTcpRow %p\n", pTcpRow);
1924 FIXME(":stub\n");
1925 return (DWORD) 0;
1929 /******************************************************************
1930 * UnenableRouter (IPHLPAPI.@)
1933 * PARAMS
1935 * pOverlapped [In/Out]
1936 * lpdwEnableCount [In/Out]
1938 * RETURNS
1940 * DWORD
1943 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
1945 TRACE("pOverlapped %p, lpdwEnableCount %p\n", pOverlapped, lpdwEnableCount);
1946 FIXME(":stub\n");
1947 /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
1948 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
1949 marking Win2K+ functions not supported */
1950 return ERROR_NOT_SUPPORTED;