1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_BASE_NET_UTIL_WIN_H_
6 #define NET_BASE_NET_UTIL_WIN_H_
8 // This file is only used to expose some of the internals
9 // of net_util_win.cc to tests.
13 #include "base/win/scoped_handle.h"
14 #include "net/base/net_export.h"
19 struct NET_EXPORT WlanApi
{
20 typedef DWORD (WINAPI
*WlanOpenHandleFunc
)(
21 DWORD
, VOID
*, DWORD
*, HANDLE
*);
22 typedef DWORD (WINAPI
*WlanEnumInterfacesFunc
)(
23 HANDLE
, VOID
*, WLAN_INTERFACE_INFO_LIST
**);
24 typedef DWORD (WINAPI
*WlanQueryInterfaceFunc
)(
25 HANDLE
, const GUID
*, WLAN_INTF_OPCODE
, VOID
*, DWORD
*, VOID
**,
26 WLAN_OPCODE_VALUE_TYPE
*);
27 typedef DWORD (WINAPI
*WlanSetInterfaceFunc
)(
28 HANDLE
, const GUID
*, WLAN_INTF_OPCODE
, DWORD
, const VOID
*, VOID
*);
29 typedef VOID (WINAPI
*WlanFreeMemoryFunc
)(VOID
*);
30 typedef DWORD (WINAPI
*WlanCloseHandleFunc
)(HANDLE
, VOID
*);
33 static WlanApi
& GetInstance();
36 DWORD
OpenHandle(DWORD client_version
, DWORD
* cur_version
, T
* handle
) const {
38 DWORD result
= open_handle_func(client_version
, NULL
, cur_version
,
40 if (result
!= ERROR_SUCCESS
)
42 handle
->Set(temp_handle
);
47 WlanOpenHandleFunc open_handle_func
;
48 WlanEnumInterfacesFunc enum_interfaces_func
;
49 WlanQueryInterfaceFunc query_interface_func
;
50 WlanSetInterfaceFunc set_interface_func
;
51 WlanFreeMemoryFunc free_memory_func
;
52 WlanCloseHandleFunc close_handle_func
;
56 struct WlanApiHandleTraits
{
57 typedef HANDLE Handle
;
59 static bool CloseHandle(HANDLE handle
) {
60 return WlanApi::GetInstance().close_handle_func(handle
, NULL
) ==
63 static bool IsHandleValid(HANDLE handle
) {
64 return base::win::HandleTraits::IsHandleValid(handle
);
66 static HANDLE
NullHandle() {
67 return base::win::HandleTraits::NullHandle();
71 typedef base::win::GenericScopedHandle
<
73 base::win::DummyVerifierTraits
> WlanHandle
;
75 struct WlanApiDeleter
{
76 inline void operator()(void* ptr
) const {
77 WlanApi::GetInstance().free_memory_func(ptr
);
81 } // namespace internal
85 #endif // NET_BASE_NET_UTIL_WIN_H_