2 * iphlpapi dll implementation
4 * Copyright (C) 2003 Juan Lang
5 * 2018 Pierre Schweitzer
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "iphlpapi_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
31 typedef struct _NAME_SERVER_LIST_CONTEXT
{
34 PIP_PER_ADAPTER_INFO pData
;
36 IP_ADDR_STRING
*pLastAddr
;
37 } NAME_SERVER_LIST_CONTEXT
, *PNAME_SERVER_LIST_CONTEXT
;
39 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
42 case DLL_PROCESS_ATTACH
:
43 DisableThreadLibraryCalls( hinstDLL
);
47 case DLL_PROCESS_DETACH
:
54 /******************************************************************
55 * AddIPAddress (IPHLPAPI.@)
64 * NTEInstance [In/Out]
71 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask Netmask
, DWORD IfIndex
, PULONG NteContext
, PULONG NteInstance
)
73 return RtlNtStatusToDosError(addIPAddress(Address
, Netmask
, IfIndex
, NteContext
, NteInstance
));
76 DWORD
getInterfaceGatewayByIndex(DWORD index
)
78 DWORD ndx
, retVal
= 0, numRoutes
= getNumRoutes();
79 RouteTable
*table
= getRouteTable();
82 for (ndx
= 0; ndx
< numRoutes
; ndx
++)
84 if ((table
->routes
[ndx
].ifIndex
== (index
)) && (table
->routes
[ndx
].dest
== 0))
85 retVal
= table
->routes
[ndx
].gateway
;
87 HeapFree(GetProcessHeap(), 0, table
);
91 /******************************************************************
92 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
97 * ppIfTable [Out] -- pointer into which the MIB_IFTABLE is
98 * allocated and returned.
99 * bOrder [In] -- passed to GetIfTable to order the table
100 * heap [In] -- heap from which the table is allocated
101 * flags [In] -- flags to HeapAlloc
103 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
104 * GetIfTable returns otherwise
107 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
108 BOOL bOrder
, HANDLE heap
, DWORD flags
)
112 TRACE("ppIfTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n", ppIfTable
,
113 (DWORD
)bOrder
, (DWORD
)heap
, flags
);
115 ret
= ERROR_INVALID_PARAMETER
;
120 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
121 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
122 *ppIfTable
= (PMIB_IFTABLE
)HeapAlloc(heap
, flags
, dwSize
);
123 ret
= GetIfTable(*ppIfTable
, &dwSize
, bOrder
);
124 if (ret
!= NO_ERROR
) {
125 HeapFree(heap
, flags
, *ppIfTable
);
130 TRACE("returning %ld\n", ret
);
135 /******************************************************************
136 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
141 * ppIpAddrTable [Out]
142 * bOrder [In] -- passed to GetIpAddrTable to order the table
143 * heap [In] -- heap from which the table is allocated
144 * flags [In] -- flags to HeapAlloc
151 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
152 BOOL bOrder
, HANDLE heap
, DWORD flags
)
156 TRACE("ppIpAddrTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
157 ppIpAddrTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
159 ret
= ERROR_INVALID_PARAMETER
;
163 *ppIpAddrTable
= NULL
;
164 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
165 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
166 *ppIpAddrTable
= (PMIB_IPADDRTABLE
)HeapAlloc(heap
, flags
, dwSize
);
167 ret
= GetIpAddrTable(*ppIpAddrTable
, &dwSize
, bOrder
);
168 if (ret
!= NO_ERROR
) {
169 HeapFree(heap
, flags
, *ppIpAddrTable
);
170 *ppIpAddrTable
= NULL
;
174 TRACE("returning %ld\n", ret
);
179 /******************************************************************
180 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
183 * ppIpForwardTable [Out] -- pointer into which the MIB_IPFORWARDTABLE is
184 * allocated and returned.
185 * bOrder [In] -- passed to GetIfTable to order the table
186 * heap [In] -- heap from which the table is allocated
187 * flags [In] -- flags to HeapAlloc
189 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
190 * GetIpForwardTable returns otherwise
193 DWORD WINAPI
AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE
*
194 ppIpForwardTable
, BOOL bOrder
, HANDLE heap
, DWORD flags
)
198 TRACE("ppIpForwardTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
199 ppIpForwardTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
200 if (!ppIpForwardTable
)
201 ret
= ERROR_INVALID_PARAMETER
;
205 *ppIpForwardTable
= NULL
;
206 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
207 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
208 *ppIpForwardTable
= (PMIB_IPFORWARDTABLE
)HeapAlloc(heap
, flags
, dwSize
);
209 ret
= GetIpForwardTable(*ppIpForwardTable
, &dwSize
, bOrder
);
210 if (ret
!= NO_ERROR
) {
211 HeapFree(heap
, flags
, *ppIpForwardTable
);
212 *ppIpForwardTable
= NULL
;
216 TRACE("returning %ld\n", ret
);
221 /******************************************************************
222 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
228 * bOrder [In] -- passed to GetIpNetTable to order the table
229 * heap [In] -- heap from which the table is allocated
230 * flags [In] -- flags to HeapAlloc
237 DWORD WINAPI
AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE
*ppIpNetTable
,
238 BOOL bOrder
, HANDLE heap
, DWORD flags
)
242 TRACE("ppIpNetTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
243 ppIpNetTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
245 ret
= ERROR_INVALID_PARAMETER
;
249 *ppIpNetTable
= NULL
;
250 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
251 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
252 *ppIpNetTable
= (PMIB_IPNETTABLE
)HeapAlloc(heap
, flags
, dwSize
);
253 ret
= GetIpNetTable(*ppIpNetTable
, &dwSize
, bOrder
);
254 if (ret
!= NO_ERROR
) {
255 HeapFree(heap
, flags
, *ppIpNetTable
);
256 *ppIpNetTable
= NULL
;
260 TRACE("returning %ld\n", ret
);
265 /******************************************************************
266 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
272 * bOrder [In] -- passed to GetTcpTable to order the table
273 * heap [In] -- heap from which the table is allocated
274 * flags [In] -- flags to HeapAlloc
281 DWORD WINAPI
AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE
*ppTcpTable
,
282 BOOL bOrder
, HANDLE heap
, DWORD flags
)
286 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
287 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
289 ret
= ERROR_INVALID_PARAMETER
;
294 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
295 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
296 *ppTcpTable
= (PMIB_TCPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
297 ret
= GetTcpTable(*ppTcpTable
, &dwSize
, bOrder
);
298 if (ret
!= NO_ERROR
) {
299 HeapFree(heap
, flags
, *ppTcpTable
);
304 TRACE("returning %ld\n", ret
);
309 /******************************************************************
310 * AllocateAndGetTcpExTableFromStack (IPHLPAPI.@)
316 * bOrder [In] -- passed to GetExtendedTcpTable to order the table
317 * heap [In] -- heap from which the table is allocated
318 * flags [In] -- flags to HeapAlloc
319 * family [In] -- passed to GetExtendedTcpTable to select INET family
326 DWORD WINAPI
AllocateAndGetTcpExTableFromStack(PVOID
*ppTcpTable
,
327 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
)
331 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family 0x%08lx\n",
332 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
);
334 ret
= ERROR_INVALID_PARAMETER
;
339 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, TCP_TABLE_OWNER_PID_ALL
, 0);
340 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
341 *ppTcpTable
= (PMIB_TCPTABLE_OWNER_PID
)HeapAlloc(heap
, flags
, dwSize
);
342 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, TCP_TABLE_OWNER_PID_ALL
, 0);
343 if (ret
!= NO_ERROR
) {
344 HeapFree(heap
, flags
, *ppTcpTable
);
349 TRACE("returning %ld\n", ret
);
354 /******************************************************************
355 * AllocateAndGetTcpExTable2FromStack (IPHLPAPI.@)
361 * bOrder [In] -- passed to GetExtendedTcpTable to order the table
362 * heap [In] -- heap from which the table is allocated
363 * flags [In] -- flags to HeapAlloc
364 * family [In] -- passed to GetExtendedTcpTable to select INET family
365 * class [In] -- passed to GetExtendedTcpTable to select information
372 DWORD WINAPI
AllocateAndGetTcpExTable2FromStack(PVOID
*ppTcpTable
,
373 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
, TCP_TABLE_CLASS
class)
377 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family %ld, class %ld\n",
378 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
, class);
380 ret
= ERROR_INVALID_PARAMETER
;
385 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, class, 0);
386 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
387 *ppTcpTable
= HeapAlloc(heap
, flags
, dwSize
);
388 ret
= GetExtendedTcpTable(*ppTcpTable
, &dwSize
, bOrder
, family
, class, 0);
389 if (ret
!= NO_ERROR
) {
390 HeapFree(heap
, flags
, *ppTcpTable
);
395 TRACE("returning %ld\n", ret
);
400 /******************************************************************
401 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
407 * bOrder [In] -- passed to GetUdpTable to order the table
408 * heap [In] -- heap from which the table is allocated
409 * flags [In] -- flags to HeapAlloc
416 DWORD WINAPI
AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE
*ppUdpTable
,
417 BOOL bOrder
, HANDLE heap
, DWORD flags
)
421 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
422 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
424 ret
= ERROR_INVALID_PARAMETER
;
429 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
430 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
431 *ppUdpTable
= (PMIB_UDPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
432 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
433 if (ret
!= NO_ERROR
) {
434 HeapFree(heap
, flags
, *ppUdpTable
);
439 TRACE("returning %ld\n", ret
);
444 /******************************************************************
445 * AllocateAndGetUdpExTableFromStack (IPHLPAPI.@)
451 * bOrder [In] -- passed to GetExtendedUdpTable to order the table
452 * heap [In] -- heap from which the table is allocated
453 * flags [In] -- flags to HeapAlloc
454 * family [In] -- passed to GetExtendedUdpTable to select INET family
461 DWORD WINAPI
AllocateAndGetUdpExTableFromStack(PVOID
*ppUdpTable
,
462 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
)
466 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family 0x%08lx\n",
467 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
);
469 ret
= ERROR_INVALID_PARAMETER
;
474 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, UDP_TABLE_OWNER_PID
, 0);
475 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
476 *ppUdpTable
= (PMIB_UDPTABLE_OWNER_PID
)HeapAlloc(heap
, flags
, dwSize
);
477 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, UDP_TABLE_OWNER_PID
, 0);
478 if (ret
!= NO_ERROR
) {
479 HeapFree(heap
, flags
, *ppUdpTable
);
484 TRACE("returning %ld\n", ret
);
489 /******************************************************************
490 * AllocateAndGetUdpExTable2FromStack (IPHLPAPI.@)
496 * bOrder [In] -- passed to GetExtendedUdpTable to order the table
497 * heap [In] -- heap from which the table is allocated
498 * flags [In] -- flags to HeapAlloc
499 * family [In] -- passed to GetExtendedUdpTable to select INET family
500 * class [In] -- passed to GetExtendedUdpTable to select information
507 DWORD WINAPI
AllocateAndGetUdpExTable2FromStack(PVOID
*ppUdpTable
,
508 BOOL bOrder
, HANDLE heap
, DWORD flags
, DWORD family
, UDP_TABLE_CLASS
class)
512 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx, family %ld, class %ld\n",
513 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
, family
, class);
515 ret
= ERROR_INVALID_PARAMETER
;
520 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, class, 0);
521 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
522 *ppUdpTable
= HeapAlloc(heap
, flags
, dwSize
);
523 ret
= GetExtendedUdpTable(*ppUdpTable
, &dwSize
, bOrder
, family
, class, 0);
524 if (ret
!= NO_ERROR
) {
525 HeapFree(heap
, flags
, *ppUdpTable
);
530 TRACE("returning %ld\n", ret
);
535 /******************************************************************
536 * CreateIpForwardEntry (IPHLPAPI.@)
548 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
550 return createIpForwardEntry( pRoute
);
554 /******************************************************************
555 * CreateIpNetEntry (IPHLPAPI.@)
567 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
569 TRACE("pArpEntry %p\n", pArpEntry
);
570 /* could use SIOCSARP on systems that support it, not sure I want to */
576 /******************************************************************
577 * CreateProxyArpEntry (IPHLPAPI.@)
591 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
593 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
596 /* marking Win2K+ functions not supported */
597 return ERROR_NOT_SUPPORTED
;
601 /******************************************************************
602 * DeleteIPAddress (IPHLPAPI.@)
614 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
616 TRACE("NTEContext %ld\n", NTEContext
);
617 return RtlNtStatusToDosError(deleteIpAddress(NTEContext
));
621 /******************************************************************
622 * DeleteIpForwardEntry (IPHLPAPI.@)
634 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
636 return deleteIpForwardEntry( pRoute
);
640 /******************************************************************
641 * DeleteIpNetEntry (IPHLPAPI.@)
653 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
655 TRACE("pArpEntry %p\n", pArpEntry
);
656 /* could use SIOCDARP on systems that support it, not sure I want to */
662 /******************************************************************
663 * DeleteProxyArpEntry (IPHLPAPI.@)
677 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
679 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
682 /* marking Win2K+ functions not supported */
683 return ERROR_NOT_SUPPORTED
;
686 /******************************************************************
687 * EnableRouter (IPHLPAPI.@)
693 * pOverlapped [In/Out]
700 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
702 TRACE("pHandle %p, pOverlapped %p\n", pHandle
, pOverlapped
);
704 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
705 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
706 marking Win2K+ functions not supported */
707 return ERROR_NOT_SUPPORTED
;
711 /******************************************************************
712 * FlushIpNetTable (IPHLPAPI.@)
724 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
726 TRACE("dwIfIndex 0x%08lx\n", dwIfIndex
);
728 /* this flushes the arp cache of the given index
729 marking Win2K+ functions not supported */
730 return ERROR_NOT_SUPPORTED
;
734 /******************************************************************
735 * GetAdapterIndex (IPHLPAPI.@)
740 * AdapterName [In/Out]
748 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
750 TRACE("AdapterName %p, IfIndex %p\n", AdapterName
, IfIndex
);
752 /* marking Win2K+ functions not supported */
753 return ERROR_NOT_SUPPORTED
;
757 /******************************************************************
758 * GetAdaptersInfo (IPHLPAPI.@)
763 * pAdapterInfo [In/Out]
764 * pOutBufLen [In/Out]
771 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
777 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
779 ret
= ERROR_INVALID_PARAMETER
;
781 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
783 if (numNonLoopbackInterfaces
> 0) {
784 /* this calculation assumes only one address in the IP_ADDR_STRING lists.
785 that's okay, because:
786 - we don't get multiple addresses per adapter anyway
787 - we don't know about per-adapter gateways
788 - DHCP and WINS servers can have max one entry per list */
789 ULONG size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
791 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
793 ret
= ERROR_BUFFER_OVERFLOW
;
796 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
799 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
800 if (*pOutBufLen
< size
) {
802 ret
= ERROR_INSUFFICIENT_BUFFER
;
807 BOOL winsEnabled
= FALSE
;
808 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
810 memset(pAdapterInfo
, 0, size
);
811 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
812 "Software\\Wine\\Wine\\Config\\Network", 0, KEY_READ
,
813 &hKey
) == ERROR_SUCCESS
) {
814 DWORD size
= sizeof(primaryWINS
.String
);
817 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
818 (PBYTE
)primaryWINS
.String
, &size
);
819 addr
= inet_addr(primaryWINS
.String
);
820 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
822 size
= sizeof(secondaryWINS
.String
);
823 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
824 (PBYTE
)secondaryWINS
.String
, &size
);
825 addr
= inet_addr(secondaryWINS
.String
);
826 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
830 TRACE("num of index is %lu\n", table
->numIndexes
);
831 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
832 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
833 DWORD addrLen
= sizeof(ptr
->Address
), type
;
835 getInterfaceNameByIndex(table
->indexes
[ndx
]);
837 ret
= ERROR_OUTOFMEMORY
;
841 /* on Win98 this is left empty, but whatever */
842 strncpy(ptr
->AdapterName
,ifname
,sizeof(ptr
->AdapterName
));
843 consumeInterfaceName(ifname
);
844 ptr
->AdapterName
[MAX_ADAPTER_NAME_LENGTH
] = '\0';
845 getInterfacePhysicalByIndex(table
->indexes
[ndx
], &addrLen
,
846 ptr
->Address
, &type
);
847 /* MS defines address length and type as UINT in some places and
848 DWORD in others, **sigh**. Don't want to assume that PUINT and
849 PDWORD are equiv (64-bit?) */
850 ptr
->AddressLength
= addrLen
;
852 ptr
->Index
= table
->indexes
[ndx
];
853 toIPAddressString(getInterfaceIPAddrByIndex(table
->indexes
[ndx
]),
854 ptr
->IpAddressList
.IpAddress
.String
);
855 toIPAddressString(getInterfaceMaskByIndex(table
->indexes
[ndx
]),
856 ptr
->IpAddressList
.IpMask
.String
);
857 ptr
->IpAddressList
.Context
= ptr
->Index
;
858 toIPAddressString(getInterfaceGatewayByIndex(table
->indexes
[ndx
]),
859 ptr
->GatewayList
.IpAddress
.String
);
860 getDhcpInfoForAdapter(table
->indexes
[ndx
], &dhcpEnabled
,
861 &dhcpServer
, &ptr
->LeaseObtained
,
863 ptr
->DhcpEnabled
= (DWORD
) dhcpEnabled
;
864 toIPAddressString(dhcpServer
,
865 ptr
->DhcpServer
.IpAddress
.String
);
867 ptr
->HaveWins
= TRUE
;
868 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
869 primaryWINS
.String
, sizeof(primaryWINS
.String
));
870 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
871 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
873 if (ndx
< table
->numIndexes
- 1)
874 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
883 ret
= ERROR_OUTOFMEMORY
;
889 TRACE("returning %ld\n", ret
);
894 /******************************************************************
895 * GetBestInterface (IPHLPAPI.@)
901 * pdwBestIfIndex [In/Out]
908 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
912 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr
, pdwBestIfIndex
);
914 ret
= ERROR_INVALID_PARAMETER
;
916 MIB_IPFORWARDROW ipRow
;
918 ret
= GetBestRoute(dwDestAddr
, 0, &ipRow
);
919 if (ret
== ERROR_SUCCESS
)
920 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
922 TRACE("returning %ld\n", ret
);
927 /******************************************************************
928 * GetBestRoute (IPHLPAPI.@)
942 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
944 PMIB_IPFORWARDTABLE table
;
947 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr
,
948 dwSourceAddr
, pBestRoute
);
950 return ERROR_INVALID_PARAMETER
;
952 AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
954 DWORD ndx
, minMaskSize
, matchedNdx
= 0;
956 for (ndx
= 0, minMaskSize
= 255; ndx
< table
->dwNumEntries
; ndx
++) {
957 if ((dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
958 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
961 if (!_BitScanForward(&hostMaskSize
, ntohl(table
->table
[ndx
].dwForwardMask
)))
965 if (hostMaskSize
< minMaskSize
) {
966 minMaskSize
= hostMaskSize
;
971 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
972 HeapFree(GetProcessHeap(), 0, table
);
976 ret
= ERROR_OUTOFMEMORY
;
977 TRACE("returning %ld\n", ret
);
981 static int TcpTableSorter(const void *a
, const void *b
)
986 PMIB_TCPROW rowA
= (PMIB_TCPROW
)a
, rowB
= (PMIB_TCPROW
)b
;
988 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
990 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
992 ret
= rowA
->dwRemoteAddr
- rowB
->dwRemoteAddr
;
994 ret
= rowA
->dwRemotePort
- rowB
->dwRemotePort
;
1003 /******************************************************************
1004 * GetExtendedTcpTable (IPHLPAPI.@)
1006 * Get the table of TCP endpoints available to the application.
1009 * pTcpTable [Out] table struct with the filtered TCP endpoints available to application
1010 * pdwSize [In/Out] estimated size of the structure returned in pTcpTable, in bytes
1011 * bOrder [In] whether to order the table
1012 * ulAf [in] version of IP used by the TCP endpoints
1013 * TableClass [in] type of the TCP table structure from TCP_TABLE_CLASS
1014 * Reserved [in] reserved - this value must be zero
1018 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
1023 DWORD WINAPI
GetExtendedTcpTable(PVOID pTcpTable
, PDWORD pdwSize
, BOOL bOrder
, ULONG ulAf
, TCP_TABLE_CLASS TableClass
, ULONG Reserved
)
1025 DWORD i
, count
, size
;
1026 DWORD ret
= NO_ERROR
;
1030 return ERROR_INVALID_PARAMETER
;
1033 if (ulAf
!= AF_INET
)
1036 return ERROR_INVALID_PARAMETER
;
1041 case TCP_TABLE_BASIC_ALL
:
1043 PMIB_TCPTABLE pOurTcpTable
= getTcpTable(ClassBasic
);
1044 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1048 size
= FIELD_OFFSET(MIB_TCPTABLE
, table
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW
);
1049 if (size
> *pdwSize
|| !pTheirTcpTable
)
1052 ret
= ERROR_INSUFFICIENT_BUFFER
;
1056 memcpy(pTheirTcpTable
, pOurTcpTable
, size
);
1059 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1060 sizeof(MIB_TCPROW
), TcpTableSorter
);
1068 case TCP_TABLE_BASIC_CONNECTIONS
:
1070 PMIB_TCPTABLE pOurTcpTable
= getTcpTable(ClassBasic
);
1071 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1075 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1077 if (pOurTcpTable
->table
[i
].State
!= MIB_TCP_STATE_LISTEN
)
1083 size
= FIELD_OFFSET(MIB_TCPTABLE
, table
) + count
* sizeof(MIB_TCPROW
);
1084 if (size
> *pdwSize
|| !pTheirTcpTable
)
1087 ret
= ERROR_INSUFFICIENT_BUFFER
;
1091 pTheirTcpTable
->dwNumEntries
= count
;
1093 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1095 if (pOurTcpTable
->table
[i
].State
!= MIB_TCP_STATE_LISTEN
)
1097 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW
));
1101 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1104 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1105 sizeof(MIB_TCPROW
), TcpTableSorter
);
1113 case TCP_TABLE_BASIC_LISTENER
:
1115 PMIB_TCPTABLE pOurTcpTable
= getTcpTable(ClassBasic
);
1116 PMIB_TCPTABLE pTheirTcpTable
= pTcpTable
;
1120 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1122 if (pOurTcpTable
->table
[i
].State
== MIB_TCP_STATE_LISTEN
)
1128 size
= FIELD_OFFSET(MIB_TCPTABLE
, table
) + count
* sizeof(MIB_TCPROW
);
1129 if (size
> *pdwSize
|| !pTheirTcpTable
)
1132 ret
= ERROR_INSUFFICIENT_BUFFER
;
1136 pTheirTcpTable
->dwNumEntries
= count
;
1138 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1140 if (pOurTcpTable
->table
[i
].State
== MIB_TCP_STATE_LISTEN
)
1142 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW
));
1146 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1149 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1150 sizeof(MIB_TCPROW
), TcpTableSorter
);
1158 case TCP_TABLE_OWNER_PID_ALL
:
1160 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getTcpTable(ClassModulePid
);
1161 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1165 size
= FIELD_OFFSET(MIB_TCPTABLE_OWNER_PID
, table
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_PID
);
1166 if (size
> *pdwSize
|| !pTheirTcpTable
)
1169 ret
= ERROR_INSUFFICIENT_BUFFER
;
1173 memcpy(pTheirTcpTable
, pOurTcpTable
, size
);
1175 /* Don't sort on PID, so use basic helper */
1177 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1178 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1186 case TCP_TABLE_OWNER_PID_CONNECTIONS
:
1188 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getTcpTable(ClassModulePid
);
1189 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1193 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1195 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1201 size
= FIELD_OFFSET(MIB_TCPTABLE_OWNER_PID
, table
) + count
* sizeof(MIB_TCPROW_OWNER_PID
);
1202 if (size
> *pdwSize
|| !pTheirTcpTable
)
1205 ret
= ERROR_INSUFFICIENT_BUFFER
;
1209 pTheirTcpTable
->dwNumEntries
= count
;
1211 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1213 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1215 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_PID
));
1219 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1221 /* Don't sort on PID, so use basic helper */
1223 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1224 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1232 case TCP_TABLE_OWNER_PID_LISTENER
:
1234 PMIB_TCPTABLE_OWNER_PID pOurTcpTable
= getTcpTable(ClassModulePid
);
1235 PMIB_TCPTABLE_OWNER_PID pTheirTcpTable
= pTcpTable
;
1239 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1241 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1247 size
= FIELD_OFFSET(MIB_TCPTABLE_OWNER_PID
, table
) + count
* sizeof(MIB_TCPROW_OWNER_PID
);
1248 if (size
> *pdwSize
|| !pTheirTcpTable
)
1251 ret
= ERROR_INSUFFICIENT_BUFFER
;
1255 pTheirTcpTable
->dwNumEntries
= count
;
1257 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1259 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1261 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_PID
));
1265 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1267 /* Don't sort on PID, so use basic helper */
1269 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1270 sizeof(MIB_TCPROW_OWNER_PID
), TcpTableSorter
);
1278 case TCP_TABLE_OWNER_MODULE_ALL
:
1280 PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable
= getTcpTable(ClassModule
);
1281 PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable
= pTcpTable
;
1285 size
= FIELD_OFFSET(MIB_TCPTABLE_OWNER_MODULE
, table
) + pOurTcpTable
->dwNumEntries
* sizeof(MIB_TCPROW_OWNER_MODULE
);
1286 if (size
> *pdwSize
|| !pTheirTcpTable
)
1289 ret
= ERROR_INSUFFICIENT_BUFFER
;
1293 memcpy(pTheirTcpTable
, pOurTcpTable
, size
);
1295 /* Don't sort on PID, so use basic helper */
1297 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1298 sizeof(MIB_TCPROW_OWNER_MODULE
), TcpTableSorter
);
1306 case TCP_TABLE_OWNER_MODULE_CONNECTIONS
:
1308 PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable
= getTcpTable(ClassModule
);
1309 PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable
= pTcpTable
;
1313 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1315 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1321 size
= FIELD_OFFSET(MIB_TCPTABLE_OWNER_MODULE
, table
) + count
* sizeof(MIB_TCPROW_OWNER_MODULE
);
1322 if (size
> *pdwSize
|| !pTheirTcpTable
)
1325 ret
= ERROR_INSUFFICIENT_BUFFER
;
1329 pTheirTcpTable
->dwNumEntries
= count
;
1331 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1333 if (pOurTcpTable
->table
[i
].dwState
!= MIB_TCP_STATE_LISTEN
)
1335 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_MODULE
));
1339 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1341 /* Don't sort on PID, so use basic helper */
1343 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1344 sizeof(MIB_TCPROW_OWNER_MODULE
), TcpTableSorter
);
1352 case TCP_TABLE_OWNER_MODULE_LISTENER
:
1354 PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable
= getTcpTable(ClassModule
);
1355 PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable
= pTcpTable
;
1359 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1361 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1367 size
= FIELD_OFFSET(MIB_TCPTABLE_OWNER_MODULE
, table
) + count
* sizeof(MIB_TCPROW_OWNER_MODULE
);
1368 if (size
> *pdwSize
|| !pTheirTcpTable
)
1371 ret
= ERROR_INSUFFICIENT_BUFFER
;
1375 pTheirTcpTable
->dwNumEntries
= count
;
1377 for (i
= 0, count
= 0; i
< pOurTcpTable
->dwNumEntries
; ++i
)
1379 if (pOurTcpTable
->table
[i
].dwState
== MIB_TCP_STATE_LISTEN
)
1381 memcpy(&pTheirTcpTable
->table
[count
], &pOurTcpTable
->table
[i
], sizeof(MIB_TCPROW_OWNER_MODULE
));
1385 ASSERT(count
== pTheirTcpTable
->dwNumEntries
);
1387 /* Don't sort on PID, so use basic helper */
1389 qsort(pTheirTcpTable
->table
, pTheirTcpTable
->dwNumEntries
,
1390 sizeof(MIB_TCPROW_OWNER_MODULE
), TcpTableSorter
);
1399 ret
= ERROR_INVALID_PARAMETER
;
1407 static int UdpTableSorter(const void *a
, const void *b
)
1412 PMIB_UDPROW rowA
= (PMIB_UDPROW
)a
, rowB
= (PMIB_UDPROW
)b
;
1414 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1416 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1423 /******************************************************************
1424 * GetExtendedUdpTable (IPHLPAPI.@)
1426 * Get the table of UDP endpoints available to the application.
1429 * pUdpTable [Out] table struct with the filtered UDP endpoints available to application
1430 * pdwSize [In/Out] estimated size of the structure returned in pUdpTable, in bytes
1431 * bOrder [In] whether to order the table
1432 * ulAf [in] version of IP used by the UDP endpoints
1433 * TableClass [in] type of the UDP table structure from UDP_TABLE_CLASS
1434 * Reserved [in] reserved - this value must be zero
1438 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
1443 DWORD WINAPI
GetExtendedUdpTable(PVOID pUdpTable
, PDWORD pdwSize
, BOOL bOrder
, ULONG ulAf
, UDP_TABLE_CLASS TableClass
, ULONG Reserved
)
1446 DWORD ret
= NO_ERROR
;
1450 return ERROR_INVALID_PARAMETER
;
1453 if (ulAf
!= AF_INET
)
1456 return ERROR_INVALID_PARAMETER
;
1461 case UDP_TABLE_BASIC
:
1463 PMIB_UDPTABLE pOurUdpTable
= getUdpTable(ClassBasic
);
1464 PMIB_UDPTABLE pTheirUdpTable
= pUdpTable
;
1468 size
= FIELD_OFFSET(MIB_UDPTABLE
, table
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW
);
1469 if (size
> *pdwSize
|| !pTheirUdpTable
)
1472 ret
= ERROR_INSUFFICIENT_BUFFER
;
1476 memcpy(pTheirUdpTable
, pOurUdpTable
, size
);
1479 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1480 sizeof(MIB_UDPROW
), UdpTableSorter
);
1488 case UDP_TABLE_OWNER_PID
:
1490 PMIB_UDPTABLE_OWNER_PID pOurUdpTable
= getUdpTable(ClassModulePid
);
1491 PMIB_UDPTABLE_OWNER_PID pTheirUdpTable
= pUdpTable
;
1495 size
= FIELD_OFFSET(MIB_UDPTABLE_OWNER_PID
, table
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_PID
);
1496 if (size
> *pdwSize
|| !pTheirUdpTable
)
1499 ret
= ERROR_INSUFFICIENT_BUFFER
;
1503 memcpy(pTheirUdpTable
, pOurUdpTable
, size
);
1506 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1507 sizeof(MIB_UDPROW_OWNER_PID
), UdpTableSorter
);
1515 case UDP_TABLE_OWNER_MODULE
:
1517 PMIB_UDPTABLE_OWNER_MODULE pOurUdpTable
= getUdpTable(ClassModule
);
1518 PMIB_UDPTABLE_OWNER_MODULE pTheirUdpTable
= pUdpTable
;
1522 size
= FIELD_OFFSET(MIB_UDPTABLE_OWNER_MODULE
, table
) + pOurUdpTable
->dwNumEntries
* sizeof(MIB_UDPROW_OWNER_MODULE
);
1523 if (size
> *pdwSize
|| !pTheirUdpTable
)
1526 ret
= ERROR_INSUFFICIENT_BUFFER
;
1530 memcpy(pTheirUdpTable
, pOurUdpTable
, size
);
1533 qsort(pTheirUdpTable
->table
, pTheirUdpTable
->dwNumEntries
,
1534 sizeof(MIB_UDPROW_OWNER_MODULE
), UdpTableSorter
);
1543 ret
= ERROR_INVALID_PARAMETER
;
1551 /******************************************************************
1552 * GetFriendlyIfIndex (IPHLPAPI.@)
1564 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
1566 /* windows doesn't validate these, either, just makes sure the top byte is
1567 cleared. I assume my ifenum module never gives an index with the top
1569 TRACE("returning %ld\n", IfIndex
);
1574 /******************************************************************
1575 * GetIcmpStatistics (IPHLPAPI.@)
1587 DWORD WINAPI
GetIcmpStatistics(PMIB_ICMP pStats
)
1591 TRACE("pStats %p\n", pStats
);
1592 ret
= getICMPStats(pStats
);
1593 TRACE("returning %ld\n", ret
);
1598 /******************************************************************
1599 * GetIfEntry (IPHLPAPI.@)
1611 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
1616 TRACE("pIfRow %p\n", pIfRow
);
1618 return ERROR_INVALID_PARAMETER
;
1620 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
);
1622 ret
= getInterfaceEntryByIndex(pIfRow
->dwIndex
, pIfRow
);
1623 if (ret
== NO_ERROR
)
1624 ret
= getInterfaceStatsByName(name
, pIfRow
);
1625 consumeInterfaceName(name
);
1628 ret
= ERROR_INVALID_DATA
;
1629 TRACE("returning %ld\n", ret
);
1634 static int IfTableSorter(const void *a
, const void *b
)
1639 ret
= ((PMIB_IFROW
)a
)->dwIndex
- ((PMIB_IFROW
)b
)->dwIndex
;
1646 /******************************************************************
1647 * GetIfTable (IPHLPAPI.@)
1661 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
1665 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize
, pdwSize
,
1668 ret
= ERROR_INVALID_PARAMETER
;
1670 DWORD numInterfaces
= getNumInterfaces();
1672 TRACE("GetIfTable: numInterfaces = %d\n", (int)numInterfaces
);
1673 size
= sizeof(MIB_IFTABLE
) + (numInterfaces
- 1) * sizeof(MIB_IFROW
);
1675 if (!pIfTable
|| *pdwSize
< size
) {
1677 ret
= ERROR_INSUFFICIENT_BUFFER
;
1680 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1683 size
= sizeof(MIB_IFTABLE
) + (table
->numIndexes
- 1) *
1685 if (*pdwSize
< size
) {
1687 ret
= ERROR_INSUFFICIENT_BUFFER
;
1692 pIfTable
->dwNumEntries
= 0;
1693 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1694 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1695 GetIfEntry(&pIfTable
->table
[ndx
]);
1696 pIfTable
->dwNumEntries
++;
1699 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
1706 ret
= ERROR_OUTOFMEMORY
;
1709 TRACE("returning %ld\n", ret
);
1714 /******************************************************************
1715 * GetInterfaceInfo (IPHLPAPI.@)
1721 * dwOutBufLen [In/Out]
1728 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1732 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1734 ret
= ERROR_INVALID_PARAMETER
;
1736 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
1738 TRACE("numNonLoopbackInterfaces == 0x%x\n", numNonLoopbackInterfaces
);
1739 size
= sizeof(IP_INTERFACE_INFO
) + (numNonLoopbackInterfaces
) *
1740 sizeof(IP_ADAPTER_INDEX_MAP
);
1742 if (!pIfTable
|| *dwOutBufLen
< size
) {
1743 *dwOutBufLen
= size
;
1744 ret
= ERROR_INSUFFICIENT_BUFFER
;
1747 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
1750 TRACE("table->numIndexes == 0x%x\n", table
->numIndexes
);
1751 size
= sizeof(IP_INTERFACE_INFO
) + (table
->numIndexes
) *
1752 sizeof(IP_ADAPTER_INDEX_MAP
);
1753 if (*dwOutBufLen
< size
) {
1754 *dwOutBufLen
= size
;
1755 ret
= ERROR_INSUFFICIENT_BUFFER
;
1760 pIfTable
->NumAdapters
= 0;
1761 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1762 const char *walker
, *name
;
1765 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1766 name
= getInterfaceNameByIndex(table
->indexes
[ndx
]);
1767 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1768 walker
&& *walker
&&
1769 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1770 walker
++, assigner
++)
1771 *assigner
= *walker
;
1773 consumeInterfaceName(name
);
1774 pIfTable
->NumAdapters
++;
1781 ret
= ERROR_OUTOFMEMORY
;
1784 TRACE("returning %ld\n", ret
);
1789 static int IpAddrTableSorter(const void *a
, const void *b
)
1794 ret
= ((PMIB_IPADDRROW
)a
)->dwAddr
- ((PMIB_IPADDRROW
)b
)->dwAddr
;
1801 /******************************************************************
1802 * GetIpAddrTable (IPHLPAPI.@)
1807 * pIpAddrTable [In/Out]
1816 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1820 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable
, pdwSize
,
1823 ret
= ERROR_INVALID_PARAMETER
;
1825 DWORD numInterfaces
= getNumInterfaces();
1826 ULONG size
= sizeof(MIB_IPADDRTABLE
) + (numInterfaces
- 1) *
1827 sizeof(MIB_IPADDRROW
);
1829 if (!pIpAddrTable
|| *pdwSize
< size
) {
1831 ret
= ERROR_INSUFFICIENT_BUFFER
;
1834 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1837 size
= sizeof(MIB_IPADDRTABLE
) + (table
->numIndexes
- 1) *
1838 sizeof(MIB_IPADDRROW
);
1839 if (*pdwSize
< size
) {
1841 ret
= ERROR_INSUFFICIENT_BUFFER
;
1846 pIpAddrTable
->dwNumEntries
= 0;
1847 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1848 pIpAddrTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1849 pIpAddrTable
->table
[ndx
].dwAddr
=
1850 getInterfaceIPAddrByIndex(table
->indexes
[ndx
]);
1851 pIpAddrTable
->table
[ndx
].dwMask
=
1852 getInterfaceMaskByIndex(table
->indexes
[ndx
]);
1853 /* the dwBCastAddr member isn't the broadcast address, it indicates
1854 * whether the interface uses the 1's broadcast address (1) or the
1855 * 0's broadcast address (0).
1857 bcast
= getInterfaceBCastAddrByIndex(table
->indexes
[ndx
]);
1858 pIpAddrTable
->table
[ndx
].dwBCastAddr
=
1859 (bcast
& pIpAddrTable
->table
[ndx
].dwMask
) ? 1 : 0;
1860 /* FIXME: hardcoded reasm size, not sure where to get it */
1861 pIpAddrTable
->table
[ndx
].dwReasmSize
= 65535;
1862 pIpAddrTable
->table
[ndx
].unused1
= 0;
1863 pIpAddrTable
->table
[ndx
].wType
= 0; /* aka unused2 */
1864 pIpAddrTable
->dwNumEntries
++;
1867 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1868 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1874 ret
= ERROR_OUTOFMEMORY
;
1877 TRACE("returning %ld\n", ret
);
1882 static int IpForwardTableSorter(const void *a
, const void *b
)
1887 PMIB_IPFORWARDROW rowA
= (PMIB_IPFORWARDROW
)a
, rowB
= (PMIB_IPFORWARDROW
)b
;
1889 ret
= rowA
->dwForwardDest
- rowB
->dwForwardDest
;
1891 ret
= rowA
->dwForwardProto
- rowB
->dwForwardProto
;
1893 ret
= rowA
->dwForwardPolicy
- rowB
->dwForwardPolicy
;
1895 ret
= rowA
->dwForwardNextHop
- rowB
->dwForwardNextHop
;
1905 /******************************************************************
1906 * GetIpForwardTable (IPHLPAPI.@)
1911 * pIpForwardTable [In/Out]
1920 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1924 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable
,
1925 pdwSize
, (DWORD
)bOrder
);
1927 ret
= ERROR_INVALID_PARAMETER
;
1929 DWORD numRoutes
= getNumRoutes();
1930 ULONG sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (numRoutes
- 1) *
1931 sizeof(MIB_IPFORWARDROW
);
1933 if (!pIpForwardTable
|| *pdwSize
< sizeNeeded
) {
1934 *pdwSize
= sizeNeeded
;
1935 ret
= ERROR_INSUFFICIENT_BUFFER
;
1938 RouteTable
*table
= getRouteTable();
1940 sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (table
->numRoutes
- 1) *
1941 sizeof(MIB_IPFORWARDROW
);
1942 if (*pdwSize
< sizeNeeded
) {
1943 *pdwSize
= sizeNeeded
;
1944 ret
= ERROR_INSUFFICIENT_BUFFER
;
1949 pIpForwardTable
->dwNumEntries
= table
->numRoutes
;
1950 for (ndx
= 0; ndx
< numRoutes
; ndx
++) {
1951 pIpForwardTable
->table
[ndx
].dwForwardIfIndex
=
1952 table
->routes
[ndx
].ifIndex
;
1953 pIpForwardTable
->table
[ndx
].dwForwardDest
=
1954 table
->routes
[ndx
].dest
;
1955 pIpForwardTable
->table
[ndx
].dwForwardMask
=
1956 table
->routes
[ndx
].mask
;
1957 pIpForwardTable
->table
[ndx
].dwForwardPolicy
= 0;
1958 pIpForwardTable
->table
[ndx
].dwForwardNextHop
=
1959 table
->routes
[ndx
].gateway
;
1960 /* FIXME: this type is appropriate for local interfaces; may not
1961 always be appropriate */
1962 pIpForwardTable
->table
[ndx
].dwForwardType
= MIB_IPROUTE_TYPE_DIRECT
;
1963 /* FIXME: other protos might be appropriate, e.g. the default route
1964 is typically set with MIB_IPPROTO_NETMGMT instead */
1965 pIpForwardTable
->table
[ndx
].dwForwardProto
= MIB_IPPROTO_LOCAL
;
1966 /* punt on age and AS */
1967 pIpForwardTable
->table
[ndx
].dwForwardAge
= 0;
1968 pIpForwardTable
->table
[ndx
].dwForwardNextHopAS
= 0;
1969 pIpForwardTable
->table
[ndx
].dwForwardMetric1
=
1970 table
->routes
[ndx
].metric
;
1971 /* rest of the metrics are 0.. */
1972 pIpForwardTable
->table
[ndx
].dwForwardMetric2
= 0;
1973 pIpForwardTable
->table
[ndx
].dwForwardMetric3
= 0;
1974 pIpForwardTable
->table
[ndx
].dwForwardMetric4
= 0;
1975 pIpForwardTable
->table
[ndx
].dwForwardMetric5
= 0;
1978 qsort(pIpForwardTable
->table
, pIpForwardTable
->dwNumEntries
,
1979 sizeof(MIB_IPFORWARDROW
), IpForwardTableSorter
);
1982 HeapFree(GetProcessHeap(), 0, table
);
1985 ret
= ERROR_OUTOFMEMORY
;
1988 TRACE("returning %ld\n", ret
);
1993 static int IpNetTableSorter(const void *a
, const void *b
)
1998 ret
= ((PMIB_IPNETROW
)a
)->dwAddr
- ((PMIB_IPNETROW
)b
)->dwAddr
;
2005 /******************************************************************
2006 * GetIpNetTable (IPHLPAPI.@)
2011 * pIpNetTable [In/Out]
2020 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
2022 DWORD ret
= NO_ERROR
;
2024 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
,
2027 ret
= ERROR_INVALID_PARAMETER
;
2029 DWORD numEntries
= getNumArpEntries();
2030 ULONG size
= sizeof(MIB_IPNETTABLE
);
2033 size
+= (numEntries
- 1) * sizeof(MIB_IPNETROW
);
2034 if (!pIpNetTable
|| *pdwSize
< size
) {
2036 ret
= ERROR_INSUFFICIENT_BUFFER
;
2039 PMIB_IPNETTABLE table
= getArpTable();
2041 size
= sizeof(MIB_IPNETTABLE
);
2042 if (table
->dwNumEntries
> 1)
2043 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPNETROW
);
2044 if (*pdwSize
< size
) {
2046 ret
= ERROR_INSUFFICIENT_BUFFER
;
2050 memcpy(pIpNetTable
, table
, size
);
2052 qsort(pIpNetTable
->table
, pIpNetTable
->dwNumEntries
,
2053 sizeof(MIB_IPNETROW
), IpNetTableSorter
);
2056 HeapFree(GetProcessHeap(), 0, table
);
2060 TRACE("returning %d\n", ret
);
2065 /******************************************************************
2066 * GetIpStatistics (IPHLPAPI.@)
2078 DWORD WINAPI
GetIpStatistics(PMIB_IPSTATS pStats
)
2080 return GetIpStatisticsEx(pStats
, PF_INET
);
2083 /******************************************************************
2084 * GetIpStatisticsEx (IPHLPAPI.@)
2097 DWORD WINAPI
GetIpStatisticsEx(PMIB_IPSTATS pStats
, DWORD dwFamily
)
2101 TRACE("pStats %p\n", pStats
);
2102 ret
= getIPStats(pStats
, dwFamily
);
2103 TRACE("returning %ld\n", ret
);
2107 /******************************************************************
2108 * GetNetworkParams (IPHLPAPI.@)
2113 * pFixedInfo [In/Out]
2114 * pOutBufLen [In/Out]
2121 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
2123 DWORD ret
, size
, type
;
2126 PIPHLP_RES_INFO resInfo
;
2128 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
2130 return ERROR_INVALID_PARAMETER
;
2132 resInfo
= getResInfo();
2134 return ERROR_OUTOFMEMORY
;
2136 size
= sizeof(FIXED_INFO
) + (resInfo
->riCount
> 1 ? (resInfo
->riCount
-1) *
2137 sizeof(IP_ADDR_STRING
) : 0);
2138 if (!pFixedInfo
|| *pOutBufLen
< size
) {
2140 disposeResInfo( resInfo
);
2141 return ERROR_BUFFER_OVERFLOW
;
2144 memset(pFixedInfo
, 0, size
);
2145 /* Check for DhcpHostname and DhcpDomain first */
2146 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2147 "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
2151 if (regReturn
== ERROR_SUCCESS
) {
2152 /* Windows doesn't honor DHCP option 12 even if RFC requires it if it is returned by DHCP server! */
2155 size
= sizeof(pFixedInfo
->HostName
);
2156 regReturn
= RegQueryValueExA(hKey
,
2160 (LPBYTE
)pFixedInfo
->HostName
,
2162 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
2166 size
= sizeof(pFixedInfo
->HostName
);
2167 regReturn
= RegQueryValueExA(hKey
,
2171 (LPBYTE
)pFixedInfo
->HostName
,
2178 size
= sizeof(pFixedInfo
->DomainName
);
2179 regReturn
= RegQueryValueExA(hKey
,
2183 (LPBYTE
)pFixedInfo
->DomainName
,
2185 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
2188 size
= sizeof(pFixedInfo
->DomainName
);
2189 regReturn
= RegQueryValueExA(hKey
,
2193 (LPBYTE
)pFixedInfo
->DomainName
,
2199 TRACE("GetComputerNameExA: %s\n", pFixedInfo
->DomainName
);
2201 if (resInfo
->riCount
> 0)
2203 CopyMemory(&pFixedInfo
->DnsServerList
, resInfo
->DnsList
, sizeof(IP_ADDR_STRING
));
2204 if (resInfo
->riCount
> 1)
2206 IP_ADDR_STRING
*pSrc
= resInfo
->DnsList
->Next
;
2207 IP_ADDR_STRING
*pTarget
= (struct _IP_ADDR_STRING
*)((char*)pFixedInfo
+ sizeof(FIXED_INFO
));
2209 pFixedInfo
->DnsServerList
.Next
= pTarget
;
2213 CopyMemory(pTarget
, pSrc
, sizeof(IP_ADDR_STRING
));
2215 if (resInfo
->riCount
> 1)
2217 pTarget
->Next
= (IP_ADDR_STRING
*)((char*)pTarget
+ sizeof(IP_ADDR_STRING
));
2218 pTarget
= pTarget
->Next
;
2223 pTarget
->Next
= NULL
;
2231 pFixedInfo
->DnsServerList
.Next
= NULL
;
2235 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
2236 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2237 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
2238 if (regReturn
!= ERROR_SUCCESS
)
2239 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2240 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
2242 if (regReturn
== ERROR_SUCCESS
)
2244 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
2246 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (PBYTE
)pFixedInfo
->ScopeId
, &size
);
2250 disposeResInfo( resInfo
);
2251 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
2252 I suppose could also check for a listener on port 53 to set EnableDns */
2254 TRACE("returning %ld\n", ret
);
2260 /******************************************************************
2261 * GetNumberOfInterfaces (IPHLPAPI.@)
2273 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
2277 TRACE("pdwNumIf %p\n", pdwNumIf
);
2279 ret
= ERROR_INVALID_PARAMETER
;
2281 *pdwNumIf
= getNumInterfaces();
2284 TRACE("returning %ld\n", ret
);
2289 static DWORD
GetOwnerModuleFromPidEntry(DWORD OwningPid
, TCPIP_OWNER_MODULE_INFO_CLASS Class
, PVOID Buffer
, PDWORD pdwSize
)
2292 DWORD FileLen
, PathLen
;
2293 WCHAR File
[MAX_PATH
], Path
[MAX_PATH
];
2294 PTCPIP_OWNER_MODULE_BASIC_INFO BasicInfo
;
2298 return ERROR_NOT_FOUND
;
2301 Process
= OpenProcess(PROCESS_QUERY_INFORMATION
| PROCESS_VM_READ
, FALSE
, OwningPid
);
2302 if (Process
== NULL
)
2304 return GetLastError();
2307 FileLen
= GetModuleBaseNameW(Process
, NULL
, File
, MAX_PATH
);
2310 PathLen
= GetModuleFileNameExW(Process
, NULL
, Path
, MAX_PATH
);
2313 CloseHandle(Process
);
2314 return GetLastError();
2320 PathLen
*= sizeof(WCHAR
);
2321 FileLen
*= sizeof(WCHAR
);
2323 else if (GetLastError() == ERROR_PARTIAL_COPY
)
2325 wcscpy(File
, L
"System");
2326 wcscpy(Path
, L
"System");
2328 PathLen
= sizeof(L
"System");
2329 FileLen
= sizeof(L
"System");
2332 CloseHandle(Process
);
2334 if (*pdwSize
< sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
) + PathLen
+ FileLen
)
2336 *pdwSize
= sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
) + PathLen
+ FileLen
;
2337 return ERROR_INSUFFICIENT_BUFFER
;
2341 BasicInfo
->pModuleName
= (PVOID
)((ULONG_PTR
)BasicInfo
+ sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
));
2342 BasicInfo
->pModulePath
= (PVOID
)((ULONG_PTR
)BasicInfo
->pModuleName
+ FileLen
);
2343 wcscpy(BasicInfo
->pModuleName
, File
);
2344 wcscpy(BasicInfo
->pModulePath
, Path
);
2345 *pdwSize
= sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
) + PathLen
+ FileLen
;
2350 static DWORD
GetOwnerModuleFromTagEntry(DWORD OwningPid
, DWORD OwningTag
, TCPIP_OWNER_MODULE_INFO_CLASS Class
, PVOID Buffer
, PDWORD pdwSize
)
2355 WCHAR SysDir
[MAX_PATH
];
2356 PTCPIP_OWNER_MODULE_BASIC_INFO BasicInfo
;
2357 ULONG (NTAPI
*_I_QueryTagInformation
)(PVOID
, DWORD
, PVOID
);
2366 /* First, secure (avoid injections) load advapi32.dll */
2367 Size
= GetSystemDirectoryW(SysDir
, MAX_PATH
);
2370 return GetLastError();
2373 Res
= StringCchCatW(&SysDir
[Size
], MAX_PATH
- Size
, L
"\\advapi32.dll");
2379 hAdvapi32
= GetModuleHandleW(SysDir
);
2380 if (hAdvapi32
== NULL
)
2382 return GetLastError();
2385 /* Now, we'll query the service associated with the tag */
2386 _I_QueryTagInformation
= (PVOID
)GetProcAddress(hAdvapi32
, "I_QueryTagInformation");
2387 if (_I_QueryTagInformation
== NULL
)
2389 return GetLastError();
2392 /* Set tag and PID for the query */
2393 ServiceQuery
.ProcessId
= OwningPid
;
2394 ServiceQuery
.ServiceTag
= OwningTag
;
2395 ServiceQuery
.TagType
= 0;
2396 ServiceQuery
.Buffer
= NULL
;
2399 Res
= _I_QueryTagInformation(NULL
, 1, &ServiceQuery
);
2400 if (Res
!= ERROR_SUCCESS
)
2405 /* Compute service name length */
2406 Size
= wcslen(ServiceQuery
.Buffer
) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
);
2408 /* We'll copy it twice, so make sure we have enough room */
2409 if (*pdwSize
< sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
) + 2 * Size
)
2411 *pdwSize
= sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
) + 2 * Size
;
2412 LocalFree(ServiceQuery
.Buffer
);
2413 return ERROR_INSUFFICIENT_BUFFER
;
2416 /* Copy back data */
2418 BasicInfo
->pModuleName
= (PVOID
)((ULONG_PTR
)BasicInfo
+ sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
));
2419 BasicInfo
->pModulePath
= (PVOID
)((ULONG_PTR
)BasicInfo
->pModuleName
+ Size
);
2420 wcscpy(BasicInfo
->pModuleName
, ServiceQuery
.Buffer
);
2421 wcscpy(BasicInfo
->pModulePath
, ServiceQuery
.Buffer
);
2422 *pdwSize
= sizeof(TCPIP_OWNER_MODULE_BASIC_INFO
) + 2 * Size
;
2423 LocalFree(ServiceQuery
.Buffer
);
2428 /******************************************************************
2429 * GetOwnerModuleFromTcpEntry (IPHLPAPI.@)
2431 * Get data about the module that issued the context bind for a specific IPv4 TCP endpoint in a MIB table row
2434 * pTcpEntry [in] pointer to a MIB_TCPROW_OWNER_MODULE structure
2435 * Class [in] TCPIP_OWNER_MODULE_INFO_CLASS enumeration value
2436 * Buffer [out] pointer a buffer containing a TCPIP_OWNER_MODULE_BASIC_INFO structure with the owner module data.
2437 * pdwSize [in, out] estimated size of the structure returned in Buffer, in bytes
2441 * Failure: ERROR_INSUFFICIENT_BUFFER, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY
2442 * ERROR_NOT_FOUND or ERROR_PARTIAL_COPY
2445 * The type of data returned in Buffer is indicated by the value of the Class parameter.
2447 DWORD WINAPI
GetOwnerModuleFromTcpEntry( PMIB_TCPROW_OWNER_MODULE pTcpEntry
, TCPIP_OWNER_MODULE_INFO_CLASS Class
, PVOID Buffer
, PDWORD pdwSize
)
2449 /* If we have a service tag, that's a service connection */
2450 if (pTcpEntry
->OwningModuleInfo
[0] != 0)
2452 return GetOwnerModuleFromTagEntry(pTcpEntry
->dwOwningPid
, (DWORD
)(pTcpEntry
->OwningModuleInfo
[0]), Class
, Buffer
, pdwSize
);
2456 return GetOwnerModuleFromPidEntry(pTcpEntry
->dwOwningPid
, Class
, Buffer
, pdwSize
);
2460 /******************************************************************
2461 * GetOwnerModuleFromUdpEntry (IPHLPAPI.@)
2463 * Get data about the module that issued the context bind for a specific IPv4 UDP endpoint in a MIB table row
2466 * pUdpEntry [in] pointer to a MIB_UDPROW_OWNER_MODULE structure
2467 * Class [in] TCPIP_OWNER_MODULE_INFO_CLASS enumeration value
2468 * Buffer [out] pointer a buffer containing a TCPIP_OWNER_MODULE_BASIC_INFO structure with the owner module data.
2469 * pdwSize [in, out] estimated size of the structure returned in Buffer, in bytes
2473 * Failure: ERROR_INSUFFICIENT_BUFFER, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY
2474 * ERROR_NOT_FOUND or ERROR_PARTIAL_COPY
2477 * The type of data returned in Buffer is indicated by the value of the Class parameter.
2479 DWORD WINAPI
GetOwnerModuleFromUdpEntry( PMIB_UDPROW_OWNER_MODULE pUdpEntry
, TCPIP_OWNER_MODULE_INFO_CLASS Class
, PVOID Buffer
, PDWORD pdwSize
)
2481 /* If we have a service tag, that's a service connection */
2482 if (pUdpEntry
->OwningModuleInfo
[0] != 0)
2484 return GetOwnerModuleFromTagEntry(pUdpEntry
->dwOwningPid
, (DWORD
)(pUdpEntry
->OwningModuleInfo
[0]), Class
, Buffer
, pdwSize
);
2488 return GetOwnerModuleFromPidEntry(pUdpEntry
->dwOwningPid
, Class
, Buffer
, pdwSize
);
2492 static void CreateNameServerListEnumNamesFunc( PWCHAR Interface
, PWCHAR Server
, PVOID Data
)
2494 IP_ADDR_STRING
*pNext
;
2495 PNAME_SERVER_LIST_CONTEXT Context
= (PNAME_SERVER_LIST_CONTEXT
)Data
;
2497 if (!Context
->NumServers
)
2499 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
2501 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, Context
->pData
->DnsServerList
.IpAddress
.String
, 16, NULL
, NULL
);
2502 Context
->pData
->DnsServerList
.IpAddress
.String
[15] = '\0';
2503 Context
->pLastAddr
= &Context
->pData
->DnsServerList
;
2508 Context
->uSizeRequired
+= sizeof(IP_ADDR_STRING
);
2509 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
2511 pNext
= (IP_ADDR_STRING
*)(((char*)Context
->pLastAddr
) + sizeof(IP_ADDR_STRING
));
2512 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, pNext
->IpAddress
.String
, 16, NULL
, NULL
);
2513 pNext
->IpAddress
.String
[15] = '\0';
2514 Context
->pLastAddr
->Next
= pNext
;
2515 Context
->pLastAddr
= pNext
;
2519 Context
->NumServers
++;
2522 /******************************************************************
2523 * GetPerAdapterInfo (IPHLPAPI.@)
2529 * pPerAdapterInfo [In/Out]
2530 * pOutBufLen [In/Out]
2537 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
2542 NAME_SERVER_LIST_CONTEXT Context
;
2543 WCHAR keyname
[200] = L
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
2546 return ERROR_INVALID_PARAMETER
;
2548 if (!pPerAdapterInfo
|| *pOutBufLen
< sizeof(IP_PER_ADAPTER_INFO
))
2550 *pOutBufLen
= sizeof(IP_PER_ADAPTER_INFO
);
2551 return ERROR_BUFFER_OVERFLOW
;
2554 ifName
= getInterfaceNameByIndex(IfIndex
);
2556 return ERROR_INVALID_PARAMETER
;
2558 MultiByteToWideChar(CP_ACP
, 0, ifName
, -1, &keyname
[62], sizeof(keyname
)/sizeof(WCHAR
) - 63);
2559 HeapFree(GetProcessHeap(), 0, (LPVOID
)ifName
);
2561 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keyname
, 0, KEY_READ
, &hkey
) != ERROR_SUCCESS
)
2563 return ERROR_NOT_SUPPORTED
;
2565 Context
.NumServers
= 0;
2566 Context
.uSizeAvailable
= *pOutBufLen
;
2567 Context
.uSizeRequired
= sizeof(IP_PER_ADAPTER_INFO
);
2568 Context
.pData
= pPerAdapterInfo
;
2570 if (*pOutBufLen
>= sizeof(IP_PER_ADAPTER_INFO
))
2571 ZeroMemory(pPerAdapterInfo
, sizeof(IP_PER_ADAPTER_INFO
));
2573 EnumNameServers(hkey
, &keyname
[62], &Context
, CreateNameServerListEnumNamesFunc
);
2575 if (Context
.uSizeRequired
> Context
.uSizeAvailable
)
2577 *pOutBufLen
= Context
.uSizeRequired
;
2579 return ERROR_BUFFER_OVERFLOW
;
2582 if(RegQueryValueExW(hkey
, L
"NameServer", NULL
, NULL
, NULL
, &dwSize
) == ERROR_SUCCESS
)
2584 pPerAdapterInfo
->AutoconfigActive
= FALSE
;
2588 pPerAdapterInfo
->AutoconfigActive
= TRUE
;
2596 /******************************************************************
2597 * GetRTTAndHopCount (IPHLPAPI.@)
2602 * DestIpAddress [In]
2612 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
2614 TRACE("DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p\n",
2615 DestIpAddress
, HopCount
, MaxHops
, RTT
);
2621 /******************************************************************
2622 * GetTcpStatisticsEx (IPHLPAPI.@)
2635 DWORD WINAPI
GetTcpStatisticsEx(PMIB_TCPSTATS pStats
, DWORD dwFamily
)
2639 TRACE("pStats %p\n", pStats
);
2640 ret
= getTCPStats(pStats
, dwFamily
);
2641 TRACE("returning %ld\n", ret
);
2645 /******************************************************************
2646 * GetTcpStatistics (IPHLPAPI.@)
2658 DWORD WINAPI
GetTcpStatistics(PMIB_TCPSTATS pStats
)
2660 return GetTcpStatisticsEx(pStats
, PF_INET
);
2664 /******************************************************************
2665 * GetTcpTable (IPHLPAPI.@)
2667 * Get the table of active TCP connections.
2670 * pTcpTable [Out] buffer for TCP connections table
2671 * pdwSize [In/Out] length of output buffer
2672 * bOrder [In] whether to order the table
2676 * Failure: error code from winerror.h
2679 * If pdwSize is less than required, the function will return
2680 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
2681 * the required byte size.
2682 * If bOrder is true, the returned table will be sorted, first by
2683 * local address and port number, then by remote address and port
2686 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
2688 return GetExtendedTcpTable(pTcpTable
, pdwSize
, bOrder
, AF_INET
, TCP_TABLE_BASIC_ALL
, 0);
2692 /******************************************************************
2693 * GetUdpStatisticsEx (IPHLPAPI.@)
2706 DWORD WINAPI
GetUdpStatisticsEx(PMIB_UDPSTATS pStats
, DWORD dwFamily
)
2710 TRACE("pStats %p\n", pStats
);
2711 ret
= getUDPStats(pStats
, dwFamily
);
2712 TRACE("returning %ld\n", ret
);
2716 /******************************************************************
2717 * GetUdpStatistics (IPHLPAPI.@)
2729 DWORD WINAPI
GetUdpStatistics(PMIB_UDPSTATS pStats
)
2731 return GetUdpStatisticsEx(pStats
, PF_INET
);
2735 /******************************************************************
2736 * GetUdpTable (IPHLPAPI.@)
2741 * pUdpTable [In/Out]
2750 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
2752 return GetExtendedUdpTable(pUdpTable
, pdwSize
, bOrder
, AF_INET
, UDP_TABLE_BASIC
, 0);
2756 /******************************************************************
2757 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
2759 * This is a Win98-only function to get information on "unidirectional"
2760 * adapters. Since this is pretty nonsensical in other contexts, it
2761 * never returns anything.
2764 * pIPIfInfo [Out] buffer for adapter infos
2765 * dwOutBufLen [Out] length of the output buffer
2769 * Failure: error code from winerror.h
2772 * Stub, returns ERROR_NOT_SUPPORTED.
2774 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
2776 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
2777 /* a unidirectional adapter?? not bloody likely! */
2778 return ERROR_NOT_SUPPORTED
;
2782 /******************************************************************
2783 * IpReleaseAddress (IPHLPAPI.@)
2785 * Release an IP obtained through DHCP,
2788 * AdapterInfo [In] adapter to release IP address
2792 * Failure: error code from winerror.h
2795 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2797 DWORD Status
, Version
= 0;
2800 return ERROR_INVALID_PARAMETER
;
2802 /* Maybe we should do this in DllMain */
2803 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2804 return ERROR_PROC_NOT_FOUND
;
2806 if (DhcpReleaseIpAddressLease(AdapterInfo
->Index
))
2807 Status
= ERROR_SUCCESS
;
2809 Status
= ERROR_PROC_NOT_FOUND
;
2817 /******************************************************************
2818 * IpRenewAddress (IPHLPAPI.@)
2820 * Renew an IP obtained through DHCP.
2823 * AdapterInfo [In] adapter to renew IP address
2827 * Failure: error code from winerror.h
2829 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2831 DWORD Status
, Version
= 0;
2834 return ERROR_INVALID_PARAMETER
;
2836 /* Maybe we should do this in DllMain */
2837 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2838 return ERROR_PROC_NOT_FOUND
;
2840 if (DhcpRenewIpAddressLease(AdapterInfo
->Index
))
2841 Status
= ERROR_SUCCESS
;
2843 Status
= ERROR_PROC_NOT_FOUND
;
2851 /******************************************************************
2852 * NotifyAddrChange (IPHLPAPI.@)
2854 * Notify caller whenever the ip-interface map is changed.
2857 * Handle [Out] handle usable in asynchronous notification
2858 * overlapped [In] overlapped structure that notifies the caller
2862 * Failure: error code from winerror.h
2865 * Stub, returns ERROR_NOT_SUPPORTED.
2867 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2869 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2870 if (Handle
) *Handle
= INVALID_HANDLE_VALUE
;
2871 if (overlapped
) ((IO_STATUS_BLOCK
*) overlapped
)->Status
= STATUS_PENDING
;
2872 return ERROR_IO_PENDING
;
2876 /******************************************************************
2877 * NotifyRouteChange (IPHLPAPI.@)
2879 * Notify caller whenever the ip routing table is changed.
2882 * Handle [Out] handle usable in asynchronous notification
2883 * overlapped [In] overlapped structure that notifies the caller
2887 * Failure: error code from winerror.h
2890 * Stub, returns ERROR_NOT_SUPPORTED.
2892 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2894 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2895 return ERROR_NOT_SUPPORTED
;
2898 /******************************************************************
2899 * SendARP (IPHLPAPI.@)
2901 * Send an ARP request.
2904 * DestIP [In] attempt to obtain this IP
2905 * SrcIP [In] optional sender IP address
2906 * pMacAddr [Out] buffer for the mac address
2907 * PhyAddrLen [In/Out] length of the output buffer
2911 * Failure: error code from winerror.h
2913 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
2918 if (IsBadWritePtr(pMacAddr
, sizeof(ULONG
)) || IsBadWritePtr(PhyAddrLen
, sizeof(ULONG
)))
2919 return ERROR_INVALID_PARAMETER
;
2924 return TCPSendIoctl(INVALID_HANDLE_VALUE
, IOCTL_QUERY_IP_HW_ADDRESS
, IPs
, &Size
, pMacAddr
, PhyAddrLen
);
2928 /******************************************************************
2929 * SetIfEntry (IPHLPAPI.@)
2931 * Set the administrative status of an interface.
2934 * pIfRow [In] dwAdminStatus member specifies the new status.
2938 * Failure: error code from winerror.h
2941 * Stub, returns ERROR_NOT_SUPPORTED.
2943 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
2945 FIXME("(pIfRow %p): stub\n", pIfRow
);
2946 /* this is supposed to set an interface administratively up or down.
2947 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2948 this sort of down is indistinguishable from other sorts of down (e.g. no
2950 return ERROR_NOT_SUPPORTED
;
2954 /******************************************************************
2955 * SetIpForwardEntry (IPHLPAPI.@)
2957 * Modify an existing route.
2960 * pRoute [In] route with the new information
2964 * Failure: error code from winerror.h
2967 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
2969 return setIpForwardEntry( pRoute
);
2973 /******************************************************************
2974 * SetIpNetEntry (IPHLPAPI.@)
2976 * Modify an existing ARP entry.
2979 * pArpEntry [In] ARP entry with the new information
2983 * Failure: error code from winerror.h
2985 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
2989 TCP_REQUEST_SET_INFORMATION_EX_ARP_ENTRY req
=
2990 TCP_REQUEST_SET_INFORMATION_INIT
;
2993 PMIB_IPNETROW arpBuff
;
2996 return ERROR_INVALID_PARAMETER
;
2998 if (!NT_SUCCESS(openTcpFile( &tcpFile
, FILE_READ_DATA
| FILE_WRITE_DATA
)))
2999 return ERROR_NOT_SUPPORTED
;
3001 if (!NT_SUCCESS(getNthIpEntity( tcpFile
, pArpEntry
->dwIndex
, &id
)))
3003 closeTcpFile(tcpFile
);
3004 return ERROR_INVALID_PARAMETER
;
3007 req
.Req
.ID
.toi_class
= INFO_CLASS_PROTOCOL
;
3008 req
.Req
.ID
.toi_type
= INFO_TYPE_PROVIDER
;
3009 req
.Req
.ID
.toi_id
= IP_MIB_ARPTABLE_ENTRY_ID
;
3010 req
.Req
.ID
.toi_entity
.tei_instance
= id
.tei_instance
;
3011 req
.Req
.ID
.toi_entity
.tei_entity
= AT_ENTITY
;
3012 req
.Req
.BufferSize
= sizeof(MIB_IPNETROW
);
3013 arpBuff
= (PMIB_IPNETROW
)&req
.Req
.Buffer
[0];
3015 RtlCopyMemory(arpBuff
, pArpEntry
, sizeof(MIB_IPNETROW
));
3017 status
= DeviceIoControl( tcpFile
,
3018 IOCTL_TCP_SET_INFORMATION_EX
,
3026 closeTcpFile(tcpFile
);
3031 return ERROR_INVALID_PARAMETER
;
3035 /******************************************************************
3036 * SetIpStatistics (IPHLPAPI.@)
3038 * Toggle IP forwarding and det the default TTL value.
3041 * pIpStats [In] IP statistics with the new information
3045 * Failure: error code from winerror.h
3048 * Stub, returns NO_ERROR.
3050 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
3052 FIXME("(pIpStats %p): stub\n", pIpStats
);
3057 /******************************************************************
3058 * SetIpTTL (IPHLPAPI.@)
3060 * Set the default TTL value.
3063 * nTTL [In] new TTL value
3067 * Failure: error code from winerror.h
3070 * Stub, returns NO_ERROR.
3072 DWORD WINAPI
SetIpTTL(UINT nTTL
)
3074 FIXME("(nTTL %d): stub\n", nTTL
);
3079 /******************************************************************
3080 * SetTcpEntry (IPHLPAPI.@)
3082 * Set the state of a TCP connection.
3085 * pTcpRow [In] specifies connection with new state
3089 * Failure: error code from winerror.h
3092 * Stub, returns NO_ERROR.
3094 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
3096 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
3101 /******************************************************************
3102 * UnenableRouter (IPHLPAPI.@)
3104 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
3105 * if it reaches zero.
3108 * pOverlapped [In/Out] should be the same as in EnableRouter()
3109 * lpdwEnableCount [Out] optional, receives reference count
3113 * Failure: error code from winerror.h
3116 * Stub, returns ERROR_NOT_SUPPORTED.
3118 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
3120 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
3122 return ERROR_NOT_SUPPORTED
;
3128 DWORD WINAPI
GetIpErrorString(IP_STATUS ErrorCode
,PWCHAR Buffer
,PDWORD Size
)
3138 PIP_ADAPTER_ORDER_MAP WINAPI
GetAdapterOrderMap(VOID
)
3147 #ifdef GetAdaptersAddressesV1
3148 DWORD WINAPI DECLSPEC_HOTPATCH
GetAdaptersAddresses(ULONG Family
,ULONG Flags
,PVOID Reserved
,PIP_ADAPTER_ADDRESSES pAdapterAddresses
,PULONG pOutBufLen
)
3150 InterfaceIndexTable
*indexTable
;
3153 ULONG ret
, requiredSize
= 0;
3154 PIP_ADAPTER_ADDRESSES currentAddress
;
3155 PUCHAR currentLocation
;
3158 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
3159 if (Reserved
) return ERROR_INVALID_PARAMETER
;
3161 indexTable
= getInterfaceIndexTable();
3163 return ERROR_NOT_ENOUGH_MEMORY
;
3165 ret
= openTcpFile(&tcpFile
, FILE_READ_DATA
);
3166 if (!NT_SUCCESS(ret
))
3167 return ERROR_NO_DATA
;
3169 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
3171 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
3173 indexTable
->indexes
[i
],
3176 /* The whole struct */
3177 requiredSize
+= sizeof(IP_ADAPTER_ADDRESSES
);
3180 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
3181 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1; //FIXME
3184 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
3186 /* Unicast address */
3187 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
3188 requiredSize
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
3190 /* FIXME: Implement multicast, anycast, and dns server stuff */
3192 /* FIXME: Implement dns suffix and description */
3193 requiredSize
+= 2 * sizeof(WCHAR
);
3195 /* We're only going to implement what's required for XP SP0 */
3198 TRACE("size: %d, requiredSize: %d\n", *pOutBufLen
, requiredSize
);
3199 if (!pAdapterAddresses
|| *pOutBufLen
< requiredSize
)
3201 *pOutBufLen
= requiredSize
;
3202 closeTcpFile(tcpFile
);
3204 return ERROR_BUFFER_OVERFLOW
;
3207 RtlZeroMemory(pAdapterAddresses
, requiredSize
);
3209 /* Let's set up the pointers */
3210 currentAddress
= pAdapterAddresses
;
3211 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
3213 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
3215 indexTable
->indexes
[i
],
3218 currentLocation
= (PUCHAR
)currentAddress
+ (ULONG_PTR
)sizeof(IP_ADAPTER_ADDRESSES
);
3220 /* FIXME: Friendly name */
3221 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
3223 currentAddress
->FriendlyName
= (PVOID
)currentLocation
;
3224 currentLocation
+= sizeof(WCHAR
);
3228 currentAddress
->AdapterName
= (PVOID
)currentLocation
;
3229 currentLocation
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
3231 /* Unicast address */
3232 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
3234 currentAddress
->FirstUnicastAddress
= (PVOID
)currentLocation
;
3235 currentLocation
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
3236 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
= (PVOID
)currentLocation
;
3237 currentLocation
+= sizeof(struct sockaddr
);
3240 /* FIXME: Implement multicast, anycast, and dns server stuff */
3242 /* FIXME: Implement dns suffix and description */
3243 currentAddress
->DnsSuffix
= (PVOID
)currentLocation
;
3244 currentLocation
+= sizeof(WCHAR
);
3246 currentAddress
->Description
= (PVOID
)currentLocation
;
3247 currentLocation
+= sizeof(WCHAR
);
3249 currentAddress
->Next
= (PVOID
)currentLocation
;
3250 /* Terminate the last address correctly */
3252 currentAddress
->Next
= NULL
;
3254 /* We're only going to implement what's required for XP SP0 */
3256 currentAddress
= currentAddress
->Next
;
3260 /* Now again, for real this time */
3262 currentAddress
= pAdapterAddresses
;
3263 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
3265 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
3267 indexTable
->indexes
[i
],
3270 /* Make sure we're not looping more than we hoped for */
3271 ASSERT(currentAddress
);
3273 /* Alignment information */
3274 currentAddress
->Length
= sizeof(IP_ADAPTER_ADDRESSES
);
3275 currentAddress
->IfIndex
= indexTable
->indexes
[i
];
3278 strcpy(currentAddress
->AdapterName
, (char *)ifInfo
.if_info
.ent
.if_descr
);
3280 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
3282 currentAddress
->FirstUnicastAddress
->Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
3283 currentAddress
->FirstUnicastAddress
->Flags
= 0; //FIXME
3284 currentAddress
->FirstUnicastAddress
->Next
= NULL
; //FIXME: Support more than one address per adapter
3285 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_family
= AF_INET
;
3286 memcpy(currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_data
,
3287 &ifInfo
.ip_addr
.iae_addr
,
3288 sizeof(ifInfo
.ip_addr
.iae_addr
));
3289 currentAddress
->FirstUnicastAddress
->Address
.iSockaddrLength
= sizeof(ifInfo
.ip_addr
.iae_addr
) + sizeof(USHORT
);
3290 currentAddress
->FirstUnicastAddress
->PrefixOrigin
= IpPrefixOriginOther
; //FIXME
3291 currentAddress
->FirstUnicastAddress
->SuffixOrigin
= IpPrefixOriginOther
; //FIXME
3292 currentAddress
->FirstUnicastAddress
->DadState
= IpDadStatePreferred
; //FIXME
3293 currentAddress
->FirstUnicastAddress
->ValidLifetime
= 0xFFFFFFFF; //FIXME
3294 currentAddress
->FirstUnicastAddress
->PreferredLifetime
= 0xFFFFFFFF; //FIXME
3295 currentAddress
->FirstUnicastAddress
->LeaseLifetime
= 0xFFFFFFFF; //FIXME
3298 /* FIXME: Implement multicast, anycast, and dns server stuff */
3299 currentAddress
->FirstAnycastAddress
= NULL
;
3300 currentAddress
->FirstMulticastAddress
= NULL
;
3301 currentAddress
->FirstDnsServerAddress
= NULL
;
3303 /* FIXME: Implement dns suffix, description, and friendly name */
3304 currentAddress
->DnsSuffix
[0] = UNICODE_NULL
;
3305 currentAddress
->Description
[0] = UNICODE_NULL
;
3306 currentAddress
->FriendlyName
[0] = UNICODE_NULL
;
3308 /* Physical Address */
3309 memcpy(currentAddress
->PhysicalAddress
, ifInfo
.if_info
.ent
.if_physaddr
, ifInfo
.if_info
.ent
.if_physaddrlen
);
3310 currentAddress
->PhysicalAddressLength
= ifInfo
.if_info
.ent
.if_physaddrlen
;
3313 currentAddress
->Flags
= 0; //FIXME
3316 currentAddress
->Mtu
= ifInfo
.if_info
.ent
.if_mtu
;
3318 /* Interface type */
3319 currentAddress
->IfType
= ifInfo
.if_info
.ent
.if_type
;
3321 /* Operational status */
3322 if(ifInfo
.if_info
.ent
.if_operstatus
>= IF_OPER_STATUS_CONNECTING
)
3323 currentAddress
->OperStatus
= IfOperStatusUp
;
3325 currentAddress
->OperStatus
= IfOperStatusDown
;
3327 /* We're only going to implement what's required for XP SP0 */
3329 /* Move to the next address */
3330 currentAddress
= currentAddress
->Next
;
3334 closeTcpFile(tcpFile
);
3344 BOOL WINAPI
CancelIPChangeNotify(LPOVERLAPPED notifyOverlapped
)
3353 DWORD WINAPI
GetBestInterfaceEx(struct sockaddr
*pDestAddr
,PDWORD pdwBestIfIndex
)
3362 DWORD WINAPI
NhpAllocateAndGetInterfaceInfoFromStack(IP_INTERFACE_NAME_INFO
**ppTable
,PDWORD pdwCount
,BOOL bOrder
,HANDLE hHeap
,DWORD dwFlags
)
3371 DWORD WINAPI
GetIcmpStatisticsEx(PMIB_ICMP_EX pStats
,DWORD dwFamily
)
3376 return ERROR_INVALID_PARAMETER
;
3378 if (dwFamily
!= AF_INET
&& dwFamily
!= AF_INET6
)
3379 return ERROR_INVALID_PARAMETER
;
3385 SetIpForwardEntryToStack(PMIB_IPFORWARDROW pRoute
)
3387 FIXME("SetIpForwardEntryToStack() stub\n");
3391 DWORD
GetInterfaceNameInternal(_In_
const GUID
* pInterfaceGUID
,
3392 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3393 _Inout_ PULONG pOutBufLen
)
3395 UNICODE_STRING GuidString
;
3397 WCHAR szKeyName
[2*MAX_PATH
];
3401 if (pInterfaceGUID
== NULL
|| pOutBufLen
== NULL
)
3402 return ERROR_INVALID_PARAMETER
;
3404 result
= RtlStringFromGUID(pInterfaceGUID
, &GuidString
);
3406 if (!NT_SUCCESS(result
))
3408 // failed to convert guid to string
3409 return RtlNtStatusToDosError(result
);
3412 hr
= StringCbPrintfW(szKeyName
, sizeof(szKeyName
), L
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", GuidString
.Buffer
);
3413 RtlFreeUnicodeString(&GuidString
);
3417 // key name is too long
3418 return ERROR_BUFFER_OVERFLOW
;
3421 result
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szKeyName
, 0, KEY_READ
, &hKey
);
3423 if (result
!= ERROR_SUCCESS
)
3425 // failed to find adapter entry
3426 return ERROR_NOT_FOUND
;
3429 result
= RegQueryValueExW(hKey
, L
"Name", NULL
, &type
, (PVOID
)pInterfaceName
, pOutBufLen
);
3433 if (result
== ERROR_MORE_DATA
)
3435 *pOutBufLen
= MAX_INTERFACE_NAME_LEN
* 2;
3436 return ERROR_INSUFFICIENT_BUFFER
;
3439 if (result
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
3441 // failed to read adapter name
3442 return ERROR_NO_DATA
;
3444 return ERROR_SUCCESS
;
3451 NhGetInterfaceNameFromDeviceGuid(_In_
const GUID
* pInterfaceGUID
,
3452 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3453 _Inout_ PULONG pOutBufLen
,
3457 SetLastError(ERROR_SUCCESS
);
3459 if (pInterfaceName
== NULL
)
3460 return ERROR_INVALID_PARAMETER
;
3462 return GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
3469 NhGetInterfaceNameFromGuid(_In_
const GUID
* pInterfaceGUID
,
3470 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
3471 _Inout_ PULONG pOutBufLen
,
3477 result
= GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
3479 if (result
== ERROR_NOT_FOUND
)
3480 SetLastError(ERROR_PATH_NOT_FOUND
);