msi: Handle the CompLocator table in the AppSearch action.
[wine] / dlls / iphlpapi / iphlpapi_main.c
1 /*
2  * iphlpapi dll implementation
3  *
4  * Copyright (C) 2003,2006 Juan Lang
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22
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
38
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"
46
47 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
48
49 #ifndef INADDR_NONE
50 #define INADDR_NONE ~0UL
51 #endif
52
53 static int resolver_initialised;
54
55 /* call res_init() just once because of a bug in Mac OS X 10.4 */
56 static void initialise_resolver(void)
57 {
58     if (!resolver_initialised)
59     {
60         res_init();
61         resolver_initialised = 1;
62     }
63 }
64
65 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
66 {
67   switch (fdwReason) {
68     case DLL_PROCESS_ATTACH:
69       DisableThreadLibraryCalls( hinstDLL );
70       break;
71
72     case DLL_PROCESS_DETACH:
73       break;
74   }
75   return TRUE;
76 }
77
78 /******************************************************************
79  *    AddIPAddress (IPHLPAPI.@)
80  *
81  * Add an IP address to an adapter.
82  *
83  * PARAMS
84  *  Address     [In]  IP address to add to the adapter
85  *  IpMask      [In]  subnet mask for the IP address
86  *  IfIndex     [In]  adapter index to add the address
87  *  NTEContext  [Out] Net Table Entry (NTE) context for the IP address
88  *  NTEInstance [Out] NTE instance for the IP address
89  *
90  * RETURNS
91  *  Success: NO_ERROR
92  *  Failure: error code from winerror.h
93  *
94  * FIXME
95  *  Stub. Currently returns ERROR_NOT_SUPPORTED.
96  */
97 DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
98 {
99   FIXME(":stub\n");
100   return ERROR_NOT_SUPPORTED;
101 }
102
103
104 /******************************************************************
105  *    AllocateAndGetIfTableFromStack (IPHLPAPI.@)
106  *
107  * Get table of local interfaces.
108  * Like GetIfTable(), but allocate the returned table from heap.
109  *
110  * PARAMS
111  *  ppIfTable [Out] pointer into which the MIB_IFTABLE is
112  *                  allocated and returned.
113  *  bOrder    [In]  whether to sort the table
114  *  heap      [In]  heap from which the table is allocated
115  *  flags     [In]  flags to HeapAlloc
116  *
117  * RETURNS
118  *  ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
119  *  GetIfTable() returns otherwise.
120  */
121 DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
122  BOOL bOrder, HANDLE heap, DWORD flags)
123 {
124   DWORD ret;
125
126   TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08x\n", ppIfTable,
127         bOrder, heap, flags);
128   if (!ppIfTable)
129     ret = ERROR_INVALID_PARAMETER;
130   else {
131     DWORD dwSize = 0;
132
133     ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
134     if (ret == ERROR_INSUFFICIENT_BUFFER) {
135       *ppIfTable = HeapAlloc(heap, flags, dwSize);
136       ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
137     }
138   }
139   TRACE("returning %d\n", ret);
140   return ret;
141 }
142
143
144 static int IpAddrTableSorter(const void *a, const void *b)
145 {
146   int ret;
147
148   if (a && b)
149     ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
150   else
151     ret = 0;
152   return ret;
153 }
154
155
156 /******************************************************************
157  *    AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
158  *
159  * Get interface-to-IP address mapping table. 
160  * Like GetIpAddrTable(), but allocate the returned table from heap.
161  *
162  * PARAMS
163  *  ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
164  *                      allocated and returned.
165  *  bOrder        [In]  whether to sort the table
166  *  heap          [In]  heap from which the table is allocated
167  *  flags         [In]  flags to HeapAlloc
168  *
169  * RETURNS
170  *  ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
171  *  failure, NO_ERROR on success.
172  */
173 DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
174  BOOL bOrder, HANDLE heap, DWORD flags)
175 {
176   DWORD ret;
177
178   TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08x\n",
179    ppIpAddrTable, bOrder, heap, flags);
180   ret = getIPAddrTable(ppIpAddrTable, heap, flags);
181   if (!ret && bOrder)
182     qsort((*ppIpAddrTable)->table, (*ppIpAddrTable)->dwNumEntries,
183      sizeof(MIB_IPADDRROW), IpAddrTableSorter);
184   TRACE("returning %d\n", ret);
185   return ret;
186 }
187
188
189 static int IpForwardTableSorter(const void *a, const void *b)
190 {
191   int ret;
192
193   if (a && b) {
194    const MIB_IPFORWARDROW* rowA = (const MIB_IPFORWARDROW*)a;
195    const MIB_IPFORWARDROW* rowB = (const MIB_IPFORWARDROW*)b;
196
197     ret = rowA->dwForwardDest - rowB->dwForwardDest;
198     if (ret == 0) {
199       ret = rowA->dwForwardProto - rowB->dwForwardProto;
200       if (ret == 0) {
201         ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy;
202         if (ret == 0)
203           ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop;
204       }
205     }
206   }
207   else
208     ret = 0;
209   return ret;
210 }
211
212
213 /******************************************************************
214  *    AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
215  *
216  * Get the route table.
217  * Like GetIpForwardTable(), but allocate the returned table from heap.
218  *
219  * PARAMS
220  *  ppIpForwardTable [Out] pointer into which the MIB_IPFORWARDTABLE is
221  *                         allocated and returned.
222  *  bOrder           [In]  whether to sort the table
223  *  heap             [In]  heap from which the table is allocated
224  *  flags            [In]  flags to HeapAlloc
225  *
226  * RETURNS
227  *  ERROR_INVALID_PARAMETER if ppIfTable is NULL, other error codes
228  *  on failure, NO_ERROR on success.
229  */
230 DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
231  ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags)
232 {
233   DWORD ret;
234
235   TRACE("ppIpForwardTable %p, bOrder %d, heap %p, flags 0x%08x\n",
236    ppIpForwardTable, bOrder, heap, flags);
237   ret = getRouteTable(ppIpForwardTable, heap, flags);
238   if (!ret && bOrder)
239     qsort((*ppIpForwardTable)->table, (*ppIpForwardTable)->dwNumEntries,
240      sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
241   TRACE("returning %d\n", ret);
242   return ret;
243 }
244
245
246 static int IpNetTableSorter(const void *a, const void *b)
247 {
248   int ret;
249
250   if (a && b)
251     ret = ((const MIB_IPNETROW*)a)->dwAddr - ((const MIB_IPNETROW*)b)->dwAddr;
252   else
253     ret = 0;
254   return ret;
255 }
256
257
258 /******************************************************************
259  *    AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
260  *
261  * Get the IP-to-physical address mapping table.
262  * Like GetIpNetTable(), but allocate the returned table from heap.
263  *
264  * PARAMS
265  *  ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE is
266  *                     allocated and returned.
267  *  bOrder       [In]  whether to sort the table
268  *  heap         [In]  heap from which the table is allocated
269  *  flags        [In]  flags to HeapAlloc
270  *
271  * RETURNS
272  *  ERROR_INVALID_PARAMETER if ppIpNetTable is NULL, other error codes
273  *  on failure, NO_ERROR on success.
274  */
275 DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable,
276  BOOL bOrder, HANDLE heap, DWORD flags)
277 {
278   DWORD ret;
279
280   TRACE("ppIpNetTable %p, bOrder %d, heap %p, flags 0x%08x\n",
281    ppIpNetTable, bOrder, heap, flags);
282   ret = getArpTable(ppIpNetTable, heap, flags);
283   if (!ret && bOrder)
284     qsort((*ppIpNetTable)->table, (*ppIpNetTable)->dwNumEntries,
285      sizeof(MIB_IPADDRROW), IpNetTableSorter);
286   TRACE("returning %d\n", ret);
287   return ret;
288 }
289
290
291 static int TcpTableSorter(const void *a, const void *b)
292 {
293   int ret;
294
295   if (a && b) {
296     const MIB_TCPROW* rowA = a;
297     const MIB_TCPROW* rowB = b;
298
299     ret = ntohl (rowA->dwLocalAddr) - ntohl (rowB->dwLocalAddr);
300     if (ret == 0) {
301        ret = ntohs ((unsigned short)rowA->dwLocalPort) -
302           ntohs ((unsigned short)rowB->dwLocalPort);
303       if (ret == 0) {
304          ret = ntohl (rowA->dwRemoteAddr) - ntohl (rowB->dwRemoteAddr);
305         if (ret == 0)
306            ret = ntohs ((unsigned short)rowA->dwRemotePort) -
307               ntohs ((unsigned short)rowB->dwRemotePort);
308       }
309     }
310   }
311   else
312     ret = 0;
313   return ret;
314 }
315
316
317 /******************************************************************
318  *    AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
319  *
320  * Get the TCP connection table.
321  * Like GetTcpTable(), but allocate the returned table from heap.
322  *
323  * PARAMS
324  *  ppTcpTable [Out] pointer into which the MIB_TCPTABLE is
325  *                   allocated and returned.
326  *  bOrder     [In]  whether to sort the table
327  *  heap       [In]  heap from which the table is allocated
328  *  flags      [In]  flags to HeapAlloc
329  *
330  * RETURNS
331  *  ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable()
332  *  returns otherwise.
333  */
334 DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
335  BOOL bOrder, HANDLE heap, DWORD flags)
336 {
337   DWORD ret;
338
339   TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
340    ppTcpTable, bOrder, heap, flags);
341
342   *ppTcpTable = NULL;
343   ret = getTcpTable(ppTcpTable, 0, heap, flags);
344   if (!ret && bOrder)
345     qsort((*ppTcpTable)->table, (*ppTcpTable)->dwNumEntries,
346      sizeof(MIB_TCPROW), TcpTableSorter);
347   TRACE("returning %d\n", ret);
348   return ret;
349 }
350
351
352 static int UdpTableSorter(const void *a, const void *b)
353 {
354   int ret;
355
356   if (a && b) {
357     const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
358     const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;
359
360     ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
361     if (ret == 0)
362       ret = rowA->dwLocalPort - rowB->dwLocalPort;
363   }
364   else
365     ret = 0;
366   return ret;
367 }
368
369
370 /******************************************************************
371  *    AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
372  *
373  * Get the UDP listener table.
374  * Like GetUdpTable(), but allocate the returned table from heap.
375  *
376  * PARAMS
377  *  ppUdpTable [Out] pointer into which the MIB_UDPTABLE is
378  *                   allocated and returned.
379  *  bOrder     [In]  whether to sort the table
380  *  heap       [In]  heap from which the table is allocated
381  *  flags      [In]  flags to HeapAlloc
382  *
383  * RETURNS
384  *  ERROR_INVALID_PARAMETER if ppUdpTable is NULL, whatever GetUdpTable()
385  *  returns otherwise.
386  */
387 DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
388  BOOL bOrder, HANDLE heap, DWORD flags)
389 {
390   DWORD ret;
391
392   TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
393    ppUdpTable, bOrder, heap, flags);
394   ret = getUdpTable(ppUdpTable, heap, flags);
395   if (!ret && bOrder)
396     qsort((*ppUdpTable)->table, (*ppUdpTable)->dwNumEntries,
397      sizeof(MIB_UDPROW), UdpTableSorter);
398   TRACE("returning %d\n", ret);
399   return ret;
400 }
401
402
403 /******************************************************************
404  *    CreateIpForwardEntry (IPHLPAPI.@)
405  *
406  * Create a route in the local computer's IP table.
407  *
408  * PARAMS
409  *  pRoute [In] new route information
410  *
411  * RETURNS
412  *  Success: NO_ERROR
413  *  Failure: error code from winerror.h
414  *
415  * FIXME
416  *  Stub, always returns NO_ERROR.
417  */
418 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
419 {
420   FIXME("(pRoute %p): stub\n", pRoute);
421   /* could use SIOCADDRT, not sure I want to */
422   return (DWORD) 0;
423 }
424
425
426 /******************************************************************
427  *    CreateIpNetEntry (IPHLPAPI.@)
428  *
429  * Create entry in the ARP table.
430  *
431  * PARAMS
432  *  pArpEntry [In] new ARP entry
433  *
434  * RETURNS
435  *  Success: NO_ERROR
436  *  Failure: error code from winerror.h
437  *
438  * FIXME
439  *  Stub, always returns NO_ERROR.
440  */
441 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
442 {
443   FIXME("(pArpEntry %p)\n", pArpEntry);
444   /* could use SIOCSARP on systems that support it, not sure I want to */
445   return (DWORD) 0;
446 }
447
448
449 /******************************************************************
450  *    CreateProxyArpEntry (IPHLPAPI.@)
451  *
452  * Create a Proxy ARP (PARP) entry for an IP address.
453  *
454  * PARAMS
455  *  dwAddress [In] IP address for which this computer acts as a proxy. 
456  *  dwMask    [In] subnet mask for dwAddress
457  *  dwIfIndex [In] interface index
458  *
459  * RETURNS
460  *  Success: NO_ERROR
461  *  Failure: error code from winerror.h
462  *
463  * FIXME
464  *  Stub, returns ERROR_NOT_SUPPORTED.
465  */
466 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
467 {
468   FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
469    dwAddress, dwMask, dwIfIndex);
470   return ERROR_NOT_SUPPORTED;
471 }
472
473
474 /******************************************************************
475  *    DeleteIPAddress (IPHLPAPI.@)
476  *
477  * Delete an IP address added with AddIPAddress().
478  *
479  * PARAMS
480  *  NTEContext [In] NTE context from AddIPAddress();
481  *
482  * RETURNS
483  *  Success: NO_ERROR
484  *  Failure: error code from winerror.h
485  *
486  * FIXME
487  *  Stub, returns ERROR_NOT_SUPPORTED.
488  */
489 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
490 {
491   FIXME("(NTEContext %d): stub\n", NTEContext);
492   return ERROR_NOT_SUPPORTED;
493 }
494
495
496 /******************************************************************
497  *    DeleteIpForwardEntry (IPHLPAPI.@)
498  *
499  * Delete a route.
500  *
501  * PARAMS
502  *  pRoute [In] route to delete
503  *
504  * RETURNS
505  *  Success: NO_ERROR
506  *  Failure: error code from winerror.h
507  *
508  * FIXME
509  *  Stub, returns NO_ERROR.
510  */
511 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
512 {
513   FIXME("(pRoute %p): stub\n", pRoute);
514   /* could use SIOCDELRT, not sure I want to */
515   return (DWORD) 0;
516 }
517
518
519 /******************************************************************
520  *    DeleteIpNetEntry (IPHLPAPI.@)
521  *
522  * Delete an ARP entry.
523  *
524  * PARAMS
525  *  pArpEntry [In] ARP entry to delete
526  *
527  * RETURNS
528  *  Success: NO_ERROR
529  *  Failure: error code from winerror.h
530  *
531  * FIXME
532  *  Stub, returns NO_ERROR.
533  */
534 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
535 {
536   FIXME("(pArpEntry %p): stub\n", pArpEntry);
537   /* could use SIOCDARP on systems that support it, not sure I want to */
538   return (DWORD) 0;
539 }
540
541
542 /******************************************************************
543  *    DeleteProxyArpEntry (IPHLPAPI.@)
544  *
545  * Delete a Proxy ARP entry.
546  *
547  * PARAMS
548  *  dwAddress [In] IP address for which this computer acts as a proxy. 
549  *  dwMask    [In] subnet mask for dwAddress
550  *  dwIfIndex [In] interface index
551  *
552  * RETURNS
553  *  Success: NO_ERROR
554  *  Failure: error code from winerror.h
555  *
556  * FIXME
557  *  Stub, returns ERROR_NOT_SUPPORTED.
558  */
559 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
560 {
561   FIXME("(dwAddress 0x%08x, dwMask 0x%08x, dwIfIndex 0x%08x): stub\n",
562    dwAddress, dwMask, dwIfIndex);
563   return ERROR_NOT_SUPPORTED;
564 }
565
566
567 /******************************************************************
568  *    EnableRouter (IPHLPAPI.@)
569  *
570  * Turn on ip forwarding.
571  *
572  * PARAMS
573  *  pHandle     [In/Out]
574  *  pOverlapped [In/Out] hEvent member should contain a valid handle.
575  *
576  * RETURNS
577  *  Success: ERROR_IO_PENDING
578  *  Failure: error code from winerror.h
579  *
580  * FIXME
581  *  Stub, returns ERROR_NOT_SUPPORTED.
582  */
583 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
584 {
585   FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle, pOverlapped);
586   /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
587      could map EACCESS to ERROR_ACCESS_DENIED, I suppose
588    */
589   return ERROR_NOT_SUPPORTED;
590 }
591
592
593 /******************************************************************
594  *    FlushIpNetTable (IPHLPAPI.@)
595  *
596  * Delete all ARP entries of an interface
597  *
598  * PARAMS
599  *  dwIfIndex [In] interface index
600  *
601  * RETURNS
602  *  Success: NO_ERROR
603  *  Failure: error code from winerror.h
604  *
605  * FIXME
606  *  Stub, returns ERROR_NOT_SUPPORTED.
607  */
608 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
609 {
610   FIXME("(dwIfIndex 0x%08x): stub\n", dwIfIndex);
611   /* this flushes the arp cache of the given index */
612   return ERROR_NOT_SUPPORTED;
613 }
614
615
616 /******************************************************************
617  *    GetAdapterIndex (IPHLPAPI.@)
618  *
619  * Get interface index from its name.
620  *
621  * PARAMS
622  *  AdapterName [In]  unicode string with the adapter name
623  *  IfIndex     [Out] returns found interface index
624  *
625  * RETURNS
626  *  Success: NO_ERROR
627  *  Failure: error code from winerror.h
628  */
629 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
630 {
631   char adapterName[MAX_ADAPTER_NAME];
632   int i;
633   DWORD ret;
634
635   TRACE("(AdapterName %p, IfIndex %p)\n", AdapterName, IfIndex);
636   /* The adapter name is guaranteed not to have any unicode characters, so
637    * this translation is never lossy */
638   for (i = 0; i < sizeof(adapterName) - 1 && AdapterName[i]; i++)
639     adapterName[i] = (char)AdapterName[i];
640   adapterName[i] = '\0';
641   ret = getInterfaceIndexByName(adapterName, IfIndex);
642   TRACE("returning %d\n", ret);
643   return ret;
644 }
645
646
647 /******************************************************************
648  *    GetAdaptersInfo (IPHLPAPI.@)
649  *
650  * Get information about adapters.
651  *
652  * PARAMS
653  *  pAdapterInfo [Out] buffer for adapter infos
654  *  pOutBufLen   [In]  length of output buffer
655  *
656  * RETURNS
657  *  Success: NO_ERROR
658  *  Failure: error code from winerror.h
659  */
660 DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
661 {
662   DWORD ret;
663
664   TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
665   if (!pOutBufLen)
666     ret = ERROR_INVALID_PARAMETER;
667   else {
668     DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
669
670     if (numNonLoopbackInterfaces > 0) {
671       DWORD numIPAddresses = getNumIPAddresses();
672       ULONG size;
673
674       /* This may slightly overestimate the amount of space needed, because
675        * the IP addresses include the loopback address, but it's easier
676        * to make sure there's more than enough space than to make sure there's
677        * precisely enough space.
678        */
679       size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
680       size += numIPAddresses  * sizeof(IP_ADDR_STRING); 
681       if (!pAdapterInfo || *pOutBufLen < size) {
682         *pOutBufLen = size;
683         ret = ERROR_BUFFER_OVERFLOW;
684       }
685       else {
686         InterfaceIndexTable *table = NULL;
687         PMIB_IPADDRTABLE ipAddrTable = NULL;
688         PMIB_IPFORWARDTABLE routeTable = NULL;
689
690         ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
691         if (!ret)
692           ret = getRouteTable(&routeTable, GetProcessHeap(), 0);
693         if (!ret)
694           table = getNonLoopbackInterfaceIndexTable();
695         if (table) {
696           size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
697           size += ipAddrTable->dwNumEntries * sizeof(IP_ADDR_STRING); 
698           if (*pOutBufLen < size) {
699             *pOutBufLen = size;
700             ret = ERROR_INSUFFICIENT_BUFFER;
701           }
702           else {
703             DWORD ndx;
704             HKEY hKey;
705             BOOL winsEnabled = FALSE;
706             IP_ADDRESS_STRING primaryWINS, secondaryWINS;
707             PIP_ADDR_STRING nextIPAddr = (PIP_ADDR_STRING)((LPBYTE)pAdapterInfo
708              + numNonLoopbackInterfaces * sizeof(IP_ADAPTER_INFO));
709
710             memset(pAdapterInfo, 0, size);
711             /* @@ Wine registry key: HKCU\Software\Wine\Network */
712             if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network",
713              &hKey) == ERROR_SUCCESS) {
714               DWORD size = sizeof(primaryWINS.String);
715               unsigned long addr;
716
717               RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
718                (LPBYTE)primaryWINS.String, &size);
719               addr = inet_addr(primaryWINS.String);
720               if (addr != INADDR_NONE && addr != INADDR_ANY)
721                 winsEnabled = TRUE;
722               size = sizeof(secondaryWINS.String);
723               RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
724                (LPBYTE)secondaryWINS.String, &size);
725               addr = inet_addr(secondaryWINS.String);
726               if (addr != INADDR_NONE && addr != INADDR_ANY)
727                 winsEnabled = TRUE;
728               RegCloseKey(hKey);
729             }
730             for (ndx = 0; ndx < table->numIndexes; ndx++) {
731               PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
732               DWORD i;
733               PIP_ADDR_STRING currentIPAddr = &ptr->IpAddressList;
734               BOOL firstIPAddr = TRUE;
735
736               /* on Win98 this is left empty, but whatever */
737               getInterfaceNameByIndex(table->indexes[ndx], ptr->AdapterName);
738               ptr->AddressLength = sizeof(ptr->Address);
739               getInterfacePhysicalByIndex(table->indexes[ndx],
740                &ptr->AddressLength, ptr->Address, &ptr->Type);
741               ptr->Index = table->indexes[ndx];
742               for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
743                 if (ipAddrTable->table[i].dwIndex == ptr->Index) {
744                   if (firstIPAddr) {
745                     toIPAddressString(ipAddrTable->table[i].dwAddr,
746                      ptr->IpAddressList.IpAddress.String);
747                     toIPAddressString(ipAddrTable->table[i].dwMask,
748                      ptr->IpAddressList.IpMask.String);
749                     firstIPAddr = FALSE;
750                   }
751                   else {
752                     currentIPAddr->Next = nextIPAddr;
753                     currentIPAddr = nextIPAddr;
754                     toIPAddressString(ipAddrTable->table[i].dwAddr,
755                      currentIPAddr->IpAddress.String);
756                     toIPAddressString(ipAddrTable->table[i].dwMask,
757                      currentIPAddr->IpMask.String);
758                     nextIPAddr++;
759                   }
760                 }
761               }
762               /* Find first router through this interface, which we'll assume
763                * is the default gateway for this adapter */
764               for (i = 0; i < routeTable->dwNumEntries; i++)
765                 if (routeTable->table[i].dwForwardIfIndex == ptr->Index
766                  && routeTable->table[i].dwForwardType ==
767                  MIB_IPROUTE_TYPE_INDIRECT)
768                   toIPAddressString(routeTable->table[i].dwForwardNextHop,
769                    ptr->GatewayList.IpAddress.String);
770               if (winsEnabled) {
771                 ptr->HaveWins = TRUE;
772                 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
773                  primaryWINS.String, sizeof(primaryWINS.String));
774                 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
775                  secondaryWINS.String, sizeof(secondaryWINS.String));
776               }
777               if (ndx < table->numIndexes - 1)
778                 ptr->Next = &pAdapterInfo[ndx + 1];
779               else
780                 ptr->Next = NULL;
781             }
782             ret = NO_ERROR;
783           }
784           HeapFree(GetProcessHeap(), 0, table);
785         }
786         else
787           ret = ERROR_OUTOFMEMORY;
788         HeapFree(GetProcessHeap(), 0, routeTable);
789         HeapFree(GetProcessHeap(), 0, ipAddrTable);
790       }
791     }
792     else
793       ret = ERROR_NO_DATA;
794   }
795   TRACE("returning %d\n", ret);
796   return ret;
797 }
798
799
800 /******************************************************************
801  *    GetBestInterface (IPHLPAPI.@)
802  *
803  * Get the interface, with the best route for the given IP address.
804  *
805  * PARAMS
806  *  dwDestAddr     [In]  IP address to search the interface for
807  *  pdwBestIfIndex [Out] found best interface
808  *
809  * RETURNS
810  *  Success: NO_ERROR
811  *  Failure: error code from winerror.h
812  */
813 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
814 {
815   DWORD ret;
816
817   TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex);
818   if (!pdwBestIfIndex)
819     ret = ERROR_INVALID_PARAMETER;
820   else {
821     MIB_IPFORWARDROW ipRow;
822
823     ret = GetBestRoute(dwDestAddr, 0, &ipRow);
824     if (ret == ERROR_SUCCESS)
825       *pdwBestIfIndex = ipRow.dwForwardIfIndex;
826   }
827   TRACE("returning %d\n", ret);
828   return ret;
829 }
830
831
832 /******************************************************************
833  *    GetBestRoute (IPHLPAPI.@)
834  *
835  * Get the best route for the given IP address.
836  *
837  * PARAMS
838  *  dwDestAddr   [In]  IP address to search the best route for
839  *  dwSourceAddr [In]  optional source IP address
840  *  pBestRoute   [Out] found best route
841  *
842  * RETURNS
843  *  Success: NO_ERROR
844  *  Failure: error code from winerror.h
845  */
846 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
847 {
848   PMIB_IPFORWARDTABLE table;
849   DWORD ret;
850
851   TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr,
852    dwSourceAddr, pBestRoute);
853   if (!pBestRoute)
854     return ERROR_INVALID_PARAMETER;
855
856   ret = AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
857   if (!ret) {
858     DWORD ndx, matchedBits, matchedNdx = table->dwNumEntries;
859
860     for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
861       if (table->table[ndx].dwForwardType != MIB_IPROUTE_TYPE_INVALID &&
862        (dwDestAddr & table->table[ndx].dwForwardMask) ==
863        (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
864         DWORD numShifts, mask;
865
866         for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
867          mask && !(mask & 1); mask >>= 1, numShifts++)
868           ;
869         if (numShifts > matchedBits) {
870           matchedBits = numShifts;
871           matchedNdx = ndx;
872         }
873         else if (!matchedBits && table->table[ndx].dwForwardType ==
874          MIB_IPROUTE_TYPE_INDIRECT) {
875           /* default to a default gateway */
876           matchedNdx = ndx;
877         }
878       }
879     }
880     if (matchedNdx < table->dwNumEntries) {
881       memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
882       ret = ERROR_SUCCESS;
883     }
884     else {
885       /* No route matches, which can happen if there's no default route. */
886       ret = ERROR_HOST_UNREACHABLE;
887     }
888     HeapFree(GetProcessHeap(), 0, table);
889   }
890   TRACE("returning %d\n", ret);
891   return ret;
892 }
893
894
895 /******************************************************************
896  *    GetFriendlyIfIndex (IPHLPAPI.@)
897  *
898  * Get a "friendly" version of IfIndex, which is one that doesn't
899  * have the top byte set.  Doesn't validate whether IfIndex is a valid
900  * adapter index.
901  *
902  * PARAMS
903  *  IfIndex [In] interface index to get the friendly one for
904  *
905  * RETURNS
906  *  A friendly version of IfIndex.
907  */
908 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
909 {
910   /* windows doesn't validate these, either, just makes sure the top byte is
911      cleared.  I assume my ifenum module never gives an index with the top
912      byte set. */
913   TRACE("returning %d\n", IfIndex);
914   return IfIndex;
915 }
916
917
918 /******************************************************************
919  *    GetIcmpStatistics (IPHLPAPI.@)
920  *
921  * Get the ICMP statistics for the local computer.
922  *
923  * PARAMS
924  *  pStats [Out] buffer for ICMP statistics
925  *
926  * RETURNS
927  *  Success: NO_ERROR
928  *  Failure: error code from winerror.h
929  */
930 DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
931 {
932   DWORD ret;
933
934   TRACE("pStats %p\n", pStats);
935   ret = getICMPStats(pStats);
936   TRACE("returning %d\n", ret);
937   return ret;
938 }
939
940
941 /******************************************************************
942  *    GetIfEntry (IPHLPAPI.@)
943  *
944  * Get information about an interface.
945  *
946  * PARAMS
947  *  pIfRow [In/Out] In:  dwIndex of MIB_IFROW selects the interface.
948  *                  Out: interface information
949  *
950  * RETURNS
951  *  Success: NO_ERROR
952  *  Failure: error code from winerror.h
953  */
954 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
955 {
956   DWORD ret;
957   char nameBuf[MAX_ADAPTER_NAME];
958   char *name;
959
960   TRACE("pIfRow %p\n", pIfRow);
961   if (!pIfRow)
962     return ERROR_INVALID_PARAMETER;
963
964   name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf);
965   if (name) {
966     ret = getInterfaceEntryByName(name, pIfRow);
967     if (ret == NO_ERROR)
968       ret = getInterfaceStatsByName(name, pIfRow);
969   }
970   else
971     ret = ERROR_INVALID_DATA;
972   TRACE("returning %d\n", ret);
973   return ret;
974 }
975
976
977 static int IfTableSorter(const void *a, const void *b)
978 {
979   int ret;
980
981   if (a && b)
982     ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
983   else
984     ret = 0;
985   return ret;
986 }
987
988
989 /******************************************************************
990  *    GetIfTable (IPHLPAPI.@)
991  *
992  * Get a table of local interfaces.
993  *
994  * PARAMS
995  *  pIfTable [Out]    buffer for local interfaces table
996  *  pdwSize  [In/Out] length of output buffer
997  *  bOrder   [In]     whether to sort the table
998  *
999  * RETURNS
1000  *  Success: NO_ERROR
1001  *  Failure: error code from winerror.h
1002  *
1003  * NOTES
1004  *  If pdwSize is less than required, the function will return
1005  *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1006  *  size.
1007  *  If bOrder is true, the returned table will be sorted by interface index.
1008  */
1009 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
1010 {
1011   DWORD ret;
1012
1013   TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize, pdwSize,
1014    (DWORD)bOrder);
1015   if (!pdwSize)
1016     ret = ERROR_INVALID_PARAMETER;
1017   else {
1018     DWORD numInterfaces = getNumInterfaces();
1019     ULONG size = sizeof(MIB_IFTABLE);
1020
1021     if (numInterfaces > 1)
1022       size += (numInterfaces - 1) * sizeof(MIB_IFROW);
1023     if (!pIfTable || *pdwSize < size) {
1024       *pdwSize = size;
1025       ret = ERROR_INSUFFICIENT_BUFFER;
1026     }
1027     else {
1028       InterfaceIndexTable *table = getInterfaceIndexTable();
1029
1030       if (table) {
1031         size = sizeof(MIB_IFTABLE);
1032         if (table->numIndexes > 1)
1033           size += (table->numIndexes - 1) * sizeof(MIB_IFROW);
1034         if (*pdwSize < size) {
1035           *pdwSize = size;
1036           ret = ERROR_INSUFFICIENT_BUFFER;
1037         }
1038         else {
1039           DWORD ndx;
1040
1041           *pdwSize = size;
1042           pIfTable->dwNumEntries = 0;
1043           for (ndx = 0; ndx < table->numIndexes; ndx++) {
1044             pIfTable->table[ndx].dwIndex = table->indexes[ndx];
1045             GetIfEntry(&pIfTable->table[ndx]);
1046             pIfTable->dwNumEntries++;
1047           }
1048           if (bOrder)
1049             qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
1050              IfTableSorter);
1051           ret = NO_ERROR;
1052         }
1053         HeapFree(GetProcessHeap(), 0, table);
1054       }
1055       else
1056         ret = ERROR_OUTOFMEMORY;
1057     }
1058   }
1059   TRACE("returning %d\n", ret);
1060   return ret;
1061 }
1062
1063
1064 /******************************************************************
1065  *    GetInterfaceInfo (IPHLPAPI.@)
1066  *
1067  * Get a list of network interface adapters.
1068  *
1069  * PARAMS
1070  *  pIfTable    [Out] buffer for interface adapters
1071  *  dwOutBufLen [Out] if buffer is too small, returns required size
1072  *
1073  * RETURNS
1074  *  Success: NO_ERROR
1075  *  Failure: error code from winerror.h
1076  *
1077  * BUGS
1078  *  MSDN states this should return non-loopback interfaces only.
1079  */
1080 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
1081 {
1082   DWORD ret;
1083
1084   TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1085   if (!dwOutBufLen)
1086     ret = ERROR_INVALID_PARAMETER;
1087   else {
1088     DWORD numInterfaces = getNumInterfaces();
1089     ULONG size = sizeof(IP_INTERFACE_INFO);
1090
1091     if (numInterfaces > 1)
1092       size += (numInterfaces - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
1093     if (!pIfTable || *dwOutBufLen < size) {
1094       *dwOutBufLen = size;
1095       ret = ERROR_INSUFFICIENT_BUFFER;
1096     }
1097     else {
1098       InterfaceIndexTable *table = getInterfaceIndexTable();
1099
1100       if (table) {
1101         size = sizeof(IP_INTERFACE_INFO);
1102         if (table->numIndexes > 1)
1103           size += (table->numIndexes - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
1104         if (*dwOutBufLen < size) {
1105           *dwOutBufLen = size;
1106           ret = ERROR_INSUFFICIENT_BUFFER;
1107         }
1108         else {
1109           DWORD ndx;
1110           char nameBuf[MAX_ADAPTER_NAME];
1111
1112           *dwOutBufLen = size;
1113           pIfTable->NumAdapters = 0;
1114           for (ndx = 0; ndx < table->numIndexes; ndx++) {
1115             const char *walker, *name;
1116             WCHAR *assigner;
1117
1118             pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1119             name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
1120             for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
1121              walker && *walker &&
1122              assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
1123              walker++, assigner++)
1124               *assigner = *walker;
1125             *assigner = 0;
1126             pIfTable->NumAdapters++;
1127           }
1128           ret = NO_ERROR;
1129         }
1130         HeapFree(GetProcessHeap(), 0, table);
1131       }
1132       else
1133         ret = ERROR_OUTOFMEMORY;
1134     }
1135   }
1136   TRACE("returning %d\n", ret);
1137   return ret;
1138 }
1139
1140
1141 /******************************************************************
1142  *    GetIpAddrTable (IPHLPAPI.@)
1143  *
1144  * Get interface-to-IP address mapping table. 
1145  *
1146  * PARAMS
1147  *  pIpAddrTable [Out]    buffer for mapping table
1148  *  pdwSize      [In/Out] length of output buffer
1149  *  bOrder       [In]     whether to sort the table
1150  *
1151  * RETURNS
1152  *  Success: NO_ERROR
1153  *  Failure: error code from winerror.h
1154  *
1155  * NOTES
1156  *  If pdwSize is less than required, the function will return
1157  *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1158  *  size.
1159  *  If bOrder is true, the returned table will be sorted by the next hop and
1160  *  an assortment of arbitrary parameters.
1161  */
1162 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1163 {
1164   DWORD ret;
1165
1166   TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable, pdwSize,
1167    (DWORD)bOrder);
1168   if (!pdwSize)
1169     ret = ERROR_INVALID_PARAMETER;
1170   else {
1171     PMIB_IPADDRTABLE table;
1172
1173     ret = getIPAddrTable(&table, GetProcessHeap(), 0);
1174     if (ret == NO_ERROR)
1175     {
1176       ULONG size = sizeof(MIB_IPADDRTABLE);
1177
1178       if (table->dwNumEntries > 1)
1179         size += (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW);
1180       if (!pIpAddrTable || *pdwSize < size) {
1181         *pdwSize = size;
1182         ret = ERROR_INSUFFICIENT_BUFFER;
1183       }
1184       else {
1185         *pdwSize = size;
1186         memcpy(pIpAddrTable, table, size);
1187         if (bOrder)
1188           qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1189            sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1190         ret = NO_ERROR;
1191       }
1192       HeapFree(GetProcessHeap(), 0, table);
1193     }
1194   }
1195   TRACE("returning %d\n", ret);
1196   return ret;
1197 }
1198
1199
1200 /******************************************************************
1201  *    GetIpForwardTable (IPHLPAPI.@)
1202  *
1203  * Get the route table.
1204  *
1205  * PARAMS
1206  *  pIpForwardTable [Out]    buffer for route table
1207  *  pdwSize         [In/Out] length of output buffer
1208  *  bOrder          [In]     whether to sort the table
1209  *
1210  * RETURNS
1211  *  Success: NO_ERROR
1212  *  Failure: error code from winerror.h
1213  *
1214  * NOTES
1215  *  If pdwSize is less than required, the function will return
1216  *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1217  *  size.
1218  *  If bOrder is true, the returned table will be sorted by the next hop and
1219  *  an assortment of arbitrary parameters.
1220  */
1221 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1222 {
1223   DWORD ret;
1224
1225   TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable,
1226    pdwSize, (DWORD)bOrder);
1227   if (!pdwSize)
1228     ret = ERROR_INVALID_PARAMETER;
1229   else {
1230     DWORD numRoutes = getNumRoutes();
1231     ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE);
1232
1233     if (numRoutes > 1)
1234       sizeNeeded += (numRoutes - 1) * sizeof(MIB_IPFORWARDROW);
1235     if (!pIpForwardTable || *pdwSize < sizeNeeded) {
1236       *pdwSize = sizeNeeded;
1237       ret = ERROR_INSUFFICIENT_BUFFER;
1238     }
1239     else {
1240       PMIB_IPFORWARDTABLE table;
1241
1242       ret = getRouteTable(&table, GetProcessHeap(), 0);
1243       if (!ret) {
1244         sizeNeeded = sizeof(MIB_IPFORWARDTABLE);
1245         if (table->dwNumEntries > 1)
1246           sizeNeeded += (table->dwNumEntries - 1) * sizeof(MIB_IPFORWARDROW);
1247         if (*pdwSize < sizeNeeded) {
1248           *pdwSize = sizeNeeded;
1249           ret = ERROR_INSUFFICIENT_BUFFER;
1250         }
1251         else {
1252           *pdwSize = sizeNeeded;
1253           memcpy(pIpForwardTable, table, sizeNeeded);
1254           if (bOrder)
1255             qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
1256              sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1257           ret = NO_ERROR;
1258         }
1259         HeapFree(GetProcessHeap(), 0, table);
1260       }
1261     }
1262   }
1263   TRACE("returning %d\n", ret);
1264   return ret;
1265 }
1266
1267
1268 /******************************************************************
1269  *    GetIpNetTable (IPHLPAPI.@)
1270  *
1271  * Get the IP-to-physical address mapping table.
1272  *
1273  * PARAMS
1274  *  pIpNetTable [Out]    buffer for mapping table
1275  *  pdwSize     [In/Out] length of output buffer
1276  *  bOrder      [In]     whether to sort the table
1277  *
1278  * RETURNS
1279  *  Success: NO_ERROR
1280  *  Failure: error code from winerror.h
1281  *
1282  * NOTES
1283  *  If pdwSize is less than required, the function will return
1284  *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1285  *  size.
1286  *  If bOrder is true, the returned table will be sorted by IP address.
1287  */
1288 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1289 {
1290   DWORD ret;
1291
1292   TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable, pdwSize,
1293    (DWORD)bOrder);
1294   if (!pdwSize)
1295     ret = ERROR_INVALID_PARAMETER;
1296   else {
1297     DWORD numEntries = getNumArpEntries();
1298     ULONG size = sizeof(MIB_IPNETTABLE);
1299
1300     if (numEntries > 1)
1301       size += (numEntries - 1) * sizeof(MIB_IPNETROW);
1302     if (!pIpNetTable || *pdwSize < size) {
1303       *pdwSize = size;
1304       ret = ERROR_INSUFFICIENT_BUFFER;
1305     }
1306     else {
1307       PMIB_IPNETTABLE table;
1308
1309       ret = getArpTable(&table, GetProcessHeap(), 0);
1310       if (!ret) {
1311         size = sizeof(MIB_IPNETTABLE);
1312         if (table->dwNumEntries > 1)
1313           size += (table->dwNumEntries - 1) * sizeof(MIB_IPNETROW);
1314         if (*pdwSize < size) {
1315           *pdwSize = size;
1316           ret = ERROR_INSUFFICIENT_BUFFER;
1317         }
1318         else {
1319           *pdwSize = size;
1320           memcpy(pIpNetTable, table, size);
1321           if (bOrder)
1322             qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
1323              sizeof(MIB_IPNETROW), IpNetTableSorter);
1324           ret = NO_ERROR;
1325         }
1326         HeapFree(GetProcessHeap(), 0, table);
1327       }
1328     }
1329   }
1330   TRACE("returning %d\n", ret);
1331   return ret;
1332 }
1333
1334
1335 /******************************************************************
1336  *    GetIpStatistics (IPHLPAPI.@)
1337  *
1338  * Get the IP statistics for the local computer.
1339  *
1340  * PARAMS
1341  *  pStats [Out] buffer for IP statistics
1342  *
1343  * RETURNS
1344  *  Success: NO_ERROR
1345  *  Failure: error code from winerror.h
1346  */
1347 DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
1348 {
1349   DWORD ret;
1350
1351   TRACE("pStats %p\n", pStats);
1352   ret = getIPStats(pStats);
1353   TRACE("returning %d\n", ret);
1354   return ret;
1355 }
1356
1357
1358 /******************************************************************
1359  *    GetNetworkParams (IPHLPAPI.@)
1360  *
1361  * Get the network parameters for the local computer.
1362  *
1363  * PARAMS
1364  *  pFixedInfo [Out]    buffer for network parameters
1365  *  pOutBufLen [In/Out] length of output buffer
1366  *
1367  * RETURNS
1368  *  Success: NO_ERROR
1369  *  Failure: error code from winerror.h
1370  *
1371  * NOTES
1372  *  If pOutBufLen is less than required, the function will return
1373  *  ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1374  *  size.
1375  */
1376 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1377 {
1378   DWORD ret, size;
1379   LONG regReturn;
1380   HKEY hKey;
1381
1382   TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1383   if (!pOutBufLen)
1384     return ERROR_INVALID_PARAMETER;
1385
1386   initialise_resolver();
1387   size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount  - 1) *
1388    sizeof(IP_ADDR_STRING) : 0);
1389   if (!pFixedInfo || *pOutBufLen < size) {
1390     *pOutBufLen = size;
1391     return ERROR_BUFFER_OVERFLOW;
1392   }
1393
1394   memset(pFixedInfo, 0, size);
1395   size = sizeof(pFixedInfo->HostName);
1396   GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1397   size = sizeof(pFixedInfo->DomainName);
1398   GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1399   if (_res.nscount > 0) {
1400     PIP_ADDR_STRING ptr;
1401     int i;
1402
1403     for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1404      i++, ptr = ptr->Next) {
1405       toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
1406        ptr->IpAddress.String);
1407       if (i == _res.nscount - 1)
1408         ptr->Next = NULL;
1409       else if (i == 0)
1410         ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
1411       else
1412         ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1413     }
1414   }
1415   pFixedInfo->NodeType = HYBRID_NODETYPE;
1416   regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1417    "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1418   if (regReturn != ERROR_SUCCESS)
1419     regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1420      "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1421      &hKey);
1422   if (regReturn == ERROR_SUCCESS)
1423   {
1424     DWORD size = sizeof(pFixedInfo->ScopeId);
1425
1426     RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1427     RegCloseKey(hKey);
1428   }
1429
1430   /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1431      I suppose could also check for a listener on port 53 to set EnableDns */
1432   ret = NO_ERROR;
1433   TRACE("returning %d\n", ret);
1434   return ret;
1435 }
1436
1437
1438 /******************************************************************
1439  *    GetNumberOfInterfaces (IPHLPAPI.@)
1440  *
1441  * Get the number of interfaces.
1442  *
1443  * PARAMS
1444  *  pdwNumIf [Out] number of interfaces
1445  *
1446  * RETURNS
1447  *  NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1448  */
1449 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
1450 {
1451   DWORD ret;
1452
1453   TRACE("pdwNumIf %p\n", pdwNumIf);
1454   if (!pdwNumIf)
1455     ret = ERROR_INVALID_PARAMETER;
1456   else {
1457     *pdwNumIf = getNumInterfaces();
1458     ret = NO_ERROR;
1459   }
1460   TRACE("returning %d\n", ret);
1461   return ret;
1462 }
1463
1464
1465 /******************************************************************
1466  *    GetPerAdapterInfo (IPHLPAPI.@)
1467  *
1468  * Get information about an adapter corresponding to an interface.
1469  *
1470  * PARAMS
1471  *  IfIndex         [In]     interface info
1472  *  pPerAdapterInfo [Out]    buffer for per adapter info
1473  *  pOutBufLen      [In/Out] length of output buffer
1474  *
1475  * RETURNS
1476  *  Success: NO_ERROR
1477  *  Failure: error code from winerror.h
1478  *
1479  * FIXME
1480  *  Stub, returns empty IP_PER_ADAPTER_INFO in every case.
1481  */
1482 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
1483 {
1484   ULONG bytesNeeded = sizeof(IP_PER_ADAPTER_INFO);
1485   DWORD ret;
1486
1487   TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex,
1488    pPerAdapterInfo, pOutBufLen);
1489   if (!pOutBufLen)
1490     ret = ERROR_INVALID_PARAMETER;
1491   else if (!pPerAdapterInfo)
1492   {
1493     *pOutBufLen = bytesNeeded;
1494     ret = NO_ERROR;
1495   }
1496   else if (*pOutBufLen < bytesNeeded)
1497   {
1498     *pOutBufLen = bytesNeeded;
1499     ret = ERROR_BUFFER_OVERFLOW;
1500   }
1501   else
1502   {
1503     memset(pPerAdapterInfo, 0, bytesNeeded);
1504     ret = NO_ERROR;
1505   }
1506   return ret;
1507 }
1508
1509
1510 /******************************************************************
1511  *    GetRTTAndHopCount (IPHLPAPI.@)
1512  *
1513  * Get round-trip time (RTT) and hop count.
1514  *
1515  * PARAMS
1516  *
1517  *  DestIpAddress [In]  destination address to get the info for
1518  *  HopCount      [Out] retrieved hop count
1519  *  MaxHops       [In]  maximum hops to search for the destination
1520  *  RTT           [Out] RTT in milliseconds
1521  *
1522  * RETURNS
1523  *  Success: TRUE
1524  *  Failure: FALSE
1525  *
1526  * FIXME
1527  *  Stub, returns FALSE.
1528  */
1529 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
1530 {
1531   FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %d, RTT %p): stub\n",
1532    DestIpAddress, HopCount, MaxHops, RTT);
1533   return FALSE;
1534 }
1535
1536
1537 /******************************************************************
1538  *    GetTcpStatistics (IPHLPAPI.@)
1539  *
1540  * Get the TCP statistics for the local computer.
1541  *
1542  * PARAMS
1543  *  pStats [Out] buffer for TCP statistics
1544  *
1545  * RETURNS
1546  *  Success: NO_ERROR
1547  *  Failure: error code from winerror.h
1548  */
1549 DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
1550 {
1551   DWORD ret;
1552
1553   TRACE("pStats %p\n", pStats);
1554   ret = getTCPStats(pStats);
1555   TRACE("returning %d\n", ret);
1556   return ret;
1557 }
1558
1559
1560 /******************************************************************
1561  *    GetTcpTable (IPHLPAPI.@)
1562  *
1563  * Get the table of active TCP connections.
1564  *
1565  * PARAMS
1566  *  pTcpTable [Out]    buffer for TCP connections table
1567  *  pdwSize   [In/Out] length of output buffer
1568  *  bOrder    [In]     whether to order the table
1569  *
1570  * RETURNS
1571  *  Success: NO_ERROR
1572  *  Failure: error code from winerror.h
1573  *
1574  * NOTES
1575  *  If pdwSize is less than required, the function will return 
1576  *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to 
1577  *  the required byte size.
1578  *  If bOrder is true, the returned table will be sorted, first by
1579  *  local address and port number, then by remote address and port
1580  *  number.
1581  */
1582 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
1583 {
1584   DWORD ret;
1585
1586   TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize,
1587    (DWORD)bOrder);
1588   if (!pdwSize)
1589     ret = ERROR_INVALID_PARAMETER;
1590   else {
1591     DWORD numEntries = getNumTcpEntries();
1592     DWORD size = sizeof(MIB_TCPTABLE);
1593
1594     if (numEntries > 1)
1595       size += (numEntries - 1) * sizeof(MIB_TCPROW);
1596     if (!pTcpTable || *pdwSize < size) {
1597       *pdwSize = size;
1598       ret = ERROR_INSUFFICIENT_BUFFER;
1599     }
1600     else {
1601       ret = getTcpTable(&pTcpTable, numEntries, 0, 0);
1602       if (!ret) {
1603         size = sizeof(MIB_TCPTABLE);
1604         if (pTcpTable->dwNumEntries > 1)
1605           size += (pTcpTable->dwNumEntries - 1) * sizeof(MIB_TCPROW);
1606         *pdwSize = size;
1607
1608         if (bOrder)
1609            qsort(pTcpTable->table, pTcpTable->dwNumEntries,
1610                  sizeof(MIB_TCPROW), TcpTableSorter);
1611         ret = NO_ERROR;
1612       }
1613     }
1614   }
1615   TRACE("returning %d\n", ret);
1616   return ret;
1617 }
1618
1619
1620 /******************************************************************
1621  *    GetUdpStatistics (IPHLPAPI.@)
1622  *
1623  * Get the UDP statistics for the local computer.
1624  *
1625  * PARAMS
1626  *  pStats [Out] buffer for UDP statistics
1627  *
1628  * RETURNS
1629  *  Success: NO_ERROR
1630  *  Failure: error code from winerror.h
1631  */
1632 DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
1633 {
1634   DWORD ret;
1635
1636   TRACE("pStats %p\n", pStats);
1637   ret = getUDPStats(pStats);
1638   TRACE("returning %d\n", ret);
1639   return ret;
1640 }
1641
1642
1643 /******************************************************************
1644  *    GetUdpTable (IPHLPAPI.@)
1645  *
1646  * Get a table of active UDP connections.
1647  *
1648  * PARAMS
1649  *  pUdpTable [Out]    buffer for UDP connections table
1650  *  pdwSize   [In/Out] length of output buffer
1651  *  bOrder    [In]     whether to order the table
1652  *
1653  * RETURNS
1654  *  Success: NO_ERROR
1655  *  Failure: error code from winerror.h
1656  *
1657  * NOTES
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.
1663  */
1664 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
1665 {
1666   DWORD ret;
1667
1668   TRACE("pUdpTable %p, pdwSize %p, bOrder %d\n", pUdpTable, pdwSize,
1669    (DWORD)bOrder);
1670   if (!pdwSize)
1671     ret = ERROR_INVALID_PARAMETER;
1672   else {
1673     DWORD numEntries = getNumUdpEntries();
1674     DWORD size = sizeof(MIB_UDPTABLE);
1675
1676     if (numEntries > 1)
1677       size += (numEntries - 1) * sizeof(MIB_UDPROW);
1678     if (!pUdpTable || *pdwSize < size) {
1679       *pdwSize = size;
1680       ret = ERROR_INSUFFICIENT_BUFFER;
1681     }
1682     else {
1683       PMIB_UDPTABLE table;
1684
1685       ret = getUdpTable(&table, GetProcessHeap(), 0);
1686       if (!ret) {
1687         size = sizeof(MIB_UDPTABLE);
1688         if (table->dwNumEntries > 1)
1689           size += (table->dwNumEntries - 1) * sizeof(MIB_UDPROW);
1690         if (*pdwSize < size) {
1691           *pdwSize = size;
1692           ret = ERROR_INSUFFICIENT_BUFFER;
1693         }
1694         else {
1695           *pdwSize = size;
1696           memcpy(pUdpTable, table, size);
1697           if (bOrder)
1698             qsort(pUdpTable->table, pUdpTable->dwNumEntries,
1699              sizeof(MIB_UDPROW), UdpTableSorter);
1700           ret = NO_ERROR;
1701         }
1702         HeapFree(GetProcessHeap(), 0, table);
1703       }
1704       else
1705         ret = ERROR_OUTOFMEMORY;
1706     }
1707   }
1708   TRACE("returning %d\n", ret);
1709   return ret;
1710 }
1711
1712
1713 /******************************************************************
1714  *    GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1715  *
1716  * This is a Win98-only function to get information on "unidirectional"
1717  * adapters.  Since this is pretty nonsensical in other contexts, it
1718  * never returns anything.
1719  *
1720  * PARAMS
1721  *  pIPIfInfo   [Out] buffer for adapter infos
1722  *  dwOutBufLen [Out] length of the output buffer
1723  *
1724  * RETURNS
1725  *  Success: NO_ERROR
1726  *  Failure: error code from winerror.h
1727  *
1728  * FIXME
1729  *  Stub, returns ERROR_NOT_SUPPORTED.
1730  */
1731 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
1732 {
1733   TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1734   /* a unidirectional adapter?? not bloody likely! */
1735   return ERROR_NOT_SUPPORTED;
1736 }
1737
1738
1739 /******************************************************************
1740  *    IpReleaseAddress (IPHLPAPI.@)
1741  *
1742  * Release an IP optained through DHCP,
1743  *
1744  * PARAMS
1745  *  AdapterInfo [In] adapter to release IP address
1746  *
1747  * RETURNS
1748  *  Success: NO_ERROR
1749  *  Failure: error code from winerror.h
1750  *
1751  * NOTES
1752  *  Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1753  *  this function does nothing.
1754  *
1755  * FIXME
1756  *  Stub, returns ERROR_NOT_SUPPORTED.
1757  */
1758 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1759 {
1760   TRACE("AdapterInfo %p\n", AdapterInfo);
1761   /* not a stub, never going to support this (and I never mark an adapter as
1762      DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1763   return ERROR_NOT_SUPPORTED;
1764 }
1765
1766
1767 /******************************************************************
1768  *    IpRenewAddress (IPHLPAPI.@)
1769  *
1770  * Renew an IP optained through DHCP.
1771  *
1772  * PARAMS
1773  *  AdapterInfo [In] adapter to renew IP address
1774  *
1775  * RETURNS
1776  *  Success: NO_ERROR
1777  *  Failure: error code from winerror.h
1778  *
1779  * NOTES
1780  *  Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1781  *  this function does nothing.
1782  *
1783  * FIXME
1784  *  Stub, returns ERROR_NOT_SUPPORTED.
1785  */
1786 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1787 {
1788   TRACE("AdapterInfo %p\n", AdapterInfo);
1789   /* not a stub, never going to support this (and I never mark an adapter as
1790      DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1791   return ERROR_NOT_SUPPORTED;
1792 }
1793
1794
1795 /******************************************************************
1796  *    NotifyAddrChange (IPHLPAPI.@)
1797  *
1798  * Notify caller whenever the ip-interface map is changed.
1799  *
1800  * PARAMS
1801  *  Handle     [Out] handle useable in asynchronus notification
1802  *  overlapped [In]  overlapped structure that notifies the caller
1803  *
1804  * RETURNS
1805  *  Success: NO_ERROR
1806  *  Failure: error code from winerror.h
1807  *
1808  * FIXME
1809  *  Stub, returns ERROR_NOT_SUPPORTED.
1810  */
1811 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1812 {
1813   FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1814   return ERROR_NOT_SUPPORTED;
1815 }
1816
1817
1818 /******************************************************************
1819  *    NotifyRouteChange (IPHLPAPI.@)
1820  *
1821  * Notify caller whenever the ip routing table is changed.
1822  *
1823  * PARAMS
1824  *  Handle     [Out] handle useable in asynchronus notification
1825  *  overlapped [In]  overlapped structure that notifies the caller
1826  *
1827  * RETURNS
1828  *  Success: NO_ERROR
1829  *  Failure: error code from winerror.h
1830  *
1831  * FIXME
1832  *  Stub, returns ERROR_NOT_SUPPORTED.
1833  */
1834 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1835 {
1836   FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1837   return ERROR_NOT_SUPPORTED;
1838 }
1839
1840
1841 /******************************************************************
1842  *    SendARP (IPHLPAPI.@)
1843  *
1844  * Send an ARP request.
1845  *
1846  * PARAMS
1847  *  DestIP     [In]     attempt to obtain this IP
1848  *  SrcIP      [In]     optional sender IP address
1849  *  pMacAddr   [Out]    buffer for the mac address
1850  *  PhyAddrLen [In/Out] length of the output buffer
1851  *
1852  * RETURNS
1853  *  Success: NO_ERROR
1854  *  Failure: error code from winerror.h
1855  *
1856  * FIXME
1857  *  Stub, returns ERROR_NOT_SUPPORTED.
1858  */
1859 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
1860 {
1861   FIXME("(DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p): stub\n",
1862    DestIP, SrcIP, pMacAddr, PhyAddrLen);
1863   return ERROR_NOT_SUPPORTED;
1864 }
1865
1866
1867 /******************************************************************
1868  *    SetIfEntry (IPHLPAPI.@)
1869  *
1870  * Set the administrative status of an interface.
1871  *
1872  * PARAMS
1873  *  pIfRow [In] dwAdminStatus member specifies the new status.
1874  *
1875  * RETURNS
1876  *  Success: NO_ERROR
1877  *  Failure: error code from winerror.h
1878  *
1879  * FIXME
1880  *  Stub, returns ERROR_NOT_SUPPORTED.
1881  */
1882 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
1883 {
1884   FIXME("(pIfRow %p): stub\n", pIfRow);
1885   /* this is supposed to set an interface administratively up or down.
1886      Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1887      this sort of down is indistinguishable from other sorts of down (e.g. no
1888      link). */
1889   return ERROR_NOT_SUPPORTED;
1890 }
1891
1892
1893 /******************************************************************
1894  *    SetIpForwardEntry (IPHLPAPI.@)
1895  *
1896  * Modify an existing route.
1897  *
1898  * PARAMS
1899  *  pRoute [In] route with the new information
1900  *
1901  * RETURNS
1902  *  Success: NO_ERROR
1903  *  Failure: error code from winerror.h
1904  *
1905  * FIXME
1906  *  Stub, returns NO_ERROR.
1907  */
1908 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
1909 {
1910   FIXME("(pRoute %p): stub\n", pRoute);
1911   /* this is to add a route entry, how's it distinguishable from
1912      CreateIpForwardEntry?
1913      could use SIOCADDRT, not sure I want to */
1914   return (DWORD) 0;
1915 }
1916
1917
1918 /******************************************************************
1919  *    SetIpNetEntry (IPHLPAPI.@)
1920  *
1921  * Modify an existing ARP entry.
1922  *
1923  * PARAMS
1924  *  pArpEntry [In] ARP entry with the new information
1925  *
1926  * RETURNS
1927  *  Success: NO_ERROR
1928  *  Failure: error code from winerror.h
1929  *
1930  * FIXME
1931  *  Stub, returns NO_ERROR.
1932  */
1933 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
1934 {
1935   FIXME("(pArpEntry %p): stub\n", pArpEntry);
1936   /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1937   return (DWORD) 0;
1938 }
1939
1940
1941 /******************************************************************
1942  *    SetIpStatistics (IPHLPAPI.@)
1943  *
1944  * Toggle IP forwarding and det the default TTL value.
1945  *
1946  * PARAMS
1947  *  pIpStats [In] IP statistics with the new information
1948  *
1949  * RETURNS
1950  *  Success: NO_ERROR
1951  *  Failure: error code from winerror.h
1952  *
1953  * FIXME
1954  *  Stub, returns NO_ERROR.
1955  */
1956 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
1957 {
1958   FIXME("(pIpStats %p): stub\n", pIpStats);
1959   return (DWORD) 0;
1960 }
1961
1962
1963 /******************************************************************
1964  *    SetIpTTL (IPHLPAPI.@)
1965  *
1966  * Set the default TTL value.
1967  *
1968  * PARAMS
1969  *  nTTL [In] new TTL value
1970  *
1971  * RETURNS
1972  *  Success: NO_ERROR
1973  *  Failure: error code from winerror.h
1974  *
1975  * FIXME
1976  *  Stub, returns NO_ERROR.
1977  */
1978 DWORD WINAPI SetIpTTL(UINT nTTL)
1979 {
1980   FIXME("(nTTL %d): stub\n", nTTL);
1981   /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1982      want to.  Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1983   return (DWORD) 0;
1984 }
1985
1986
1987 /******************************************************************
1988  *    SetTcpEntry (IPHLPAPI.@)
1989  *
1990  * Set the state of a TCP connection.
1991  *
1992  * PARAMS
1993  *  pTcpRow [In] specifies connection with new state
1994  *
1995  * RETURNS
1996  *  Success: NO_ERROR
1997  *  Failure: error code from winerror.h
1998  *
1999  * FIXME
2000  *  Stub, returns NO_ERROR.
2001  */
2002 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
2003 {
2004   FIXME("(pTcpRow %p): stub\n", pTcpRow);
2005   return (DWORD) 0;
2006 }
2007
2008
2009 /******************************************************************
2010  *    UnenableRouter (IPHLPAPI.@)
2011  *
2012  * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2013  * if it reaches zero.
2014  *
2015  * PARAMS
2016  *  pOverlapped     [In/Out] should be the same as in EnableRouter()
2017  *  lpdwEnableCount [Out]    optional, receives reference count
2018  *
2019  * RETURNS
2020  *  Success: NO_ERROR
2021  *  Failure: error code from winerror.h
2022  *
2023  * FIXME
2024  *  Stub, returns ERROR_NOT_SUPPORTED.
2025  */
2026 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
2027 {
2028   FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
2029    lpdwEnableCount);
2030   /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
2031      could map EACCESS to ERROR_ACCESS_DENIED, I suppose
2032    */
2033   return ERROR_NOT_SUPPORTED;
2034 }