1 | /* $Id: utils.h 87696 2021-02-10 17:10:58Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * ComHostUtils.cpp
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*******************************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 |
|
---|
22 | #ifndef VBOX_INCLUDED_SRC_NetLib_utils_h
|
---|
23 | #define VBOX_INCLUDED_SRC_NetLib_utils_h
|
---|
24 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
25 | # pragma once
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | #include "cpp/utils.h"
|
---|
29 |
|
---|
30 | typedef ComPtr<IVirtualBox> ComVirtualBoxPtr;
|
---|
31 | typedef ComPtr<IVirtualBoxClient> ComVirtualBoxClientPtr;
|
---|
32 | typedef ComPtr<IDHCPServer> ComDhcpServerPtr;
|
---|
33 | typedef ComPtr<IHost> ComHostPtr;
|
---|
34 | typedef ComPtr<INATNetwork> ComNatPtr;
|
---|
35 | typedef com::SafeArray<BSTR> ComBstrArray;
|
---|
36 |
|
---|
37 | typedef std::vector<RTNETADDRIPV4> AddressList;
|
---|
38 | typedef std::map<RTNETADDRIPV4, int> AddressToOffsetMapping;
|
---|
39 |
|
---|
40 |
|
---|
41 | int localMappings(const ComNatPtr&, AddressToOffsetMapping&);
|
---|
42 | int hostDnsSearchList(const ComHostPtr&, std::vector<std::string>&);
|
---|
43 | int hostDnsDomain(const ComHostPtr&, std::string& domainStr);
|
---|
44 |
|
---|
45 |
|
---|
46 | class NATNetworkEventAdapter
|
---|
47 | {
|
---|
48 | public:
|
---|
49 | virtual ~NATNetworkEventAdapter() { /* Make VC++ 19.2 happy. */ }
|
---|
50 | virtual HRESULT HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent) = 0;
|
---|
51 | };
|
---|
52 |
|
---|
53 |
|
---|
54 | class NATNetworkListener
|
---|
55 | {
|
---|
56 | public:
|
---|
57 | NATNetworkListener():m_pNAT(NULL){}
|
---|
58 |
|
---|
59 | HRESULT init(NATNetworkEventAdapter *pNAT)
|
---|
60 | {
|
---|
61 | AssertPtrReturn(pNAT, E_INVALIDARG);
|
---|
62 |
|
---|
63 | m_pNAT = pNAT;
|
---|
64 | return S_OK;
|
---|
65 | }
|
---|
66 |
|
---|
67 | HRESULT init()
|
---|
68 | {
|
---|
69 | m_pNAT = NULL;
|
---|
70 | return S_OK;
|
---|
71 | }
|
---|
72 |
|
---|
73 | void uninit() { m_pNAT = NULL; }
|
---|
74 |
|
---|
75 | HRESULT HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent)
|
---|
76 | {
|
---|
77 | if (m_pNAT)
|
---|
78 | return m_pNAT->HandleEvent(aEventType, pEvent);
|
---|
79 | else
|
---|
80 | return E_FAIL;
|
---|
81 | }
|
---|
82 |
|
---|
83 | private:
|
---|
84 | NATNetworkEventAdapter *m_pNAT;
|
---|
85 | };
|
---|
86 | typedef ListenerImpl<NATNetworkListener, NATNetworkEventAdapter*> NATNetworkListenerImpl;
|
---|
87 |
|
---|
88 | # ifdef VBOX_WITH_XPCOM
|
---|
89 | class NS_CLASSINFO_NAME(NATNetworkListenerImpl);
|
---|
90 | # endif
|
---|
91 |
|
---|
92 | typedef ComPtr<NATNetworkListenerImpl> ComNatListenerPtr;
|
---|
93 | typedef com::SafeArray<VBoxEventType_T> ComEventTypeArray;
|
---|
94 |
|
---|
95 | /* XXX: const is commented out because of compilation erro on Windows host, but it's intended that this function
|
---|
96 | isn't modify event type array */
|
---|
97 | int createNatListener(ComNatListenerPtr& listener, const ComVirtualBoxPtr& vboxptr,
|
---|
98 | NATNetworkEventAdapter *adapter, /* const */ ComEventTypeArray& events);
|
---|
99 | int destroyNatListener(ComNatListenerPtr& listener, const ComVirtualBoxPtr& vboxptr);
|
---|
100 | int createClientListener(ComNatListenerPtr& listener, const ComVirtualBoxClientPtr& vboxclientptr,
|
---|
101 | NATNetworkEventAdapter *adapter, /* const */ ComEventTypeArray& events);
|
---|
102 | int destroyClientListener(ComNatListenerPtr& listener, const ComVirtualBoxClientPtr& vboxclientptr);
|
---|
103 |
|
---|
104 | #endif /* !VBOX_INCLUDED_SRC_NetLib_utils_h */
|
---|