credui: Updated French translation.
[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               getInterfacePhysicalByIndex(table->indexes[ndx],
739                &ptr->AddressLength, ptr->Address, &ptr->Type);
740               ptr->Index = table->indexes[ndx];
741               for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
742                 if (ipAddrTable->table[i].dwIndex == ptr->Index) {
743                   if (firstIPAddr) {
744                     toIPAddressString(ipAddrTable->table[i].dwAddr,
745                      ptr->IpAddressList.IpAddress.String);
746                     toIPAddressString(ipAddrTable->table[i].dwMask,
747                      ptr->IpAddressList.IpMask.String);
748                     firstIPAddr = FALSE;
749                   }
750                   else {
751                     currentIPAddr->Next = nextIPAddr;
752                     currentIPAddr = nextIPAddr;
753                     toIPAddressString(ipAddrTable->table[i].dwAddr,
754                      currentIPAddr->IpAddress.String);
755                     toIPAddressString(ipAddrTable->table[i].dwMask,
756                      currentIPAddr->IpMask.String);
757                     nextIPAddr++;
758                   }
759                 }
760               }
761               /* Find first router through this interface, which we'll assume
762                * is the default gateway for this adapter */
763               for (i = 0; i < routeTable->dwNumEntries; i++)
764                 if (routeTable->table[i].dwForwardIfIndex == ptr->Index
765                  && routeTable->table[i].dwForwardType ==
766                  MIB_IPROUTE_TYPE_INDIRECT)
767                   toIPAddressString(routeTable->table[i].dwForwardNextHop,
768                    ptr->GatewayList.IpAddress.String);
769               if (winsEnabled) {
770                 ptr->HaveWins = TRUE;
771                 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
772                  primaryWINS.String, sizeof(primaryWINS.String));
773                 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
774                  secondaryWINS.String, sizeof(secondaryWINS.String));
775               }
776               if (ndx < table->numIndexes - 1)
777                 ptr->Next = &pAdapterInfo[ndx + 1];
778               else
779                 ptr->Next = NULL;
780             }
781             ret = NO_ERROR;
782           }
783           HeapFree(GetProcessHeap(), 0, table);
784         }
785         else
786           ret = ERROR_OUTOFMEMORY;
787         HeapFree(GetProcessHeap(), 0, routeTable);
788         HeapFree(GetProcessHeap(), 0, ipAddrTable);
789       }
790     }
791     else
792       ret = ERROR_NO_DATA;
793   }
794   TRACE("returning %d\n", ret);
795   return ret;
796 }
797
798
799 /******************************************************************
800  *    GetBestInterface (IPHLPAPI.@)
801  *
802  * Get the interface, with the best route for the given IP address.
803  *
804  * PARAMS
805  *  dwDestAddr     [In]  IP address to search the interface for
806  *  pdwBestIfIndex [Out] found best interface
807  *
808  * RETURNS
809  *  Success: NO_ERROR
810  *  Failure: error code from winerror.h
811  */
812 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
813 {
814   DWORD ret;
815
816   TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex);
817   if (!pdwBestIfIndex)
818     ret = ERROR_INVALID_PARAMETER;
819   else {
820     MIB_IPFORWARDROW ipRow;
821
822     ret = GetBestRoute(dwDestAddr, 0, &ipRow);
823     if (ret == ERROR_SUCCESS)
824       *pdwBestIfIndex = ipRow.dwForwardIfIndex;
825   }
826   TRACE("returning %d\n", ret);
827   return ret;
828 }
829
830
831 /******************************************************************
832  *    GetBestRoute (IPHLPAPI.@)
833  *
834  * Get the best route for the given IP address.
835  *
836  * PARAMS
837  *  dwDestAddr   [In]  IP address to search the best route for
838  *  dwSourceAddr [In]  optional source IP address
839  *  pBestRoute   [Out] found best route
840  *
841  * RETURNS
842  *  Success: NO_ERROR
843  *  Failure: error code from winerror.h
844  */
845 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
846 {
847   PMIB_IPFORWARDTABLE table;
848   DWORD ret;
849
850   TRACE("dwDestAddr 0x%08x, dwSourceAddr 0x%08x, pBestRoute %p\n", dwDestAddr,
851    dwSourceAddr, pBestRoute);
852   if (!pBestRoute)
853     return ERROR_INVALID_PARAMETER;
854
855   ret = AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
856   if (!ret) {
857     DWORD ndx, matchedBits, matchedNdx = table->dwNumEntries;
858
859     for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
860       if (table->table[ndx].dwForwardType != MIB_IPROUTE_TYPE_INVALID &&
861        (dwDestAddr & table->table[ndx].dwForwardMask) ==
862        (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
863         DWORD numShifts, mask;
864
865         for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
866          mask && !(mask & 1); mask >>= 1, numShifts++)
867           ;
868         if (numShifts > matchedBits) {
869           matchedBits = numShifts;
870           matchedNdx = ndx;
871         }
872         else if (!matchedBits && table->table[ndx].dwForwardType ==
873          MIB_IPROUTE_TYPE_INDIRECT) {
874           /* default to a default gateway */
875           matchedNdx = ndx;
876         }
877       }
878     }
879     if (matchedNdx < table->dwNumEntries) {
880       memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
881       ret = ERROR_SUCCESS;
882     }
883     else {
884       /* No route matches, which can happen if there's no default route. */
885       ret = ERROR_HOST_UNREACHABLE;
886     }
887     HeapFree(GetProcessHeap(), 0, table);
888   }
889   TRACE("returning %d\n", ret);
890   return ret;
891 }
892
893
894 /******************************************************************
895  *    GetFriendlyIfIndex (IPHLPAPI.@)
896  *
897  * Get a "friendly" version of IfIndex, which is one that doesn't
898  * have the top byte set.  Doesn't validate whether IfIndex is a valid
899  * adapter index.
900  *
901  * PARAMS
902  *  IfIndex [In] interface index to get the friendly one for
903  *
904  * RETURNS
905  *  A friendly version of IfIndex.
906  */
907 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
908 {
909   /* windows doesn't validate these, either, just makes sure the top byte is
910      cleared.  I assume my ifenum module never gives an index with the top
911      byte set. */
912   TRACE("returning %d\n", IfIndex);
913   return IfIndex;
914 }
915
916
917 /******************************************************************
918  *    GetIcmpStatistics (IPHLPAPI.@)
919  *
920  * Get the ICMP statistics for the local computer.
921  *
922  * PARAMS
923  *  pStats [Out] buffer for ICMP statistics
924  *
925  * RETURNS
926  *  Success: NO_ERROR
927  *  Failure: error code from winerror.h
928  */
929 DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
930 {
931   DWORD ret;
932
933   TRACE("pStats %p\n", pStats);
934   ret = getICMPStats(pStats);
935   TRACE("returning %d\n", ret);
936   return ret;
937 }
938
939
940 /******************************************************************
941  *    GetIfEntry (IPHLPAPI.@)
942  *
943  * Get information about an interface.
944  *
945  * PARAMS
946  *  pIfRow [In/Out] In:  dwIndex of MIB_IFROW selects the interface.
947  *                  Out: interface information
948  *
949  * RETURNS
950  *  Success: NO_ERROR
951  *  Failure: error code from winerror.h
952  */
953 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
954 {
955   DWORD ret;
956   char nameBuf[MAX_ADAPTER_NAME];
957   char *name;
958
959   TRACE("pIfRow %p\n", pIfRow);
960   if (!pIfRow)
961     return ERROR_INVALID_PARAMETER;
962
963   name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf);
964   if (name) {
965     ret = getInterfaceEntryByName(name, pIfRow);
966     if (ret == NO_ERROR)
967       ret = getInterfaceStatsByName(name, pIfRow);
968   }
969   else
970     ret = ERROR_INVALID_DATA;
971   TRACE("returning %d\n", ret);
972   return ret;
973 }
974
975
976 static int IfTableSorter(const void *a, const void *b)
977 {
978   int ret;
979
980   if (a && b)
981     ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
982   else
983     ret = 0;
984   return ret;
985 }
986
987
988 /******************************************************************
989  *    GetIfTable (IPHLPAPI.@)
990  *
991  * Get a table of local interfaces.
992  *
993  * PARAMS
994  *  pIfTable [Out]    buffer for local interfaces table
995  *  pdwSize  [In/Out] length of output buffer
996  *  bOrder   [In]     whether to sort the table
997  *
998  * RETURNS
999  *  Success: NO_ERROR
1000  *  Failure: error code from winerror.h
1001  *
1002  * NOTES
1003  *  If pdwSize is less than required, the function will return
1004  *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1005  *  size.
1006  *  If bOrder is true, the returned table will be sorted by interface index.
1007  */
1008 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
1009 {
1010   DWORD ret;
1011
1012   TRACE("pIfTable %p, pdwSize %p, bOrder %d\n", pdwSize, pdwSize,
1013    (DWORD)bOrder);
1014   if (!pdwSize)
1015     ret = ERROR_INVALID_PARAMETER;
1016   else {
1017     DWORD numInterfaces = getNumInterfaces();
1018     ULONG size = sizeof(MIB_IFTABLE);
1019
1020     if (numInterfaces > 1)
1021       size += (numInterfaces - 1) * sizeof(MIB_IFROW);
1022     if (!pIfTable || *pdwSize < size) {
1023       *pdwSize = size;
1024       ret = ERROR_INSUFFICIENT_BUFFER;
1025     }
1026     else {
1027       InterfaceIndexTable *table = getInterfaceIndexTable();
1028
1029       if (table) {
1030         size = sizeof(MIB_IFTABLE);
1031         if (table->numIndexes > 1)
1032           size += (table->numIndexes - 1) * sizeof(MIB_IFROW);
1033         if (*pdwSize < size) {
1034           *pdwSize = size;
1035           ret = ERROR_INSUFFICIENT_BUFFER;
1036         }
1037         else {
1038           DWORD ndx;
1039
1040           *pdwSize = size;
1041           pIfTable->dwNumEntries = 0;
1042           for (ndx = 0; ndx < table->numIndexes; ndx++) {
1043             pIfTable->table[ndx].dwIndex = table->indexes[ndx];
1044             GetIfEntry(&pIfTable->table[ndx]);
1045             pIfTable->dwNumEntries++;
1046           }
1047           if (bOrder)
1048             qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
1049              IfTableSorter);
1050           ret = NO_ERROR;
1051         }
1052         HeapFree(GetProcessHeap(), 0, table);
1053       }
1054       else
1055         ret = ERROR_OUTOFMEMORY;
1056     }
1057   }
1058   TRACE("returning %d\n", ret);
1059   return ret;
1060 }
1061
1062
1063 /******************************************************************
1064  *    GetInterfaceInfo (IPHLPAPI.@)
1065  *
1066  * Get a list of network interface adapters.
1067  *
1068  * PARAMS
1069  *  pIfTable    [Out] buffer for interface adapters
1070  *  dwOutBufLen [Out] if buffer is too small, returns required size
1071  *
1072  * RETURNS
1073  *  Success: NO_ERROR
1074  *  Failure: error code from winerror.h
1075  *
1076  * BUGS
1077  *  MSDN states this should return non-loopback interfaces only.
1078  */
1079 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
1080 {
1081   DWORD ret;
1082
1083   TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1084   if (!dwOutBufLen)
1085     ret = ERROR_INVALID_PARAMETER;
1086   else {
1087     DWORD numInterfaces = getNumInterfaces();
1088     ULONG size = sizeof(IP_INTERFACE_INFO);
1089
1090     if (numInterfaces > 1)
1091       size += (numInterfaces - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
1092     if (!pIfTable || *dwOutBufLen < size) {
1093       *dwOutBufLen = size;
1094       ret = ERROR_INSUFFICIENT_BUFFER;
1095     }
1096     else {
1097       InterfaceIndexTable *table = getInterfaceIndexTable();
1098
1099       if (table) {
1100         size = sizeof(IP_INTERFACE_INFO);
1101         if (table->numIndexes > 1)
1102           size += (table->numIndexes - 1) * sizeof(IP_ADAPTER_INDEX_MAP);
1103         if (*dwOutBufLen < size) {
1104           *dwOutBufLen = size;
1105           ret = ERROR_INSUFFICIENT_BUFFER;
1106         }
1107         else {
1108           DWORD ndx;
1109           char nameBuf[MAX_ADAPTER_NAME];
1110
1111           *dwOutBufLen = size;
1112           pIfTable->NumAdapters = 0;
1113           for (ndx = 0; ndx < table->numIndexes; ndx++) {
1114             const char *walker, *name;
1115             WCHAR *assigner;
1116
1117             pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1118             name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
1119             for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
1120              walker && *walker &&
1121              assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
1122              walker++, assigner++)
1123               *assigner = *walker;
1124             *assigner = 0;
1125             pIfTable->NumAdapters++;
1126           }
1127           ret = NO_ERROR;
1128         }
1129         HeapFree(GetProcessHeap(), 0, table);
1130       }
1131       else
1132         ret = ERROR_OUTOFMEMORY;
1133     }
1134   }
1135   TRACE("returning %d\n", ret);
1136   return ret;
1137 }
1138
1139
1140 /******************************************************************
1141  *    GetIpAddrTable (IPHLPAPI.@)
1142  *
1143  * Get interface-to-IP address mapping table. 
1144  *
1145  * PARAMS
1146  *  pIpAddrTable [Out]    buffer for mapping table
1147  *  pdwSize      [In/Out] length of output buffer
1148  *  bOrder       [In]     whether to sort the table
1149  *
1150  * RETURNS
1151  *  Success: NO_ERROR
1152  *  Failure: error code from winerror.h
1153  *
1154  * NOTES
1155  *  If pdwSize is less than required, the function will return
1156  *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1157  *  size.
1158  *  If bOrder is true, the returned table will be sorted by the next hop and
1159  *  an assortment of arbitrary parameters.
1160  */
1161 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1162 {
1163   DWORD ret;
1164
1165   TRACE("pIpAddrTable %p, pdwSize %p, bOrder %d\n", pIpAddrTable, pdwSize,
1166    (DWORD)bOrder);
1167   if (!pdwSize)
1168     ret = ERROR_INVALID_PARAMETER;
1169   else {
1170     PMIB_IPADDRTABLE table;
1171
1172     ret = getIPAddrTable(&table, GetProcessHeap(), 0);
1173     if (ret == NO_ERROR)
1174     {
1175       ULONG size = sizeof(MIB_IPADDRTABLE);
1176
1177       if (table->dwNumEntries > 1)
1178         size += (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW);
1179       if (!pIpAddrTable || *pdwSize < size) {
1180         *pdwSize = size;
1181         ret = ERROR_INSUFFICIENT_BUFFER;
1182       }
1183       else {
1184         *pdwSize = size;
1185         memcpy(pIpAddrTable, table, size);
1186         if (bOrder)
1187           qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1188            sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1189         ret = NO_ERROR;
1190       }
1191       HeapFree(GetProcessHeap(), 0, table);
1192     }
1193   }
1194   TRACE("returning %d\n", ret);
1195   return ret;
1196 }
1197
1198
1199 /******************************************************************
1200  *    GetIpForwardTable (IPHLPAPI.@)
1201  *
1202  * Get the route table.
1203  *
1204  * PARAMS
1205  *  pIpForwardTable [Out]    buffer for route table
1206  *  pdwSize         [In/Out] length of output buffer
1207  *  bOrder          [In]     whether to sort the table
1208  *
1209  * RETURNS
1210  *  Success: NO_ERROR
1211  *  Failure: error code from winerror.h
1212  *
1213  * NOTES
1214  *  If pdwSize is less than required, the function will return
1215  *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1216  *  size.
1217  *  If bOrder is true, the returned table will be sorted by the next hop and
1218  *  an assortment of arbitrary parameters.
1219  */
1220 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1221 {
1222   DWORD ret;
1223
1224   TRACE("pIpForwardTable %p, pdwSize %p, bOrder %d\n", pIpForwardTable,
1225    pdwSize, (DWORD)bOrder);
1226   if (!pdwSize)
1227     ret = ERROR_INVALID_PARAMETER;
1228   else {
1229     DWORD numRoutes = getNumRoutes();
1230     ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE);
1231
1232     if (numRoutes > 1)
1233       sizeNeeded += (numRoutes - 1) * sizeof(MIB_IPFORWARDROW);
1234     if (!pIpForwardTable || *pdwSize < sizeNeeded) {
1235       *pdwSize = sizeNeeded;
1236       ret = ERROR_INSUFFICIENT_BUFFER;
1237     }
1238     else {
1239       PMIB_IPFORWARDTABLE table;
1240
1241       ret = getRouteTable(&table, GetProcessHeap(), 0);
1242       if (!ret) {
1243         sizeNeeded = sizeof(MIB_IPFORWARDTABLE);
1244         if (table->dwNumEntries > 1)
1245           sizeNeeded += (table->dwNumEntries - 1) * sizeof(MIB_IPFORWARDROW);
1246         if (*pdwSize < sizeNeeded) {
1247           *pdwSize = sizeNeeded;
1248           ret = ERROR_INSUFFICIENT_BUFFER;
1249         }
1250         else {
1251           *pdwSize = sizeNeeded;
1252           memcpy(pIpForwardTable, table, sizeNeeded);
1253           if (bOrder)
1254             qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
1255              sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1256           ret = NO_ERROR;
1257         }
1258         HeapFree(GetProcessHeap(), 0, table);
1259       }
1260     }
1261   }
1262   TRACE("returning %d\n", ret);
1263   return ret;
1264 }
1265
1266
1267 /******************************************************************
1268  *    GetIpNetTable (IPHLPAPI.@)
1269  *
1270  * Get the IP-to-physical address mapping table.
1271  *
1272  * PARAMS
1273  *  pIpNetTable [Out]    buffer for mapping table
1274  *  pdwSize     [In/Out] length of output buffer
1275  *  bOrder      [In]     whether to sort the table
1276  *
1277  * RETURNS
1278  *  Success: NO_ERROR
1279  *  Failure: error code from winerror.h
1280  *
1281  * NOTES
1282  *  If pdwSize is less than required, the function will return
1283  *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
1284  *  size.
1285  *  If bOrder is true, the returned table will be sorted by IP address.
1286  */
1287 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1288 {
1289   DWORD ret;
1290
1291   TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable, pdwSize,
1292    (DWORD)bOrder);
1293   if (!pdwSize)
1294     ret = ERROR_INVALID_PARAMETER;
1295   else {
1296     DWORD numEntries = getNumArpEntries();
1297     ULONG size = sizeof(MIB_IPNETTABLE);
1298
1299     if (numEntries > 1)
1300       size += (numEntries - 1) * sizeof(MIB_IPNETROW);
1301     if (!pIpNetTable || *pdwSize < size) {
1302       *pdwSize = size;
1303       ret = ERROR_INSUFFICIENT_BUFFER;
1304     }
1305     else {
1306       PMIB_IPNETTABLE table;
1307
1308       ret = getArpTable(&table, GetProcessHeap(), 0);
1309       if (!ret) {
1310         size = sizeof(MIB_IPNETTABLE);
1311         if (table->dwNumEntries > 1)
1312           size += (table->dwNumEntries - 1) * sizeof(MIB_IPNETROW);
1313         if (*pdwSize < size) {
1314           *pdwSize = size;
1315           ret = ERROR_INSUFFICIENT_BUFFER;
1316         }
1317         else {
1318           *pdwSize = size;
1319           memcpy(pIpNetTable, table, size);
1320           if (bOrder)
1321             qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
1322              sizeof(MIB_IPNETROW), IpNetTableSorter);
1323           ret = NO_ERROR;
1324         }
1325         HeapFree(GetProcessHeap(), 0, table);
1326       }
1327     }
1328   }
1329   TRACE("returning %d\n", ret);
1330   return ret;
1331 }
1332
1333
1334 /******************************************************************
1335  *    GetIpStatistics (IPHLPAPI.@)
1336  *
1337  * Get the IP statistics for the local computer.
1338  *
1339  * PARAMS
1340  *  pStats [Out] buffer for IP statistics
1341  *
1342  * RETURNS
1343  *  Success: NO_ERROR
1344  *  Failure: error code from winerror.h
1345  */
1346 DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
1347 {
1348   DWORD ret;
1349
1350   TRACE("pStats %p\n", pStats);
1351   ret = getIPStats(pStats);
1352   TRACE("returning %d\n", ret);
1353   return ret;
1354 }
1355
1356
1357 /******************************************************************
1358  *    GetNetworkParams (IPHLPAPI.@)
1359  *
1360  * Get the network parameters for the local computer.
1361  *
1362  * PARAMS
1363  *  pFixedInfo [Out]    buffer for network parameters
1364  *  pOutBufLen [In/Out] length of output buffer
1365  *
1366  * RETURNS
1367  *  Success: NO_ERROR
1368  *  Failure: error code from winerror.h
1369  *
1370  * NOTES
1371  *  If pOutBufLen is less than required, the function will return
1372  *  ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
1373  *  size.
1374  */
1375 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1376 {
1377   DWORD ret, size;
1378   LONG regReturn;
1379   HKEY hKey;
1380
1381   TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1382   if (!pOutBufLen)
1383     return ERROR_INVALID_PARAMETER;
1384
1385   initialise_resolver();
1386   size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount  - 1) *
1387    sizeof(IP_ADDR_STRING) : 0);
1388   if (!pFixedInfo || *pOutBufLen < size) {
1389     *pOutBufLen = size;
1390     return ERROR_BUFFER_OVERFLOW;
1391   }
1392
1393   memset(pFixedInfo, 0, size);
1394   size = sizeof(pFixedInfo->HostName);
1395   GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
1396   size = sizeof(pFixedInfo->DomainName);
1397   GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
1398   if (_res.nscount > 0) {
1399     PIP_ADDR_STRING ptr;
1400     int i;
1401
1402     for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1403      i++, ptr = ptr->Next) {
1404       toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
1405        ptr->IpAddress.String);
1406       if (i == _res.nscount - 1)
1407         ptr->Next = NULL;
1408       else if (i == 0)
1409         ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
1410       else
1411         ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1412     }
1413   }
1414   pFixedInfo->NodeType = HYBRID_NODETYPE;
1415   regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1416    "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
1417   if (regReturn != ERROR_SUCCESS)
1418     regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1419      "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
1420      &hKey);
1421   if (regReturn == ERROR_SUCCESS)
1422   {
1423     DWORD size = sizeof(pFixedInfo->ScopeId);
1424
1425     RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1426     RegCloseKey(hKey);
1427   }
1428
1429   /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1430      I suppose could also check for a listener on port 53 to set EnableDns */
1431   ret = NO_ERROR;
1432   TRACE("returning %d\n", ret);
1433   return ret;
1434 }
1435
1436
1437 /******************************************************************
1438  *    GetNumberOfInterfaces (IPHLPAPI.@)
1439  *
1440  * Get the number of interfaces.
1441  *
1442  * PARAMS
1443  *  pdwNumIf [Out] number of interfaces
1444  *
1445  * RETURNS
1446  *  NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1447  */
1448 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
1449 {
1450   DWORD ret;
1451
1452   TRACE("pdwNumIf %p\n", pdwNumIf);
1453   if (!pdwNumIf)
1454     ret = ERROR_INVALID_PARAMETER;
1455   else {
1456     *pdwNumIf = getNumInterfaces();
1457     ret = NO_ERROR;
1458   }
1459   TRACE("returning %d\n", ret);
1460   return ret;
1461 }
1462
1463
1464 /******************************************************************
1465  *    GetPerAdapterInfo (IPHLPAPI.@)
1466  *
1467  * Get information about an adapter corresponding to an interface.
1468  *
1469  * PARAMS
1470  *  IfIndex         [In]     interface info
1471  *  pPerAdapterInfo [Out]    buffer for per adapter info
1472  *  pOutBufLen      [In/Out] length of output buffer
1473  *
1474  * RETURNS
1475  *  Success: NO_ERROR
1476  *  Failure: error code from winerror.h
1477  *
1478  * FIXME
1479  *  Stub, returns empty IP_PER_ADAPTER_INFO in every case.
1480  */
1481 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
1482 {
1483   ULONG bytesNeeded = sizeof(IP_PER_ADAPTER_INFO);
1484   DWORD ret;
1485
1486   TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex,
1487    pPerAdapterInfo, pOutBufLen);
1488   if (!pOutBufLen)
1489     ret = ERROR_INVALID_PARAMETER;
1490   else if (!pPerAdapterInfo)
1491   {
1492     *pOutBufLen = bytesNeeded;
1493     ret = NO_ERROR;
1494   }
1495   else if (*pOutBufLen < bytesNeeded)
1496   {
1497     *pOutBufLen = bytesNeeded;
1498     ret = ERROR_BUFFER_OVERFLOW;
1499   }
1500   else
1501   {
1502     memset(pPerAdapterInfo, 0, bytesNeeded);
1503     ret = NO_ERROR;
1504   }
1505   return ret;
1506 }
1507
1508
1509 /******************************************************************
1510  *    GetRTTAndHopCount (IPHLPAPI.@)
1511  *
1512  * Get round-trip time (RTT) and hop count.
1513  *
1514  * PARAMS
1515  *
1516  *  DestIpAddress [In]  destination address to get the info for
1517  *  HopCount      [Out] retrieved hop count
1518  *  MaxHops       [In]  maximum hops to search for the destination
1519  *  RTT           [Out] RTT in milliseconds
1520  *
1521  * RETURNS
1522  *  Success: TRUE
1523  *  Failure: FALSE
1524  *
1525  * FIXME
1526  *  Stub, returns FALSE.
1527  */
1528 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
1529 {
1530   FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %d, RTT %p): stub\n",
1531    DestIpAddress, HopCount, MaxHops, RTT);
1532   return FALSE;
1533 }
1534
1535
1536 /******************************************************************
1537  *    GetTcpStatistics (IPHLPAPI.@)
1538  *
1539  * Get the TCP statistics for the local computer.
1540  *
1541  * PARAMS
1542  *  pStats [Out] buffer for TCP statistics
1543  *
1544  * RETURNS
1545  *  Success: NO_ERROR
1546  *  Failure: error code from winerror.h
1547  */
1548 DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
1549 {
1550   DWORD ret;
1551
1552   TRACE("pStats %p\n", pStats);
1553   ret = getTCPStats(pStats);
1554   TRACE("returning %d\n", ret);
1555   return ret;
1556 }
1557
1558
1559 /******************************************************************
1560  *    GetTcpTable (IPHLPAPI.@)
1561  *
1562  * Get the table of active TCP connections.
1563  *
1564  * PARAMS
1565  *  pTcpTable [Out]    buffer for TCP connections table
1566  *  pdwSize   [In/Out] length of output buffer
1567  *  bOrder    [In]     whether to order the table
1568  *
1569  * RETURNS
1570  *  Success: NO_ERROR
1571  *  Failure: error code from winerror.h
1572  *
1573  * NOTES
1574  *  If pdwSize is less than required, the function will return 
1575  *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to 
1576  *  the required byte size.
1577  *  If bOrder is true, the returned table will be sorted, first by
1578  *  local address and port number, then by remote address and port
1579  *  number.
1580  */
1581 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
1582 {
1583   DWORD ret;
1584
1585   TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize,
1586    (DWORD)bOrder);
1587   if (!pdwSize)
1588     ret = ERROR_INVALID_PARAMETER;
1589   else {
1590     DWORD numEntries = getNumTcpEntries();
1591     DWORD size = sizeof(MIB_TCPTABLE);
1592
1593     if (numEntries > 1)
1594       size += (numEntries - 1) * sizeof(MIB_TCPROW);
1595     if (!pTcpTable || *pdwSize < size) {
1596       *pdwSize = size;
1597       ret = ERROR_INSUFFICIENT_BUFFER;
1598     }
1599     else {
1600       ret = getTcpTable(&pTcpTable, numEntries, 0, 0);
1601       if (!ret) {
1602         size = sizeof(MIB_TCPTABLE);
1603         if (pTcpTable->dwNumEntries > 1)
1604           size += (pTcpTable->dwNumEntries - 1) * sizeof(MIB_TCPROW);
1605         *pdwSize = size;
1606
1607         if (bOrder)
1608            qsort(pTcpTable->table, pTcpTable->dwNumEntries,
1609                  sizeof(MIB_TCPROW), TcpTableSorter);
1610         ret = NO_ERROR;
1611       }
1612     }
1613   }
1614   TRACE("returning %d\n", ret);
1615   return ret;
1616 }
1617
1618
1619 /******************************************************************
1620  *    GetUdpStatistics (IPHLPAPI.@)
1621  *
1622  * Get the UDP statistics for the local computer.
1623  *
1624  * PARAMS
1625  *  pStats [Out] buffer for UDP statistics
1626  *
1627  * RETURNS
1628  *  Success: NO_ERROR
1629  *  Failure: error code from winerror.h
1630  */
1631 DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
1632 {
1633   DWORD ret;
1634
1635   TRACE("pStats %p\n", pStats);
1636   ret = getUDPStats(pStats);
1637   TRACE("returning %d\n", ret);
1638   return ret;
1639 }
1640
1641
1642 /******************************************************************
1643  *    GetUdpTable (IPHLPAPI.@)
1644  *
1645  * Get a table of active UDP connections.
1646  *
1647  * PARAMS
1648  *  pUdpTable [Out]    buffer for UDP connections table
1649  *  pdwSize   [In/Out] length of output buffer
1650  *  bOrder    [In]     whether to order the table
1651  *
1652  * RETURNS
1653  *  Success: NO_ERROR
1654  *  Failure: error code from winerror.h
1655  *
1656  * NOTES
1657  *  If pdwSize is less than required, the function will return 
1658  *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
1659  *  required byte size.
1660  *  If bOrder is true, the returned table will be sorted, first by
1661  *  local address, then by local port number.
1662  */
1663 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
1664 {
1665   DWORD ret;
1666
1667   TRACE("pUdpTable %p, pdwSize %p, bOrder %d\n", pUdpTable, pdwSize,
1668    (DWORD)bOrder);
1669   if (!pdwSize)
1670     ret = ERROR_INVALID_PARAMETER;
1671   else {
1672     DWORD numEntries = getNumUdpEntries();
1673     DWORD size = sizeof(MIB_UDPTABLE);
1674
1675     if (numEntries > 1)
1676       size += (numEntries - 1) * sizeof(MIB_UDPROW);
1677     if (!pUdpTable || *pdwSize < size) {
1678       *pdwSize = size;
1679       ret = ERROR_INSUFFICIENT_BUFFER;
1680     }
1681     else {
1682       PMIB_UDPTABLE table;
1683
1684       ret = getUdpTable(&table, GetProcessHeap(), 0);
1685       if (!ret) {
1686         size = sizeof(MIB_UDPTABLE);
1687         if (table->dwNumEntries > 1)
1688           size += (table->dwNumEntries - 1) * sizeof(MIB_UDPROW);
1689         if (*pdwSize < size) {
1690           *pdwSize = size;
1691           ret = ERROR_INSUFFICIENT_BUFFER;
1692         }
1693         else {
1694           *pdwSize = size;
1695           memcpy(pUdpTable, table, size);
1696           if (bOrder)
1697             qsort(pUdpTable->table, pUdpTable->dwNumEntries,
1698              sizeof(MIB_UDPROW), UdpTableSorter);
1699           ret = NO_ERROR;
1700         }
1701         HeapFree(GetProcessHeap(), 0, table);
1702       }
1703       else
1704         ret = ERROR_OUTOFMEMORY;
1705     }
1706   }
1707   TRACE("returning %d\n", ret);
1708   return ret;
1709 }
1710
1711
1712 /******************************************************************
1713  *    GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1714  *
1715  * This is a Win98-only function to get information on "unidirectional"
1716  * adapters.  Since this is pretty nonsensical in other contexts, it
1717  * never returns anything.
1718  *
1719  * PARAMS
1720  *  pIPIfInfo   [Out] buffer for adapter infos
1721  *  dwOutBufLen [Out] length of the output buffer
1722  *
1723  * RETURNS
1724  *  Success: NO_ERROR
1725  *  Failure: error code from winerror.h
1726  *
1727  * FIXME
1728  *  Stub, returns ERROR_NOT_SUPPORTED.
1729  */
1730 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
1731 {
1732   TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1733   /* a unidirectional adapter?? not bloody likely! */
1734   return ERROR_NOT_SUPPORTED;
1735 }
1736
1737
1738 /******************************************************************
1739  *    IpReleaseAddress (IPHLPAPI.@)
1740  *
1741  * Release an IP optained through DHCP,
1742  *
1743  * PARAMS
1744  *  AdapterInfo [In] adapter to release IP address
1745  *
1746  * RETURNS
1747  *  Success: NO_ERROR
1748  *  Failure: error code from winerror.h
1749  *
1750  * NOTES
1751  *  Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1752  *  this function does nothing.
1753  *
1754  * FIXME
1755  *  Stub, returns ERROR_NOT_SUPPORTED.
1756  */
1757 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1758 {
1759   TRACE("AdapterInfo %p\n", AdapterInfo);
1760   /* not a stub, never going to support this (and I never mark an adapter as
1761      DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1762   return ERROR_NOT_SUPPORTED;
1763 }
1764
1765
1766 /******************************************************************
1767  *    IpRenewAddress (IPHLPAPI.@)
1768  *
1769  * Renew an IP optained through DHCP.
1770  *
1771  * PARAMS
1772  *  AdapterInfo [In] adapter to renew IP address
1773  *
1774  * RETURNS
1775  *  Success: NO_ERROR
1776  *  Failure: error code from winerror.h
1777  *
1778  * NOTES
1779  *  Since GetAdaptersInfo never returns adapters that have DHCP enabled,
1780  *  this function does nothing.
1781  *
1782  * FIXME
1783  *  Stub, returns ERROR_NOT_SUPPORTED.
1784  */
1785 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
1786 {
1787   TRACE("AdapterInfo %p\n", AdapterInfo);
1788   /* not a stub, never going to support this (and I never mark an adapter as
1789      DHCP enabled, see GetAdaptersInfo, so this should never get called) */
1790   return ERROR_NOT_SUPPORTED;
1791 }
1792
1793
1794 /******************************************************************
1795  *    NotifyAddrChange (IPHLPAPI.@)
1796  *
1797  * Notify caller whenever the ip-interface map is changed.
1798  *
1799  * PARAMS
1800  *  Handle     [Out] handle useable in asynchronus notification
1801  *  overlapped [In]  overlapped structure that notifies the caller
1802  *
1803  * RETURNS
1804  *  Success: NO_ERROR
1805  *  Failure: error code from winerror.h
1806  *
1807  * FIXME
1808  *  Stub, returns ERROR_NOT_SUPPORTED.
1809  */
1810 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1811 {
1812   FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1813   return ERROR_NOT_SUPPORTED;
1814 }
1815
1816
1817 /******************************************************************
1818  *    NotifyRouteChange (IPHLPAPI.@)
1819  *
1820  * Notify caller whenever the ip routing table is changed.
1821  *
1822  * PARAMS
1823  *  Handle     [Out] handle useable in asynchronus notification
1824  *  overlapped [In]  overlapped structure that notifies the caller
1825  *
1826  * RETURNS
1827  *  Success: NO_ERROR
1828  *  Failure: error code from winerror.h
1829  *
1830  * FIXME
1831  *  Stub, returns ERROR_NOT_SUPPORTED.
1832  */
1833 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
1834 {
1835   FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1836   return ERROR_NOT_SUPPORTED;
1837 }
1838
1839
1840 /******************************************************************
1841  *    SendARP (IPHLPAPI.@)
1842  *
1843  * Send an ARP request.
1844  *
1845  * PARAMS
1846  *  DestIP     [In]     attempt to obtain this IP
1847  *  SrcIP      [In]     optional sender IP address
1848  *  pMacAddr   [Out]    buffer for the mac address
1849  *  PhyAddrLen [In/Out] length of the output buffer
1850  *
1851  * RETURNS
1852  *  Success: NO_ERROR
1853  *  Failure: error code from winerror.h
1854  *
1855  * FIXME
1856  *  Stub, returns ERROR_NOT_SUPPORTED.
1857  */
1858 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
1859 {
1860   FIXME("(DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p): stub\n",
1861    DestIP, SrcIP, pMacAddr, PhyAddrLen);
1862   return ERROR_NOT_SUPPORTED;
1863 }
1864
1865
1866 /******************************************************************
1867  *    SetIfEntry (IPHLPAPI.@)
1868  *
1869  * Set the administrative status of an interface.
1870  *
1871  * PARAMS
1872  *  pIfRow [In] dwAdminStatus member specifies the new status.
1873  *
1874  * RETURNS
1875  *  Success: NO_ERROR
1876  *  Failure: error code from winerror.h
1877  *
1878  * FIXME
1879  *  Stub, returns ERROR_NOT_SUPPORTED.
1880  */
1881 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
1882 {
1883   FIXME("(pIfRow %p): stub\n", pIfRow);
1884   /* this is supposed to set an interface administratively up or down.
1885      Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
1886      this sort of down is indistinguishable from other sorts of down (e.g. no
1887      link). */
1888   return ERROR_NOT_SUPPORTED;
1889 }
1890
1891
1892 /******************************************************************
1893  *    SetIpForwardEntry (IPHLPAPI.@)
1894  *
1895  * Modify an existing route.
1896  *
1897  * PARAMS
1898  *  pRoute [In] route with the new information
1899  *
1900  * RETURNS
1901  *  Success: NO_ERROR
1902  *  Failure: error code from winerror.h
1903  *
1904  * FIXME
1905  *  Stub, returns NO_ERROR.
1906  */
1907 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
1908 {
1909   FIXME("(pRoute %p): stub\n", pRoute);
1910   /* this is to add a route entry, how's it distinguishable from
1911      CreateIpForwardEntry?
1912      could use SIOCADDRT, not sure I want to */
1913   return (DWORD) 0;
1914 }
1915
1916
1917 /******************************************************************
1918  *    SetIpNetEntry (IPHLPAPI.@)
1919  *
1920  * Modify an existing ARP entry.
1921  *
1922  * PARAMS
1923  *  pArpEntry [In] ARP entry with the new information
1924  *
1925  * RETURNS
1926  *  Success: NO_ERROR
1927  *  Failure: error code from winerror.h
1928  *
1929  * FIXME
1930  *  Stub, returns NO_ERROR.
1931  */
1932 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
1933 {
1934   FIXME("(pArpEntry %p): stub\n", pArpEntry);
1935   /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
1936   return (DWORD) 0;
1937 }
1938
1939
1940 /******************************************************************
1941  *    SetIpStatistics (IPHLPAPI.@)
1942  *
1943  * Toggle IP forwarding and det the default TTL value.
1944  *
1945  * PARAMS
1946  *  pIpStats [In] IP statistics with the new information
1947  *
1948  * RETURNS
1949  *  Success: NO_ERROR
1950  *  Failure: error code from winerror.h
1951  *
1952  * FIXME
1953  *  Stub, returns NO_ERROR.
1954  */
1955 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
1956 {
1957   FIXME("(pIpStats %p): stub\n", pIpStats);
1958   return (DWORD) 0;
1959 }
1960
1961
1962 /******************************************************************
1963  *    SetIpTTL (IPHLPAPI.@)
1964  *
1965  * Set the default TTL value.
1966  *
1967  * PARAMS
1968  *  nTTL [In] new TTL value
1969  *
1970  * RETURNS
1971  *  Success: NO_ERROR
1972  *  Failure: error code from winerror.h
1973  *
1974  * FIXME
1975  *  Stub, returns NO_ERROR.
1976  */
1977 DWORD WINAPI SetIpTTL(UINT nTTL)
1978 {
1979   FIXME("(nTTL %d): stub\n", nTTL);
1980   /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
1981      want to.  Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
1982   return (DWORD) 0;
1983 }
1984
1985
1986 /******************************************************************
1987  *    SetTcpEntry (IPHLPAPI.@)
1988  *
1989  * Set the state of a TCP connection.
1990  *
1991  * PARAMS
1992  *  pTcpRow [In] specifies connection with new state
1993  *
1994  * RETURNS
1995  *  Success: NO_ERROR
1996  *  Failure: error code from winerror.h
1997  *
1998  * FIXME
1999  *  Stub, returns NO_ERROR.
2000  */
2001 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
2002 {
2003   FIXME("(pTcpRow %p): stub\n", pTcpRow);
2004   return (DWORD) 0;
2005 }
2006
2007
2008 /******************************************************************
2009  *    UnenableRouter (IPHLPAPI.@)
2010  *
2011  * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2012  * if it reaches zero.
2013  *
2014  * PARAMS
2015  *  pOverlapped     [In/Out] should be the same as in EnableRouter()
2016  *  lpdwEnableCount [Out]    optional, receives reference count
2017  *
2018  * RETURNS
2019  *  Success: NO_ERROR
2020  *  Failure: error code from winerror.h
2021  *
2022  * FIXME
2023  *  Stub, returns ERROR_NOT_SUPPORTED.
2024  */
2025 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
2026 {
2027   FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
2028    lpdwEnableCount);
2029   /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
2030      could map EACCESS to ERROR_ACCESS_DENIED, I suppose
2031    */
2032   return ERROR_NOT_SUPPORTED;
2033 }