2 * iphlpapi dll implementation
4 * Copyright (C) 2003 Juan Lang
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.
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.
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
24 #include "iphlpapi_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
29 typedef struct _NAME_SERVER_LIST_CONTEXT
{
32 PIP_PER_ADAPTER_INFO pData
;
34 IP_ADDR_STRING
*pLastAddr
;
35 } NAME_SERVER_LIST_CONTEXT
, *PNAME_SERVER_LIST_CONTEXT
;
37 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
40 case DLL_PROCESS_ATTACH
:
41 DisableThreadLibraryCalls( hinstDLL
);
45 case DLL_PROCESS_DETACH
:
52 /******************************************************************
53 * AddIPAddress (IPHLPAPI.@)
62 * NTEInstance [In/Out]
69 DWORD WINAPI
AddIPAddress(IPAddr Address
, IPMask Netmask
, DWORD IfIndex
, PULONG NteContext
, PULONG NteInstance
)
71 return RtlNtStatusToDosError(addIPAddress(Address
, Netmask
, IfIndex
, NteContext
, NteInstance
));
74 DWORD
getInterfaceGatewayByIndex(DWORD index
)
76 DWORD ndx
, retVal
= 0, numRoutes
= getNumRoutes();
77 RouteTable
*table
= getRouteTable();
80 for (ndx
= 0; ndx
< numRoutes
; ndx
++)
82 if ((table
->routes
[ndx
].ifIndex
== (index
)) && (table
->routes
[ndx
].dest
== 0))
83 retVal
= table
->routes
[ndx
].gateway
;
85 HeapFree(GetProcessHeap(), 0, table
);
89 /******************************************************************
90 * AllocateAndGetIfTableFromStack (IPHLPAPI.@)
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
101 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
102 * GetIfTable returns otherwise
105 DWORD WINAPI
AllocateAndGetIfTableFromStack(PMIB_IFTABLE
*ppIfTable
,
106 BOOL bOrder
, HANDLE heap
, DWORD flags
)
110 TRACE("ppIfTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n", ppIfTable
,
111 (DWORD
)bOrder
, (DWORD
)heap
, flags
);
113 ret
= ERROR_INVALID_PARAMETER
;
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
);
128 TRACE("returning %ld\n", ret
);
133 /******************************************************************
134 * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
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
149 DWORD WINAPI
AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE
*ppIpAddrTable
,
150 BOOL bOrder
, HANDLE heap
, DWORD flags
)
154 TRACE("ppIpAddrTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
155 ppIpAddrTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
157 ret
= ERROR_INVALID_PARAMETER
;
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
;
172 TRACE("returning %ld\n", ret
);
177 /******************************************************************
178 * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
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
187 * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever
188 * GetIpForwardTable returns otherwise
191 DWORD WINAPI
AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE
*
192 ppIpForwardTable
, BOOL bOrder
, HANDLE heap
, DWORD flags
)
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
;
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
;
214 TRACE("returning %ld\n", ret
);
219 /******************************************************************
220 * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
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
235 DWORD WINAPI
AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE
*ppIpNetTable
,
236 BOOL bOrder
, HANDLE heap
, DWORD flags
)
240 TRACE("ppIpNetTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
241 ppIpNetTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
243 ret
= ERROR_INVALID_PARAMETER
;
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
;
258 TRACE("returning %ld\n", ret
);
263 /******************************************************************
264 * AllocateAndGetTcpTableFromStack (IPHLPAPI.@)
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
279 DWORD WINAPI
AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE
*ppTcpTable
,
280 BOOL bOrder
, HANDLE heap
, DWORD flags
)
284 TRACE("ppTcpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
285 ppTcpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
287 ret
= ERROR_INVALID_PARAMETER
;
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
);
302 TRACE("returning %ld\n", ret
);
307 /******************************************************************
308 * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
314 * bOrder [In] -- passed to GetUdpTable to order the table
315 * heap [In] -- heap from which the table is allocated
316 * flags [In] -- flags to HeapAlloc
323 DWORD WINAPI
AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE
*ppUdpTable
,
324 BOOL bOrder
, HANDLE heap
, DWORD flags
)
328 TRACE("ppUdpTable %p, bOrder %ld, heap 0x%08lx, flags 0x%08lx\n",
329 ppUdpTable
, (DWORD
)bOrder
, (DWORD
)heap
, flags
);
331 ret
= ERROR_INVALID_PARAMETER
;
336 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
337 if (ret
== ERROR_INSUFFICIENT_BUFFER
) {
338 *ppUdpTable
= (PMIB_UDPTABLE
)HeapAlloc(heap
, flags
, dwSize
);
339 ret
= GetUdpTable(*ppUdpTable
, &dwSize
, bOrder
);
340 if (ret
!= NO_ERROR
) {
341 HeapFree(heap
, flags
, *ppUdpTable
);
346 TRACE("returning %ld\n", ret
);
351 /******************************************************************
352 * CreateIpForwardEntry (IPHLPAPI.@)
364 DWORD WINAPI
CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
366 return createIpForwardEntry( pRoute
);
370 /******************************************************************
371 * CreateIpNetEntry (IPHLPAPI.@)
383 DWORD WINAPI
CreateIpNetEntry(PMIB_IPNETROW pArpEntry
)
385 TRACE("pArpEntry %p\n", pArpEntry
);
386 /* could use SIOCSARP on systems that support it, not sure I want to */
392 /******************************************************************
393 * CreateProxyArpEntry (IPHLPAPI.@)
407 DWORD WINAPI
CreateProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
409 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
412 /* marking Win2K+ functions not supported */
413 return ERROR_NOT_SUPPORTED
;
417 /******************************************************************
418 * DeleteIPAddress (IPHLPAPI.@)
430 DWORD WINAPI
DeleteIPAddress(ULONG NTEContext
)
432 TRACE("NTEContext %ld\n", NTEContext
);
433 return RtlNtStatusToDosError(deleteIpAddress(NTEContext
));
437 /******************************************************************
438 * DeleteIpForwardEntry (IPHLPAPI.@)
450 DWORD WINAPI
DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
452 return deleteIpForwardEntry( pRoute
);
456 /******************************************************************
457 * DeleteIpNetEntry (IPHLPAPI.@)
469 DWORD WINAPI
DeleteIpNetEntry(PMIB_IPNETROW pArpEntry
)
471 TRACE("pArpEntry %p\n", pArpEntry
);
472 /* could use SIOCDARP on systems that support it, not sure I want to */
478 /******************************************************************
479 * DeleteProxyArpEntry (IPHLPAPI.@)
493 DWORD WINAPI
DeleteProxyArpEntry(DWORD dwAddress
, DWORD dwMask
, DWORD dwIfIndex
)
495 TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress
,
498 /* marking Win2K+ functions not supported */
499 return ERROR_NOT_SUPPORTED
;
502 /******************************************************************
503 * EnableRouter (IPHLPAPI.@)
509 * pOverlapped [In/Out]
516 DWORD WINAPI
EnableRouter(HANDLE
* pHandle
, OVERLAPPED
* pOverlapped
)
518 TRACE("pHandle %p, pOverlapped %p\n", pHandle
, pOverlapped
);
520 /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to
521 could map EACCESS to ERROR_ACCESS_DENIED, I suppose
522 marking Win2K+ functions not supported */
523 return ERROR_NOT_SUPPORTED
;
527 /******************************************************************
528 * FlushIpNetTable (IPHLPAPI.@)
540 DWORD WINAPI
FlushIpNetTable(DWORD dwIfIndex
)
542 TRACE("dwIfIndex 0x%08lx\n", dwIfIndex
);
544 /* this flushes the arp cache of the given index
545 marking Win2K+ functions not supported */
546 return ERROR_NOT_SUPPORTED
;
550 /******************************************************************
551 * GetAdapterIndex (IPHLPAPI.@)
556 * AdapterName [In/Out]
564 DWORD WINAPI
GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
566 TRACE("AdapterName %p, IfIndex %p\n", AdapterName
, IfIndex
);
568 /* marking Win2K+ functions not supported */
569 return ERROR_NOT_SUPPORTED
;
573 /******************************************************************
574 * GetAdaptersInfo (IPHLPAPI.@)
579 * pAdapterInfo [In/Out]
580 * pOutBufLen [In/Out]
587 DWORD WINAPI
GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
593 TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo
, pOutBufLen
);
595 ret
= ERROR_INVALID_PARAMETER
;
597 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
599 if (numNonLoopbackInterfaces
> 0) {
600 /* this calculation assumes only one address in the IP_ADDR_STRING lists.
601 that's okay, because:
602 - we don't get multiple addresses per adapter anyway
603 - we don't know about per-adapter gateways
604 - DHCP and WINS servers can have max one entry per list */
605 ULONG size
= sizeof(IP_ADAPTER_INFO
) * numNonLoopbackInterfaces
;
607 if (!pAdapterInfo
|| *pOutBufLen
< size
) {
609 ret
= ERROR_BUFFER_OVERFLOW
;
612 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
615 size
= sizeof(IP_ADAPTER_INFO
) * table
->numIndexes
;
616 if (*pOutBufLen
< size
) {
618 ret
= ERROR_INSUFFICIENT_BUFFER
;
623 BOOL winsEnabled
= FALSE
;
624 IP_ADDRESS_STRING primaryWINS
, secondaryWINS
;
626 memset(pAdapterInfo
, 0, size
);
627 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
628 "Software\\Wine\\Wine\\Config\\Network", 0, KEY_READ
,
629 &hKey
) == ERROR_SUCCESS
) {
630 DWORD size
= sizeof(primaryWINS
.String
);
633 RegQueryValueExA(hKey
, "WinsServer", NULL
, NULL
,
634 (PBYTE
)primaryWINS
.String
, &size
);
635 addr
= inet_addr(primaryWINS
.String
);
636 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
638 size
= sizeof(secondaryWINS
.String
);
639 RegQueryValueExA(hKey
, "BackupWinsServer", NULL
, NULL
,
640 (PBYTE
)secondaryWINS
.String
, &size
);
641 addr
= inet_addr(secondaryWINS
.String
);
642 if (addr
!= INADDR_NONE
&& addr
!= INADDR_ANY
)
646 TRACE("num of index is %lu\n", table
->numIndexes
);
647 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
648 PIP_ADAPTER_INFO ptr
= &pAdapterInfo
[ndx
];
649 DWORD addrLen
= sizeof(ptr
->Address
), type
;
651 getInterfaceNameByIndex(table
->indexes
[ndx
]);
653 ret
= ERROR_OUTOFMEMORY
;
657 /* on Win98 this is left empty, but whatever */
658 strncpy(ptr
->AdapterName
,ifname
,sizeof(ptr
->AdapterName
));
659 consumeInterfaceName(ifname
);
660 ptr
->AdapterName
[MAX_ADAPTER_NAME_LENGTH
] = '\0';
661 getInterfacePhysicalByIndex(table
->indexes
[ndx
], &addrLen
,
662 ptr
->Address
, &type
);
663 /* MS defines address length and type as UINT in some places and
664 DWORD in others, **sigh**. Don't want to assume that PUINT and
665 PDWORD are equiv (64-bit?) */
666 ptr
->AddressLength
= addrLen
;
668 ptr
->Index
= table
->indexes
[ndx
];
669 toIPAddressString(getInterfaceIPAddrByIndex(table
->indexes
[ndx
]),
670 ptr
->IpAddressList
.IpAddress
.String
);
671 toIPAddressString(getInterfaceMaskByIndex(table
->indexes
[ndx
]),
672 ptr
->IpAddressList
.IpMask
.String
);
673 ptr
->IpAddressList
.Context
= ptr
->Index
;
674 toIPAddressString(getInterfaceGatewayByIndex(table
->indexes
[ndx
]),
675 ptr
->GatewayList
.IpAddress
.String
);
676 getDhcpInfoForAdapter(table
->indexes
[ndx
], &dhcpEnabled
,
677 &dhcpServer
, &ptr
->LeaseObtained
,
679 ptr
->DhcpEnabled
= (DWORD
) dhcpEnabled
;
680 toIPAddressString(dhcpServer
,
681 ptr
->DhcpServer
.IpAddress
.String
);
683 ptr
->HaveWins
= TRUE
;
684 memcpy(ptr
->PrimaryWinsServer
.IpAddress
.String
,
685 primaryWINS
.String
, sizeof(primaryWINS
.String
));
686 memcpy(ptr
->SecondaryWinsServer
.IpAddress
.String
,
687 secondaryWINS
.String
, sizeof(secondaryWINS
.String
));
689 if (ndx
< table
->numIndexes
- 1)
690 ptr
->Next
= &pAdapterInfo
[ndx
+ 1];
699 ret
= ERROR_OUTOFMEMORY
;
705 TRACE("returning %ld\n", ret
);
710 /******************************************************************
711 * GetBestInterface (IPHLPAPI.@)
717 * pdwBestIfIndex [In/Out]
724 DWORD WINAPI
GetBestInterface(IPAddr dwDestAddr
, PDWORD pdwBestIfIndex
)
728 TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr
, pdwBestIfIndex
);
730 ret
= ERROR_INVALID_PARAMETER
;
732 MIB_IPFORWARDROW ipRow
;
734 ret
= GetBestRoute(dwDestAddr
, 0, &ipRow
);
735 if (ret
== ERROR_SUCCESS
)
736 *pdwBestIfIndex
= ipRow
.dwForwardIfIndex
;
738 TRACE("returning %ld\n", ret
);
743 /******************************************************************
744 * GetBestRoute (IPHLPAPI.@)
758 DWORD WINAPI
GetBestRoute(DWORD dwDestAddr
, DWORD dwSourceAddr
, PMIB_IPFORWARDROW pBestRoute
)
760 PMIB_IPFORWARDTABLE table
;
763 TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr
,
764 dwSourceAddr
, pBestRoute
);
766 return ERROR_INVALID_PARAMETER
;
768 AllocateAndGetIpForwardTableFromStack(&table
, FALSE
, GetProcessHeap(), 0);
770 DWORD ndx
, matchedBits
, matchedNdx
= 0;
772 for (ndx
= 0, matchedBits
= 0; ndx
< table
->dwNumEntries
; ndx
++) {
773 if ((dwDestAddr
& table
->table
[ndx
].dwForwardMask
) ==
774 (table
->table
[ndx
].dwForwardDest
& table
->table
[ndx
].dwForwardMask
)) {
775 DWORD numShifts
, mask
;
777 for (numShifts
= 0, mask
= table
->table
[ndx
].dwForwardMask
;
778 mask
&& !(mask
& 1); mask
>>= 1, numShifts
++)
780 if (numShifts
> matchedBits
) {
781 matchedBits
= numShifts
;
786 memcpy(pBestRoute
, &table
->table
[matchedNdx
], sizeof(MIB_IPFORWARDROW
));
787 HeapFree(GetProcessHeap(), 0, table
);
791 ret
= ERROR_OUTOFMEMORY
;
792 TRACE("returning %ld\n", ret
);
796 /******************************************************************
797 * GetExtendedTcpTable (IPHLPAPI.@)
799 * Get the table of TCP endpoints available to the application.
802 * pTcpTable [Out] table struct with the filtered TCP endpoints available to application
803 * pdwSize [In/Out] estimated size of the structure returned in pTcpTable, in bytes
804 * bOrder [In] whether to order the table
805 * ulAf [in] version of IP used by the TCP endpoints
806 * TableClass [in] type of the TCP table structure from TCP_TABLE_CLASS
807 * Reserved [in] reserved - this value must be zero
811 * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER
816 DWORD WINAPI
GetExtendedTcpTable(PVOID pTcpTable
, PDWORD pdwSize
, BOOL bOrder
, ULONG ulAf
, TCP_TABLE_CLASS TableClass
, ULONG Reserved
)
818 DWORD ret
= NO_ERROR
;
820 if (TableClass
== TCP_TABLE_OWNER_PID_ALL
) {
822 *pdwSize
= sizeof(MIB_TCPTABLE_OWNER_PID
);
823 return ERROR_INSUFFICIENT_BUFFER
;
825 ZeroMemory(pTcpTable
, sizeof(MIB_TCPTABLE_OWNER_PID
));
836 /******************************************************************
837 * GetFriendlyIfIndex (IPHLPAPI.@)
849 DWORD WINAPI
GetFriendlyIfIndex(DWORD IfIndex
)
851 /* windows doesn't validate these, either, just makes sure the top byte is
852 cleared. I assume my ifenum module never gives an index with the top
854 TRACE("returning %ld\n", IfIndex
);
859 /******************************************************************
860 * GetIcmpStatistics (IPHLPAPI.@)
872 DWORD WINAPI
GetIcmpStatistics(PMIB_ICMP pStats
)
876 TRACE("pStats %p\n", pStats
);
877 ret
= getICMPStats(pStats
);
878 TRACE("returning %ld\n", ret
);
883 /******************************************************************
884 * GetIfEntry (IPHLPAPI.@)
896 DWORD WINAPI
GetIfEntry(PMIB_IFROW pIfRow
)
901 TRACE("pIfRow %p\n", pIfRow
);
903 return ERROR_INVALID_PARAMETER
;
905 name
= getInterfaceNameByIndex(pIfRow
->dwIndex
);
907 ret
= getInterfaceEntryByIndex(pIfRow
->dwIndex
, pIfRow
);
909 ret
= getInterfaceStatsByName(name
, pIfRow
);
910 consumeInterfaceName(name
);
913 ret
= ERROR_INVALID_DATA
;
914 TRACE("returning %ld\n", ret
);
919 static int IfTableSorter(const void *a
, const void *b
)
924 ret
= ((PMIB_IFROW
)a
)->dwIndex
- ((PMIB_IFROW
)b
)->dwIndex
;
931 /******************************************************************
932 * GetIfTable (IPHLPAPI.@)
946 DWORD WINAPI
GetIfTable(PMIB_IFTABLE pIfTable
, PULONG pdwSize
, BOOL bOrder
)
950 TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize
, pdwSize
,
953 ret
= ERROR_INVALID_PARAMETER
;
955 DWORD numInterfaces
= getNumInterfaces();
957 TRACE("GetIfTable: numInterfaces = %d\n", (int)numInterfaces
);
958 size
= sizeof(MIB_IFTABLE
) + (numInterfaces
- 1) * sizeof(MIB_IFROW
);
960 if (!pIfTable
|| *pdwSize
< size
) {
962 ret
= ERROR_INSUFFICIENT_BUFFER
;
965 InterfaceIndexTable
*table
= getInterfaceIndexTable();
968 size
= sizeof(MIB_IFTABLE
) + (table
->numIndexes
- 1) *
970 if (*pdwSize
< size
) {
972 ret
= ERROR_INSUFFICIENT_BUFFER
;
977 pIfTable
->dwNumEntries
= 0;
978 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
979 pIfTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
980 GetIfEntry(&pIfTable
->table
[ndx
]);
981 pIfTable
->dwNumEntries
++;
984 qsort(pIfTable
->table
, pIfTable
->dwNumEntries
, sizeof(MIB_IFROW
),
991 ret
= ERROR_OUTOFMEMORY
;
994 TRACE("returning %ld\n", ret
);
999 /******************************************************************
1000 * GetInterfaceInfo (IPHLPAPI.@)
1006 * dwOutBufLen [In/Out]
1013 DWORD WINAPI
GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG dwOutBufLen
)
1017 TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable
, dwOutBufLen
);
1019 ret
= ERROR_INVALID_PARAMETER
;
1021 DWORD numNonLoopbackInterfaces
= getNumNonLoopbackInterfaces();
1023 TRACE("numNonLoopbackInterfaces == 0x%x\n", numNonLoopbackInterfaces
);
1024 size
= sizeof(IP_INTERFACE_INFO
) + (numNonLoopbackInterfaces
) *
1025 sizeof(IP_ADAPTER_INDEX_MAP
);
1027 if (!pIfTable
|| *dwOutBufLen
< size
) {
1028 *dwOutBufLen
= size
;
1029 ret
= ERROR_INSUFFICIENT_BUFFER
;
1032 InterfaceIndexTable
*table
= getNonLoopbackInterfaceIndexTable();
1035 TRACE("table->numIndexes == 0x%x\n", table
->numIndexes
);
1036 size
= sizeof(IP_INTERFACE_INFO
) + (table
->numIndexes
) *
1037 sizeof(IP_ADAPTER_INDEX_MAP
);
1038 if (*dwOutBufLen
< size
) {
1039 *dwOutBufLen
= size
;
1040 ret
= ERROR_INSUFFICIENT_BUFFER
;
1045 pIfTable
->NumAdapters
= 0;
1046 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1047 const char *walker
, *name
;
1050 pIfTable
->Adapter
[ndx
].Index
= table
->indexes
[ndx
];
1051 name
= getInterfaceNameByIndex(table
->indexes
[ndx
]);
1052 for (walker
= name
, assigner
= pIfTable
->Adapter
[ndx
].Name
;
1053 walker
&& *walker
&&
1054 assigner
- pIfTable
->Adapter
[ndx
].Name
< MAX_ADAPTER_NAME
- 1;
1055 walker
++, assigner
++)
1056 *assigner
= *walker
;
1058 consumeInterfaceName(name
);
1059 pIfTable
->NumAdapters
++;
1066 ret
= ERROR_OUTOFMEMORY
;
1069 TRACE("returning %ld\n", ret
);
1074 static int IpAddrTableSorter(const void *a
, const void *b
)
1079 ret
= ((PMIB_IPADDRROW
)a
)->dwAddr
- ((PMIB_IPADDRROW
)b
)->dwAddr
;
1086 /******************************************************************
1087 * GetIpAddrTable (IPHLPAPI.@)
1092 * pIpAddrTable [In/Out]
1101 DWORD WINAPI
GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable
, PULONG pdwSize
, BOOL bOrder
)
1105 TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable
, pdwSize
,
1108 ret
= ERROR_INVALID_PARAMETER
;
1110 DWORD numInterfaces
= getNumInterfaces();
1111 ULONG size
= sizeof(MIB_IPADDRTABLE
) + (numInterfaces
- 1) *
1112 sizeof(MIB_IPADDRROW
);
1114 if (!pIpAddrTable
|| *pdwSize
< size
) {
1116 ret
= ERROR_INSUFFICIENT_BUFFER
;
1119 InterfaceIndexTable
*table
= getInterfaceIndexTable();
1122 size
= sizeof(MIB_IPADDRTABLE
) + (table
->numIndexes
- 1) *
1123 sizeof(MIB_IPADDRROW
);
1124 if (*pdwSize
< size
) {
1126 ret
= ERROR_INSUFFICIENT_BUFFER
;
1131 pIpAddrTable
->dwNumEntries
= 0;
1132 for (ndx
= 0; ndx
< table
->numIndexes
; ndx
++) {
1133 pIpAddrTable
->table
[ndx
].dwIndex
= table
->indexes
[ndx
];
1134 pIpAddrTable
->table
[ndx
].dwAddr
=
1135 getInterfaceIPAddrByIndex(table
->indexes
[ndx
]);
1136 pIpAddrTable
->table
[ndx
].dwMask
=
1137 getInterfaceMaskByIndex(table
->indexes
[ndx
]);
1138 /* the dwBCastAddr member isn't the broadcast address, it indicates
1139 * whether the interface uses the 1's broadcast address (1) or the
1140 * 0's broadcast address (0).
1142 bcast
= getInterfaceBCastAddrByIndex(table
->indexes
[ndx
]);
1143 pIpAddrTable
->table
[ndx
].dwBCastAddr
=
1144 (bcast
& pIpAddrTable
->table
[ndx
].dwMask
) ? 1 : 0;
1145 /* FIXME: hardcoded reasm size, not sure where to get it */
1146 pIpAddrTable
->table
[ndx
].dwReasmSize
= 65535;
1147 pIpAddrTable
->table
[ndx
].unused1
= 0;
1148 pIpAddrTable
->table
[ndx
].wType
= 0; /* aka unused2 */
1149 pIpAddrTable
->dwNumEntries
++;
1152 qsort(pIpAddrTable
->table
, pIpAddrTable
->dwNumEntries
,
1153 sizeof(MIB_IPADDRROW
), IpAddrTableSorter
);
1159 ret
= ERROR_OUTOFMEMORY
;
1162 TRACE("returning %ld\n", ret
);
1167 static int IpForwardTableSorter(const void *a
, const void *b
)
1172 PMIB_IPFORWARDROW rowA
= (PMIB_IPFORWARDROW
)a
, rowB
= (PMIB_IPFORWARDROW
)b
;
1174 ret
= rowA
->dwForwardDest
- rowB
->dwForwardDest
;
1176 ret
= rowA
->dwForwardProto
- rowB
->dwForwardProto
;
1178 ret
= rowA
->dwForwardPolicy
- rowB
->dwForwardPolicy
;
1180 ret
= rowA
->dwForwardNextHop
- rowB
->dwForwardNextHop
;
1190 /******************************************************************
1191 * GetIpForwardTable (IPHLPAPI.@)
1196 * pIpForwardTable [In/Out]
1205 DWORD WINAPI
GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable
, PULONG pdwSize
, BOOL bOrder
)
1209 TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable
,
1210 pdwSize
, (DWORD
)bOrder
);
1212 ret
= ERROR_INVALID_PARAMETER
;
1214 DWORD numRoutes
= getNumRoutes();
1215 ULONG sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (numRoutes
- 1) *
1216 sizeof(MIB_IPFORWARDROW
);
1218 if (!pIpForwardTable
|| *pdwSize
< sizeNeeded
) {
1219 *pdwSize
= sizeNeeded
;
1220 ret
= ERROR_INSUFFICIENT_BUFFER
;
1223 RouteTable
*table
= getRouteTable();
1225 sizeNeeded
= sizeof(MIB_IPFORWARDTABLE
) + (table
->numRoutes
- 1) *
1226 sizeof(MIB_IPFORWARDROW
);
1227 if (*pdwSize
< sizeNeeded
) {
1228 *pdwSize
= sizeNeeded
;
1229 ret
= ERROR_INSUFFICIENT_BUFFER
;
1234 pIpForwardTable
->dwNumEntries
= table
->numRoutes
;
1235 for (ndx
= 0; ndx
< numRoutes
; ndx
++) {
1236 pIpForwardTable
->table
[ndx
].dwForwardIfIndex
=
1237 table
->routes
[ndx
].ifIndex
;
1238 pIpForwardTable
->table
[ndx
].dwForwardDest
=
1239 table
->routes
[ndx
].dest
;
1240 pIpForwardTable
->table
[ndx
].dwForwardMask
=
1241 table
->routes
[ndx
].mask
;
1242 pIpForwardTable
->table
[ndx
].dwForwardPolicy
= 0;
1243 pIpForwardTable
->table
[ndx
].dwForwardNextHop
=
1244 table
->routes
[ndx
].gateway
;
1245 /* FIXME: this type is appropriate for local interfaces; may not
1246 always be appropriate */
1247 pIpForwardTable
->table
[ndx
].dwForwardType
= MIB_IPROUTE_TYPE_DIRECT
;
1248 /* FIXME: other protos might be appropriate, e.g. the default route
1249 is typically set with MIB_IPPROTO_NETMGMT instead */
1250 pIpForwardTable
->table
[ndx
].dwForwardProto
= MIB_IPPROTO_LOCAL
;
1251 /* punt on age and AS */
1252 pIpForwardTable
->table
[ndx
].dwForwardAge
= 0;
1253 pIpForwardTable
->table
[ndx
].dwForwardNextHopAS
= 0;
1254 pIpForwardTable
->table
[ndx
].dwForwardMetric1
=
1255 table
->routes
[ndx
].metric
;
1256 /* rest of the metrics are 0.. */
1257 pIpForwardTable
->table
[ndx
].dwForwardMetric2
= 0;
1258 pIpForwardTable
->table
[ndx
].dwForwardMetric3
= 0;
1259 pIpForwardTable
->table
[ndx
].dwForwardMetric4
= 0;
1260 pIpForwardTable
->table
[ndx
].dwForwardMetric5
= 0;
1263 qsort(pIpForwardTable
->table
, pIpForwardTable
->dwNumEntries
,
1264 sizeof(MIB_IPFORWARDROW
), IpForwardTableSorter
);
1267 HeapFree(GetProcessHeap(), 0, table
);
1270 ret
= ERROR_OUTOFMEMORY
;
1273 TRACE("returning %ld\n", ret
);
1278 static int IpNetTableSorter(const void *a
, const void *b
)
1283 ret
= ((PMIB_IPNETROW
)a
)->dwAddr
- ((PMIB_IPNETROW
)b
)->dwAddr
;
1290 /******************************************************************
1291 * GetIpNetTable (IPHLPAPI.@)
1296 * pIpNetTable [In/Out]
1305 DWORD WINAPI
GetIpNetTable(PMIB_IPNETTABLE pIpNetTable
, PULONG pdwSize
, BOOL bOrder
)
1307 DWORD ret
= NO_ERROR
;
1309 TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable
, pdwSize
,
1312 ret
= ERROR_INVALID_PARAMETER
;
1314 DWORD numEntries
= getNumArpEntries();
1315 ULONG size
= sizeof(MIB_IPNETTABLE
);
1318 size
+= (numEntries
- 1) * sizeof(MIB_IPNETROW
);
1319 if (!pIpNetTable
|| *pdwSize
< size
) {
1321 ret
= ERROR_INSUFFICIENT_BUFFER
;
1324 PMIB_IPNETTABLE table
= getArpTable();
1326 size
= sizeof(MIB_IPNETTABLE
);
1327 if (table
->dwNumEntries
> 1)
1328 size
+= (table
->dwNumEntries
- 1) * sizeof(MIB_IPNETROW
);
1329 if (*pdwSize
< size
) {
1331 ret
= ERROR_INSUFFICIENT_BUFFER
;
1335 memcpy(pIpNetTable
, table
, size
);
1337 qsort(pIpNetTable
->table
, pIpNetTable
->dwNumEntries
,
1338 sizeof(MIB_IPNETROW
), IpNetTableSorter
);
1341 HeapFree(GetProcessHeap(), 0, table
);
1345 TRACE("returning %d\n", ret
);
1350 /******************************************************************
1351 * GetIpStatistics (IPHLPAPI.@)
1363 DWORD WINAPI
GetIpStatistics(PMIB_IPSTATS pStats
)
1365 return GetIpStatisticsEx(pStats
, PF_INET
);
1368 /******************************************************************
1369 * GetIpStatisticsEx (IPHLPAPI.@)
1382 DWORD WINAPI
GetIpStatisticsEx(PMIB_IPSTATS pStats
, DWORD dwFamily
)
1386 TRACE("pStats %p\n", pStats
);
1387 ret
= getIPStats(pStats
, dwFamily
);
1388 TRACE("returning %ld\n", ret
);
1392 /******************************************************************
1393 * GetNetworkParams (IPHLPAPI.@)
1398 * pFixedInfo [In/Out]
1399 * pOutBufLen [In/Out]
1406 DWORD WINAPI
GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
1408 DWORD ret
, size
, type
;
1411 PIPHLP_RES_INFO resInfo
;
1413 TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo
, pOutBufLen
);
1415 return ERROR_INVALID_PARAMETER
;
1417 resInfo
= getResInfo();
1419 return ERROR_OUTOFMEMORY
;
1421 size
= sizeof(FIXED_INFO
) + (resInfo
->riCount
> 1 ? (resInfo
->riCount
-1) *
1422 sizeof(IP_ADDR_STRING
) : 0);
1423 if (!pFixedInfo
|| *pOutBufLen
< size
) {
1425 disposeResInfo( resInfo
);
1426 return ERROR_BUFFER_OVERFLOW
;
1429 memset(pFixedInfo
, 0, size
);
1430 /* Check for DhcpHostname and DhcpDomain first */
1431 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1432 "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
1436 if (regReturn
== ERROR_SUCCESS
) {
1437 /* Windows doesn't honor DHCP option 12 even if RFC requires it if it is returned by DHCP server! */
1440 size
= sizeof(pFixedInfo
->HostName
);
1441 regReturn
= RegQueryValueExA(hKey
,
1445 (LPBYTE
)pFixedInfo
->HostName
,
1447 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
1451 size
= sizeof(pFixedInfo
->HostName
);
1452 regReturn
= RegQueryValueExA(hKey
,
1456 (LPBYTE
)pFixedInfo
->HostName
,
1463 size
= sizeof(pFixedInfo
->DomainName
);
1464 regReturn
= RegQueryValueExA(hKey
,
1468 (LPBYTE
)pFixedInfo
->DomainName
,
1470 if (regReturn
== ERROR_FILE_NOT_FOUND
|| (regReturn
== ERROR_SUCCESS
&& size
< 1))
1473 size
= sizeof(pFixedInfo
->DomainName
);
1474 regReturn
= RegQueryValueExA(hKey
,
1478 (LPBYTE
)pFixedInfo
->DomainName
,
1484 TRACE("GetComputerNameExA: %s\n", pFixedInfo
->DomainName
);
1486 if (resInfo
->riCount
> 0)
1488 CopyMemory(&pFixedInfo
->DnsServerList
, resInfo
->DnsList
, sizeof(IP_ADDR_STRING
));
1489 if (resInfo
->riCount
> 1)
1491 IP_ADDR_STRING
*pSrc
= resInfo
->DnsList
->Next
;
1492 IP_ADDR_STRING
*pTarget
= (struct _IP_ADDR_STRING
*)((char*)pFixedInfo
+ sizeof(FIXED_INFO
));
1494 pFixedInfo
->DnsServerList
.Next
= pTarget
;
1498 CopyMemory(pTarget
, pSrc
, sizeof(IP_ADDR_STRING
));
1500 if (resInfo
->riCount
> 1)
1502 pTarget
->Next
= (IP_ADDR_STRING
*)((char*)pTarget
+ sizeof(IP_ADDR_STRING
));
1503 pTarget
= pTarget
->Next
;
1508 pTarget
->Next
= NULL
;
1516 pFixedInfo
->DnsServerList
.Next
= NULL
;
1520 pFixedInfo
->NodeType
= HYBRID_NODETYPE
;
1521 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1522 "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ
, &hKey
);
1523 if (regReturn
!= ERROR_SUCCESS
)
1524 regReturn
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
1525 "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ
,
1527 if (regReturn
== ERROR_SUCCESS
)
1529 DWORD size
= sizeof(pFixedInfo
->ScopeId
);
1531 RegQueryValueExA(hKey
, "ScopeID", NULL
, NULL
, (PBYTE
)pFixedInfo
->ScopeId
, &size
);
1535 disposeResInfo( resInfo
);
1536 /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward
1537 I suppose could also check for a listener on port 53 to set EnableDns */
1539 TRACE("returning %ld\n", ret
);
1545 /******************************************************************
1546 * GetNumberOfInterfaces (IPHLPAPI.@)
1558 DWORD WINAPI
GetNumberOfInterfaces(PDWORD pdwNumIf
)
1562 TRACE("pdwNumIf %p\n", pdwNumIf
);
1564 ret
= ERROR_INVALID_PARAMETER
;
1566 *pdwNumIf
= getNumInterfaces();
1569 TRACE("returning %ld\n", ret
);
1574 /******************************************************************
1575 * GetOwnerModuleFromTcpEntry (IPHLPAPI.@)
1577 * Get data about the module that issued the context bind for a specific IPv4 TCP endpoint in a MIB table row
1580 * pTcpEntry [in] pointer to a MIB_TCPROW_OWNER_MODULE structure
1581 * Class [in] TCPIP_OWNER_MODULE_INFO_CLASS enumeration value
1582 * Buffer [out] pointer a buffer containing a TCPIP_OWNER_MODULE_BASIC_INFO structure with the owner module data.
1583 * pdwSize [in, out] estimated size of the structure returned in Buffer, in bytes
1587 * Failure: ERROR_INSUFFICIENT_BUFFER, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY
1588 * ERROR_NOT_FOUND or ERROR_PARTIAL_COPY
1591 * The type of data returned in Buffer is indicated by the value of the Class parameter.
1593 DWORD WINAPI
GetOwnerModuleFromTcpEntry( PMIB_TCPROW_OWNER_MODULE pTcpEntry
, TCPIP_OWNER_MODULE_INFO_CLASS Class
, PVOID Buffer
, PDWORD pdwSize
)
1595 DWORD ret
= NO_ERROR
;
1600 static void CreateNameServerListEnumNamesFunc( PWCHAR Interface
, PWCHAR Server
, PVOID Data
)
1602 IP_ADDR_STRING
*pNext
;
1603 PNAME_SERVER_LIST_CONTEXT Context
= (PNAME_SERVER_LIST_CONTEXT
)Data
;
1605 if (!Context
->NumServers
)
1607 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
1609 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, Context
->pData
->DnsServerList
.IpAddress
.String
, 16, NULL
, NULL
);
1610 Context
->pData
->DnsServerList
.IpAddress
.String
[15] = '\0';
1611 Context
->pLastAddr
= &Context
->pData
->DnsServerList
;
1616 Context
->uSizeRequired
+= sizeof(IP_ADDR_STRING
);
1617 if (Context
->uSizeAvailable
>= Context
->uSizeRequired
)
1619 pNext
= (IP_ADDR_STRING
*)(((char*)Context
->pLastAddr
) + sizeof(IP_ADDR_STRING
));
1620 WideCharToMultiByte(CP_ACP
, 0, Server
, -1, pNext
->IpAddress
.String
, 16, NULL
, NULL
);
1621 pNext
->IpAddress
.String
[15] = '\0';
1622 Context
->pLastAddr
->Next
= pNext
;
1623 Context
->pLastAddr
= pNext
;
1627 Context
->NumServers
++;
1630 /******************************************************************
1631 * GetPerAdapterInfo (IPHLPAPI.@)
1637 * pPerAdapterInfo [In/Out]
1638 * pOutBufLen [In/Out]
1645 DWORD WINAPI
GetPerAdapterInfo(ULONG IfIndex
, PIP_PER_ADAPTER_INFO pPerAdapterInfo
, PULONG pOutBufLen
)
1650 NAME_SERVER_LIST_CONTEXT Context
;
1651 WCHAR keyname
[200] = L
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
1654 return ERROR_INVALID_PARAMETER
;
1656 if (!pPerAdapterInfo
|| *pOutBufLen
< sizeof(IP_PER_ADAPTER_INFO
))
1658 *pOutBufLen
= sizeof(IP_PER_ADAPTER_INFO
);
1659 return ERROR_BUFFER_OVERFLOW
;
1662 ifName
= getInterfaceNameByIndex(IfIndex
);
1664 return ERROR_INVALID_PARAMETER
;
1666 MultiByteToWideChar(CP_ACP
, 0, ifName
, -1, &keyname
[62], sizeof(keyname
)/sizeof(WCHAR
) - 63);
1667 HeapFree(GetProcessHeap(), 0, (LPVOID
)ifName
);
1669 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, keyname
, 0, KEY_READ
, &hkey
) != ERROR_SUCCESS
)
1671 return ERROR_NOT_SUPPORTED
;
1673 Context
.NumServers
= 0;
1674 Context
.uSizeAvailable
= *pOutBufLen
;
1675 Context
.uSizeRequired
= sizeof(IP_PER_ADAPTER_INFO
);
1676 Context
.pData
= pPerAdapterInfo
;
1678 if (*pOutBufLen
>= sizeof(IP_PER_ADAPTER_INFO
))
1679 ZeroMemory(pPerAdapterInfo
, sizeof(IP_PER_ADAPTER_INFO
));
1681 EnumNameServers(hkey
, &keyname
[62], &Context
, CreateNameServerListEnumNamesFunc
);
1683 if (Context
.uSizeRequired
> Context
.uSizeAvailable
)
1685 *pOutBufLen
= Context
.uSizeRequired
;
1687 return ERROR_BUFFER_OVERFLOW
;
1690 if(RegQueryValueExW(hkey
, L
"NameServer", NULL
, NULL
, NULL
, &dwSize
) == ERROR_SUCCESS
)
1692 pPerAdapterInfo
->AutoconfigActive
= FALSE
;
1696 pPerAdapterInfo
->AutoconfigActive
= TRUE
;
1704 /******************************************************************
1705 * GetRTTAndHopCount (IPHLPAPI.@)
1710 * DestIpAddress [In]
1720 BOOL WINAPI
GetRTTAndHopCount(IPAddr DestIpAddress
, PULONG HopCount
, ULONG MaxHops
, PULONG RTT
)
1722 TRACE("DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p\n",
1723 DestIpAddress
, HopCount
, MaxHops
, RTT
);
1729 /******************************************************************
1730 * GetTcpStatisticsEx (IPHLPAPI.@)
1743 DWORD WINAPI
GetTcpStatisticsEx(PMIB_TCPSTATS pStats
, DWORD dwFamily
)
1747 TRACE("pStats %p\n", pStats
);
1748 ret
= getTCPStats(pStats
, dwFamily
);
1749 TRACE("returning %ld\n", ret
);
1753 /******************************************************************
1754 * GetTcpStatistics (IPHLPAPI.@)
1766 DWORD WINAPI
GetTcpStatistics(PMIB_TCPSTATS pStats
)
1768 return GetTcpStatisticsEx(pStats
, PF_INET
);
1772 static int TcpTableSorter(const void *a
, const void *b
)
1777 PMIB_TCPROW rowA
= (PMIB_TCPROW
)a
, rowB
= (PMIB_TCPROW
)b
;
1779 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1781 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1783 ret
= rowA
->dwRemoteAddr
- rowB
->dwRemoteAddr
;
1785 ret
= rowA
->dwRemotePort
- rowB
->dwRemotePort
;
1795 /******************************************************************
1796 * GetTcpTable (IPHLPAPI.@)
1798 * Get the table of active TCP connections.
1801 * pTcpTable [Out] buffer for TCP connections table
1802 * pdwSize [In/Out] length of output buffer
1803 * bOrder [In] whether to order the table
1807 * Failure: error code from winerror.h
1810 * If pdwSize is less than required, the function will return
1811 * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to
1812 * the required byte size.
1813 * If bOrder is true, the returned table will be sorted, first by
1814 * local address and port number, then by remote address and port
1817 DWORD WINAPI
GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
1819 DWORD ret
= ERROR_NO_DATA
;
1821 TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable
, pdwSize
,
1824 ret
= ERROR_INVALID_PARAMETER
;
1826 DWORD numEntries
= getNumTcpEntries();
1827 DWORD size
= sizeof(MIB_TCPTABLE
);
1830 size
+= (numEntries
- 1) * sizeof(MIB_TCPROW
);
1831 if (!pTcpTable
|| *pdwSize
< size
) {
1833 ret
= ERROR_INSUFFICIENT_BUFFER
;
1836 PMIB_TCPTABLE pOurTcpTable
= getTcpTable();
1839 size
= sizeof(MIB_TCPTABLE
);
1840 if (pOurTcpTable
->dwNumEntries
> 1)
1841 size
+= (pOurTcpTable
->dwNumEntries
- 1) * sizeof(MIB_TCPROW
);
1843 if (*pdwSize
< size
)
1847 ret
= ERROR_INSUFFICIENT_BUFFER
;
1851 memcpy(pTcpTable
, pOurTcpTable
, size
);
1854 qsort(pTcpTable
->table
, pTcpTable
->dwNumEntries
,
1855 sizeof(MIB_TCPROW
), TcpTableSorter
);
1864 TRACE("returning %d\n", ret
);
1869 /******************************************************************
1870 * GetUdpStatisticsEx (IPHLPAPI.@)
1883 DWORD WINAPI
GetUdpStatisticsEx(PMIB_UDPSTATS pStats
, DWORD dwFamily
)
1887 TRACE("pStats %p\n", pStats
);
1888 ret
= getUDPStats(pStats
, dwFamily
);
1889 TRACE("returning %ld\n", ret
);
1893 /******************************************************************
1894 * GetUdpStatistics (IPHLPAPI.@)
1906 DWORD WINAPI
GetUdpStatistics(PMIB_UDPSTATS pStats
)
1908 return GetUdpStatisticsEx(pStats
, PF_INET
);
1912 static int UdpTableSorter(const void *a
, const void *b
)
1917 PMIB_UDPROW rowA
= (PMIB_UDPROW
)a
, rowB
= (PMIB_UDPROW
)b
;
1919 ret
= rowA
->dwLocalAddr
- rowB
->dwLocalAddr
;
1921 ret
= rowA
->dwLocalPort
- rowB
->dwLocalPort
;
1929 /******************************************************************
1930 * GetUdpTable (IPHLPAPI.@)
1935 * pUdpTable [In/Out]
1944 DWORD WINAPI
GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
1948 TRACE("pUdpTable %p, pdwSize %p, bOrder %ld\n", pUdpTable
, pdwSize
,
1951 ret
= ERROR_INVALID_PARAMETER
;
1953 DWORD numEntries
= getNumUdpEntries();
1954 ULONG size
= sizeof(MIB_UDPTABLE
) + (numEntries
- 1) * sizeof(MIB_UDPROW
);
1956 if (!pUdpTable
|| *pdwSize
< size
) {
1958 ret
= ERROR_INSUFFICIENT_BUFFER
;
1961 PMIB_UDPTABLE table
= getUdpTable();
1964 size
= sizeof(MIB_UDPTABLE
) + (table
->dwNumEntries
- 1) *
1966 if (*pdwSize
< size
) {
1968 ret
= ERROR_INSUFFICIENT_BUFFER
;
1971 memcpy(pUdpTable
, table
, size
);
1973 qsort(pUdpTable
->table
, pUdpTable
->dwNumEntries
,
1974 sizeof(MIB_UDPROW
), UdpTableSorter
);
1980 ret
= ERROR_OUTOFMEMORY
;
1983 TRACE("returning %ld\n", ret
);
1988 /******************************************************************
1989 * GetUniDirectionalAdapterInfo (IPHLPAPI.@)
1991 * This is a Win98-only function to get information on "unidirectional"
1992 * adapters. Since this is pretty nonsensical in other contexts, it
1993 * never returns anything.
1996 * pIPIfInfo [Out] buffer for adapter infos
1997 * dwOutBufLen [Out] length of the output buffer
2001 * Failure: error code from winerror.h
2004 * Stub, returns ERROR_NOT_SUPPORTED.
2006 DWORD WINAPI
GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo
, PULONG dwOutBufLen
)
2008 TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo
, dwOutBufLen
);
2009 /* a unidirectional adapter?? not bloody likely! */
2010 return ERROR_NOT_SUPPORTED
;
2014 /******************************************************************
2015 * IpReleaseAddress (IPHLPAPI.@)
2017 * Release an IP obtained through DHCP,
2020 * AdapterInfo [In] adapter to release IP address
2024 * Failure: error code from winerror.h
2027 DWORD WINAPI
IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2029 DWORD Status
, Version
= 0;
2032 return ERROR_INVALID_PARAMETER
;
2034 /* Maybe we should do this in DllMain */
2035 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2036 return ERROR_PROC_NOT_FOUND
;
2038 if (DhcpReleaseIpAddressLease(AdapterInfo
->Index
))
2039 Status
= ERROR_SUCCESS
;
2041 Status
= ERROR_PROC_NOT_FOUND
;
2049 /******************************************************************
2050 * IpRenewAddress (IPHLPAPI.@)
2052 * Renew an IP obtained through DHCP.
2055 * AdapterInfo [In] adapter to renew IP address
2059 * Failure: error code from winerror.h
2061 DWORD WINAPI
IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo
)
2063 DWORD Status
, Version
= 0;
2066 return ERROR_INVALID_PARAMETER
;
2068 /* Maybe we should do this in DllMain */
2069 if (DhcpCApiInitialize(&Version
) != ERROR_SUCCESS
)
2070 return ERROR_PROC_NOT_FOUND
;
2072 if (DhcpRenewIpAddressLease(AdapterInfo
->Index
))
2073 Status
= ERROR_SUCCESS
;
2075 Status
= ERROR_PROC_NOT_FOUND
;
2083 /******************************************************************
2084 * NotifyAddrChange (IPHLPAPI.@)
2086 * Notify caller whenever the ip-interface map is changed.
2089 * Handle [Out] handle usable in asynchronous notification
2090 * overlapped [In] overlapped structure that notifies the caller
2094 * Failure: error code from winerror.h
2097 * Stub, returns ERROR_NOT_SUPPORTED.
2099 DWORD WINAPI
NotifyAddrChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2101 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2102 if (Handle
) *Handle
= INVALID_HANDLE_VALUE
;
2103 if (overlapped
) ((IO_STATUS_BLOCK
*) overlapped
)->Status
= STATUS_PENDING
;
2104 return ERROR_IO_PENDING
;
2108 /******************************************************************
2109 * NotifyRouteChange (IPHLPAPI.@)
2111 * Notify caller whenever the ip routing table is changed.
2114 * Handle [Out] handle usable in asynchronous notification
2115 * overlapped [In] overlapped structure that notifies the caller
2119 * Failure: error code from winerror.h
2122 * Stub, returns ERROR_NOT_SUPPORTED.
2124 DWORD WINAPI
NotifyRouteChange(PHANDLE Handle
, LPOVERLAPPED overlapped
)
2126 FIXME("(Handle %p, overlapped %p): stub\n", Handle
, overlapped
);
2127 return ERROR_NOT_SUPPORTED
;
2130 /******************************************************************
2131 * SendARP (IPHLPAPI.@)
2133 * Send an ARP request.
2136 * DestIP [In] attempt to obtain this IP
2137 * SrcIP [In] optional sender IP address
2138 * pMacAddr [Out] buffer for the mac address
2139 * PhyAddrLen [In/Out] length of the output buffer
2143 * Failure: error code from winerror.h
2145 DWORD WINAPI
SendARP(IPAddr DestIP
, IPAddr SrcIP
, PULONG pMacAddr
, PULONG PhyAddrLen
)
2150 if (IsBadWritePtr(pMacAddr
, sizeof(ULONG
)) || IsBadWritePtr(PhyAddrLen
, sizeof(ULONG
)))
2151 return ERROR_INVALID_PARAMETER
;
2156 return TCPSendIoctl(INVALID_HANDLE_VALUE
, IOCTL_QUERY_IP_HW_ADDRESS
, IPs
, &Size
, pMacAddr
, PhyAddrLen
);
2160 /******************************************************************
2161 * SetIfEntry (IPHLPAPI.@)
2163 * Set the administrative status of an interface.
2166 * pIfRow [In] dwAdminStatus member specifies the new status.
2170 * Failure: error code from winerror.h
2173 * Stub, returns ERROR_NOT_SUPPORTED.
2175 DWORD WINAPI
SetIfEntry(PMIB_IFROW pIfRow
)
2177 FIXME("(pIfRow %p): stub\n", pIfRow
);
2178 /* this is supposed to set an interface administratively up or down.
2179 Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and
2180 this sort of down is indistinguishable from other sorts of down (e.g. no
2182 return ERROR_NOT_SUPPORTED
;
2186 /******************************************************************
2187 * SetIpForwardEntry (IPHLPAPI.@)
2189 * Modify an existing route.
2192 * pRoute [In] route with the new information
2196 * Failure: error code from winerror.h
2199 DWORD WINAPI
SetIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
2201 return setIpForwardEntry( pRoute
);
2205 /******************************************************************
2206 * SetIpNetEntry (IPHLPAPI.@)
2208 * Modify an existing ARP entry.
2211 * pArpEntry [In] ARP entry with the new information
2215 * Failure: error code from winerror.h
2217 DWORD WINAPI
SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
2221 TCP_REQUEST_SET_INFORMATION_EX_ARP_ENTRY req
=
2222 TCP_REQUEST_SET_INFORMATION_INIT
;
2225 PMIB_IPNETROW arpBuff
;
2228 return ERROR_INVALID_PARAMETER
;
2230 if (!NT_SUCCESS(openTcpFile( &tcpFile
, FILE_READ_DATA
| FILE_WRITE_DATA
)))
2231 return ERROR_NOT_SUPPORTED
;
2233 if (!NT_SUCCESS(getNthIpEntity( tcpFile
, pArpEntry
->dwIndex
, &id
)))
2235 closeTcpFile(tcpFile
);
2236 return ERROR_INVALID_PARAMETER
;
2239 req
.Req
.ID
.toi_class
= INFO_CLASS_PROTOCOL
;
2240 req
.Req
.ID
.toi_type
= INFO_TYPE_PROVIDER
;
2241 req
.Req
.ID
.toi_id
= IP_MIB_ARPTABLE_ENTRY_ID
;
2242 req
.Req
.ID
.toi_entity
.tei_instance
= id
.tei_instance
;
2243 req
.Req
.ID
.toi_entity
.tei_entity
= AT_ENTITY
;
2244 req
.Req
.BufferSize
= sizeof(MIB_IPNETROW
);
2245 arpBuff
= (PMIB_IPNETROW
)&req
.Req
.Buffer
[0];
2247 RtlCopyMemory(arpBuff
, pArpEntry
, sizeof(MIB_IPNETROW
));
2249 status
= DeviceIoControl( tcpFile
,
2250 IOCTL_TCP_SET_INFORMATION_EX
,
2258 closeTcpFile(tcpFile
);
2263 return ERROR_INVALID_PARAMETER
;
2267 /******************************************************************
2268 * SetIpStatistics (IPHLPAPI.@)
2270 * Toggle IP forwarding and det the default TTL value.
2273 * pIpStats [In] IP statistics with the new information
2277 * Failure: error code from winerror.h
2280 * Stub, returns NO_ERROR.
2282 DWORD WINAPI
SetIpStatistics(PMIB_IPSTATS pIpStats
)
2284 FIXME("(pIpStats %p): stub\n", pIpStats
);
2289 /******************************************************************
2290 * SetIpTTL (IPHLPAPI.@)
2292 * Set the default TTL value.
2295 * nTTL [In] new TTL value
2299 * Failure: error code from winerror.h
2302 * Stub, returns NO_ERROR.
2304 DWORD WINAPI
SetIpTTL(UINT nTTL
)
2306 FIXME("(nTTL %d): stub\n", nTTL
);
2311 /******************************************************************
2312 * SetTcpEntry (IPHLPAPI.@)
2314 * Set the state of a TCP connection.
2317 * pTcpRow [In] specifies connection with new state
2321 * Failure: error code from winerror.h
2324 * Stub, returns NO_ERROR.
2326 DWORD WINAPI
SetTcpEntry(PMIB_TCPROW pTcpRow
)
2328 FIXME("(pTcpRow %p): stub\n", pTcpRow
);
2333 /******************************************************************
2334 * UnenableRouter (IPHLPAPI.@)
2336 * Decrement the IP-forwarding reference count. Turn off IP-forwarding
2337 * if it reaches zero.
2340 * pOverlapped [In/Out] should be the same as in EnableRouter()
2341 * lpdwEnableCount [Out] optional, receives reference count
2345 * Failure: error code from winerror.h
2348 * Stub, returns ERROR_NOT_SUPPORTED.
2350 DWORD WINAPI
UnenableRouter(OVERLAPPED
* pOverlapped
, LPDWORD lpdwEnableCount
)
2352 FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped
,
2354 return ERROR_NOT_SUPPORTED
;
2360 DWORD WINAPI
GetIpErrorString(IP_STATUS ErrorCode
,PWCHAR Buffer
,PDWORD Size
)
2370 PIP_ADAPTER_ORDER_MAP WINAPI
GetAdapterOrderMap(VOID
)
2379 #ifdef GetAdaptersAddressesV1
2380 DWORD WINAPI DECLSPEC_HOTPATCH
GetAdaptersAddresses(ULONG Family
,ULONG Flags
,PVOID Reserved
,PIP_ADAPTER_ADDRESSES pAdapterAddresses
,PULONG pOutBufLen
)
2382 InterfaceIndexTable
*indexTable
;
2385 ULONG ret
, requiredSize
= 0;
2386 PIP_ADAPTER_ADDRESSES currentAddress
;
2387 PUCHAR currentLocation
;
2390 if (!pOutBufLen
) return ERROR_INVALID_PARAMETER
;
2391 if (Reserved
) return ERROR_INVALID_PARAMETER
;
2393 indexTable
= getInterfaceIndexTable();
2395 return ERROR_NOT_ENOUGH_MEMORY
;
2397 ret
= openTcpFile(&tcpFile
, FILE_READ_DATA
);
2398 if (!NT_SUCCESS(ret
))
2399 return ERROR_NO_DATA
;
2401 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
2403 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
2405 indexTable
->indexes
[i
],
2408 /* The whole struct */
2409 requiredSize
+= sizeof(IP_ADAPTER_ADDRESSES
);
2412 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
2413 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1; //FIXME
2416 requiredSize
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
2418 /* Unicast address */
2419 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
2420 requiredSize
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
2422 /* FIXME: Implement multicast, anycast, and dns server stuff */
2424 /* FIXME: Implement dns suffix and description */
2425 requiredSize
+= 2 * sizeof(WCHAR
);
2427 /* We're only going to implement what's required for XP SP0 */
2430 TRACE("size: %d, requiredSize: %d\n", *pOutBufLen
, requiredSize
);
2431 if (!pAdapterAddresses
|| *pOutBufLen
< requiredSize
)
2433 *pOutBufLen
= requiredSize
;
2434 closeTcpFile(tcpFile
);
2436 return ERROR_BUFFER_OVERFLOW
;
2439 RtlZeroMemory(pAdapterAddresses
, requiredSize
);
2441 /* Let's set up the pointers */
2442 currentAddress
= pAdapterAddresses
;
2443 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
2445 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
2447 indexTable
->indexes
[i
],
2450 currentLocation
= (PUCHAR
)currentAddress
+ (ULONG_PTR
)sizeof(IP_ADAPTER_ADDRESSES
);
2452 /* FIXME: Friendly name */
2453 if (!(Flags
& GAA_FLAG_SKIP_FRIENDLY_NAME
))
2455 currentAddress
->FriendlyName
= (PVOID
)currentLocation
;
2456 currentLocation
+= sizeof(WCHAR
);
2460 currentAddress
->AdapterName
= (PVOID
)currentLocation
;
2461 currentLocation
+= strlen((char *)ifInfo
.if_info
.ent
.if_descr
) + 1;
2463 /* Unicast address */
2464 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
2466 currentAddress
->FirstUnicastAddress
= (PVOID
)currentLocation
;
2467 currentLocation
+= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
2468 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
= (PVOID
)currentLocation
;
2469 currentLocation
+= sizeof(struct sockaddr
);
2472 /* FIXME: Implement multicast, anycast, and dns server stuff */
2474 /* FIXME: Implement dns suffix and description */
2475 currentAddress
->DnsSuffix
= (PVOID
)currentLocation
;
2476 currentLocation
+= sizeof(WCHAR
);
2478 currentAddress
->Description
= (PVOID
)currentLocation
;
2479 currentLocation
+= sizeof(WCHAR
);
2481 currentAddress
->Next
= (PVOID
)currentLocation
;
2482 /* Terminate the last address correctly */
2484 currentAddress
->Next
= NULL
;
2486 /* We're only going to implement what's required for XP SP0 */
2488 currentAddress
= currentAddress
->Next
;
2492 /* Now again, for real this time */
2494 currentAddress
= pAdapterAddresses
;
2495 for (i
= indexTable
->numIndexes
; i
>= 0; i
--)
2497 if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile
,
2499 indexTable
->indexes
[i
],
2502 /* Make sure we're not looping more than we hoped for */
2503 ASSERT(currentAddress
);
2505 /* Alignment information */
2506 currentAddress
->Length
= sizeof(IP_ADAPTER_ADDRESSES
);
2507 currentAddress
->IfIndex
= indexTable
->indexes
[i
];
2510 strcpy(currentAddress
->AdapterName
, (char *)ifInfo
.if_info
.ent
.if_descr
);
2512 if (!(Flags
& GAA_FLAG_SKIP_UNICAST
))
2514 currentAddress
->FirstUnicastAddress
->Length
= sizeof(IP_ADAPTER_UNICAST_ADDRESS
);
2515 currentAddress
->FirstUnicastAddress
->Flags
= 0; //FIXME
2516 currentAddress
->FirstUnicastAddress
->Next
= NULL
; //FIXME: Support more than one address per adapter
2517 currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_family
= AF_INET
;
2518 memcpy(currentAddress
->FirstUnicastAddress
->Address
.lpSockaddr
->sa_data
,
2519 &ifInfo
.ip_addr
.iae_addr
,
2520 sizeof(ifInfo
.ip_addr
.iae_addr
));
2521 currentAddress
->FirstUnicastAddress
->Address
.iSockaddrLength
= sizeof(ifInfo
.ip_addr
.iae_addr
) + sizeof(USHORT
);
2522 currentAddress
->FirstUnicastAddress
->PrefixOrigin
= IpPrefixOriginOther
; //FIXME
2523 currentAddress
->FirstUnicastAddress
->SuffixOrigin
= IpPrefixOriginOther
; //FIXME
2524 currentAddress
->FirstUnicastAddress
->DadState
= IpDadStatePreferred
; //FIXME
2525 currentAddress
->FirstUnicastAddress
->ValidLifetime
= 0xFFFFFFFF; //FIXME
2526 currentAddress
->FirstUnicastAddress
->PreferredLifetime
= 0xFFFFFFFF; //FIXME
2527 currentAddress
->FirstUnicastAddress
->LeaseLifetime
= 0xFFFFFFFF; //FIXME
2530 /* FIXME: Implement multicast, anycast, and dns server stuff */
2531 currentAddress
->FirstAnycastAddress
= NULL
;
2532 currentAddress
->FirstMulticastAddress
= NULL
;
2533 currentAddress
->FirstDnsServerAddress
= NULL
;
2535 /* FIXME: Implement dns suffix, description, and friendly name */
2536 currentAddress
->DnsSuffix
[0] = UNICODE_NULL
;
2537 currentAddress
->Description
[0] = UNICODE_NULL
;
2538 currentAddress
->FriendlyName
[0] = UNICODE_NULL
;
2540 /* Physical Address */
2541 memcpy(currentAddress
->PhysicalAddress
, ifInfo
.if_info
.ent
.if_physaddr
, ifInfo
.if_info
.ent
.if_physaddrlen
);
2542 currentAddress
->PhysicalAddressLength
= ifInfo
.if_info
.ent
.if_physaddrlen
;
2545 currentAddress
->Flags
= 0; //FIXME
2548 currentAddress
->Mtu
= ifInfo
.if_info
.ent
.if_mtu
;
2550 /* Interface type */
2551 currentAddress
->IfType
= ifInfo
.if_info
.ent
.if_type
;
2553 /* Operational status */
2554 if(ifInfo
.if_info
.ent
.if_operstatus
>= IF_OPER_STATUS_CONNECTING
)
2555 currentAddress
->OperStatus
= IfOperStatusUp
;
2557 currentAddress
->OperStatus
= IfOperStatusDown
;
2559 /* We're only going to implement what's required for XP SP0 */
2561 /* Move to the next address */
2562 currentAddress
= currentAddress
->Next
;
2566 closeTcpFile(tcpFile
);
2576 BOOL WINAPI
CancelIPChangeNotify(LPOVERLAPPED notifyOverlapped
)
2585 DWORD WINAPI
GetBestInterfaceEx(struct sockaddr
*pDestAddr
,PDWORD pdwBestIfIndex
)
2594 DWORD WINAPI
NhpAllocateAndGetInterfaceInfoFromStack(IP_INTERFACE_NAME_INFO
**ppTable
,PDWORD pdwCount
,BOOL bOrder
,HANDLE hHeap
,DWORD dwFlags
)
2603 DWORD WINAPI
GetIcmpStatisticsEx(PMIB_ICMP_EX pStats
,DWORD dwFamily
)
2608 return ERROR_INVALID_PARAMETER
;
2610 if (dwFamily
!= AF_INET
&& dwFamily
!= AF_INET6
)
2611 return ERROR_INVALID_PARAMETER
;
2617 SetIpForwardEntryToStack(PMIB_IPFORWARDROW pRoute
)
2619 FIXME("SetIpForwardEntryToStack() stub\n");
2623 DWORD
GetInterfaceNameInternal(_In_
const GUID
* pInterfaceGUID
,
2624 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
2625 _Inout_ PULONG pOutBufLen
)
2627 UNICODE_STRING GuidString
;
2629 WCHAR szKeyName
[2*MAX_PATH
];
2633 if (pInterfaceGUID
== NULL
|| pOutBufLen
== NULL
)
2634 return ERROR_INVALID_PARAMETER
;
2636 result
= RtlStringFromGUID(pInterfaceGUID
, &GuidString
);
2638 if (!NT_SUCCESS(result
))
2640 // failed to convert guid to string
2641 return RtlNtStatusToDosError(result
);
2644 hr
= StringCbPrintfW(szKeyName
, sizeof(szKeyName
), L
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", GuidString
.Buffer
);
2645 RtlFreeUnicodeString(&GuidString
);
2649 // key name is too long
2650 return ERROR_BUFFER_OVERFLOW
;
2653 result
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szKeyName
, 0, KEY_READ
, &hKey
);
2655 if (result
!= ERROR_SUCCESS
)
2657 // failed to find adapter entry
2658 return ERROR_NOT_FOUND
;
2661 result
= RegQueryValueExW(hKey
, L
"Name", NULL
, &type
, (PVOID
)pInterfaceName
, pOutBufLen
);
2665 if (result
== ERROR_MORE_DATA
)
2667 *pOutBufLen
= MAX_INTERFACE_NAME_LEN
* 2;
2668 return ERROR_INSUFFICIENT_BUFFER
;
2671 if (result
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
2673 // failed to read adapter name
2674 return ERROR_NO_DATA
;
2676 return ERROR_SUCCESS
;
2683 NhGetInterfaceNameFromDeviceGuid(_In_
const GUID
* pInterfaceGUID
,
2684 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
2685 _Inout_ PULONG pOutBufLen
,
2689 SetLastError(ERROR_SUCCESS
);
2691 if (pInterfaceName
== NULL
)
2692 return ERROR_INVALID_PARAMETER
;
2694 return GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
2701 NhGetInterfaceNameFromGuid(_In_
const GUID
* pInterfaceGUID
,
2702 _Out_writes_bytes_to_(*pOutBufLen
, *pOutBufLen
) PWCHAR pInterfaceName
,
2703 _Inout_ PULONG pOutBufLen
,
2709 result
= GetInterfaceNameInternal(pInterfaceGUID
, pInterfaceName
, pOutBufLen
);
2711 if (result
== ERROR_NOT_FOUND
)
2712 SetLastError(ERROR_PATH_NOT_FOUND
);