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