iphlpapi_main.c 53.5 KB
Newer Older
1 2 3
/*
 * iphlpapi dll implementation
 *
4
 * Copyright (C) 2003,2006 Juan Lang
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 22
 */

#include "config.h"

23
#include <stdarg.h>
24
#include <stdlib.h>
25
#include <sys/types.h>
26
#ifdef HAVE_NETINET_IN_H
27
# include <netinet/in.h>
28
#endif
29 30 31
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
32
#ifdef HAVE_ARPA_NAMESER_H
33
# include <arpa/nameser.h>
34
#endif
35 36 37 38
#ifdef HAVE_RESOLV_H
# include <resolv.h>
#endif

39
#include "windef.h"
40
#include "winbase.h"
41
#include "winreg.h"
42 43 44 45 46 47 48
#include "iphlpapi.h"
#include "ifenum.h"
#include "ipstats.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);

49 50 51 52
#ifndef INADDR_NONE
#define INADDR_NONE ~0UL
#endif

Juan Lang's avatar
Juan Lang committed
53 54 55 56 57 58 59 60 61 62 63 64
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
  switch (fdwReason) {
    case DLL_PROCESS_ATTACH:
      DisableThreadLibraryCalls( hinstDLL );
      break;

    case DLL_PROCESS_DETACH:
      break;
  }
  return TRUE;
}
65 66 67 68

/******************************************************************
 *    AddIPAddress (IPHLPAPI.@)
 *
69
 * Add an IP address to an adapter.
70 71
 *
 * PARAMS
72 73 74 75 76
 *  Address     [In]  IP address to add to the adapter
 *  IpMask      [In]  subnet mask for the IP address
 *  IfIndex     [In]  adapter index to add the address
 *  NTEContext  [Out] Net Table Entry (NTE) context for the IP address
 *  NTEInstance [Out] NTE instance for the IP address
77 78
 *
 * RETURNS
79 80
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
81
 *
82 83
 * FIXME
 *  Stub. Currently returns ERROR_NOT_SUPPORTED.
84 85 86 87 88 89 90 91
 */
DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
{
  FIXME(":stub\n");
  return ERROR_NOT_SUPPORTED;
}


92 93 94
/******************************************************************
 *    AllocateAndGetIfTableFromStack (IPHLPAPI.@)
 *
95 96
 * Get table of local interfaces.
 * Like GetIfTable(), but allocate the returned table from heap.
97 98
 *
 * PARAMS
99 100
 *  ppIfTable [Out] pointer into which the MIB_IFTABLE is
 *                  allocated and returned.
101
 *  bOrder    [In]  whether to sort the table
102 103
 *  heap      [In]  heap from which the table is allocated
 *  flags     [In]  flags to HeapAlloc
104
 *
105 106 107
 * RETURNS
 *  ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
 *  GetIfTable() returns otherwise.
108 109 110 111 112 113
 */
DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
 BOOL bOrder, HANDLE heap, DWORD flags)
{
  DWORD ret;

114 115
  TRACE("ppIfTable %p, bOrder %d, heap %p, flags 0x%08lx\n", ppIfTable,
        bOrder, heap, flags);
116 117 118 119 120 121 122
  if (!ppIfTable)
    ret = ERROR_INVALID_PARAMETER;
  else {
    DWORD dwSize = 0;

    ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
    if (ret == ERROR_INSUFFICIENT_BUFFER) {
123
      *ppIfTable = HeapAlloc(heap, flags, dwSize);
124 125 126
      ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
    }
  }
127
  TRACE("returning %ld\n", ret);
128 129 130 131
  return ret;
}


132 133 134 135 136 137 138 139 140 141 142 143
static int IpAddrTableSorter(const void *a, const void *b)
{
  int ret;

  if (a && b)
    ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
  else
    ret = 0;
  return ret;
}


144 145 146
/******************************************************************
 *    AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
 *
147 148
 * Get interface-to-IP address mapping table. 
 * Like GetIpAddrTable(), but allocate the returned table from heap.
149 150
 *
 * PARAMS
151 152
 *  ppIpAddrTable [Out] pointer into which the MIB_IPADDRTABLE is
 *                      allocated and returned.
153
 *  bOrder        [In]  whether to sort the table
154 155
 *  heap          [In]  heap from which the table is allocated
 *  flags         [In]  flags to HeapAlloc
156 157
 *
 * RETURNS
158 159
 *  ERROR_INVALID_PARAMETER if ppIpAddrTable is NULL, other error codes on
 *  failure, NO_ERROR on success.
160 161 162 163 164 165
 */
DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
 BOOL bOrder, HANDLE heap, DWORD flags)
{
  DWORD ret;

166 167
  TRACE("ppIpAddrTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
   ppIpAddrTable, bOrder, heap, flags);
168 169 170 171 172 173 174
  ret = getIPAddrTable(ppIpAddrTable, heap, flags);
  if (!ret && bOrder)
    qsort((*ppIpAddrTable)->table, (*ppIpAddrTable)->dwNumEntries,
     sizeof(MIB_IPADDRROW), IpAddrTableSorter);
  TRACE("returning %ld\n", ret);
  return ret;
}
175

176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

static int IpForwardTableSorter(const void *a, const void *b)
{
  int ret;

  if (a && b) {
   const MIB_IPFORWARDROW* rowA = (const MIB_IPFORWARDROW*)a;
   const MIB_IPFORWARDROW* rowB = (const MIB_IPFORWARDROW*)b;

    ret = rowA->dwForwardDest - rowB->dwForwardDest;
    if (ret == 0) {
      ret = rowA->dwForwardProto - rowB->dwForwardProto;
      if (ret == 0) {
        ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy;
        if (ret == 0)
          ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop;
      }
193 194
    }
  }
195 196
  else
    ret = 0;
197 198 199 200 201 202 203
  return ret;
}


/******************************************************************
 *    AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
 *
204 205
 * Get the route table.
 * Like GetIpForwardTable(), but allocate the returned table from heap.
206 207
 *
 * PARAMS
208 209
 *  ppIpForwardTable [Out] pointer into which the MIB_IPFORWARDTABLE is
 *                         allocated and returned.
210
 *  bOrder           [In]  whether to sort the table
211 212
 *  heap             [In]  heap from which the table is allocated
 *  flags            [In]  flags to HeapAlloc
213
 *
214
 * RETURNS
215 216
 *  ERROR_INVALID_PARAMETER if ppIfTable is NULL, other error codes
 *  on failure, NO_ERROR on success.
217 218 219 220 221 222
 */
DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
 ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags)
{
  DWORD ret;

223 224
  TRACE("ppIpForwardTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
   ppIpForwardTable, bOrder, heap, flags);
225 226 227 228
  ret = getRouteTable(ppIpForwardTable, heap, flags);
  if (!ret && bOrder)
    qsort((*ppIpForwardTable)->table, (*ppIpForwardTable)->dwNumEntries,
     sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
229
  TRACE("returning %ld\n", ret);
230 231 232 233
  return ret;
}


234 235 236 237 238 239 240 241 242 243 244 245
static int IpNetTableSorter(const void *a, const void *b)
{
  int ret;

  if (a && b)
    ret = ((const MIB_IPNETROW*)a)->dwAddr - ((const MIB_IPNETROW*)b)->dwAddr;
  else
    ret = 0;
  return ret;
}


246 247 248
/******************************************************************
 *    AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
 *
249 250
 * Get the IP-to-physical address mapping table.
 * Like GetIpNetTable(), but allocate the returned table from heap.
251 252
 *
 * PARAMS
253 254
 *  ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE is
 *                     allocated and returned.
255
 *  bOrder       [In]  whether to sort the table
256 257
 *  heap         [In]  heap from which the table is allocated
 *  flags        [In]  flags to HeapAlloc
258 259
 *
 * RETURNS
260 261
 *  ERROR_INVALID_PARAMETER if ppIpNetTable is NULL, other error codes
 *  on failure, NO_ERROR on success.
262 263 264 265 266 267
 */
DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable,
 BOOL bOrder, HANDLE heap, DWORD flags)
{
  DWORD ret;

268 269
  TRACE("ppIpNetTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
   ppIpNetTable, bOrder, heap, flags);
270 271 272 273 274 275 276
  ret = getArpTable(ppIpNetTable, heap, flags);
  if (!ret && bOrder)
    qsort((*ppIpNetTable)->table, (*ppIpNetTable)->dwNumEntries,
     sizeof(MIB_IPADDRROW), IpNetTableSorter);
  TRACE("returning %ld\n", ret);
  return ret;
}
277

278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294

static int TcpTableSorter(const void *a, const void *b)
{
  int ret;

  if (a && b) {
    const MIB_TCPROW* rowA = a;
    const MIB_TCPROW* rowB = b;

    ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
    if (ret == 0) {
      ret = rowA->dwLocalPort - rowB->dwLocalPort;
      if (ret == 0) {
        ret = rowA->dwRemoteAddr - rowB->dwRemoteAddr;
        if (ret == 0)
          ret = rowA->dwRemotePort - rowB->dwRemotePort;
      }
295 296
    }
  }
297 298
  else
    ret = 0;
299 300 301 302 303 304 305
  return ret;
}


/******************************************************************
 *    AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
 *
306 307
 * Get the TCP connection table.
 * Like GetTcpTable(), but allocate the returned table from heap.
308 309
 *
 * PARAMS
310 311
 *  ppTcpTable [Out] pointer into which the MIB_TCPTABLE is
 *                   allocated and returned.
312
 *  bOrder     [In]  whether to sort the table
313 314
 *  heap       [In]  heap from which the table is allocated
 *  flags      [In]  flags to HeapAlloc
315 316
 *
 * RETURNS
317 318
 *  ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable()
 *  returns otherwise.
319 320 321 322 323 324
 */
DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
 BOOL bOrder, HANDLE heap, DWORD flags)
{
  DWORD ret;

325 326
  TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
   ppTcpTable, bOrder, heap, flags);
327 328 329 330 331 332 333
  ret = getTcpTable(ppTcpTable, heap, flags);
  if (!ret && bOrder)
    qsort((*ppTcpTable)->table, (*ppTcpTable)->dwNumEntries,
     sizeof(MIB_TCPROW), TcpTableSorter);
  TRACE("returning %ld\n", ret);
  return ret;
}
334

335 336 337 338 339 340 341 342 343 344 345 346

static int UdpTableSorter(const void *a, const void *b)
{
  int ret;

  if (a && b) {
    const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
    const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;

    ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
    if (ret == 0)
      ret = rowA->dwLocalPort - rowB->dwLocalPort;
347
  }
348 349
  else
    ret = 0;
350 351 352 353 354 355 356
  return ret;
}


/******************************************************************
 *    AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
 *
357 358
 * Get the UDP listener table.
 * Like GetUdpTable(), but allocate the returned table from heap.
359 360
 *
 * PARAMS
361 362
 *  ppUdpTable [Out] pointer into which the MIB_UDPTABLE is
 *                   allocated and returned.
363
 *  bOrder     [In]  whether to sort the table
364 365
 *  heap       [In]  heap from which the table is allocated
 *  flags      [In]  flags to HeapAlloc
366 367
 *
 * RETURNS
368 369
 *  ERROR_INVALID_PARAMETER if ppUdpTable is NULL, whatever GetUdpTable()
 *  returns otherwise.
370 371 372 373 374 375
 */
DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
 BOOL bOrder, HANDLE heap, DWORD flags)
{
  DWORD ret;

376 377
  TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08lx\n",
   ppUdpTable, bOrder, heap, flags);
378 379 380 381
  ret = getUdpTable(ppUdpTable, heap, flags);
  if (!ret && bOrder)
    qsort((*ppUdpTable)->table, (*ppUdpTable)->dwNumEntries,
     sizeof(MIB_UDPROW), UdpTableSorter);
382
  TRACE("returning %ld\n", ret);
383 384 385 386
  return ret;
}


387 388 389
/******************************************************************
 *    CreateIpForwardEntry (IPHLPAPI.@)
 *
390
 * Create a route in the local computer's IP table.
391 392
 *
 * PARAMS
393
 *  pRoute [In] new route information
394 395
 *
 * RETURNS
396 397
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
398
 *
399
 * FIXME
400
 *  Stub, always returns NO_ERROR.
401 402 403
 */
DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
{
404
  FIXME("(pRoute %p): stub\n", pRoute);
405 406 407 408 409 410 411 412
  /* could use SIOCADDRT, not sure I want to */
  return (DWORD) 0;
}


/******************************************************************
 *    CreateIpNetEntry (IPHLPAPI.@)
 *
413
 * Create entry in the ARP table.
414 415
 *
 * PARAMS
416
 *  pArpEntry [In] new ARP entry
417 418
 *
 * RETURNS
419 420
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
421
 *
422
 * FIXME
423
 *  Stub, always returns NO_ERROR.
424 425 426
 */
DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
{
427
  FIXME("(pArpEntry %p)\n", pArpEntry);
428 429 430 431 432 433 434 435
  /* could use SIOCSARP on systems that support it, not sure I want to */
  return (DWORD) 0;
}


/******************************************************************
 *    CreateProxyArpEntry (IPHLPAPI.@)
 *
436
 * Create a Proxy ARP (PARP) entry for an IP address.
437 438
 *
 * PARAMS
439 440 441
 *  dwAddress [In] IP address for which this computer acts as a proxy. 
 *  dwMask    [In] subnet mask for dwAddress
 *  dwIfIndex [In] interface index
442 443
 *
 * RETURNS
444 445
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
446
 *
447 448
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
449 450 451
 */
DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
{
452 453
  FIXME("(dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx): stub\n",
   dwAddress, dwMask, dwIfIndex);
454 455 456 457 458 459 460
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    DeleteIPAddress (IPHLPAPI.@)
 *
461
 * Delete an IP address added with AddIPAddress().
462 463
 *
 * PARAMS
464
 *  NTEContext [In] NTE context from AddIPAddress();
465 466
 *
 * RETURNS
467 468
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
469
 *
470 471
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
472 473 474
 */
DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
{
475
  FIXME("(NTEContext %ld): stub\n", NTEContext);
476 477 478 479 480 481 482
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    DeleteIpForwardEntry (IPHLPAPI.@)
 *
483
 * Delete a route.
484 485
 *
 * PARAMS
486
 *  pRoute [In] route to delete
487 488
 *
 * RETURNS
489 490
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
491
 *
492 493
 * FIXME
 *  Stub, returns NO_ERROR.
494 495 496
 */
DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
{
497
  FIXME("(pRoute %p): stub\n", pRoute);
498 499 500 501 502 503 504 505
  /* could use SIOCDELRT, not sure I want to */
  return (DWORD) 0;
}


/******************************************************************
 *    DeleteIpNetEntry (IPHLPAPI.@)
 *
506
 * Delete an ARP entry.
507 508
 *
 * PARAMS
509
 *  pArpEntry [In] ARP entry to delete
510 511
 *
 * RETURNS
512 513
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
514
 *
515 516
 * FIXME
 *  Stub, returns NO_ERROR.
517 518 519
 */
DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
{
520
  FIXME("(pArpEntry %p): stub\n", pArpEntry);
521 522 523 524 525 526 527 528
  /* could use SIOCDARP on systems that support it, not sure I want to */
  return (DWORD) 0;
}


/******************************************************************
 *    DeleteProxyArpEntry (IPHLPAPI.@)
 *
529
 * Delete a Proxy ARP entry.
530 531
 *
 * PARAMS
532 533 534
 *  dwAddress [In] IP address for which this computer acts as a proxy. 
 *  dwMask    [In] subnet mask for dwAddress
 *  dwIfIndex [In] interface index
535 536
 *
 * RETURNS
537 538
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
539
 *
540 541
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
542 543 544
 */
DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
{
545 546
  FIXME("(dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx): stub\n",
   dwAddress, dwMask, dwIfIndex);
547 548 549 550 551 552 553
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    EnableRouter (IPHLPAPI.@)
 *
554
 * Turn on ip forwarding.
555 556
 *
 * PARAMS
557 558
 *  pHandle     [In/Out]
 *  pOverlapped [In/Out] hEvent member should contain a valid handle.
559 560
 *
 * RETURNS
561 562
 *  Success: ERROR_IO_PENDING
 *  Failure: error code from winerror.h
563
 *
564 565
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
566 567 568
 */
DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
{
569
  FIXME("(pHandle %p, pOverlapped %p): stub\n", pHandle, pOverlapped);
570 571
  /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
     could map EACCESS to ERROR_ACCESS_DENIED, I suppose
572
   */
573 574 575 576 577 578 579
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    FlushIpNetTable (IPHLPAPI.@)
 *
580
 * Delete all ARP entries of an interface
581 582
 *
 * PARAMS
583
 *  dwIfIndex [In] interface index
584 585
 *
 * RETURNS
586 587
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
588
 *
589 590
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
591 592 593
 */
DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
{
594
  FIXME("(dwIfIndex 0x%08lx): stub\n", dwIfIndex);
595
  /* this flushes the arp cache of the given index */
596 597 598 599 600 601 602
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    GetAdapterIndex (IPHLPAPI.@)
 *
603
 * Get interface index from its name.
604 605
 *
 * PARAMS
606 607
 *  AdapterName [In]  unicode string with the adapter name
 *  IfIndex     [Out] returns found interface index
608 609
 *
 * RETURNS
610 611
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
612
 *
613 614
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
615 616 617
 */
DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
{
618
  FIXME("(AdapterName %p, IfIndex %p): stub\n", AdapterName, IfIndex);
619
  /* FIXME: implement using getInterfaceIndexByName */
620 621 622 623 624 625 626
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    GetAdaptersInfo (IPHLPAPI.@)
 *
627
 * Get information about adapters.
628
 *
629 630 631
 * PARAMS
 *  pAdapterInfo [Out] buffer for adapter infos
 *  pOutBufLen   [In]  length of output buffer
632 633
 *
 * RETURNS
634 635
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
636 637 638 639 640
 */
DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
{
  DWORD ret;

641
  TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
642 643 644 645 646 647
  if (!pOutBufLen)
    ret = ERROR_INVALID_PARAMETER;
  else {
    DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();

    if (numNonLoopbackInterfaces > 0) {
648 649 650 651 652 653 654 655 656
      DWORD numIPAddresses = getNumIPAddresses();
      ULONG size;

      /* This may slightly overestimate the amount of space needed, because
       * the IP addresses include the loopback address, but it's easier
       * to make sure there's more than enough space than to make sure there's
       * precisely enough space.
       */
      size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
657
      size += numIPAddresses  * sizeof(IP_ADDR_STRING); 
658 659 660 661 662
      if (!pAdapterInfo || *pOutBufLen < size) {
        *pOutBufLen = size;
        ret = ERROR_BUFFER_OVERFLOW;
      }
      else {
663 664
        InterfaceIndexTable *table = NULL;
        PMIB_IPADDRTABLE ipAddrTable = NULL;
665

666 667 668
        ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
        if (!ret)
          table = getNonLoopbackInterfaceIndexTable();
669 670
        if (table) {
          size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
671
          size += ipAddrTable->dwNumEntries * sizeof(IP_ADDR_STRING); 
672 673 674 675 676 677
          if (*pOutBufLen < size) {
            *pOutBufLen = size;
            ret = ERROR_INSUFFICIENT_BUFFER;
          }
          else {
            DWORD ndx;
678 679 680
            HKEY hKey;
            BOOL winsEnabled = FALSE;
            IP_ADDRESS_STRING primaryWINS, secondaryWINS;
681 682
            PIP_ADDR_STRING nextIPAddr = (PIP_ADDR_STRING)((LPBYTE)pAdapterInfo
             + numNonLoopbackInterfaces * sizeof(IP_ADAPTER_INFO));
683 684

            memset(pAdapterInfo, 0, size);
685
            /* @@ Wine registry key: HKCU\Software\Wine\Network */
686 687
            if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network",
             &hKey) == ERROR_SUCCESS) {
688 689 690 691
              DWORD size = sizeof(primaryWINS.String);
              unsigned long addr;

              RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
692
               (LPBYTE)primaryWINS.String, &size);
693 694 695 696 697
              addr = inet_addr(primaryWINS.String);
              if (addr != INADDR_NONE && addr != INADDR_ANY)
                winsEnabled = TRUE;
              size = sizeof(secondaryWINS.String);
              RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
698
               (LPBYTE)secondaryWINS.String, &size);
699 700 701 702 703
              addr = inet_addr(secondaryWINS.String);
              if (addr != INADDR_NONE && addr != INADDR_ANY)
                winsEnabled = TRUE;
              RegCloseKey(hKey);
            }
704 705
            for (ndx = 0; ndx < table->numIndexes; ndx++) {
              PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
706 707 708
              DWORD addrLen = sizeof(ptr->Address), type, i;
              PIP_ADDR_STRING currentIPAddr = &ptr->IpAddressList;
              BOOL firstIPAddr = TRUE;
709 710

              /* on Win98 this is left empty, but whatever */
711
              getInterfaceNameByIndex(table->indexes[ndx], ptr->AdapterName);
712 713 714 715 716 717 718 719
              getInterfacePhysicalByIndex(table->indexes[ndx], &addrLen,
               ptr->Address, &type);
              /* MS defines address length and type as UINT in some places and
                 DWORD in others, **sigh**.  Don't want to assume that PUINT and
                 PDWORD are equiv (64-bit?) */
              ptr->AddressLength = addrLen;
              ptr->Type = type;
              ptr->Index = table->indexes[ndx];
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
              for (i = 0; i < ipAddrTable->dwNumEntries; i++) {
                if (ipAddrTable->table[i].dwIndex == ptr->Index) {
                  if (firstIPAddr) {
                    toIPAddressString(ipAddrTable->table[i].dwAddr,
                     ptr->IpAddressList.IpAddress.String);
                    toIPAddressString(ipAddrTable->table[i].dwBCastAddr,
                     ptr->IpAddressList.IpMask.String);
                    firstIPAddr = FALSE;
                  }
                  else {
                    currentIPAddr->Next = nextIPAddr;
                    currentIPAddr = nextIPAddr;
                    toIPAddressString(ipAddrTable->table[i].dwAddr,
                     currentIPAddr->IpAddress.String);
                    toIPAddressString(ipAddrTable->table[i].dwBCastAddr,
                     currentIPAddr->IpMask.String);
                    nextIPAddr++;
                  }
                }
              }
740 741 742 743 744 745 746
              if (winsEnabled) {
                ptr->HaveWins = TRUE;
                memcpy(ptr->PrimaryWinsServer.IpAddress.String,
                 primaryWINS.String, sizeof(primaryWINS.String));
                memcpy(ptr->SecondaryWinsServer.IpAddress.String,
                 secondaryWINS.String, sizeof(secondaryWINS.String));
              }
747 748 749 750
              if (ndx < table->numIndexes - 1)
                ptr->Next = &pAdapterInfo[ndx + 1];
              else
                ptr->Next = NULL;
751 752 753
            }
            ret = NO_ERROR;
          }
754
          HeapFree(GetProcessHeap(), 0, table);
755 756 757
        }
        else
          ret = ERROR_OUTOFMEMORY;
758
        HeapFree(GetProcessHeap(), 0, ipAddrTable);
759 760 761 762 763
      }
    }
    else
      ret = ERROR_NO_DATA;
  }
764
  TRACE("returning %ld\n", ret);
765 766 767 768 769 770 771
  return ret;
}


/******************************************************************
 *    GetBestInterface (IPHLPAPI.@)
 *
772
 * Get the interface, with the best route for the given IP address.
773
 *
774 775 776
 * PARAMS
 *  dwDestAddr     [In]  IP address to search the interface for
 *  pdwBestIfIndex [Out] found best interface
777 778
 *
 * RETURNS
779 780
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
781 782 783
 */
DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
{
784 785
  DWORD ret;

786
  TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex);
787 788 789 790 791 792 793 794 795
  if (!pdwBestIfIndex)
    ret = ERROR_INVALID_PARAMETER;
  else {
    MIB_IPFORWARDROW ipRow;

    ret = GetBestRoute(dwDestAddr, 0, &ipRow);
    if (ret == ERROR_SUCCESS)
      *pdwBestIfIndex = ipRow.dwForwardIfIndex;
  }
796
  TRACE("returning %ld\n", ret);
797
  return ret;
798 799 800 801 802 803
}


/******************************************************************
 *    GetBestRoute (IPHLPAPI.@)
 *
804
 * Get the best route for the given IP address.
805
 *
806 807 808 809
 * PARAMS
 *  dwDestAddr   [In]  IP address to search the best route for
 *  dwSourceAddr [In]  optional source IP address
 *  pBestRoute   [Out] found best route
810 811
 *
 * RETURNS
812 813
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
814 815 816
 */
DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
{
817 818 819
  PMIB_IPFORWARDTABLE table;
  DWORD ret;

820 821
  TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr,
   dwSourceAddr, pBestRoute);
822 823 824 825 826 827 828 829
  if (!pBestRoute)
    return ERROR_INVALID_PARAMETER;

  AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
  if (table) {
    DWORD ndx, matchedBits, matchedNdx = 0;

    for (ndx = 0, matchedBits = 0; ndx < table->dwNumEntries; ndx++) {
830 831
      if (table->table[ndx].dwForwardType != MIB_IPROUTE_TYPE_INVALID &&
       (dwDestAddr & table->table[ndx].dwForwardMask) ==
832 833 834 835 836 837 838 839 840 841 842 843
       (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
        DWORD numShifts, mask;

        for (numShifts = 0, mask = table->table[ndx].dwForwardMask;
         mask && !(mask & 1); mask >>= 1, numShifts++)
          ;
        if (numShifts > matchedBits) {
          matchedBits = numShifts;
          matchedNdx = ndx;
        }
      }
    }
844 845 846 847 848 849 850 851
    if (matchedNdx < table->dwNumEntries) {
      memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
      ret = ERROR_SUCCESS;
    }
    else {
      /* No route matches, which can happen if there's no default route. */
      ret = ERROR_HOST_UNREACHABLE;
    }
852 853 854 855
    HeapFree(GetProcessHeap(), 0, table);
  }
  else
    ret = ERROR_OUTOFMEMORY;
856
  TRACE("returning %ld\n", ret);
857
  return ret;
858 859 860 861 862 863
}


/******************************************************************
 *    GetFriendlyIfIndex (IPHLPAPI.@)
 *
864
 * Get a "friendly" version of IfIndex, which is one that doesn't
865 866
 * have the top byte set.  Doesn't validate whether IfIndex is a valid
 * adapter index.
867 868
 *
 * PARAMS
869
 *  IfIndex [In] interface index to get the friendly one for
870 871
 *
 * RETURNS
872
 *  A friendly version of IfIndex.
873 874 875 876
 */
DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
{
  /* windows doesn't validate these, either, just makes sure the top byte is
877
     cleared.  I assume my ifenum module never gives an index with the top
878
     byte set. */
879
  TRACE("returning %ld\n", IfIndex);
880 881 882 883 884 885 886
  return IfIndex;
}


/******************************************************************
 *    GetIcmpStatistics (IPHLPAPI.@)
 *
887
 * Get the ICMP statistics for the local computer.
888
 *
889 890
 * PARAMS
 *  pStats [Out] buffer for ICMP statistics
891 892
 *
 * RETURNS
893 894
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
895 896 897
 */
DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
{
898 899 900 901 902 903
  DWORD ret;

  TRACE("pStats %p\n", pStats);
  ret = getICMPStats(pStats);
  TRACE("returning %ld\n", ret);
  return ret;
904 905 906 907 908 909
}


/******************************************************************
 *    GetIfEntry (IPHLPAPI.@)
 *
910
 * Get information about an interface.
911
 *
912 913 914
 * PARAMS
 *  pIfRow [In/Out] In:  dwIndex of MIB_IFROW selects the interface.
 *                  Out: interface information
915 916
 *
 * RETURNS
917 918
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
919 920 921 922
 */
DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
{
  DWORD ret;
923 924
  char nameBuf[MAX_ADAPTER_NAME];
  char *name;
925

926
  TRACE("pIfRow %p\n", pIfRow);
927 928 929
  if (!pIfRow)
    return ERROR_INVALID_PARAMETER;

930
  name = getInterfaceNameByIndex(pIfRow->dwIndex, nameBuf);
931 932 933 934 935 936 937
  if (name) {
    ret = getInterfaceEntryByName(name, pIfRow);
    if (ret == NO_ERROR)
      ret = getInterfaceStatsByName(name, pIfRow);
  }
  else
    ret = ERROR_INVALID_DATA;
938
  TRACE("returning %ld\n", ret);
939 940 941 942
  return ret;
}


943 944 945 946 947
static int IfTableSorter(const void *a, const void *b)
{
  int ret;

  if (a && b)
Eric Pouech's avatar
Eric Pouech committed
948
    ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
949 950 951 952 953 954
  else
    ret = 0;
  return ret;
}


955 956 957
/******************************************************************
 *    GetIfTable (IPHLPAPI.@)
 *
958
 * Get a table of local interfaces.
959 960
 *
 * PARAMS
961 962 963
 *  pIfTable [Out]    buffer for local interfaces table
 *  pdwSize  [In/Out] length of output buffer
 *  bOrder   [In]     whether to sort the table
964 965
 *
 * RETURNS
966 967
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
968
 *
969 970 971 972 973
 * NOTES
 *  If pdwSize is less than required, the function will return
 *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
 *  size.
 *  If bOrder is true, the returned table will be sorted by interface index.
974 975 976 977 978
 */
DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
{
  DWORD ret;

979 980
  TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize, pdwSize,
   (DWORD)bOrder);
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
  if (!pdwSize)
    ret = ERROR_INVALID_PARAMETER;
  else {
    DWORD numInterfaces = getNumInterfaces();
    ULONG size = sizeof(MIB_IFTABLE) + (numInterfaces - 1) * sizeof(MIB_IFROW);

    if (!pIfTable || *pdwSize < size) {
      *pdwSize = size;
      ret = ERROR_INSUFFICIENT_BUFFER;
    }
    else {
      InterfaceIndexTable *table = getInterfaceIndexTable();

      if (table) {
        size = sizeof(MIB_IFTABLE) + (table->numIndexes - 1) *
         sizeof(MIB_IFROW);
        if (*pdwSize < size) {
          *pdwSize = size;
          ret = ERROR_INSUFFICIENT_BUFFER;
        }
        else {
          DWORD ndx;

1004
          *pdwSize = size;
1005 1006 1007 1008 1009 1010
          pIfTable->dwNumEntries = 0;
          for (ndx = 0; ndx < table->numIndexes; ndx++) {
            pIfTable->table[ndx].dwIndex = table->indexes[ndx];
            GetIfEntry(&pIfTable->table[ndx]);
            pIfTable->dwNumEntries++;
          }
1011 1012 1013
          if (bOrder)
            qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
             IfTableSorter);
1014 1015
          ret = NO_ERROR;
        }
1016
        HeapFree(GetProcessHeap(), 0, table);
1017 1018 1019 1020 1021
      }
      else
        ret = ERROR_OUTOFMEMORY;
    }
  }
1022
  TRACE("returning %ld\n", ret);
1023 1024 1025 1026 1027 1028 1029
  return ret;
}


/******************************************************************
 *    GetInterfaceInfo (IPHLPAPI.@)
 *
1030
 * Get a list of network interface adapters.
1031
 *
1032
 * PARAMS
1033
 *  pIfTable    [Out] buffer for interface adapters
1034
 *  dwOutBufLen [Out] if buffer is too small, returns required size
1035 1036
 *
 * RETURNS
1037 1038
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1039 1040 1041
 *
 * BUGS
 *  MSDN states this should return non-loopback interfaces only.
1042 1043 1044 1045 1046
 */
DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
{
  DWORD ret;

1047
  TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
  if (!dwOutBufLen)
    ret = ERROR_INVALID_PARAMETER;
  else {
    DWORD numInterfaces = getNumInterfaces();
    ULONG size = sizeof(IP_INTERFACE_INFO) + (numInterfaces - 1) *
     sizeof(IP_ADAPTER_INDEX_MAP);

    if (!pIfTable || *dwOutBufLen < size) {
      *dwOutBufLen = size;
      ret = ERROR_INSUFFICIENT_BUFFER;
    }
    else {
      InterfaceIndexTable *table = getInterfaceIndexTable();

      if (table) {
        size = sizeof(IP_INTERFACE_INFO) + (table->numIndexes - 1) *
         sizeof(IP_ADAPTER_INDEX_MAP);
        if (*dwOutBufLen < size) {
          *dwOutBufLen = size;
          ret = ERROR_INSUFFICIENT_BUFFER;
        }
        else {
          DWORD ndx;
1071
          char nameBuf[MAX_ADAPTER_NAME];
1072

1073
          *dwOutBufLen = size;
1074 1075 1076 1077 1078 1079
          pIfTable->NumAdapters = 0;
          for (ndx = 0; ndx < table->numIndexes; ndx++) {
            const char *walker, *name;
            WCHAR *assigner;

            pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1080
            name = getInterfaceNameByIndex(table->indexes[ndx], nameBuf);
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
            for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
             walker && *walker &&
             assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
             walker++, assigner++)
              *assigner = *walker;
            *assigner = 0;
            pIfTable->NumAdapters++;
          }
          ret = NO_ERROR;
        }
1091
        HeapFree(GetProcessHeap(), 0, table);
1092 1093 1094 1095 1096
      }
      else
        ret = ERROR_OUTOFMEMORY;
    }
  }
1097
  TRACE("returning %ld\n", ret);
1098 1099 1100 1101 1102 1103 1104
  return ret;
}


/******************************************************************
 *    GetIpAddrTable (IPHLPAPI.@)
 *
1105
 * Get interface-to-IP address mapping table. 
1106 1107
 *
 * PARAMS
1108 1109 1110
 *  pIpAddrTable [Out]    buffer for mapping table
 *  pdwSize      [In/Out] length of output buffer
 *  bOrder       [In]     whether to sort the table
1111 1112
 *
 * RETURNS
1113 1114
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1115
 *
1116 1117 1118 1119 1120 1121
 * NOTES
 *  If pdwSize is less than required, the function will return
 *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
 *  size.
 *  If bOrder is true, the returned table will be sorted by the next hop and
 *  an assortment of arbitrary parameters.
1122 1123 1124 1125 1126
 */
DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
{
  DWORD ret;

1127 1128
  TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable, pdwSize,
   (DWORD)bOrder);
1129 1130 1131
  if (!pdwSize)
    ret = ERROR_INVALID_PARAMETER;
  else {
1132
    PMIB_IPADDRTABLE table;
1133

1134 1135 1136 1137 1138
    ret = getIPAddrTable(&table, GetProcessHeap(), 0);
    if (ret == NO_ERROR)
    {
      ULONG size = sizeof(MIB_IPADDRTABLE) + (table->dwNumEntries - 1) *
       sizeof(MIB_IPADDRROW);
1139

1140 1141 1142
      if (!pIpAddrTable || *pdwSize < size) {
        *pdwSize = size;
        ret = ERROR_INSUFFICIENT_BUFFER;
1143
      }
1144 1145 1146 1147 1148 1149 1150 1151
      else {
        *pdwSize = size;
        memcpy(pIpAddrTable, table, sizeof(MIB_IPADDRTABLE) +
         (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW));
        if (bOrder)
          qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
           sizeof(MIB_IPADDRROW), IpAddrTableSorter);
        ret = NO_ERROR;
1152
      }
1153
      HeapFree(GetProcessHeap(), 0, table);
1154 1155
    }
  }
1156
  TRACE("returning %ld\n", ret);
1157 1158 1159 1160
  return ret;
}


1161 1162 1163
/******************************************************************
 *    GetIpForwardTable (IPHLPAPI.@)
 *
1164
 * Get the route table.
1165 1166
 *
 * PARAMS
1167 1168 1169
 *  pIpForwardTable [Out]    buffer for route table
 *  pdwSize         [In/Out] length of output buffer
 *  bOrder          [In]     whether to sort the table
1170 1171
 *
 * RETURNS
1172 1173
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1174
 *
1175 1176 1177 1178 1179 1180
 * NOTES
 *  If pdwSize is less than required, the function will return
 *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
 *  size.
 *  If bOrder is true, the returned table will be sorted by the next hop and
 *  an assortment of arbitrary parameters.
1181 1182 1183 1184 1185
 */
DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
{
  DWORD ret;

1186 1187
  TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable,
   pdwSize, (DWORD)bOrder);
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
  if (!pdwSize)
    ret = ERROR_INVALID_PARAMETER;
  else {
    DWORD numRoutes = getNumRoutes();
    ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) *
     sizeof(MIB_IPFORWARDROW);

    if (!pIpForwardTable || *pdwSize < sizeNeeded) {
      *pdwSize = sizeNeeded;
      ret = ERROR_INSUFFICIENT_BUFFER;
    }
    else {
1200 1201 1202 1203 1204
      PMIB_IPFORWARDTABLE table;

      ret = getRouteTable(&table, GetProcessHeap(), 0);
      if (!ret) {
        sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (table->dwNumEntries - 1) *
1205 1206 1207 1208 1209 1210
         sizeof(MIB_IPFORWARDROW);
        if (*pdwSize < sizeNeeded) {
          *pdwSize = sizeNeeded;
          ret = ERROR_INSUFFICIENT_BUFFER;
        }
        else {
1211 1212
          *pdwSize = sizeNeeded;
          memcpy(pIpForwardTable, table, sizeNeeded);
1213 1214 1215
          if (bOrder)
            qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
             sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1216 1217
          ret = NO_ERROR;
        }
1218
        HeapFree(GetProcessHeap(), 0, table);
1219 1220 1221
      }
    }
  }
1222
  TRACE("returning %ld\n", ret);
1223 1224 1225 1226 1227 1228 1229
  return ret;
}


/******************************************************************
 *    GetIpNetTable (IPHLPAPI.@)
 *
1230
 * Get the IP-to-physical address mapping table.
1231 1232
 *
 * PARAMS
1233 1234 1235
 *  pIpNetTable [Out]    buffer for mapping table
 *  pdwSize     [In/Out] length of output buffer
 *  bOrder      [In]     whether to sort the table
1236 1237
 *
 * RETURNS
1238 1239
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1240
 *
1241 1242 1243 1244 1245
 * NOTES
 *  If pdwSize is less than required, the function will return
 *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the required byte
 *  size.
 *  If bOrder is true, the returned table will be sorted by IP address.
1246 1247 1248 1249 1250
 */
DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
{
  DWORD ret;

1251 1252
  TRACE("pIpNetTable %p, pdwSize %p, bOrder %ld\n", pIpNetTable, pdwSize,
   (DWORD)bOrder);
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
  if (!pdwSize)
    ret = ERROR_INVALID_PARAMETER;
  else {
    DWORD numEntries = getNumArpEntries();
    ULONG size = sizeof(MIB_IPNETTABLE) + (numEntries - 1) *
     sizeof(MIB_IPNETROW);

    if (!pIpNetTable || *pdwSize < size) {
      *pdwSize = size;
      ret = ERROR_INSUFFICIENT_BUFFER;
    }
    else {
1265
      PMIB_IPNETTABLE table;
1266

1267 1268
      ret = getArpTable(&table, GetProcessHeap(), 0);
      if (!ret) {
1269 1270 1271 1272 1273 1274 1275
        size = sizeof(MIB_IPNETTABLE) + (table->dwNumEntries - 1) *
         sizeof(MIB_IPNETROW);
        if (*pdwSize < size) {
          *pdwSize = size;
          ret = ERROR_INSUFFICIENT_BUFFER;
        }
        else {
1276
          *pdwSize = size;
1277
          memcpy(pIpNetTable, table, size);
1278 1279 1280
          if (bOrder)
            qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
             sizeof(MIB_IPNETROW), IpNetTableSorter);
1281 1282
          ret = NO_ERROR;
        }
1283
        HeapFree(GetProcessHeap(), 0, table);
1284 1285 1286
      }
    }
  }
1287
  TRACE("returning %ld\n", ret);
1288 1289 1290 1291 1292 1293 1294
  return ret;
}


/******************************************************************
 *    GetIpStatistics (IPHLPAPI.@)
 *
1295
 * Get the IP statistics for the local computer.
1296
 *
1297 1298
 * PARAMS
 *  pStats [Out] buffer for IP statistics
1299 1300
 *
 * RETURNS
1301 1302
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1303 1304 1305
 */
DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
{
1306 1307 1308 1309 1310 1311
  DWORD ret;

  TRACE("pStats %p\n", pStats);
  ret = getIPStats(pStats);
  TRACE("returning %ld\n", ret);
  return ret;
1312 1313 1314 1315 1316 1317
}


/******************************************************************
 *    GetNetworkParams (IPHLPAPI.@)
 *
1318
 * Get the network parameters for the local computer.
1319
 *
1320 1321
 * PARAMS
 *  pFixedInfo [Out]    buffer for network parameters
1322
 *  pOutBufLen [In/Out] length of output buffer
1323 1324
 *
 * RETURNS
1325 1326
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1327
 *
1328 1329 1330 1331
 * NOTES
 *  If pOutBufLen is less than required, the function will return
 *  ERROR_INSUFFICIENT_BUFFER, and pOutBufLen will be set to the required byte
 *  size.
1332 1333 1334
 */
DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
{
1335 1336
  DWORD ret, size;
  LONG regReturn;
1337
  HKEY hKey;
1338

1339
  TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1340 1341 1342
  if (!pOutBufLen)
    return ERROR_INVALID_PARAMETER;

1343 1344 1345
  res_init();
  size = sizeof(FIXED_INFO) + (_res.nscount > 0 ? (_res.nscount  - 1) *
   sizeof(IP_ADDR_STRING) : 0);
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
  if (!pFixedInfo || *pOutBufLen < size) {
    *pOutBufLen = size;
    return ERROR_BUFFER_OVERFLOW;
  }

  memset(pFixedInfo, 0, size);
  size = sizeof(pFixedInfo->HostName);
  GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size);
  size = sizeof(pFixedInfo->DomainName);
  GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size);
  if (_res.nscount > 0) {
    PIP_ADDR_STRING ptr;
    int i;

1360
    for (i = 0, ptr = &pFixedInfo->DnsServerList; i < _res.nscount && ptr;
1361 1362 1363
     i++, ptr = ptr->Next) {
      toIPAddressString(_res.nsaddr_list[i].sin_addr.s_addr,
       ptr->IpAddress.String);
1364 1365 1366 1367 1368 1369
      if (i == _res.nscount - 1)
        ptr->Next = NULL;
      else if (i == 0)
        ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
      else
        ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
1370 1371
    }
  }
1372
  pFixedInfo->NodeType = HYBRID_NODETYPE;
1373 1374 1375 1376 1377 1378 1379
  regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
   "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
  if (regReturn != ERROR_SUCCESS)
    regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
     "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
     &hKey);
  if (regReturn == ERROR_SUCCESS)
1380 1381 1382
  {
    DWORD size = sizeof(pFixedInfo->ScopeId);

1383
    RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (LPBYTE)pFixedInfo->ScopeId, &size);
1384 1385 1386
    RegCloseKey(hKey);
  }

1387 1388
  /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
     I suppose could also check for a listener on port 53 to set EnableDns */
1389 1390 1391
  ret = NO_ERROR;
  TRACE("returning %ld\n", ret);
  return ret;
1392 1393 1394 1395 1396 1397
}


/******************************************************************
 *    GetNumberOfInterfaces (IPHLPAPI.@)
 *
1398
 * Get the number of interfaces.
1399 1400
 *
 * PARAMS
1401
 *  pdwNumIf [Out] number of interfaces
1402 1403
 *
 * RETURNS
1404
 *  NO_ERROR on success, ERROR_INVALID_PARAMETER if pdwNumIf is NULL.
1405 1406 1407 1408 1409
 */
DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
{
  DWORD ret;

1410
  TRACE("pdwNumIf %p\n", pdwNumIf);
1411 1412 1413 1414 1415 1416
  if (!pdwNumIf)
    ret = ERROR_INVALID_PARAMETER;
  else {
    *pdwNumIf = getNumInterfaces();
    ret = NO_ERROR;
  }
1417
  TRACE("returning %ld\n", ret);
1418 1419 1420 1421 1422 1423 1424
  return ret;
}


/******************************************************************
 *    GetPerAdapterInfo (IPHLPAPI.@)
 *
1425
 * Get information about an adapter corresponding to an interface.
1426 1427
 *
 * PARAMS
1428 1429 1430
 *  IfIndex         [In]     interface info
 *  pPerAdapterInfo [Out]    buffer for per adapter info
 *  pOutBufLen      [In/Out] length of output buffer
1431 1432
 *
 * RETURNS
1433 1434 1435 1436 1437
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
 *
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
1438 1439 1440
 */
DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
{
1441
  TRACE("(IfIndex %ld, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex,
1442
   pPerAdapterInfo, pOutBufLen);
1443 1444 1445 1446 1447 1448 1449
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    GetRTTAndHopCount (IPHLPAPI.@)
 *
1450
 * Get round-trip time (RTT) and hop count.
1451 1452 1453
 *
 * PARAMS
 *
1454 1455 1456 1457
 *  DestIpAddress [In]  destination address to get the info for
 *  HopCount      [Out] retrieved hop count
 *  MaxHops       [In]  maximum hops to search for the destination
 *  RTT           [Out] RTT in milliseconds
1458 1459
 *
 * RETURNS
1460 1461
 *  Success: TRUE
 *  Failure: FALSE
1462
 *
1463 1464
 * FIXME
 *  Stub, returns FALSE.
1465 1466 1467
 */
BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
{
1468
  FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p): stub\n",
1469
   DestIpAddress, HopCount, MaxHops, RTT);
1470
  return FALSE;
1471 1472 1473 1474 1475 1476
}


/******************************************************************
 *    GetTcpStatistics (IPHLPAPI.@)
 *
1477
 * Get the TCP statistics for the local computer.
1478
 *
1479 1480
 * PARAMS
 *  pStats [Out] buffer for TCP statistics
1481 1482
 *
 * RETURNS
1483 1484
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1485 1486 1487
 */
DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
{
1488 1489 1490 1491 1492 1493
  DWORD ret;

  TRACE("pStats %p\n", pStats);
  ret = getTCPStats(pStats);
  TRACE("returning %ld\n", ret);
  return ret;
1494 1495 1496 1497 1498 1499
}


/******************************************************************
 *    GetTcpTable (IPHLPAPI.@)
 *
1500
 * Get the table of active TCP connections.
1501 1502
 *
 * PARAMS
1503 1504 1505
 *  pTcpTable [Out]    buffer for TCP connections table
 *  pdwSize   [In/Out] length of output buffer
 *  bOrder    [In]     whether to order the table
1506 1507
 *
 * RETURNS
1508 1509
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1510
 *
1511 1512 1513 1514 1515 1516 1517
 * NOTES
 *  If pdwSize is less than required, the function will return 
 *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to 
 *  the required byte size.
 *  If bOrder is true, the returned table will be sorted, first by
 *  local address and port number, then by remote address and port
 *  number.
1518 1519 1520 1521 1522
 */
DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
{
  DWORD ret;

1523 1524
  TRACE("pTcpTable %p, pdwSize %p, bOrder %ld\n", pTcpTable, pdwSize,
   (DWORD)bOrder);
1525 1526 1527 1528
  if (!pdwSize)
    ret = ERROR_INVALID_PARAMETER;
  else {
    DWORD numEntries = getNumTcpEntries();
1529
    DWORD size = sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW);
1530 1531 1532 1533 1534 1535

    if (!pTcpTable || *pdwSize < size) {
      *pdwSize = size;
      ret = ERROR_INSUFFICIENT_BUFFER;
    }
    else {
1536
      PMIB_TCPTABLE table;
1537

1538 1539
      ret = getTcpTable(&table, GetProcessHeap(), 0);
      if (!ret) {
1540 1541 1542 1543 1544 1545 1546
        size = sizeof(MIB_TCPTABLE) + (table->dwNumEntries - 1) *
         sizeof(MIB_TCPROW);
        if (*pdwSize < size) {
          *pdwSize = size;
          ret = ERROR_INSUFFICIENT_BUFFER;
        }
        else {
1547
          *pdwSize = size;
1548
          memcpy(pTcpTable, table, size);
1549 1550 1551
          if (bOrder)
            qsort(pTcpTable->table, pTcpTable->dwNumEntries,
             sizeof(MIB_TCPROW), TcpTableSorter);
1552 1553
          ret = NO_ERROR;
        }
1554
        HeapFree(GetProcessHeap(), 0, table);
1555 1556 1557 1558 1559
      }
      else
        ret = ERROR_OUTOFMEMORY;
    }
  }
1560
  TRACE("returning %ld\n", ret);
1561 1562 1563 1564 1565 1566 1567
  return ret;
}


/******************************************************************
 *    GetUdpStatistics (IPHLPAPI.@)
 *
1568
 * Get the UDP statistics for the local computer.
1569
 *
1570 1571
 * PARAMS
 *  pStats [Out] buffer for UDP statistics
1572 1573
 *
 * RETURNS
1574 1575
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1576 1577 1578
 */
DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
{
1579 1580 1581 1582 1583 1584
  DWORD ret;

  TRACE("pStats %p\n", pStats);
  ret = getUDPStats(pStats);
  TRACE("returning %ld\n", ret);
  return ret;
1585 1586 1587 1588 1589 1590
}


/******************************************************************
 *    GetUdpTable (IPHLPAPI.@)
 *
1591
 * Get a table of active UDP connections.
1592 1593
 *
 * PARAMS
1594 1595 1596
 *  pUdpTable [Out]    buffer for UDP connections table
 *  pdwSize   [In/Out] length of output buffer
 *  bOrder    [In]     whether to order the table
1597 1598
 *
 * RETURNS
1599 1600
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1601
 *
1602 1603 1604 1605 1606 1607
 * NOTES
 *  If pdwSize is less than required, the function will return 
 *  ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to the
 *  required byte size.
 *  If bOrder is true, the returned table will be sorted, first by
 *  local address, then by local port number.
1608 1609 1610 1611 1612
 */
DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
{
  DWORD ret;

1613 1614
  TRACE("pUdpTable %p, pdwSize %p, bOrder %ld\n", pUdpTable, pdwSize,
   (DWORD)bOrder);
1615 1616 1617 1618
  if (!pdwSize)
    ret = ERROR_INVALID_PARAMETER;
  else {
    DWORD numEntries = getNumUdpEntries();
1619
    DWORD size = sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW);
1620 1621 1622 1623 1624 1625

    if (!pUdpTable || *pdwSize < size) {
      *pdwSize = size;
      ret = ERROR_INSUFFICIENT_BUFFER;
    }
    else {
1626
      PMIB_UDPTABLE table;
1627

1628 1629
      ret = getUdpTable(&table, GetProcessHeap(), 0);
      if (!ret) {
1630 1631 1632 1633 1634 1635 1636
        size = sizeof(MIB_UDPTABLE) + (table->dwNumEntries - 1) *
         sizeof(MIB_UDPROW);
        if (*pdwSize < size) {
          *pdwSize = size;
          ret = ERROR_INSUFFICIENT_BUFFER;
        }
        else {
1637
          *pdwSize = size;
1638
          memcpy(pUdpTable, table, size);
1639 1640 1641
          if (bOrder)
            qsort(pUdpTable->table, pUdpTable->dwNumEntries,
             sizeof(MIB_UDPROW), UdpTableSorter);
1642 1643
          ret = NO_ERROR;
        }
1644
        HeapFree(GetProcessHeap(), 0, table);
1645 1646 1647 1648 1649
      }
      else
        ret = ERROR_OUTOFMEMORY;
    }
  }
1650
  TRACE("returning %ld\n", ret);
1651 1652 1653 1654 1655 1656 1657
  return ret;
}


/******************************************************************
 *    GetUniDirectionalAdapterInfo (IPHLPAPI.@)
 *
1658 1659 1660
 * This is a Win98-only function to get information on "unidirectional"
 * adapters.  Since this is pretty nonsensical in other contexts, it
 * never returns anything.
1661 1662
 *
 * PARAMS
1663 1664
 *  pIPIfInfo   [Out] buffer for adapter infos
 *  dwOutBufLen [Out] length of the output buffer
1665 1666
 *
 * RETURNS
1667 1668
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1669
 *
1670 1671
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
1672 1673 1674
 */
DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
{
1675
  TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
1676 1677 1678 1679 1680 1681 1682 1683
  /* a unidirectional adapter?? not bloody likely! */
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    IpReleaseAddress (IPHLPAPI.@)
 *
1684
 * Release an IP optained through DHCP,
1685 1686
 *
 * PARAMS
1687
 *  AdapterInfo [In] adapter to release IP address
1688 1689
 *
 * RETURNS
1690 1691
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1692
 *
1693 1694 1695 1696 1697 1698
 * NOTES
 *  Since GetAdaptersInfo never returns adapters that have DHCP enabled,
 *  this function does nothing.
 *
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
1699 1700 1701
 */
DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
{
1702
  TRACE("AdapterInfo %p\n", AdapterInfo);
1703 1704 1705 1706 1707 1708 1709 1710 1711
  /* not a stub, never going to support this (and I never mark an adapter as
     DHCP enabled, see GetAdaptersInfo, so this should never get called) */
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    IpRenewAddress (IPHLPAPI.@)
 *
1712
 * Renew an IP optained through DHCP.
1713 1714
 *
 * PARAMS
1715
 *  AdapterInfo [In] adapter to renew IP address
1716 1717
 *
 * RETURNS
1718 1719 1720 1721 1722 1723
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
 *
 * NOTES
 *  Since GetAdaptersInfo never returns adapters that have DHCP enabled,
 *  this function does nothing.
1724
 *
1725 1726
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
1727 1728 1729
 */
DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
{
1730
  TRACE("AdapterInfo %p\n", AdapterInfo);
1731 1732 1733 1734 1735 1736 1737 1738 1739
  /* not a stub, never going to support this (and I never mark an adapter as
     DHCP enabled, see GetAdaptersInfo, so this should never get called) */
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    NotifyAddrChange (IPHLPAPI.@)
 *
1740
 * Notify caller whenever the ip-interface map is changed.
1741 1742
 *
 * PARAMS
1743 1744
 *  Handle     [Out] handle useable in asynchronus notification
 *  overlapped [In]  overlapped structure that notifies the caller
1745 1746
 *
 * RETURNS
1747 1748
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1749
 *
1750 1751
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
1752 1753 1754
 */
DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
{
1755
  FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1756 1757 1758 1759 1760 1761 1762
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    NotifyRouteChange (IPHLPAPI.@)
 *
1763
 * Notify caller whenever the ip routing table is changed.
1764 1765
 *
 * PARAMS
1766 1767
 *  Handle     [Out] handle useable in asynchronus notification
 *  overlapped [In]  overlapped structure that notifies the caller
1768 1769
 *
 * RETURNS
1770 1771
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1772
 *
1773 1774
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
1775 1776 1777
 */
DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
{
1778
  FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
1779 1780 1781 1782 1783 1784 1785
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    SendARP (IPHLPAPI.@)
 *
1786
 * Send an ARP request.
1787 1788
 *
 * PARAMS
1789
 *  DestIP     [In]     attempt to obtain this IP
1790 1791 1792
 *  SrcIP      [In]     optional sender IP address
 *  pMacAddr   [Out]    buffer for the mac address
 *  PhyAddrLen [In/Out] length of the output buffer
1793 1794
 *
 * RETURNS
1795 1796
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1797
 *
1798 1799
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
1800 1801 1802
 */
DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
{
1803 1804
  FIXME("(DestIP 0x%08lx, SrcIP 0x%08lx, pMacAddr %p, PhyAddrLen %p): stub\n",
   DestIP, SrcIP, pMacAddr, PhyAddrLen);
1805 1806 1807 1808 1809 1810 1811
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    SetIfEntry (IPHLPAPI.@)
 *
1812
 * Set the administrative status of an interface.
1813 1814
 *
 * PARAMS
1815
 *  pIfRow [In] dwAdminStatus member specifies the new status.
1816 1817
 *
 * RETURNS
1818 1819
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1820
 *
1821 1822
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
1823 1824 1825
 */
DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
{
1826
  FIXME("(pIfRow %p): stub\n", pIfRow);
1827
  /* this is supposed to set an interface administratively up or down.
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837
     Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
     this sort of down is indistinguishable from other sorts of down (e.g. no
     link). */
  return ERROR_NOT_SUPPORTED;
}


/******************************************************************
 *    SetIpForwardEntry (IPHLPAPI.@)
 *
1838
 * Modify an existing route.
1839 1840
 *
 * PARAMS
1841
 *  pRoute [In] route with the new information
1842 1843
 *
 * RETURNS
1844 1845
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1846
 *
1847 1848
 * FIXME
 *  Stub, returns NO_ERROR.
1849 1850 1851
 */
DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
{
1852
  FIXME("(pRoute %p): stub\n", pRoute);
1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
  /* this is to add a route entry, how's it distinguishable from
     CreateIpForwardEntry?
     could use SIOCADDRT, not sure I want to */
  return (DWORD) 0;
}


/******************************************************************
 *    SetIpNetEntry (IPHLPAPI.@)
 *
1863
 * Modify an existing ARP entry.
1864 1865
 *
 * PARAMS
1866
 *  pArpEntry [In] ARP entry with the new information
1867 1868
 *
 * RETURNS
1869 1870
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1871
 *
1872 1873
 * FIXME
 *  Stub, returns NO_ERROR.
1874 1875 1876
 */
DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
{
1877
  FIXME("(pArpEntry %p): stub\n", pArpEntry);
1878 1879 1880 1881 1882 1883 1884 1885
  /* same as CreateIpNetEntry here, could use SIOCSARP, not sure I want to */
  return (DWORD) 0;
}


/******************************************************************
 *    SetIpStatistics (IPHLPAPI.@)
 *
1886
 * Toggle IP forwarding and det the default TTL value.
1887 1888
 *
 * PARAMS
1889
 *  pIpStats [In] IP statistics with the new information
1890 1891
 *
 * RETURNS
1892 1893
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1894
 *
1895 1896
 * FIXME
 *  Stub, returns NO_ERROR.
1897 1898 1899
 */
DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
{
1900
  FIXME("(pIpStats %p): stub\n", pIpStats);
1901 1902 1903 1904 1905 1906 1907
  return (DWORD) 0;
}


/******************************************************************
 *    SetIpTTL (IPHLPAPI.@)
 *
1908
 * Set the default TTL value.
1909 1910
 *
 * PARAMS
1911
 *  nTTL [In] new TTL value
1912 1913
 *
 * RETURNS
1914 1915
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1916
 *
1917 1918
 * FIXME
 *  Stub, returns NO_ERROR.
1919 1920 1921
 */
DWORD WINAPI SetIpTTL(UINT nTTL)
{
1922
  FIXME("(nTTL %d): stub\n", nTTL);
1923 1924 1925 1926 1927 1928 1929 1930 1931
  /* could echo nTTL > /proc/net/sys/net/ipv4/ip_default_ttl, not sure I
     want to.  Could map EACCESS to ERROR_ACCESS_DENIED, I suppose */
  return (DWORD) 0;
}


/******************************************************************
 *    SetTcpEntry (IPHLPAPI.@)
 *
1932
 * Set the state of a TCP connection.
1933 1934
 *
 * PARAMS
1935
 *  pTcpRow [In] specifies connection with new state
1936 1937
 *
 * RETURNS
1938 1939
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1940
 *
1941 1942
 * FIXME
 *  Stub, returns NO_ERROR.
1943 1944 1945
 */
DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
{
1946
  FIXME("(pTcpRow %p): stub\n", pTcpRow);
1947 1948 1949 1950 1951 1952 1953
  return (DWORD) 0;
}


/******************************************************************
 *    UnenableRouter (IPHLPAPI.@)
 *
1954 1955
 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
 * if it reaches zero.
1956 1957
 *
 * PARAMS
1958 1959
 *  pOverlapped     [In/Out] should be the same as in EnableRouter()
 *  lpdwEnableCount [Out]    optional, receives reference count
1960 1961
 *
 * RETURNS
1962 1963
 *  Success: NO_ERROR
 *  Failure: error code from winerror.h
1964
 *
1965 1966
 * FIXME
 *  Stub, returns ERROR_NOT_SUPPORTED.
1967 1968 1969
 */
DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
{
1970 1971
  FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
   lpdwEnableCount);
1972 1973
  /* could echo "0" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
     could map EACCESS to ERROR_ACCESS_DENIED, I suppose
1974
   */
1975 1976
  return ERROR_NOT_SUPPORTED;
}