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