[IPHLPAPI] Implement AllocateAndGetUdpExTable2FromStack()
[reactos.git] / dll / win32 / iphlpapi / iphlpapi_main.c
1 /*
2 * iphlpapi dll implementation
3 *
4 * Copyright (C) 2003 Juan Lang
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #define DEBUG
22
23 #include <config.h>
24 #include "iphlpapi_private.h"
25 #include <strsafe.h>
26
27 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
28
29 typedef struct _NAME_SERVER_LIST_CONTEXT {
30 ULONG uSizeAvailable;
31 ULONG uSizeRequired;
32 PIP_PER_ADAPTER_INFO pData;
33 UINT NumServers;
34 IP_ADDR_STRING *pLastAddr;
35 } NAME_SERVER_LIST_CONTEXT, *PNAME_SERVER_LIST_CONTEXT;
36
37 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
38 {
39 switch (fdwReason) {
40 case DLL_PROCESS_ATTACH:
41 DisableThreadLibraryCalls( hinstDLL );
42 interfaceMapInit();
43 break;
44
45 case DLL_PROCESS_DETACH:
46 interfaceMapFree();
47 break;
48 }
49 return TRUE;
50 }
51
52 /******************************************************************
53 * AddIPAddress (IPHLPAPI.@)
54 *
55 *
56 * PARAMS
57 *
58 * Address [In]
59 * IpMask [In]
60 * IfIndex [In]
61 * NTEContext [In/Out]
62 * NTEInstance [In/Out]
63 *
64 * RETURNS
65 *
66 * DWORD
67 *
68 */
69 DWORD WINAPI AddIPAddress(IPAddr Address, IPMask Netmask, DWORD IfIndex, PULONG NteContext, PULONG NteInstance)
70 {
71 return RtlNtStatusToDosError(addIPAddress(Address, Netmask, IfIndex, NteContext, NteInstance));
72 }
73
74 DWORD getInterfaceGatewayByIndex(DWORD index)
75 {
76 DWORD ndx, retVal = 0, numRoutes = getNumRoutes();
77 RouteTable *table = getRouteTable();
78 if (!table) return 0;
79
80 for (ndx = 0; ndx < numRoutes; ndx++)
81 {
82 if ((table->routes[ndx].ifIndex == (index)) && (table->routes[ndx].dest == 0))
83 retVal = table->routes[ndx].gateway;
84 }
85 HeapFree(GetProcessHeap(), 0, table);
86 return retVal;
87 }
88
89 /******************************************************************
90 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
91 *
92 *
93 * PARAMS
94 *
95 * ppIfTable [Out] -- pointer into which the MIB_IFTABLE is
96 * allocated and returned.
97 * bOrder [In] -- passed to GetIfTable to order the table
98 * heap [In] -- heap from which the table is allocated
99 * flags [In] -- flags to HeapAlloc
100 *
101 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
102 * GetIfTable returns otherwise
103 *
104 */
105 DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
106 BOOL bOrder, HANDLE heap, DWORD flags)
107 {
108 DWORD ret;
109
110 TRACE("ppIfTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n", ppIfTable,
111 (DWORD)bOrder, (DWORD)heap, flags);
112 if (!ppIfTable)
113 ret = ERROR_INVALID_PARAMETER;
114 else {
115 DWORD dwSize = 0;
116
117 *ppIfTable = NULL;
118 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
119 if (ret == ERROR_INSUFFICIENT_BUFFER) {
120 *ppIfTable = (PMIB_IFTABLE)HeapAlloc(heap, flags, dwSize);
121 ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
122 if (ret != NO_ERROR) {
123 HeapFree(heap, flags, *ppIfTable);
124 *ppIfTable = NULL;
125 }
126 }
127 }
128 TRACE("returning %ld\n", ret);
129 return ret;
130 }
131
132
133 /******************************************************************
134 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
135 *
136 *
137 * PARAMS
138 *
139 * ppIpAddrTable [Out]
140 * bOrder [In] -- passed to GetIpAddrTable to order the table
141 * heap [In] -- heap from which the table is allocated
142 * flags [In] -- flags to HeapAlloc
143 *
144 * RETURNS
145 *
146 * DWORD
147 *
148 */
149 DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
150 BOOL bOrder, HANDLE heap, DWORD flags)
151 {
152 DWORD ret;
153
154 TRACE("ppIpAddrTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
155 ppIpAddrTable, (DWORD)bOrder, (DWORD)heap, flags);
156 if (!ppIpAddrTable)
157 ret = ERROR_INVALID_PARAMETER;
158 else {
159 DWORD dwSize = 0;
160
161 *ppIpAddrTable = NULL;
162 ret = GetIpAddrTable(*ppIpAddrTable, &dwSize, bOrder);
163 if (ret == ERROR_INSUFFICIENT_BUFFER) {
164 *ppIpAddrTable = (PMIB_IPADDRTABLE)HeapAlloc(heap, flags, dwSize);
165 ret = GetIpAddrTable(*ppIpAddrTable, &dwSize, bOrder);
166 if (ret != NO_ERROR) {
167 HeapFree(heap, flags, *ppIpAddrTable);
168 *ppIpAddrTable = NULL;
169 }
170 }
171 }
172 TRACE("returning %ld\n", ret);
173 return ret;
174 }
175
176
177 /******************************************************************
178 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
179 *
180 *
181 * ppIpForwardTable [Out] -- pointer into which the MIB_IPFORWARDTABLE is
182 * allocated and returned.
183 * bOrder [In] -- passed to GetIfTable to order the table
184 * heap [In] -- heap from which the table is allocated
185 * flags [In] -- flags to HeapAlloc
186 *
187 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
188 * GetIpForwardTable returns otherwise
189 *
190 */
191 DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
192 ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags)
193 {
194 DWORD ret;
195
196 TRACE("ppIpForwardTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
197 ppIpForwardTable, (DWORD)bOrder, (DWORD)heap, flags);
198 if (!ppIpForwardTable)
199 ret = ERROR_INVALID_PARAMETER;
200 else {
201 DWORD dwSize = 0;
202
203 *ppIpForwardTable = NULL;
204 ret = GetIpForwardTable(*ppIpForwardTable, &dwSize, bOrder);
205 if (ret == ERROR_INSUFFICIENT_BUFFER) {
206 *ppIpForwardTable = (PMIB_IPFORWARDTABLE)HeapAlloc(heap, flags, dwSize);
207 ret = GetIpForwardTable(*ppIpForwardTable, &dwSize, bOrder);
208 if (ret != NO_ERROR) {
209 HeapFree(heap, flags, *ppIpForwardTable);
210 *ppIpForwardTable = NULL;
211 }
212 }
213 }
214 TRACE("returning %ld\n", ret);
215 return ret;
216 }
217
218
219 /******************************************************************
220 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
221 *
222 *
223 * PARAMS
224 *
225 * ppIpNetTable [Out]
226 * bOrder [In] -- passed to GetIpNetTable to order the table
227 * heap [In] -- heap from which the table is allocated
228 * flags [In] -- flags to HeapAlloc
229 *
230 * RETURNS
231 *
232 * DWORD
233 *
234 */
235 DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable,
236 BOOL bOrder, HANDLE heap, DWORD flags)
237 {
238 DWORD ret;
239
240 TRACE("ppIpNetTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
241 ppIpNetTable, (DWORD)bOrder, (DWORD)heap, flags);
242 if (!ppIpNetTable)
243 ret = ERROR_INVALID_PARAMETER;
244 else {
245 DWORD dwSize = 0;
246
247 *ppIpNetTable = NULL;
248 ret = GetIpNetTable(*ppIpNetTable, &dwSize, bOrder);
249 if (ret == ERROR_INSUFFICIENT_BUFFER) {
250 *ppIpNetTable = (PMIB_IPNETTABLE)HeapAlloc(heap, flags, dwSize);
251 ret = GetIpNetTable(*ppIpNetTable, &dwSize, bOrder);
252 if (ret != NO_ERROR) {
253 HeapFree(heap, flags, *ppIpNetTable);
254 *ppIpNetTable = NULL;
255 }
256 }
257 }
258 TRACE("returning %ld\n", ret);
259 return ret;
260 }
261
262
263 /******************************************************************
264 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
265 *
266 *
267 * PARAMS
268 *
269 * ppTcpTable [Out]
270 * bOrder [In] -- passed to GetTcpTable to order the table
271 * heap [In] -- heap from which the table is allocated
272 * flags [In] -- flags to HeapAlloc
273 *
274 * RETURNS
275 *
276 * DWORD
277 *
278 */
279 DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
280 BOOL bOrder, HANDLE heap, DWORD flags)
281 {
282 DWORD ret;
283
284 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
285 ppTcpTable, (DWORD)bOrder, (DWORD)heap, flags);
286 if (!ppTcpTable)
287 ret = ERROR_INVALID_PARAMETER;
288 else {
289 DWORD dwSize = 0;
290
291 *ppTcpTable = NULL;
292 ret = GetTcpTable(*ppTcpTable, &dwSize, bOrder);
293 if (ret == ERROR_INSUFFICIENT_BUFFER) {
294 *ppTcpTable = (PMIB_TCPTABLE)HeapAlloc(heap, flags, dwSize);
295 ret = GetTcpTable(*ppTcpTable, &dwSize, bOrder);
296 if (ret != NO_ERROR) {
297 HeapFree(heap, flags, *ppTcpTable);
298 *ppTcpTable = NULL;
299 }
300 }
301 }
302 TRACE("returning %ld\n", ret);
303 return ret;
304 }
305
306
307 /******************************************************************
308 * AllocateAndGetTcpExTableFromStack (IPHLPAPI.@)
309 *
310 *
311 * PARAMS
312 *
313 * ppTcpTable [Out]
314 * bOrder [In] -- passed to GetExtendedTcpTable to order the table
315 * heap [In] -- heap from which the table is allocated
316 * flags [In] -- flags to HeapAlloc
317 * family [In] -- passed to GetExtendedTcpTable to select INET family
318 *
319 * RETURNS
320 *
321 * DWORD
322 *
323 */
324 DWORD WINAPI AllocateAndGetTcpExTableFromStack(PMIB_TCPTABLE_OWNER_PID *ppTcpTable,
325 BOOL bOrder, HANDLE heap, DWORD flags, DWORD family)
326 {
327 DWORD ret;
328
329 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family 0x%08lx\n",
330 ppTcpTable, (DWORD)bOrder, (DWORD)heap, flags, family);
331 if (!ppTcpTable)
332 ret = ERROR_INVALID_PARAMETER;
333 else {
334 DWORD dwSize = 0;
335
336 *ppTcpTable = NULL;
337 ret = GetExtendedTcpTable(*ppTcpTable, &dwSize, bOrder, family, TCP_TABLE_OWNER_PID_ALL, 0);
338 if (ret == ERROR_INSUFFICIENT_BUFFER) {
339 *ppTcpTable = (PMIB_TCPTABLE_OWNER_PID)HeapAlloc(heap, flags, dwSize);
340 ret = GetExtendedTcpTable(*ppTcpTable, &dwSize, bOrder, family, TCP_TABLE_OWNER_PID_ALL, 0);
341 if (ret != NO_ERROR) {
342 HeapFree(heap, flags, *ppTcpTable);
343 *ppTcpTable = NULL;
344 }
345 }
346 }
347 TRACE("returning %ld\n", ret);
348 return ret;
349 }
350
351
352 /******************************************************************
353 * AllocateAndGetTcpExTable2FromStack (IPHLPAPI.@)
354 *
355 *
356 * PARAMS
357 *
358 * ppTcpTable [Out]
359 * bOrder [In] -- passed to GetExtendedTcpTable to order the table
360 * heap [In] -- heap from which the table is allocated
361 * flags [In] -- flags to HeapAlloc
362 * family [In] -- passed to GetExtendedTcpTable to select INET family
363 * class [In] -- passed to GetExtendedTcpTable to select information
364 *
365 * RETURNS
366 *
367 * DWORD
368 *
369 */
370 DWORD WINAPI AllocateAndGetTcpExTable2FromStack(PVOID *ppTcpTable,
371 BOOL bOrder, HANDLE heap, DWORD flags, DWORD family, TCP_TABLE_CLASS class)
372 {
373 DWORD ret;
374
375 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family %ld, class %ld\n",
376 ppTcpTable, (DWORD)bOrder, (DWORD)heap, flags, family, class);
377 if (!ppTcpTable)
378 ret = ERROR_INVALID_PARAMETER;
379 else {
380 DWORD dwSize = 0;
381
382 *ppTcpTable = NULL;
383 ret = GetExtendedTcpTable(*ppTcpTable, &dwSize, bOrder, family, class, 0);
384 if (ret == ERROR_INSUFFICIENT_BUFFER) {
385 *ppTcpTable = HeapAlloc(heap, flags, dwSize);
386 ret = GetExtendedTcpTable(*ppTcpTable, &dwSize, bOrder, family, class, 0);
387 if (ret != NO_ERROR) {
388 HeapFree(heap, flags, *ppTcpTable);
389 *ppTcpTable = NULL;
390 }
391 }
392 }
393 TRACE("returning %ld\n", ret);
394 return ret;
395 }
396
397
398 /******************************************************************
399 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
400 *
401 *
402 * PARAMS
403 *
404 * ppUdpTable [Out]
405 * bOrder [In] -- passed to GetUdpTable to order the table
406 * heap [In] -- heap from which the table is allocated
407 * flags [In] -- flags to HeapAlloc
408 *
409 * RETURNS
410 *
411 * DWORD
412 *
413 */
414 DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
415 BOOL bOrder, HANDLE heap, DWORD flags)
416 {
417 DWORD ret;
418
419 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
420 ppUdpTable, (DWORD)bOrder, (DWORD)heap, flags);
421 if (!ppUdpTable)
422 ret = ERROR_INVALID_PARAMETER;
423 else {
424 DWORD dwSize = 0;
425
426 *ppUdpTable = NULL;
427 ret = GetUdpTable(*ppUdpTable, &dwSize, bOrder);
428 if (ret == ERROR_INSUFFICIENT_BUFFER) {
429 *ppUdpTable = (PMIB_UDPTABLE)HeapAlloc(heap, flags, dwSize);
430 ret = GetUdpTable(*ppUdpTable, &dwSize, bOrder);
431 if (ret != NO_ERROR) {
432 HeapFree(heap, flags, *ppUdpTable);
433 *ppUdpTable = NULL;
434 }
435 }
436 }
437 TRACE("returning %ld\n", ret);
438 return ret;
439 }
440
441
442 /******************************************************************
443 * AllocateAndGetUdpExTableFromStack (IPHLPAPI.@)
444 *
445 *
446 * PARAMS
447 *
448 * ppUdpTable [Out]
449 * bOrder [In] -- passed to GetExtendedUdpTable to order the table
450 * heap [In] -- heap from which the table is allocated
451 * flags [In] -- flags to HeapAlloc
452 * family [In] -- passed to GetExtendedUdpTable to select INET family
453 *
454 * RETURNS
455 *
456 * DWORD
457 *
458 */
459 DWORD WINAPI AllocateAndGetUdpExTableFromStack(PMIB_UDPTABLE_OWNER_PID *ppUdpTable,
460 BOOL bOrder, HANDLE heap, DWORD flags, DWORD family)
461 {
462 DWORD ret;
463
464 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family 0x%08lx\n",
465 ppUdpTable, (DWORD)bOrder, (DWORD)heap, flags, family);
466 if (!ppUdpTable)
467 ret = ERROR_INVALID_PARAMETER;
468 else {
469 DWORD dwSize = 0;
470
471 *ppUdpTable = NULL;
472 ret = GetExtendedUdpTable(*ppUdpTable, &dwSize, bOrder, family, UDP_TABLE_OWNER_PID, 0);
473 if (ret == ERROR_INSUFFICIENT_BUFFER) {
474 *ppUdpTable = (PMIB_UDPTABLE_OWNER_PID)HeapAlloc(heap, flags, dwSize);
475 ret = GetExtendedUdpTable(*ppUdpTable, &dwSize, bOrder, family, UDP_TABLE_OWNER_PID, 0);
476 if (ret != NO_ERROR) {
477 HeapFree(heap, flags, *ppUdpTable);
478 *ppUdpTable = NULL;
479 }
480 }
481 }
482 TRACE("returning %ld\n", ret);
483 return ret;
484 }
485
486
487 /******************************************************************
488 * AllocateAndGetUdpExTable2FromStack (IPHLPAPI.@)
489 *
490 *
491 * PARAMS
492 *
493 * ppUdpTable [Out]
494 * bOrder [In] -- passed to GetExtendedUdpTable to order the table
495 * heap [In] -- heap from which the table is allocated
496 * flags [In] -- flags to HeapAlloc
497 * family [In] -- passed to GetExtendedUdpTable to select INET family
498 * class [In] -- passed to GetExtendedUdpTable to select information
499 *
500 * RETURNS
501 *
502 * DWORD
503 *
504 */
505 DWORD WINAPI AllocateAndGetUdpExTable2FromStack(PVOID *ppUdpTable,
506 BOOL bOrder, HANDLE heap, DWORD flags, DWORD family, UDP_TABLE_CLASS class)
507 {
508 DWORD ret;
509
510 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family %ld, class %ld\n",
511 ppUdpTable, (DWORD)bOrder, (DWORD)heap, flags, family, class);
512 if (!ppUdpTable)
513 ret = ERROR_INVALID_PARAMETER;
514 else {
515 DWORD dwSize = 0;
516
517 *ppUdpTable = NULL;
518 ret = GetExtendedUdpTable(*ppUdpTable, &dwSize, bOrder, family, class, 0);
519 if (ret == ERROR_INSUFFICIENT_BUFFER) {
520 *ppUdpTable = HeapAlloc(heap, flags, dwSize);
521 ret = GetExtendedUdpTable(*ppUdpTable, &dwSize, bOrder, family, class, 0);
522 if (ret != NO_ERROR) {
523 HeapFree(heap, flags, *ppUdpTable);
524 *ppUdpTable = NULL;
525 }
526 }
527 }
528 TRACE("returning %ld\n", ret);
529 return ret;
530 }
531
532
533 /******************************************************************
534 * CreateIpForwardEntry (IPHLPAPI.@)
535 *
536 *
537 * PARAMS
538 *
539 * pRoute [In/Out]
540 *
541 * RETURNS
542 *
543 * DWORD
544 *
545 */
546 DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
547 {
548 return createIpForwardEntry( pRoute );
549 }
550
551
552 /******************************************************************
553 * CreateIpNetEntry (IPHLPAPI.@)
554 *
555 *
556 * PARAMS
557 *
558 * pArpEntry [In/Out]
559 *
560 * RETURNS
561 *
562 * DWORD
563 *
564 */
565 DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry)
566 {
567 TRACE("pArpEntry %p\n", pArpEntry);
568 /* could use SIOCSARP on systems that support it, not sure I want to */
569 FIXME(":stub\n");
570 return (DWORD) 0;
571 }
572
573
574 /******************************************************************
575 * CreateProxyArpEntry (IPHLPAPI.@)
576 *
577 *
578 * PARAMS
579 *
580 * dwAddress [In]
581 * dwMask [In]
582 * dwIfIndex [In]
583 *
584 * RETURNS
585 *
586 * DWORD
587 *
588 */
589 DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
590 {
591 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress,
592 dwMask, dwIfIndex);
593 FIXME(":stub\n");
594 /* marking Win2K+ functions not supported */
595 return ERROR_NOT_SUPPORTED;
596 }
597
598
599 /******************************************************************
600 * DeleteIPAddress (IPHLPAPI.@)
601 *
602 *
603 * PARAMS
604 *
605 * NTEContext [In]
606 *
607 * RETURNS
608 *
609 * DWORD
610 *
611 */
612 DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
613 {
614 TRACE("NTEContext %ld\n", NTEContext);
615 return RtlNtStatusToDosError(deleteIpAddress(NTEContext));
616 }
617
618
619 /******************************************************************
620 * DeleteIpForwardEntry (IPHLPAPI.@)
621 *
622 *
623 * PARAMS
624 *
625 * pRoute [In/Out]
626 *
627 * RETURNS
628 *
629 * DWORD
630 *
631 */
632 DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
633 {
634 return deleteIpForwardEntry( pRoute );
635 }
636
637
638 /******************************************************************
639 * DeleteIpNetEntry (IPHLPAPI.@)
640 *
641 *
642 * PARAMS
643 *
644 * pArpEntry [In/Out]
645 *
646 * RETURNS
647 *
648 * DWORD
649 *
650 */
651 DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
652 {
653 TRACE("pArpEntry %p\n", pArpEntry);
654 /* could use SIOCDARP on systems that support it, not sure I want to */
655 FIXME(":stub\n");
656 return (DWORD) 0;
657 }
658
659
660 /******************************************************************
661 * DeleteProxyArpEntry (IPHLPAPI.@)
662 *
663 *
664 * PARAMS
665 *
666 * dwAddress [In]
667 * dwMask [In]
668 * dwIfIndex [In]
669 *
670 * RETURNS
671 *
672 * DWORD
673 *
674 */
675 DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
676 {
677 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress,
678 dwMask, dwIfIndex);
679 FIXME(":stub\n");
680 /* marking Win2K+ functions not supported */
681 return ERROR_NOT_SUPPORTED;
682 }
683
684 /******************************************************************
685 * EnableRouter (IPHLPAPI.@)
686 *
687 *
688 * PARAMS
689 *
690 * pHandle [In/Out]
691 * pOverlapped [In/Out]
692 *
693 * RETURNS
694 *
695 * DWORD
696 *
697 */
698 DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped)
699 {
700 TRACE("pHandle %p, pOverlapped %p\n", pHandle, pOverlapped);
701 FIXME(":stub\n");
702 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
703 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
704 marking Win2K+ functions not supported */
705 return ERROR_NOT_SUPPORTED;
706 }
707
708
709 /******************************************************************
710 * FlushIpNetTable (IPHLPAPI.@)
711 *
712 *
713 * PARAMS
714 *
715 * dwIfIndex [In]
716 *
717 * RETURNS
718 *
719 * DWORD
720 *
721 */
722 DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
723 {
724 TRACE("dwIfIndex 0x%08lx\n", dwIfIndex);
725 FIXME(":stub\n");
726 /* this flushes the arp cache of the given index
727 marking Win2K+ functions not supported */
728 return ERROR_NOT_SUPPORTED;
729 }
730
731
732 /******************************************************************
733 * GetAdapterIndex (IPHLPAPI.@)
734 *
735 *
736 * PARAMS
737 *
738 * AdapterName [In/Out]
739 * IfIndex [In/Out]
740 *
741 * RETURNS
742 *
743 * DWORD
744 *
745 */
746 DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
747 {
748 TRACE("AdapterName %p, IfIndex %p\n", AdapterName, IfIndex);
749 FIXME(":stub\n");
750 /* marking Win2K+ functions not supported */
751 return ERROR_NOT_SUPPORTED;
752 }
753
754
755 /******************************************************************
756 * GetAdaptersInfo (IPHLPAPI.@)
757 *
758 *
759 * PARAMS
760 *
761 * pAdapterInfo [In/Out]
762 * pOutBufLen [In/Out]
763 *
764 * RETURNS
765 *
766 * DWORD
767 *
768 */
769 DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
770 {
771 DWORD ret;
772 BOOL dhcpEnabled;
773 DWORD dhcpServer;
774
775 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
776 if (!pOutBufLen)
777 ret = ERROR_INVALID_PARAMETER;
778 else {
779 DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
780
781 if (numNonLoopbackInterfaces > 0) {
782 /* this calculation assumes only one address in the IP_ADDR_STRING lists.
783 that's okay, because:
784 - we don't get multiple addresses per adapter anyway
785 - we don't know about per-adapter gateways
786 - DHCP and WINS servers can have max one entry per list */
787 ULONG size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
788
789 if (!pAdapterInfo || *pOutBufLen < size) {
790 *pOutBufLen = size;
791 ret = ERROR_BUFFER_OVERFLOW;
792 }
793 else {
794 InterfaceIndexTable *table = getNonLoopbackInterfaceIndexTable();
795
796 if (table) {
797 size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
798 if (*pOutBufLen < size) {
799 *pOutBufLen = size;
800 ret = ERROR_INSUFFICIENT_BUFFER;
801 }
802 else {
803 DWORD ndx;
804 HKEY hKey;
805 BOOL winsEnabled = FALSE;
806 IP_ADDRESS_STRING primaryWINS, secondaryWINS;
807
808 memset(pAdapterInfo, 0, size);
809 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
810 "Software\\Wine\\Wine\\Config\\Network", 0, KEY_READ,
811 &hKey) == ERROR_SUCCESS) {
812 DWORD size = sizeof(primaryWINS.String);
813 unsigned long addr;
814
815 RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
816 (PBYTE)primaryWINS.String, &size);
817 addr = inet_addr(primaryWINS.String);
818 if (addr != INADDR_NONE && addr != INADDR_ANY)
819 winsEnabled = TRUE;
820 size = sizeof(secondaryWINS.String);
821 RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
822 (PBYTE)secondaryWINS.String, &size);
823 addr = inet_addr(secondaryWINS.String);
824 if (addr != INADDR_NONE && addr != INADDR_ANY)
825 winsEnabled = TRUE;
826 RegCloseKey(hKey);
827 }
828 TRACE("num of index is %lu\n", table->numIndexes);
829 for (ndx = 0; ndx < table->numIndexes; ndx++) {
830 PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx];
831 DWORD addrLen = sizeof(ptr->Address), type;
832 const char *ifname =
833 getInterfaceNameByIndex(table->indexes[ndx]);
834 if (!ifname) {
835 ret = ERROR_OUTOFMEMORY;
836 break;
837 }
838
839 /* on Win98 this is left empty, but whatever */
840 strncpy(ptr->AdapterName,ifname,sizeof(ptr->AdapterName));
841 consumeInterfaceName(ifname);
842 ptr->AdapterName[MAX_ADAPTER_NAME_LENGTH] = '\0';
843 getInterfacePhysicalByIndex(table->indexes[ndx], &addrLen,
844 ptr->Address, &type);
845 /* MS defines address length and type as UINT in some places and
846 DWORD in others, **sigh**. Don't want to assume that PUINT and
847 PDWORD are equiv (64-bit?) */
848 ptr->AddressLength = addrLen;
849 ptr->Type = type;
850 ptr->Index = table->indexes[ndx];
851 toIPAddressString(getInterfaceIPAddrByIndex(table->indexes[ndx]),
852 ptr->IpAddressList.IpAddress.String);
853 toIPAddressString(getInterfaceMaskByIndex(table->indexes[ndx]),
854 ptr->IpAddressList.IpMask.String);
855 ptr->IpAddressList.Context = ptr->Index;
856 toIPAddressString(getInterfaceGatewayByIndex(table->indexes[ndx]),
857 ptr->GatewayList.IpAddress.String);
858 getDhcpInfoForAdapter(table->indexes[ndx], &dhcpEnabled,
859 &dhcpServer, &ptr->LeaseObtained,
860 &ptr->LeaseExpires);
861 ptr->DhcpEnabled = (DWORD) dhcpEnabled;
862 toIPAddressString(dhcpServer,
863 ptr->DhcpServer.IpAddress.String);
864 if (winsEnabled) {
865 ptr->HaveWins = TRUE;
866 memcpy(ptr->PrimaryWinsServer.IpAddress.String,
867 primaryWINS.String, sizeof(primaryWINS.String));
868 memcpy(ptr->SecondaryWinsServer.IpAddress.String,
869 secondaryWINS.String, sizeof(secondaryWINS.String));
870 }
871 if (ndx < table->numIndexes - 1)
872 ptr->Next = &pAdapterInfo[ndx + 1];
873 else
874 ptr->Next = NULL;
875 }
876 ret = NO_ERROR;
877 }
878 free(table);
879 }
880 else
881 ret = ERROR_OUTOFMEMORY;
882 }
883 }
884 else
885 ret = ERROR_NO_DATA;
886 }
887 TRACE("returning %ld\n", ret);
888 return ret;
889 }
890
891
892 /******************************************************************
893 * GetBestInterface (IPHLPAPI.@)
894 *
895 *
896 * PARAMS
897 *
898 * dwDestAddr [In]
899 * pdwBestIfIndex [In/Out]
900 *
901 * RETURNS
902 *
903 * DWORD
904 *
905 */
906 DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex)
907 {
908 DWORD ret;
909
910 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex);
911 if (!pdwBestIfIndex)
912 ret = ERROR_INVALID_PARAMETER;
913 else {
914 MIB_IPFORWARDROW ipRow;
915
916 ret = GetBestRoute(dwDestAddr, 0, &ipRow);
917 if (ret == ERROR_SUCCESS)
918 *pdwBestIfIndex = ipRow.dwForwardIfIndex;
919 }
920 TRACE("returning %ld\n", ret);
921 return ret;
922 }
923
924
925 /******************************************************************
926 * GetBestRoute (IPHLPAPI.@)
927 *
928 *
929 * PARAMS
930 *
931 * dwDestAddr [In]
932 * dwSourceAddr [In]
933 * OUT [In]
934 *
935 * RETURNS
936 *
937 * DWORD
938 *
939 */
940 DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute)
941 {
942 PMIB_IPFORWARDTABLE table;
943 DWORD ret;
944
945 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr,
946 dwSourceAddr, pBestRoute);
947 if (!pBestRoute)
948 return ERROR_INVALID_PARAMETER;
949
950 AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0);
951 if (table) {
952 DWORD ndx, minMaskSize, matchedNdx = 0;
953
954 for (ndx = 0, minMaskSize = 255; ndx < table->dwNumEntries; ndx++) {
955 if ((dwDestAddr & table->table[ndx].dwForwardMask) ==
956 (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) {
957 DWORD hostMaskSize;
958
959 if (!_BitScanForward(&hostMaskSize, ntohl(table->table[ndx].dwForwardMask)))
960 {
961 hostMaskSize = 32;
962 }
963 if (hostMaskSize < minMaskSize) {
964 minMaskSize = hostMaskSize;
965 matchedNdx = ndx;
966 }
967 }
968 }
969 memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW));
970 HeapFree(GetProcessHeap(), 0, table);
971 ret = ERROR_SUCCESS;
972 }
973 else
974 ret = ERROR_OUTOFMEMORY;
975 TRACE("returning %ld\n", ret);
976 return ret;
977 }
978
979 static int TcpTableSorter(const void *a, const void *b)
980 {
981 int ret;
982
983 if (a && b) {
984 PMIB_TCPROW rowA = (PMIB_TCPROW)a, rowB = (PMIB_TCPROW)b;
985
986 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
987 if (ret == 0) {
988 ret = rowA->dwLocalPort - rowB->dwLocalPort;
989 if (ret == 0) {
990 ret = rowA->dwRemoteAddr - rowB->dwRemoteAddr;
991 if (ret == 0)
992 ret = rowA->dwRemotePort - rowB->dwRemotePort;
993 }
994 }
995 }
996 else
997 ret = 0;
998 return ret;
999 }
1000
1001 /******************************************************************
1002 * GetExtendedTcpTable (IPHLPAPI.@)
1003 *
1004 * Get the table of TCP endpoints available to the application.
1005 *
1006 * PARAMS
1007 * pTcpTable [Out] table struct with the filtered TCP endpoints available to application
1008 * pdwSize [In/Out] estimated size of the structure returned in pTcpTable, in bytes
1009 * bOrder [In] whether to order the table
1010 * ulAf [in] version of IP used by the TCP endpoints
1011 * TableClass [in] type of the TCP table structure from TCP_TABLE_CLASS
1012 * Reserved [in] reserved - this value must be zero
1013 *
1014 * RETURNS
1015 * Success: NO_ERROR
1016 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
1017 *
1018 * NOTES
1019 */
1020
1021 DWORD WINAPI GetExtendedTcpTable(PVOID pTcpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, TCP_TABLE_CLASS TableClass, ULONG Reserved)
1022 {
1023 DWORD i, count;
1024 DWORD ret = NO_ERROR;
1025
1026 if (!pdwSize)
1027 {
1028 return ERROR_INVALID_PARAMETER;
1029 }
1030
1031 if (ulAf != AF_INET)
1032 {
1033 UNIMPLEMENTED;
1034 return ERROR_INVALID_PARAMETER;
1035 }
1036
1037 switch (TableClass)
1038 {
1039 case TCP_TABLE_BASIC_ALL:
1040 {
1041 PMIB_TCPTABLE pOurTcpTable = getTcpTable();
1042 PMIB_TCPTABLE pTheirTcpTable = pTcpTable;
1043
1044 if (pOurTcpTable)
1045 {
1046 if (sizeof(DWORD) + pOurTcpTable->dwNumEntries * sizeof(MIB_TCPROW) > *pdwSize || !pTheirTcpTable)
1047 {
1048 *pdwSize = sizeof(DWORD) + pOurTcpTable->dwNumEntries * sizeof(MIB_TCPROW);
1049 ret = ERROR_INSUFFICIENT_BUFFER;
1050 }
1051 else
1052 {
1053 memcpy(pTheirTcpTable, pOurTcpTable, sizeof(DWORD) + pOurTcpTable->dwNumEntries * sizeof(MIB_TCPROW));
1054
1055 if (bOrder)
1056 qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries,
1057 sizeof(MIB_TCPROW), TcpTableSorter);
1058 }
1059
1060 free(pOurTcpTable);
1061 }
1062 }
1063 break;
1064
1065 case TCP_TABLE_BASIC_CONNECTIONS:
1066 {
1067 PMIB_TCPTABLE pOurTcpTable = getTcpTable();
1068 PMIB_TCPTABLE pTheirTcpTable = pTcpTable;
1069
1070 if (pOurTcpTable)
1071 {
1072 for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i)
1073 {
1074 if (pOurTcpTable->table[i].State != MIB_TCP_STATE_LISTEN)
1075 {
1076 ++count;
1077 }
1078 }
1079
1080 if (sizeof(DWORD) + count * sizeof(MIB_TCPROW) > *pdwSize || !pTheirTcpTable)
1081 {
1082 *pdwSize = sizeof(DWORD) + count * sizeof(MIB_TCPROW);
1083 ret = ERROR_INSUFFICIENT_BUFFER;
1084 }
1085 else
1086 {
1087 pTheirTcpTable->dwNumEntries = count;
1088
1089 for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i)
1090 {
1091 if (pOurTcpTable->table[i].State != MIB_TCP_STATE_LISTEN)
1092 {
1093 memcpy(&pTheirTcpTable->table[count], &pOurTcpTable->table[i], sizeof(MIB_TCPROW));
1094 ++count;
1095 }
1096 }
1097 ASSERT(count == pTheirTcpTable->dwNumEntries);
1098
1099 if (bOrder)
1100 qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries,
1101 sizeof(MIB_TCPROW), TcpTableSorter);
1102 }
1103
1104 free(pOurTcpTable);
1105 }
1106 }
1107 break;
1108
1109 case TCP_TABLE_BASIC_LISTENER:
1110 {
1111 PMIB_TCPTABLE pOurTcpTable = getTcpTable();
1112 PMIB_TCPTABLE pTheirTcpTable = pTcpTable;
1113
1114 if (pOurTcpTable)
1115 {
1116 for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i)
1117 {
1118 if (pOurTcpTable->table[i].State == MIB_TCP_STATE_LISTEN)
1119 {
1120 ++count;
1121 }
1122 }
1123
1124 if (sizeof(DWORD) + count * sizeof(MIB_TCPROW) > *pdwSize || !pTheirTcpTable)
1125 {
1126 *pdwSize = sizeof(DWORD) + count * sizeof(MIB_TCPROW);
1127 ret = ERROR_INSUFFICIENT_BUFFER;
1128 }
1129 else
1130 {
1131 pTheirTcpTable->dwNumEntries = count;
1132
1133 for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i)
1134 {
1135 if (pOurTcpTable->table[i].State == MIB_TCP_STATE_LISTEN)
1136 {
1137 memcpy(&pTheirTcpTable->table[count], &pOurTcpTable->table[i], sizeof(MIB_TCPROW));
1138 ++count;
1139 }
1140 }
1141 ASSERT(count == pTheirTcpTable->dwNumEntries);
1142
1143 if (bOrder)
1144 qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries,
1145 sizeof(MIB_TCPROW), TcpTableSorter);
1146 }
1147
1148 free(pOurTcpTable);
1149 }
1150 }
1151 break;
1152
1153 case TCP_TABLE_OWNER_PID_ALL:
1154 {
1155 PMIB_TCPTABLE_OWNER_PID pOurTcpTable = getOwnerTcpTable();
1156 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable = pTcpTable;
1157
1158 if (pOurTcpTable)
1159 {
1160 if (sizeof(DWORD) + pOurTcpTable->dwNumEntries * sizeof(MIB_TCPROW_OWNER_PID) > *pdwSize || !pTheirTcpTable)
1161 {
1162 *pdwSize = sizeof(DWORD) + pOurTcpTable->dwNumEntries * sizeof(MIB_TCPROW_OWNER_PID);
1163 ret = ERROR_INSUFFICIENT_BUFFER;
1164 }
1165 else
1166 {
1167 memcpy(pTheirTcpTable, pOurTcpTable, sizeof(DWORD) + pOurTcpTable->dwNumEntries * sizeof(MIB_TCPROW_OWNER_PID));
1168
1169 /* Don't sort on PID, so use basic helper */
1170 if (bOrder)
1171 qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries,
1172 sizeof(MIB_TCPROW_OWNER_PID), TcpTableSorter);
1173 }
1174
1175 free(pOurTcpTable);
1176 }
1177 }
1178 break;
1179
1180 case TCP_TABLE_OWNER_PID_CONNECTIONS:
1181 {
1182 PMIB_TCPTABLE_OWNER_PID pOurTcpTable = getOwnerTcpTable();
1183 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable = pTcpTable;
1184
1185 if (pOurTcpTable)
1186 {
1187 for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i)
1188 {
1189 if (pOurTcpTable->table[i].dwState != MIB_TCP_STATE_LISTEN)
1190 {
1191 ++count;
1192 }
1193 }
1194
1195 if (sizeof(DWORD) + count * sizeof(MIB_TCPROW_OWNER_PID) > *pdwSize || !pTheirTcpTable)
1196 {
1197 *pdwSize = sizeof(DWORD) + count * sizeof(MIB_TCPROW_OWNER_PID);
1198 ret = ERROR_INSUFFICIENT_BUFFER;
1199 }
1200 else
1201 {
1202 pTheirTcpTable->dwNumEntries = count;
1203
1204 for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i)
1205 {
1206 if (pOurTcpTable->table[i].dwState != MIB_TCP_STATE_LISTEN)
1207 {
1208 memcpy(&pTheirTcpTable->table[count], &pOurTcpTable->table[i], sizeof(MIB_TCPROW_OWNER_PID));
1209 ++count;
1210 }
1211 }
1212 ASSERT(count == pTheirTcpTable->dwNumEntries);
1213
1214 /* Don't sort on PID, so use basic helper */
1215 if (bOrder)
1216 qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries,
1217 sizeof(MIB_TCPROW_OWNER_PID), TcpTableSorter);
1218 }
1219
1220 free(pOurTcpTable);
1221 }
1222 }
1223 break;
1224
1225 case TCP_TABLE_OWNER_PID_LISTENER:
1226 {
1227 PMIB_TCPTABLE_OWNER_PID pOurTcpTable = getOwnerTcpTable();
1228 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable = pTcpTable;
1229
1230 if (pOurTcpTable)
1231 {
1232 for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i)
1233 {
1234 if (pOurTcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN)
1235 {
1236 ++count;
1237 }
1238 }
1239
1240 if (sizeof(DWORD) + count * sizeof(MIB_TCPROW_OWNER_PID) > *pdwSize || !pTheirTcpTable)
1241 {
1242 *pdwSize = sizeof(DWORD) + count * sizeof(MIB_TCPROW_OWNER_PID);
1243 ret = ERROR_INSUFFICIENT_BUFFER;
1244 }
1245 else
1246 {
1247 pTheirTcpTable->dwNumEntries = count;
1248
1249 for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i)
1250 {
1251 if (pOurTcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN)
1252 {
1253 memcpy(&pTheirTcpTable->table[count], &pOurTcpTable->table[i], sizeof(MIB_TCPROW_OWNER_PID));
1254 ++count;
1255 }
1256 }
1257 ASSERT(count == pTheirTcpTable->dwNumEntries);
1258
1259 /* Don't sort on PID, so use basic helper */
1260 if (bOrder)
1261 qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries,
1262 sizeof(MIB_TCPROW_OWNER_PID), TcpTableSorter);
1263 }
1264
1265 free(pOurTcpTable);
1266 }
1267 }
1268 break;
1269
1270 default:
1271 UNIMPLEMENTED;
1272 ret = ERROR_INVALID_PARAMETER;
1273 break;
1274 }
1275
1276 return ret;
1277 }
1278
1279
1280 static int UdpTableSorter(const void *a, const void *b)
1281 {
1282 int ret;
1283
1284 if (a && b) {
1285 PMIB_UDPROW rowA = (PMIB_UDPROW)a, rowB = (PMIB_UDPROW)b;
1286
1287 ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
1288 if (ret == 0)
1289 ret = rowA->dwLocalPort - rowB->dwLocalPort;
1290 }
1291 else
1292 ret = 0;
1293 return ret;
1294 }
1295
1296 /******************************************************************
1297 * GetExtendedUdpTable (IPHLPAPI.@)
1298 *
1299 * Get the table of UDP endpoints available to the application.
1300 *
1301 * PARAMS
1302 * pUdpTable [Out] table struct with the filtered UDP endpoints available to application
1303 * pdwSize [In/Out] estimated size of the structure returned in pUdpTable, in bytes
1304 * bOrder [In] whether to order the table
1305 * ulAf [in] version of IP used by the UDP endpoints
1306 * TableClass [in] type of the UDP table structure from UDP_TABLE_CLASS
1307 * Reserved [in] reserved - this value must be zero
1308 *
1309 * RETURNS
1310 * Success: NO_ERROR
1311 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
1312 *
1313 * NOTES
1314 */
1315
1316 DWORD WINAPI GetExtendedUdpTable(PVOID pUdpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, UDP_TABLE_CLASS TableClass, ULONG Reserved)
1317 {
1318 DWORD ret = NO_ERROR;
1319
1320 if (!pdwSize)
1321 {
1322 return ERROR_INVALID_PARAMETER;
1323 }
1324
1325 if (ulAf != AF_INET)
1326 {
1327 UNIMPLEMENTED;
1328 return ERROR_INVALID_PARAMETER;
1329 }
1330
1331 switch (TableClass)
1332 {
1333 case UDP_TABLE_BASIC:
1334 {
1335 PMIB_UDPTABLE pOurUdpTable = getUdpTable();
1336 PMIB_UDPTABLE pTheirUdpTable = pUdpTable;
1337
1338 if (pOurUdpTable)
1339 {
1340 if (sizeof(DWORD) + pOurUdpTable->dwNumEntries * sizeof(MIB_UDPROW) > *pdwSize || !pTheirUdpTable)
1341 {
1342 *pdwSize = sizeof(DWORD) + pOurUdpTable->dwNumEntries * sizeof(MIB_UDPROW);
1343 ret = ERROR_INSUFFICIENT_BUFFER;
1344 }
1345 else
1346 {
1347 memcpy(pTheirUdpTable, pOurUdpTable, sizeof(DWORD) + pOurUdpTable->dwNumEntries * sizeof(MIB_UDPROW_OWNER_PID));
1348
1349 if (bOrder)
1350 qsort(pTheirUdpTable->table, pTheirUdpTable->dwNumEntries,
1351 sizeof(MIB_UDPROW), UdpTableSorter);
1352 }
1353
1354 free(pOurUdpTable);
1355 }
1356 }
1357 break;
1358
1359 case UDP_TABLE_OWNER_PID:
1360 {
1361 PMIB_UDPTABLE_OWNER_PID pOurUdpTable = getOwnerUdpTable();
1362 PMIB_UDPTABLE_OWNER_PID pTheirUdpTable = pUdpTable;
1363
1364 if (pOurUdpTable)
1365 {
1366 if (sizeof(DWORD) + pOurUdpTable->dwNumEntries * sizeof(MIB_UDPROW_OWNER_PID) > *pdwSize || !pTheirUdpTable)
1367 {
1368 *pdwSize = sizeof(DWORD) + pOurUdpTable->dwNumEntries * sizeof(MIB_UDPROW_OWNER_PID);
1369 ret = ERROR_INSUFFICIENT_BUFFER;
1370 }
1371 else
1372 {
1373 memcpy(pTheirUdpTable, pOurUdpTable, sizeof(DWORD) + pOurUdpTable->dwNumEntries * sizeof(MIB_UDPROW_OWNER_PID));
1374
1375 if (bOrder)
1376 qsort(pTheirUdpTable->table, pTheirUdpTable->dwNumEntries,
1377 sizeof(MIB_UDPROW_OWNER_PID), UdpTableSorter);
1378 }
1379
1380 free(pOurUdpTable);
1381 }
1382 }
1383 break;
1384
1385 default:
1386 UNIMPLEMENTED;
1387 ret = ERROR_INVALID_PARAMETER;
1388 break;
1389 }
1390
1391 return ret;
1392 }
1393
1394
1395 /******************************************************************
1396 * GetFriendlyIfIndex (IPHLPAPI.@)
1397 *
1398 *
1399 * PARAMS
1400 *
1401 * IfIndex [In]
1402 *
1403 * RETURNS
1404 *
1405 * DWORD
1406 *
1407 */
1408 DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex)
1409 {
1410 /* windows doesn't validate these, either, just makes sure the top byte is
1411 cleared. I assume my ifenum module never gives an index with the top
1412 byte set. */
1413 TRACE("returning %ld\n", IfIndex);
1414 return IfIndex;
1415 }
1416
1417
1418 /******************************************************************
1419 * GetIcmpStatistics (IPHLPAPI.@)
1420 *
1421 *
1422 * PARAMS
1423 *
1424 * pStats [In/Out]
1425 *
1426 * RETURNS
1427 *
1428 * DWORD
1429 *
1430 */
1431 DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats)
1432 {
1433 DWORD ret;
1434
1435 TRACE("pStats %p\n", pStats);
1436 ret = getICMPStats(pStats);
1437 TRACE("returning %ld\n", ret);
1438 return ret;
1439 }
1440
1441
1442 /******************************************************************
1443 * GetIfEntry (IPHLPAPI.@)
1444 *
1445 *
1446 * PARAMS
1447 *
1448 * pIfRow [In/Out]
1449 *
1450 * RETURNS
1451 *
1452 * DWORD
1453 *
1454 */
1455 DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
1456 {
1457 DWORD ret;
1458 const char *name;
1459
1460 TRACE("pIfRow %p\n", pIfRow);
1461 if (!pIfRow)
1462 return ERROR_INVALID_PARAMETER;
1463
1464 name = getInterfaceNameByIndex(pIfRow->dwIndex);
1465 if (name) {
1466 ret = getInterfaceEntryByIndex(pIfRow->dwIndex, pIfRow);
1467 if (ret == NO_ERROR)
1468 ret = getInterfaceStatsByName(name, pIfRow);
1469 consumeInterfaceName(name);
1470 }
1471 else
1472 ret = ERROR_INVALID_DATA;
1473 TRACE("returning %ld\n", ret);
1474 return ret;
1475 }
1476
1477
1478 static int IfTableSorter(const void *a, const void *b)
1479 {
1480 int ret;
1481
1482 if (a && b)
1483 ret = ((PMIB_IFROW)a)->dwIndex - ((PMIB_IFROW)b)->dwIndex;
1484 else
1485 ret = 0;
1486 return ret;
1487 }
1488
1489
1490 /******************************************************************
1491 * GetIfTable (IPHLPAPI.@)
1492 *
1493 *
1494 * PARAMS
1495 *
1496 * pIfTable [In/Out]
1497 * pdwSize [In/Out]
1498 * bOrder [In]
1499 *
1500 * RETURNS
1501 *
1502 * DWORD
1503 *
1504 */
1505 DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
1506 {
1507 DWORD ret;
1508
1509 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize, pdwSize,
1510 (DWORD)bOrder);
1511 if (!pdwSize)
1512 ret = ERROR_INVALID_PARAMETER;
1513 else {
1514 DWORD numInterfaces = getNumInterfaces();
1515 ULONG size;
1516 TRACE("GetIfTable: numInterfaces = %d\n", (int)numInterfaces);
1517 size = sizeof(MIB_IFTABLE) + (numInterfaces - 1) * sizeof(MIB_IFROW);
1518
1519 if (!pIfTable || *pdwSize < size) {
1520 *pdwSize = size;
1521 ret = ERROR_INSUFFICIENT_BUFFER;
1522 }
1523 else {
1524 InterfaceIndexTable *table = getInterfaceIndexTable();
1525
1526 if (table) {
1527 size = sizeof(MIB_IFTABLE) + (table->numIndexes - 1) *
1528 sizeof(MIB_IFROW);
1529 if (*pdwSize < size) {
1530 *pdwSize = size;
1531 ret = ERROR_INSUFFICIENT_BUFFER;
1532 }
1533 else {
1534 DWORD ndx;
1535
1536 pIfTable->dwNumEntries = 0;
1537 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1538 pIfTable->table[ndx].dwIndex = table->indexes[ndx];
1539 GetIfEntry(&pIfTable->table[ndx]);
1540 pIfTable->dwNumEntries++;
1541 }
1542 if (bOrder)
1543 qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW),
1544 IfTableSorter);
1545 ret = NO_ERROR;
1546 }
1547 free(table);
1548 }
1549 else
1550 ret = ERROR_OUTOFMEMORY;
1551 }
1552 }
1553 TRACE("returning %ld\n", ret);
1554 return ret;
1555 }
1556
1557
1558 /******************************************************************
1559 * GetInterfaceInfo (IPHLPAPI.@)
1560 *
1561 *
1562 * PARAMS
1563 *
1564 * pIfTable [In/Out]
1565 * dwOutBufLen [In/Out]
1566 *
1567 * RETURNS
1568 *
1569 * DWORD
1570 *
1571 */
1572 DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
1573 {
1574 DWORD ret;
1575
1576 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen);
1577 if (!dwOutBufLen)
1578 ret = ERROR_INVALID_PARAMETER;
1579 else {
1580 DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
1581 ULONG size;
1582 TRACE("numNonLoopbackInterfaces == 0x%x\n", numNonLoopbackInterfaces);
1583 size = sizeof(IP_INTERFACE_INFO) + (numNonLoopbackInterfaces) *
1584 sizeof(IP_ADAPTER_INDEX_MAP);
1585
1586 if (!pIfTable || *dwOutBufLen < size) {
1587 *dwOutBufLen = size;
1588 ret = ERROR_INSUFFICIENT_BUFFER;
1589 }
1590 else {
1591 InterfaceIndexTable *table = getNonLoopbackInterfaceIndexTable();
1592
1593 if (table) {
1594 TRACE("table->numIndexes == 0x%x\n", table->numIndexes);
1595 size = sizeof(IP_INTERFACE_INFO) + (table->numIndexes) *
1596 sizeof(IP_ADAPTER_INDEX_MAP);
1597 if (*dwOutBufLen < size) {
1598 *dwOutBufLen = size;
1599 ret = ERROR_INSUFFICIENT_BUFFER;
1600 }
1601 else {
1602 DWORD ndx;
1603
1604 pIfTable->NumAdapters = 0;
1605 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1606 const char *walker, *name;
1607 WCHAR *assigner;
1608
1609 pIfTable->Adapter[ndx].Index = table->indexes[ndx];
1610 name = getInterfaceNameByIndex(table->indexes[ndx]);
1611 for (walker = name, assigner = pIfTable->Adapter[ndx].Name;
1612 walker && *walker &&
1613 assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1;
1614 walker++, assigner++)
1615 *assigner = *walker;
1616 *assigner = 0;
1617 consumeInterfaceName(name);
1618 pIfTable->NumAdapters++;
1619 }
1620 ret = NO_ERROR;
1621 }
1622 free(table);
1623 }
1624 else
1625 ret = ERROR_OUTOFMEMORY;
1626 }
1627 }
1628 TRACE("returning %ld\n", ret);
1629 return ret;
1630 }
1631
1632
1633 static int IpAddrTableSorter(const void *a, const void *b)
1634 {
1635 int ret;
1636
1637 if (a && b)
1638 ret = ((PMIB_IPADDRROW)a)->dwAddr - ((PMIB_IPADDRROW)b)->dwAddr;
1639 else
1640 ret = 0;
1641 return ret;
1642 }
1643
1644
1645 /******************************************************************
1646 * GetIpAddrTable (IPHLPAPI.@)
1647 *
1648 *
1649 * PARAMS
1650 *
1651 * pIpAddrTable [In/Out]
1652 * pdwSize [In/Out]
1653 * bOrder [In]
1654 *
1655 * RETURNS
1656 *
1657 * DWORD
1658 *
1659 */
1660 DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
1661 {
1662 DWORD ret;
1663
1664 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable, pdwSize,
1665 (DWORD)bOrder);
1666 if (!pdwSize)
1667 ret = ERROR_INVALID_PARAMETER;
1668 else {
1669 DWORD numInterfaces = getNumInterfaces();
1670 ULONG size = sizeof(MIB_IPADDRTABLE) + (numInterfaces - 1) *
1671 sizeof(MIB_IPADDRROW);
1672
1673 if (!pIpAddrTable || *pdwSize < size) {
1674 *pdwSize = size;
1675 ret = ERROR_INSUFFICIENT_BUFFER;
1676 }
1677 else {
1678 InterfaceIndexTable *table = getInterfaceIndexTable();
1679
1680 if (table) {
1681 size = sizeof(MIB_IPADDRTABLE) + (table->numIndexes - 1) *
1682 sizeof(MIB_IPADDRROW);
1683 if (*pdwSize < size) {
1684 *pdwSize = size;
1685 ret = ERROR_INSUFFICIENT_BUFFER;
1686 }
1687 else {
1688 DWORD ndx, bcast;
1689
1690 pIpAddrTable->dwNumEntries = 0;
1691 for (ndx = 0; ndx < table->numIndexes; ndx++) {
1692 pIpAddrTable->table[ndx].dwIndex = table->indexes[ndx];
1693 pIpAddrTable->table[ndx].dwAddr =
1694 getInterfaceIPAddrByIndex(table->indexes[ndx]);
1695 pIpAddrTable->table[ndx].dwMask =
1696 getInterfaceMaskByIndex(table->indexes[ndx]);
1697 /* the dwBCastAddr member isn't the broadcast address, it indicates
1698 * whether the interface uses the 1's broadcast address (1) or the
1699 * 0's broadcast address (0).
1700 */
1701 bcast = getInterfaceBCastAddrByIndex(table->indexes[ndx]);
1702 pIpAddrTable->table[ndx].dwBCastAddr =
1703 (bcast & pIpAddrTable->table[ndx].dwMask) ? 1 : 0;
1704 /* FIXME: hardcoded reasm size, not sure where to get it */
1705 pIpAddrTable->table[ndx].dwReasmSize = 65535;
1706 pIpAddrTable->table[ndx].unused1 = 0;
1707 pIpAddrTable->table[ndx].wType = 0; /* aka unused2 */
1708 pIpAddrTable->dwNumEntries++;
1709 }
1710 if (bOrder)
1711 qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries,
1712 sizeof(MIB_IPADDRROW), IpAddrTableSorter);
1713 ret = NO_ERROR;
1714 }
1715 free(table);
1716 }
1717 else
1718 ret = ERROR_OUTOFMEMORY;
1719 }
1720 }
1721 TRACE("returning %ld\n", ret);
1722 return ret;
1723 }
1724
1725
1726 static int IpForwardTableSorter(const void *a, const void *b)
1727 {
1728 int ret;
1729
1730 if (a && b) {
1731 PMIB_IPFORWARDROW rowA = (PMIB_IPFORWARDROW)a, rowB = (PMIB_IPFORWARDROW)b;
1732
1733 ret = rowA->dwForwardDest - rowB->dwForwardDest;
1734 if (ret == 0) {
1735 ret = rowA->dwForwardProto - rowB->dwForwardProto;
1736 if (ret == 0) {
1737 ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy;
1738 if (ret == 0)
1739 ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop;
1740 }
1741 }
1742 }
1743 else
1744 ret = 0;
1745 return ret;
1746 }
1747
1748
1749 /******************************************************************
1750 * GetIpForwardTable (IPHLPAPI.@)
1751 *
1752 *
1753 * PARAMS
1754 *
1755 * pIpForwardTable [In/Out]
1756 * pdwSize [In/Out]
1757 * bOrder [In]
1758 *
1759 * RETURNS
1760 *
1761 * DWORD
1762 *
1763 */
1764 DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
1765 {
1766 DWORD ret;
1767
1768 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable,
1769 pdwSize, (DWORD)bOrder);
1770 if (!pdwSize)
1771 ret = ERROR_INVALID_PARAMETER;
1772 else {
1773 DWORD numRoutes = getNumRoutes();
1774 ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) *
1775 sizeof(MIB_IPFORWARDROW);
1776
1777 if (!pIpForwardTable || *pdwSize < sizeNeeded) {
1778 *pdwSize = sizeNeeded;
1779 ret = ERROR_INSUFFICIENT_BUFFER;
1780 }
1781 else {
1782 RouteTable *table = getRouteTable();
1783 if (table) {
1784 sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (table->numRoutes - 1) *
1785 sizeof(MIB_IPFORWARDROW);
1786 if (*pdwSize < sizeNeeded) {
1787 *pdwSize = sizeNeeded;
1788 ret = ERROR_INSUFFICIENT_BUFFER;
1789 }
1790 else {
1791 DWORD ndx;
1792
1793 pIpForwardTable->dwNumEntries = table->numRoutes;
1794 for (ndx = 0; ndx < numRoutes; ndx++) {
1795 pIpForwardTable->table[ndx].dwForwardIfIndex =
1796 table->routes[ndx].ifIndex;
1797 pIpForwardTable->table[ndx].dwForwardDest =
1798 table->routes[ndx].dest;
1799 pIpForwardTable->table[ndx].dwForwardMask =
1800 table->routes[ndx].mask;
1801 pIpForwardTable->table[ndx].dwForwardPolicy = 0;
1802 pIpForwardTable->table[ndx].dwForwardNextHop =
1803 table->routes[ndx].gateway;
1804 /* FIXME: this type is appropriate for local interfaces; may not
1805 always be appropriate */
1806 pIpForwardTable->table[ndx].dwForwardType = MIB_IPROUTE_TYPE_DIRECT;
1807 /* FIXME: other protos might be appropriate, e.g. the default route
1808 is typically set with MIB_IPPROTO_NETMGMT instead */
1809 pIpForwardTable->table[ndx].dwForwardProto = MIB_IPPROTO_LOCAL;
1810 /* punt on age and AS */
1811 pIpForwardTable->table[ndx].dwForwardAge = 0;
1812 pIpForwardTable->table[ndx].dwForwardNextHopAS = 0;
1813 pIpForwardTable->table[ndx].dwForwardMetric1 =
1814 table->routes[ndx].metric;
1815 /* rest of the metrics are 0.. */
1816 pIpForwardTable->table[ndx].dwForwardMetric2 = 0;
1817 pIpForwardTable->table[ndx].dwForwardMetric3 = 0;
1818 pIpForwardTable->table[ndx].dwForwardMetric4 = 0;
1819 pIpForwardTable->table[ndx].dwForwardMetric5 = 0;
1820 }
1821 if (bOrder)
1822 qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
1823 sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
1824 ret = NO_ERROR;
1825 }
1826 HeapFree(GetProcessHeap(), 0, table);
1827 }
1828 else
1829 ret = ERROR_OUTOFMEMORY;
1830 }
1831 }
1832 TRACE("returning %ld\n", ret);
1833 return ret;
1834 }
1835
1836
1837 static int IpNetTableSorter(const void *a, const void *b)
1838 {
1839 int ret;
1840
1841 if (a && b)
1842 ret = ((PMIB_IPNETROW)a)->dwAddr - ((PMIB_IPNETROW)b)->dwAddr;
1843 else
1844 ret = 0;
1845 return ret;
1846 }
1847
1848
1849 /******************************************************************
1850 * GetIpNetTable (IPHLPAPI.@)
1851 *
1852 *
1853 * PARAMS
1854 *
1855 * pIpNetTable [In/Out]
1856 * pdwSize [In/Out]
1857 * bOrder [In]
1858 *
1859 * RETURNS
1860 *
1861 * DWORD
1862 *
1863 */
1864 DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
1865 {
1866 DWORD ret = NO_ERROR;
1867
1868 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable, pdwSize,
1869 (DWORD)bOrder);
1870 if (!pdwSize)
1871 ret = ERROR_INVALID_PARAMETER;
1872 else {
1873 DWORD numEntries = getNumArpEntries();
1874 ULONG size = sizeof(MIB_IPNETTABLE);
1875
1876 if (numEntries > 1)
1877 size += (numEntries - 1) * sizeof(MIB_IPNETROW);
1878 if (!pIpNetTable || *pdwSize < size) {
1879 *pdwSize = size;
1880 ret = ERROR_INSUFFICIENT_BUFFER;
1881 }
1882 else {
1883 PMIB_IPNETTABLE table = getArpTable();
1884 if (table) {
1885 size = sizeof(MIB_IPNETTABLE);
1886 if (table->dwNumEntries > 1)
1887 size += (table->dwNumEntries - 1) * sizeof(MIB_IPNETROW);
1888 if (*pdwSize < size) {
1889 *pdwSize = size;
1890 ret = ERROR_INSUFFICIENT_BUFFER;
1891 }
1892 else {
1893 *pdwSize = size;
1894 memcpy(pIpNetTable, table, size);
1895 if (bOrder)
1896 qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
1897 sizeof(MIB_IPNETROW), IpNetTableSorter);
1898 ret = NO_ERROR;
1899 }
1900 HeapFree(GetProcessHeap(), 0, table);
1901 }
1902 }
1903 }
1904 TRACE("returning %d\n", ret);
1905 return ret;
1906 }
1907
1908
1909 /******************************************************************
1910 * GetIpStatistics (IPHLPAPI.@)
1911 *
1912 *
1913 * PARAMS
1914 *
1915 * pStats [In/Out]
1916 *
1917 * RETURNS
1918 *
1919 * DWORD
1920 *
1921 */
1922 DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats)
1923 {
1924 return GetIpStatisticsEx(pStats, PF_INET);
1925 }
1926
1927 /******************************************************************
1928 * GetIpStatisticsEx (IPHLPAPI.@)
1929 *
1930 *
1931 * PARAMS
1932 *
1933 * pStats [In/Out]
1934 * dwFamily [In]
1935 *
1936 * RETURNS
1937 *
1938 * DWORD
1939 *
1940 */
1941 DWORD WINAPI GetIpStatisticsEx(PMIB_IPSTATS pStats, DWORD dwFamily)
1942 {
1943 DWORD ret;
1944
1945 TRACE("pStats %p\n", pStats);
1946 ret = getIPStats(pStats, dwFamily);
1947 TRACE("returning %ld\n", ret);
1948 return ret;
1949 }
1950
1951 /******************************************************************
1952 * GetNetworkParams (IPHLPAPI.@)
1953 *
1954 *
1955 * PARAMS
1956 *
1957 * pFixedInfo [In/Out]
1958 * pOutBufLen [In/Out]
1959 *
1960 * RETURNS
1961 *
1962 * DWORD
1963 *
1964 */
1965 DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
1966 {
1967 DWORD ret, size, type;
1968 LONG regReturn;
1969 HKEY hKey;
1970 PIPHLP_RES_INFO resInfo;
1971
1972 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen);
1973 if (!pOutBufLen)
1974 return ERROR_INVALID_PARAMETER;
1975
1976 resInfo = getResInfo();
1977 if (!resInfo)
1978 return ERROR_OUTOFMEMORY;
1979
1980 size = sizeof(FIXED_INFO) + (resInfo->riCount > 1 ? (resInfo->riCount-1) *
1981 sizeof(IP_ADDR_STRING) : 0);
1982 if (!pFixedInfo || *pOutBufLen < size) {
1983 *pOutBufLen = size;
1984 disposeResInfo( resInfo );
1985 return ERROR_BUFFER_OVERFLOW;
1986 }
1987
1988 memset(pFixedInfo, 0, size);
1989 /* Check for DhcpHostname and DhcpDomain first */
1990 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1991 "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
1992 0,
1993 KEY_READ,
1994 &hKey);
1995 if (regReturn == ERROR_SUCCESS) {
1996 /* Windows doesn't honor DHCP option 12 even if RFC requires it if it is returned by DHCP server! */
1997 #if 0
1998 type = REG_SZ;
1999 size = sizeof(pFixedInfo->HostName);
2000 regReturn = RegQueryValueExA(hKey,
2001 "DhcpHostname",
2002 NULL,
2003 &type,
2004 (LPBYTE)pFixedInfo->HostName,
2005 &size);
2006 if (regReturn == ERROR_FILE_NOT_FOUND || (regReturn == ERROR_SUCCESS && size < 1))
2007 {
2008 #endif
2009 type = REG_SZ;
2010 size = sizeof(pFixedInfo->HostName);
2011 regReturn = RegQueryValueExA(hKey,
2012 "Hostname",
2013 NULL,
2014 &type,
2015 (LPBYTE)pFixedInfo->HostName,
2016 &size);
2017 #if 0
2018 }
2019 #endif
2020
2021 type = REG_SZ;
2022 size = sizeof(pFixedInfo->DomainName);
2023 regReturn = RegQueryValueExA(hKey,
2024 "DhcpDomain",
2025 NULL,
2026 &type,
2027 (LPBYTE)pFixedInfo->DomainName,
2028 &size);
2029 if (regReturn == ERROR_FILE_NOT_FOUND || (regReturn == ERROR_SUCCESS && size < 1))
2030 {
2031 type = REG_SZ;
2032 size = sizeof(pFixedInfo->DomainName);
2033 regReturn = RegQueryValueExA(hKey,
2034 "Domain",
2035 NULL,
2036 &type,
2037 (LPBYTE)pFixedInfo->DomainName,
2038 &size);
2039 }
2040 RegCloseKey(hKey);
2041 }
2042
2043 TRACE("GetComputerNameExA: %s\n", pFixedInfo->DomainName);
2044
2045 if (resInfo->riCount > 0)
2046 {
2047 CopyMemory(&pFixedInfo->DnsServerList, resInfo->DnsList, sizeof(IP_ADDR_STRING));
2048 if (resInfo->riCount > 1)
2049 {
2050 IP_ADDR_STRING *pSrc = resInfo->DnsList->Next;
2051 IP_ADDR_STRING *pTarget = (struct _IP_ADDR_STRING*)((char*)pFixedInfo + sizeof(FIXED_INFO));
2052
2053 pFixedInfo->DnsServerList.Next = pTarget;
2054
2055 do
2056 {
2057 CopyMemory(pTarget, pSrc, sizeof(IP_ADDR_STRING));
2058 resInfo->riCount--;
2059 if (resInfo->riCount > 1)
2060 {
2061 pTarget->Next = (IP_ADDR_STRING*)((char*)pTarget + sizeof(IP_ADDR_STRING));
2062 pTarget = pTarget->Next;
2063 pSrc = pSrc->Next;
2064 }
2065 else
2066 {
2067 pTarget->Next = NULL;
2068 break;
2069 }
2070 }
2071 while(TRUE);
2072 }
2073 else
2074 {
2075 pFixedInfo->DnsServerList.Next = NULL;
2076 }
2077 }
2078
2079 pFixedInfo->NodeType = HYBRID_NODETYPE;
2080 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
2081 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
2082 if (regReturn != ERROR_SUCCESS)
2083 regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
2084 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ,
2085 &hKey);
2086 if (regReturn == ERROR_SUCCESS)
2087 {
2088 DWORD size = sizeof(pFixedInfo->ScopeId);
2089
2090 RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (PBYTE)pFixedInfo->ScopeId, &size);
2091 RegCloseKey(hKey);
2092 }
2093
2094 disposeResInfo( resInfo );
2095 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
2096 I suppose could also check for a listener on port 53 to set EnableDns */
2097 ret = NO_ERROR;
2098 TRACE("returning %ld\n", ret);
2099
2100 return ret;
2101 }
2102
2103
2104 /******************************************************************
2105 * GetNumberOfInterfaces (IPHLPAPI.@)
2106 *
2107 *
2108 * PARAMS
2109 *
2110 * pdwNumIf [In/Out]
2111 *
2112 * RETURNS
2113 *
2114 * DWORD
2115 *
2116 */
2117 DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
2118 {
2119 DWORD ret;
2120
2121 TRACE("pdwNumIf %p\n", pdwNumIf);
2122 if (!pdwNumIf)
2123 ret = ERROR_INVALID_PARAMETER;
2124 else {
2125 *pdwNumIf = getNumInterfaces();
2126 ret = NO_ERROR;
2127 }
2128 TRACE("returning %ld\n", ret);
2129 return ret;
2130 }
2131
2132
2133 /******************************************************************
2134 * GetOwnerModuleFromTcpEntry (IPHLPAPI.@)
2135 *
2136 * Get data about the module that issued the context bind for a specific IPv4 TCP endpoint in a MIB table row
2137 *
2138 * PARAMS
2139 * pTcpEntry [in] pointer to a MIB_TCPROW_OWNER_MODULE structure
2140 * Class [in] TCPIP_OWNER_MODULE_INFO_CLASS enumeration value
2141 * Buffer [out] pointer a buffer containing a TCPIP_OWNER_MODULE_BASIC_INFO structure with the owner module data.
2142 * pdwSize [in, out] estimated size of the structure returned in Buffer, in bytes
2143 *
2144 * RETURNS
2145 * Success: NO_ERROR
2146 * Failure: ERROR_INSUFFICIENT_BUFFER, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY
2147 * ERROR_NOT_FOUND or ERROR_PARTIAL_COPY
2148 *
2149 * NOTES
2150 * The type of data returned in Buffer is indicated by the value of the Class parameter.
2151 */
2152 DWORD WINAPI GetOwnerModuleFromTcpEntry( PMIB_TCPROW_OWNER_MODULE pTcpEntry, TCPIP_OWNER_MODULE_INFO_CLASS Class, PVOID Buffer, PDWORD pdwSize)
2153 {
2154 DWORD ret = NO_ERROR;
2155 UNIMPLEMENTED;
2156 return ret;
2157 }
2158
2159 static void CreateNameServerListEnumNamesFunc( PWCHAR Interface, PWCHAR Server, PVOID Data)
2160 {
2161 IP_ADDR_STRING *pNext;
2162 PNAME_SERVER_LIST_CONTEXT Context = (PNAME_SERVER_LIST_CONTEXT)Data;
2163
2164 if (!Context->NumServers)
2165 {
2166 if (Context->uSizeAvailable >= Context->uSizeRequired)
2167 {
2168 WideCharToMultiByte(CP_ACP, 0, Server, -1, Context->pData->DnsServerList.IpAddress.String, 16, NULL, NULL);
2169 Context->pData->DnsServerList.IpAddress.String[15] = '\0';
2170 Context->pLastAddr = &Context->pData->DnsServerList;
2171 }
2172 }
2173 else
2174 {
2175 Context->uSizeRequired += sizeof(IP_ADDR_STRING);
2176 if (Context->uSizeAvailable >= Context->uSizeRequired)
2177 {
2178 pNext = (IP_ADDR_STRING*)(((char*)Context->pLastAddr) + sizeof(IP_ADDR_STRING));
2179 WideCharToMultiByte(CP_ACP, 0, Server, -1, pNext->IpAddress.String, 16, NULL, NULL);
2180 pNext->IpAddress.String[15] = '\0';
2181 Context->pLastAddr->Next = pNext;
2182 Context->pLastAddr = pNext;
2183 pNext->Next = NULL;
2184 }
2185 }
2186 Context->NumServers++;
2187 }
2188
2189 /******************************************************************
2190 * GetPerAdapterInfo (IPHLPAPI.@)
2191 *
2192 *
2193 * PARAMS
2194 *
2195 * IfIndex [In]
2196 * pPerAdapterInfo [In/Out]
2197 * pOutBufLen [In/Out]
2198 *
2199 * RETURNS
2200 *
2201 * DWORD
2202 *
2203 */
2204 DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
2205 {
2206 HKEY hkey;
2207 DWORD dwSize = 0;
2208 const char *ifName;
2209 NAME_SERVER_LIST_CONTEXT Context;
2210 WCHAR keyname[200] = L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
2211
2212 if (!pOutBufLen)
2213 return ERROR_INVALID_PARAMETER;
2214
2215 if (!pPerAdapterInfo || *pOutBufLen < sizeof(IP_PER_ADAPTER_INFO))
2216 {
2217 *pOutBufLen = sizeof(IP_PER_ADAPTER_INFO);
2218 return ERROR_BUFFER_OVERFLOW;
2219 }
2220
2221 ifName = getInterfaceNameByIndex(IfIndex);
2222 if (!ifName)
2223 return ERROR_INVALID_PARAMETER;
2224
2225 MultiByteToWideChar(CP_ACP, 0, ifName, -1, &keyname[62], sizeof(keyname)/sizeof(WCHAR) - 63);
2226 HeapFree(GetProcessHeap(), 0, (LPVOID)ifName);
2227
2228 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyname, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
2229 {
2230 return ERROR_NOT_SUPPORTED;
2231 }
2232 Context.NumServers = 0;
2233 Context.uSizeAvailable = *pOutBufLen;
2234 Context.uSizeRequired = sizeof(IP_PER_ADAPTER_INFO);
2235 Context.pData = pPerAdapterInfo;
2236
2237 if (*pOutBufLen >= sizeof(IP_PER_ADAPTER_INFO))
2238 ZeroMemory(pPerAdapterInfo, sizeof(IP_PER_ADAPTER_INFO));
2239
2240 EnumNameServers(hkey, &keyname[62], &Context, CreateNameServerListEnumNamesFunc);
2241
2242 if (Context.uSizeRequired > Context.uSizeAvailable)
2243 {
2244 *pOutBufLen = Context.uSizeRequired;
2245 RegCloseKey(hkey);
2246 return ERROR_BUFFER_OVERFLOW;
2247 }
2248
2249 if(RegQueryValueExW(hkey, L"NameServer", NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS)
2250 {
2251 pPerAdapterInfo->AutoconfigActive = FALSE;
2252 }
2253 else
2254 {
2255 pPerAdapterInfo->AutoconfigActive = TRUE;
2256 }
2257
2258 RegCloseKey(hkey);
2259 return NOERROR;
2260 }
2261
2262
2263 /******************************************************************
2264 * GetRTTAndHopCount (IPHLPAPI.@)
2265 *
2266 *
2267 * PARAMS
2268 *
2269 * DestIpAddress [In]
2270 * HopCount [In/Out]
2271 * MaxHops [In]
2272 * RTT [In/Out]
2273 *
2274 * RETURNS
2275 *
2276 * BOOL
2277 *
2278 */
2279 BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT)
2280 {
2281 TRACE("DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p\n",
2282 DestIpAddress, HopCount, MaxHops, RTT);
2283 FIXME(":stub\n");
2284 return (BOOL) 0;
2285 }
2286
2287
2288 /******************************************************************
2289 * GetTcpStatisticsEx (IPHLPAPI.@)
2290 *
2291 *
2292 * PARAMS
2293 *
2294 * pStats [In/Out]
2295 * dwFamily [In]
2296 *
2297 * RETURNS
2298 *
2299 * DWORD
2300 *
2301 */
2302 DWORD WINAPI GetTcpStatisticsEx(PMIB_TCPSTATS pStats, DWORD dwFamily)
2303 {
2304 DWORD ret;
2305
2306 TRACE("pStats %p\n", pStats);
2307 ret = getTCPStats(pStats, dwFamily);
2308 TRACE("returning %ld\n", ret);
2309 return ret;
2310 }
2311
2312 /******************************************************************
2313 * GetTcpStatistics (IPHLPAPI.@)
2314 *
2315 *
2316 * PARAMS
2317 *
2318 * pStats [In/Out]
2319 *
2320 * RETURNS
2321 *
2322 * DWORD
2323 *
2324 */
2325 DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
2326 {
2327 return GetTcpStatisticsEx(pStats, PF_INET);
2328 }
2329
2330
2331 /******************************************************************
2332 * GetTcpTable (IPHLPAPI.@)
2333 *
2334 * Get the table of active TCP connections.
2335 *
2336 * PARAMS
2337 * pTcpTable [Out] buffer for TCP connections table
2338 * pdwSize [In/Out] length of output buffer
2339 * bOrder [In] whether to order the table
2340 *
2341 * RETURNS
2342 * Success: NO_ERROR
2343 * Failure: error code from winerror.h
2344 *
2345 * NOTES
2346 * If pdwSize is less than required, the function will return
2347 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
2348 * the required byte size.
2349 * If bOrder is true, the returned table will be sorted, first by
2350 * local address and port number, then by remote address and port
2351 * number.
2352 */
2353 DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
2354 {
2355 return GetExtendedTcpTable(pTcpTable, pdwSize, bOrder, AF_INET, TCP_TABLE_BASIC_ALL, 0);
2356 }
2357
2358
2359 /******************************************************************
2360 * GetUdpStatisticsEx (IPHLPAPI.@)
2361 *
2362 *
2363 * PARAMS
2364 *
2365 * pStats [In/Out]
2366 * dwFamily [In]
2367 *
2368 * RETURNS
2369 *
2370 * DWORD
2371 *
2372 */
2373 DWORD WINAPI GetUdpStatisticsEx(PMIB_UDPSTATS pStats, DWORD dwFamily)
2374 {
2375 DWORD ret;
2376
2377 TRACE("pStats %p\n", pStats);
2378 ret = getUDPStats(pStats, dwFamily);
2379 TRACE("returning %ld\n", ret);
2380 return ret;
2381 }
2382
2383 /******************************************************************
2384 * GetUdpStatistics (IPHLPAPI.@)
2385 *
2386 *
2387 * PARAMS
2388 *
2389 * pStats [In/Out]
2390 *
2391 * RETURNS
2392 *
2393 * DWORD
2394 *
2395 */
2396 DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats)
2397 {
2398 return GetUdpStatisticsEx(pStats, PF_INET);
2399 }
2400
2401
2402 /******************************************************************
2403 * GetUdpTable (IPHLPAPI.@)
2404 *
2405 *
2406 * PARAMS
2407 *
2408 * pUdpTable [In/Out]
2409 * pdwSize [In/Out]
2410 * bOrder [In]
2411 *
2412 * RETURNS
2413 *
2414 * DWORD
2415 *
2416 */
2417 DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
2418 {
2419 return GetExtendedUdpTable(pUdpTable, pdwSize, bOrder, AF_INET, UDP_TABLE_BASIC, 0);
2420 }
2421
2422
2423 /******************************************************************
2424 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
2425 *
2426 * This is a Win98-only function to get information on "unidirectional"
2427 * adapters. Since this is pretty nonsensical in other contexts, it
2428 * never returns anything.
2429 *
2430 * PARAMS
2431 * pIPIfInfo [Out] buffer for adapter infos
2432 * dwOutBufLen [Out] length of the output buffer
2433 *
2434 * RETURNS
2435 * Success: NO_ERROR
2436 * Failure: error code from winerror.h
2437 *
2438 * FIXME
2439 * Stub, returns ERROR_NOT_SUPPORTED.
2440 */
2441 DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen)
2442 {
2443 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen);
2444 /* a unidirectional adapter?? not bloody likely! */
2445 return ERROR_NOT_SUPPORTED;
2446 }
2447
2448
2449 /******************************************************************
2450 * IpReleaseAddress (IPHLPAPI.@)
2451 *
2452 * Release an IP obtained through DHCP,
2453 *
2454 * PARAMS
2455 * AdapterInfo [In] adapter to release IP address
2456 *
2457 * RETURNS
2458 * Success: NO_ERROR
2459 * Failure: error code from winerror.h
2460 *
2461 */
2462 DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
2463 {
2464 DWORD Status, Version = 0;
2465
2466 if (!AdapterInfo)
2467 return ERROR_INVALID_PARAMETER;
2468
2469 /* Maybe we should do this in DllMain */
2470 if (DhcpCApiInitialize(&Version) != ERROR_SUCCESS)
2471 return ERROR_PROC_NOT_FOUND;
2472
2473 if (DhcpReleaseIpAddressLease(AdapterInfo->Index))
2474 Status = ERROR_SUCCESS;
2475 else
2476 Status = ERROR_PROC_NOT_FOUND;
2477
2478 DhcpCApiCleanup();
2479
2480 return Status;
2481 }
2482
2483
2484 /******************************************************************
2485 * IpRenewAddress (IPHLPAPI.@)
2486 *
2487 * Renew an IP obtained through DHCP.
2488 *
2489 * PARAMS
2490 * AdapterInfo [In] adapter to renew IP address
2491 *
2492 * RETURNS
2493 * Success: NO_ERROR
2494 * Failure: error code from winerror.h
2495 */
2496 DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
2497 {
2498 DWORD Status, Version = 0;
2499
2500 if (!AdapterInfo)
2501 return ERROR_INVALID_PARAMETER;
2502
2503 /* Maybe we should do this in DllMain */
2504 if (DhcpCApiInitialize(&Version) != ERROR_SUCCESS)
2505 return ERROR_PROC_NOT_FOUND;
2506
2507 if (DhcpRenewIpAddressLease(AdapterInfo->Index))
2508 Status = ERROR_SUCCESS;
2509 else
2510 Status = ERROR_PROC_NOT_FOUND;
2511
2512 DhcpCApiCleanup();
2513
2514 return Status;
2515 }
2516
2517
2518 /******************************************************************
2519 * NotifyAddrChange (IPHLPAPI.@)
2520 *
2521 * Notify caller whenever the ip-interface map is changed.
2522 *
2523 * PARAMS
2524 * Handle [Out] handle usable in asynchronous notification
2525 * overlapped [In] overlapped structure that notifies the caller
2526 *
2527 * RETURNS
2528 * Success: NO_ERROR
2529 * Failure: error code from winerror.h
2530 *
2531 * FIXME
2532 * Stub, returns ERROR_NOT_SUPPORTED.
2533 */
2534 DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
2535 {
2536 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
2537 if (Handle) *Handle = INVALID_HANDLE_VALUE;
2538 if (overlapped) ((IO_STATUS_BLOCK *) overlapped)->Status = STATUS_PENDING;
2539 return ERROR_IO_PENDING;
2540 }
2541
2542
2543 /******************************************************************
2544 * NotifyRouteChange (IPHLPAPI.@)
2545 *
2546 * Notify caller whenever the ip routing table is changed.
2547 *
2548 * PARAMS
2549 * Handle [Out] handle usable in asynchronous notification
2550 * overlapped [In] overlapped structure that notifies the caller
2551 *
2552 * RETURNS
2553 * Success: NO_ERROR
2554 * Failure: error code from winerror.h
2555 *
2556 * FIXME
2557 * Stub, returns ERROR_NOT_SUPPORTED.
2558 */
2559 DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped)
2560 {
2561 FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped);
2562 return ERROR_NOT_SUPPORTED;
2563 }
2564
2565 /******************************************************************
2566 * SendARP (IPHLPAPI.@)
2567 *
2568 * Send an ARP request.
2569 *
2570 * PARAMS
2571 * DestIP [In] attempt to obtain this IP
2572 * SrcIP [In] optional sender IP address
2573 * pMacAddr [Out] buffer for the mac address
2574 * PhyAddrLen [In/Out] length of the output buffer
2575 *
2576 * RETURNS
2577 * Success: NO_ERROR
2578 * Failure: error code from winerror.h
2579 */
2580 DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
2581 {
2582 IPAddr IPs[2];
2583 ULONG Size;
2584
2585 if (IsBadWritePtr(pMacAddr, sizeof(ULONG)) || IsBadWritePtr(PhyAddrLen, sizeof(ULONG)))
2586 return ERROR_INVALID_PARAMETER;
2587
2588 IPs[0] = DestIP;
2589 IPs[1] = SrcIP;
2590 Size = sizeof(IPs);
2591 return TCPSendIoctl(INVALID_HANDLE_VALUE, IOCTL_QUERY_IP_HW_ADDRESS, IPs, &Size, pMacAddr, PhyAddrLen);
2592 }
2593
2594
2595 /******************************************************************
2596 * SetIfEntry (IPHLPAPI.@)
2597 *
2598 * Set the administrative status of an interface.
2599 *
2600 * PARAMS
2601 * pIfRow [In] dwAdminStatus member specifies the new status.
2602 *
2603 * RETURNS
2604 * Success: NO_ERROR
2605 * Failure: error code from winerror.h
2606 *
2607 * FIXME
2608 * Stub, returns ERROR_NOT_SUPPORTED.
2609 */
2610 DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow)
2611 {
2612 FIXME("(pIfRow %p): stub\n", pIfRow);
2613 /* this is supposed to set an interface administratively up or down.
2614 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2615 this sort of down is indistinguishable from other sorts of down (e.g. no
2616 link). */
2617 return ERROR_NOT_SUPPORTED;
2618 }
2619
2620
2621 /******************************************************************
2622 * SetIpForwardEntry (IPHLPAPI.@)
2623 *
2624 * Modify an existing route.
2625 *
2626 * PARAMS
2627 * pRoute [In] route with the new information
2628 *
2629 * RETURNS
2630 * Success: NO_ERROR
2631 * Failure: error code from winerror.h
2632 *
2633 */
2634 DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute)
2635 {
2636 return setIpForwardEntry( pRoute );
2637 }
2638
2639
2640 /******************************************************************
2641 * SetIpNetEntry (IPHLPAPI.@)
2642 *
2643 * Modify an existing ARP entry.
2644 *
2645 * PARAMS
2646 * pArpEntry [In] ARP entry with the new information
2647 *
2648 * RETURNS
2649 * Success: NO_ERROR
2650 * Failure: error code from winerror.h
2651 */
2652 DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
2653 {
2654 HANDLE tcpFile;
2655 NTSTATUS status;
2656 TCP_REQUEST_SET_INFORMATION_EX_ARP_ENTRY req =
2657 TCP_REQUEST_SET_INFORMATION_INIT;
2658 TDIEntityID id;
2659 DWORD returnSize;
2660 PMIB_IPNETROW arpBuff;
2661
2662 if (!pArpEntry)
2663 return ERROR_INVALID_PARAMETER;
2664
2665 if (!NT_SUCCESS(openTcpFile( &tcpFile, FILE_READ_DATA | FILE_WRITE_DATA )))
2666 return ERROR_NOT_SUPPORTED;
2667
2668 if (!NT_SUCCESS(getNthIpEntity( tcpFile, pArpEntry->dwIndex, &id )))
2669 {
2670 closeTcpFile(tcpFile);
2671 return ERROR_INVALID_PARAMETER;
2672 }
2673
2674 req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
2675 req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
2676 req.Req.ID.toi_id = IP_MIB_ARPTABLE_ENTRY_ID;
2677 req.Req.ID.toi_entity.tei_instance = id.tei_instance;
2678 req.Req.ID.toi_entity.tei_entity = AT_ENTITY;
2679 req.Req.BufferSize = sizeof(MIB_IPNETROW);
2680 arpBuff = (PMIB_IPNETROW)&req.Req.Buffer[0];
2681
2682 RtlCopyMemory(arpBuff, pArpEntry, sizeof(MIB_IPNETROW));
2683
2684 status = DeviceIoControl( tcpFile,
2685 IOCTL_TCP_SET_INFORMATION_EX,
2686 &req,
2687 sizeof(req),
2688 NULL,
2689 0,
2690 &returnSize,
2691 NULL );
2692
2693 closeTcpFile(tcpFile);
2694
2695 if (status)
2696 return NO_ERROR;
2697 else
2698 return ERROR_INVALID_PARAMETER;
2699 }
2700
2701
2702 /******************************************************************
2703 * SetIpStatistics (IPHLPAPI.@)
2704 *
2705 * Toggle IP forwarding and det the default TTL value.
2706 *
2707 * PARAMS
2708 * pIpStats [In] IP statistics with the new information
2709 *
2710 * RETURNS
2711 * Success: NO_ERROR
2712 * Failure: error code from winerror.h
2713 *
2714 * FIXME
2715 * Stub, returns NO_ERROR.
2716 */
2717 DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats)
2718 {
2719 FIXME("(pIpStats %p): stub\n", pIpStats);
2720 return 0;
2721 }
2722
2723
2724 /******************************************************************
2725 * SetIpTTL (IPHLPAPI.@)
2726 *
2727 * Set the default TTL value.
2728 *
2729 * PARAMS
2730 * nTTL [In] new TTL value
2731 *
2732 * RETURNS
2733 * Success: NO_ERROR
2734 * Failure: error code from winerror.h
2735 *
2736 * FIXME
2737 * Stub, returns NO_ERROR.
2738 */
2739 DWORD WINAPI SetIpTTL(UINT nTTL)
2740 {
2741 FIXME("(nTTL %d): stub\n", nTTL);
2742 return 0;
2743 }
2744
2745
2746 /******************************************************************
2747 * SetTcpEntry (IPHLPAPI.@)
2748 *
2749 * Set the state of a TCP connection.
2750 *
2751 * PARAMS
2752 * pTcpRow [In] specifies connection with new state
2753 *
2754 * RETURNS
2755 * Success: NO_ERROR
2756 * Failure: error code from winerror.h
2757 *
2758 * FIXME
2759 * Stub, returns NO_ERROR.
2760 */
2761 DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow)
2762 {
2763 FIXME("(pTcpRow %p): stub\n", pTcpRow);
2764 return 0;
2765 }
2766
2767
2768 /******************************************************************
2769 * UnenableRouter (IPHLPAPI.@)
2770 *
2771 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2772 * if it reaches zero.
2773 *
2774 * PARAMS
2775 * pOverlapped [In/Out] should be the same as in EnableRouter()
2776 * lpdwEnableCount [Out] optional, receives reference count
2777 *
2778 * RETURNS
2779 * Success: NO_ERROR
2780 * Failure: error code from winerror.h
2781 *
2782 * FIXME
2783 * Stub, returns ERROR_NOT_SUPPORTED.
2784 */
2785 DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount)
2786 {
2787 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped,
2788 lpdwEnableCount);
2789 return ERROR_NOT_SUPPORTED;
2790 }
2791
2792 /*
2793 * @unimplemented
2794 */
2795 DWORD WINAPI GetIpErrorString(IP_STATUS ErrorCode,PWCHAR Buffer,PDWORD Size)
2796 {
2797 FIXME(":stub\n");
2798 return 0L;
2799 }
2800
2801
2802 /*
2803 * @unimplemented
2804 */
2805 PIP_ADAPTER_ORDER_MAP WINAPI GetAdapterOrderMap(VOID)
2806 {
2807 FIXME(":stub\n");
2808 return 0L;
2809 }
2810
2811 /*
2812 * @implemented
2813 */
2814 #ifdef GetAdaptersAddressesV1
2815 DWORD WINAPI DECLSPEC_HOTPATCH GetAdaptersAddresses(ULONG Family,ULONG Flags,PVOID Reserved,PIP_ADAPTER_ADDRESSES pAdapterAddresses,PULONG pOutBufLen)
2816 {
2817 InterfaceIndexTable *indexTable;
2818 IFInfo ifInfo;
2819 int i;
2820 ULONG ret, requiredSize = 0;
2821 PIP_ADAPTER_ADDRESSES currentAddress;
2822 PUCHAR currentLocation;
2823 HANDLE tcpFile;
2824
2825 if (!pOutBufLen) return ERROR_INVALID_PARAMETER;
2826 if (Reserved) return ERROR_INVALID_PARAMETER;
2827
2828 indexTable = getInterfaceIndexTable();
2829 if (!indexTable)
2830 return ERROR_NOT_ENOUGH_MEMORY;
2831
2832 ret = openTcpFile(&tcpFile, FILE_READ_DATA);
2833 if (!NT_SUCCESS(ret))
2834 return ERROR_NO_DATA;
2835
2836 for (i = indexTable->numIndexes; i >= 0; i--)
2837 {
2838 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile,
2839 NULL,
2840 indexTable->indexes[i],
2841 &ifInfo)))
2842 {
2843 /* The whole struct */
2844 requiredSize += sizeof(IP_ADAPTER_ADDRESSES);
2845
2846 /* Friendly name */
2847 if (!(Flags & GAA_FLAG_SKIP_FRIENDLY_NAME))
2848 requiredSize += strlen((char *)ifInfo.if_info.ent.if_descr) + 1; //FIXME
2849
2850 /* Adapter name */
2851 requiredSize += strlen((char *)ifInfo.if_info.ent.if_descr) + 1;
2852
2853 /* Unicast address */
2854 if (!(Flags & GAA_FLAG_SKIP_UNICAST))
2855 requiredSize += sizeof(IP_ADAPTER_UNICAST_ADDRESS);
2856
2857 /* FIXME: Implement multicast, anycast, and dns server stuff */
2858
2859 /* FIXME: Implement dns suffix and description */
2860 requiredSize += 2 * sizeof(WCHAR);
2861
2862 /* We're only going to implement what's required for XP SP0 */
2863 }
2864 }
2865 TRACE("size: %d, requiredSize: %d\n", *pOutBufLen, requiredSize);
2866 if (!pAdapterAddresses || *pOutBufLen < requiredSize)
2867 {
2868 *pOutBufLen = requiredSize;
2869 closeTcpFile(tcpFile);
2870 free(indexTable);
2871 return ERROR_BUFFER_OVERFLOW;
2872 }
2873
2874 RtlZeroMemory(pAdapterAddresses, requiredSize);
2875
2876 /* Let's set up the pointers */
2877 currentAddress = pAdapterAddresses;
2878 for (i = indexTable->numIndexes; i >= 0; i--)
2879 {
2880 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile,
2881 NULL,
2882 indexTable->indexes[i],
2883 &ifInfo)))
2884 {
2885 currentLocation = (PUCHAR)currentAddress + (ULONG_PTR)sizeof(IP_ADAPTER_ADDRESSES);
2886
2887 /* FIXME: Friendly name */
2888 if (!(Flags & GAA_FLAG_SKIP_FRIENDLY_NAME))
2889 {
2890 currentAddress->FriendlyName = (PVOID)currentLocation;
2891 currentLocation += sizeof(WCHAR);
2892 }
2893
2894 /* Adapter name */
2895 currentAddress->AdapterName = (PVOID)currentLocation;
2896 currentLocation += strlen((char *)ifInfo.if_info.ent.if_descr) + 1;
2897
2898 /* Unicast address */
2899 if (!(Flags & GAA_FLAG_SKIP_UNICAST))
2900 {
2901 currentAddress->FirstUnicastAddress = (PVOID)currentLocation;
2902 currentLocation += sizeof(IP_ADAPTER_UNICAST_ADDRESS);
2903 currentAddress->FirstUnicastAddress->Address.lpSockaddr = (PVOID)currentLocation;
2904 currentLocation += sizeof(struct sockaddr);
2905 }
2906
2907 /* FIXME: Implement multicast, anycast, and dns server stuff */
2908
2909 /* FIXME: Implement dns suffix and description */
2910 currentAddress->DnsSuffix = (PVOID)currentLocation;
2911 currentLocation += sizeof(WCHAR);
2912
2913 currentAddress->Description = (PVOID)currentLocation;
2914 currentLocation += sizeof(WCHAR);
2915
2916 currentAddress->Next = (PVOID)currentLocation;
2917 /* Terminate the last address correctly */
2918 if(i==0)
2919 currentAddress->Next = NULL;
2920
2921 /* We're only going to implement what's required for XP SP0 */
2922
2923 currentAddress = currentAddress->Next;
2924 }
2925 }
2926
2927 /* Now again, for real this time */
2928
2929 currentAddress = pAdapterAddresses;
2930 for (i = indexTable->numIndexes; i >= 0; i--)
2931 {
2932 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile,
2933 NULL,
2934 indexTable->indexes[i],
2935 &ifInfo)))
2936 {
2937 /* Make sure we're not looping more than we hoped for */
2938 ASSERT(currentAddress);
2939
2940 /* Alignment information */
2941 currentAddress->Length = sizeof(IP_ADAPTER_ADDRESSES);
2942 currentAddress->IfIndex = indexTable->indexes[i];
2943
2944 /* Adapter name */
2945 strcpy(currentAddress->AdapterName, (char *)ifInfo.if_info.ent.if_descr);
2946
2947 if (!(Flags & GAA_FLAG_SKIP_UNICAST))
2948 {
2949 currentAddress->FirstUnicastAddress->Length = sizeof(IP_ADAPTER_UNICAST_ADDRESS);
2950 currentAddress->FirstUnicastAddress->Flags = 0; //FIXME
2951 currentAddress->FirstUnicastAddress->Next = NULL; //FIXME: Support more than one address per adapter
2952 currentAddress->FirstUnicastAddress->Address.lpSockaddr->sa_family = AF_INET;
2953 memcpy(currentAddress->FirstUnicastAddress->Address.lpSockaddr->sa_data,
2954 &ifInfo.ip_addr.iae_addr,
2955 sizeof(ifInfo.ip_addr.iae_addr));
2956 currentAddress->FirstUnicastAddress->Address.iSockaddrLength = sizeof(ifInfo.ip_addr.iae_addr) + sizeof(USHORT);
2957 currentAddress->FirstUnicastAddress->PrefixOrigin = IpPrefixOriginOther; //FIXME
2958 currentAddress->FirstUnicastAddress->SuffixOrigin = IpPrefixOriginOther; //FIXME
2959 currentAddress->FirstUnicastAddress->DadState = IpDadStatePreferred; //FIXME
2960 currentAddress->FirstUnicastAddress->ValidLifetime = 0xFFFFFFFF; //FIXME
2961 currentAddress->FirstUnicastAddress->PreferredLifetime = 0xFFFFFFFF; //FIXME
2962 currentAddress->FirstUnicastAddress->LeaseLifetime = 0xFFFFFFFF; //FIXME
2963 }
2964
2965 /* FIXME: Implement multicast, anycast, and dns server stuff */
2966 currentAddress->FirstAnycastAddress = NULL;
2967 currentAddress->FirstMulticastAddress = NULL;
2968 currentAddress->FirstDnsServerAddress = NULL;
2969
2970 /* FIXME: Implement dns suffix, description, and friendly name */
2971 currentAddress->DnsSuffix[0] = UNICODE_NULL;
2972 currentAddress->Description[0] = UNICODE_NULL;
2973 currentAddress->FriendlyName[0] = UNICODE_NULL;
2974
2975 /* Physical Address */
2976 memcpy(currentAddress->PhysicalAddress, ifInfo.if_info.ent.if_physaddr, ifInfo.if_info.ent.if_physaddrlen);
2977 currentAddress->PhysicalAddressLength = ifInfo.if_info.ent.if_physaddrlen;
2978
2979 /* Flags */
2980 currentAddress->Flags = 0; //FIXME
2981
2982 /* MTU */
2983 currentAddress->Mtu = ifInfo.if_info.ent.if_mtu;
2984
2985 /* Interface type */
2986 currentAddress->IfType = ifInfo.if_info.ent.if_type;
2987
2988 /* Operational status */
2989 if(ifInfo.if_info.ent.if_operstatus >= IF_OPER_STATUS_CONNECTING)
2990 currentAddress->OperStatus = IfOperStatusUp;
2991 else
2992 currentAddress->OperStatus = IfOperStatusDown;
2993
2994 /* We're only going to implement what's required for XP SP0 */
2995
2996 /* Move to the next address */
2997 currentAddress = currentAddress->Next;
2998 }
2999 }
3000
3001 closeTcpFile(tcpFile);
3002 free(indexTable);
3003
3004 return NO_ERROR;
3005 }
3006 #endif
3007
3008 /*
3009 * @unimplemented
3010 */
3011 BOOL WINAPI CancelIPChangeNotify(LPOVERLAPPED notifyOverlapped)
3012 {
3013 FIXME(":stub\n");
3014 return 0L;
3015 }
3016
3017 /*
3018 * @unimplemented
3019 */
3020 DWORD WINAPI GetBestInterfaceEx(struct sockaddr *pDestAddr,PDWORD pdwBestIfIndex)
3021 {
3022 FIXME(":stub\n");
3023 return 0L;
3024 }
3025
3026 /*
3027 * @unimplemented
3028 */
3029 DWORD WINAPI NhpAllocateAndGetInterfaceInfoFromStack(IP_INTERFACE_NAME_INFO **ppTable,PDWORD pdwCount,BOOL bOrder,HANDLE hHeap,DWORD dwFlags)
3030 {
3031 FIXME(":stub\n");
3032 return 0L;
3033 }
3034
3035 /*
3036 * @unimplemented
3037 */
3038 DWORD WINAPI GetIcmpStatisticsEx(PMIB_ICMP_EX pStats,DWORD dwFamily)
3039 {
3040 FIXME(":stub\n");
3041
3042 if (!pStats)
3043 return ERROR_INVALID_PARAMETER;
3044
3045 if (dwFamily != AF_INET && dwFamily != AF_INET6)
3046 return ERROR_INVALID_PARAMETER;
3047
3048 return 0L;
3049 }
3050
3051 DWORD WINAPI
3052 SetIpForwardEntryToStack(PMIB_IPFORWARDROW pRoute)
3053 {
3054 FIXME("SetIpForwardEntryToStack() stub\n");
3055 return 0L;
3056 }
3057
3058 DWORD GetInterfaceNameInternal(_In_ const GUID * pInterfaceGUID,
3059 _Out_writes_bytes_to_(*pOutBufLen, *pOutBufLen) PWCHAR pInterfaceName,
3060 _Inout_ PULONG pOutBufLen)
3061 {
3062 UNICODE_STRING GuidString;
3063 DWORD result, type;
3064 WCHAR szKeyName[2*MAX_PATH];
3065 HRESULT hr;
3066 HKEY hKey;
3067
3068 if (pInterfaceGUID == NULL || pOutBufLen == NULL)
3069 return ERROR_INVALID_PARAMETER;
3070
3071 result = RtlStringFromGUID(pInterfaceGUID, &GuidString);
3072
3073 if (!NT_SUCCESS(result))
3074 {
3075 // failed to convert guid to string
3076 return RtlNtStatusToDosError(result);
3077 }
3078
3079 hr = StringCbPrintfW(szKeyName, sizeof(szKeyName), L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", GuidString.Buffer);
3080 RtlFreeUnicodeString(&GuidString);
3081
3082 if (FAILED(hr))
3083 {
3084 // key name is too long
3085 return ERROR_BUFFER_OVERFLOW;
3086 }
3087
3088 result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_READ, &hKey);
3089
3090 if (result != ERROR_SUCCESS)
3091 {
3092 // failed to find adapter entry
3093 return ERROR_NOT_FOUND;
3094 }
3095
3096 result = RegQueryValueExW(hKey, L"Name", NULL, &type, (PVOID)pInterfaceName, pOutBufLen);
3097
3098 RegCloseKey(hKey);
3099
3100 if (result == ERROR_MORE_DATA)
3101 {
3102 *pOutBufLen = MAX_INTERFACE_NAME_LEN * 2;
3103 return ERROR_INSUFFICIENT_BUFFER;
3104 }
3105
3106 if (result != ERROR_SUCCESS || type != REG_SZ)
3107 {
3108 // failed to read adapter name
3109 return ERROR_NO_DATA;
3110 }
3111 return ERROR_SUCCESS;
3112 }
3113
3114 /*
3115 * @implemented
3116 */
3117 DWORD WINAPI
3118 NhGetInterfaceNameFromDeviceGuid(_In_ const GUID * pInterfaceGUID,
3119 _Out_writes_bytes_to_(*pOutBufLen, *pOutBufLen) PWCHAR pInterfaceName,
3120 _Inout_ PULONG pOutBufLen,
3121 DWORD dwUnknown4,
3122 DWORD dwUnknown5)
3123 {
3124 SetLastError(ERROR_SUCCESS);
3125
3126 if (pInterfaceName == NULL)
3127 return ERROR_INVALID_PARAMETER;
3128
3129 return GetInterfaceNameInternal(pInterfaceGUID, pInterfaceName, pOutBufLen);
3130 }
3131
3132 /*
3133 * @implemented
3134 */
3135 DWORD WINAPI
3136 NhGetInterfaceNameFromGuid(_In_ const GUID * pInterfaceGUID,
3137 _Out_writes_bytes_to_(*pOutBufLen, *pOutBufLen) PWCHAR pInterfaceName,
3138 _Inout_ PULONG pOutBufLen,
3139 DWORD dwUnknown4,
3140 DWORD dwUnknown5)
3141 {
3142 DWORD result;
3143
3144 result = GetInterfaceNameInternal(pInterfaceGUID, pInterfaceName, pOutBufLen);
3145
3146 if (result == ERROR_NOT_FOUND)
3147 SetLastError(ERROR_PATH_NOT_FOUND);
3148
3149 return result;
3150 }