VirtualBox

source: vbox/trunk/src/VBox/NetworkServices/NetLib/utils.h@ 87695

Last change on this file since 87695 was 87695, checked in by vboxsync, 4 years ago

NAT/Net: G/c unused code. bugref:9929.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: utils.h 87695 2021-02-10 17:10:05Z 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
30typedef ComPtr<IVirtualBox> ComVirtualBoxPtr;
31typedef ComPtr<IVirtualBoxClient> ComVirtualBoxClientPtr;
32typedef ComPtr<IDHCPServer> ComDhcpServerPtr;
33typedef ComPtr<IHost> ComHostPtr;
34typedef ComPtr<INATNetwork> ComNatPtr;
35typedef com::SafeArray<BSTR> ComBstrArray;
36
37typedef std::vector<RTNETADDRIPV4> AddressList;
38typedef std::map<RTNETADDRIPV4, int> AddressToOffsetMapping;
39
40
41inline RTNETADDRIPV4 networkid(const RTNETADDRIPV4& addr, const RTNETADDRIPV4& netmask)
42{
43 RTNETADDRIPV4 netid;
44 netid.u = addr.u & netmask.u;
45 return netid;
46}
47
48
49int localMappings(const ComNatPtr&, AddressToOffsetMapping&);
50int hostDnsSearchList(const ComHostPtr&, std::vector<std::string>&);
51int hostDnsDomain(const ComHostPtr&, std::string& domainStr);
52
53
54class NATNetworkEventAdapter
55{
56public:
57 virtual ~NATNetworkEventAdapter() { /* Make VC++ 19.2 happy. */ }
58 virtual HRESULT HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent) = 0;
59};
60
61
62class NATNetworkListener
63{
64public:
65 NATNetworkListener():m_pNAT(NULL){}
66
67 HRESULT init(NATNetworkEventAdapter *pNAT)
68 {
69 AssertPtrReturn(pNAT, E_INVALIDARG);
70
71 m_pNAT = pNAT;
72 return S_OK;
73 }
74
75 HRESULT init()
76 {
77 m_pNAT = NULL;
78 return S_OK;
79 }
80
81 void uninit() { m_pNAT = NULL; }
82
83 HRESULT HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent)
84 {
85 if (m_pNAT)
86 return m_pNAT->HandleEvent(aEventType, pEvent);
87 else
88 return E_FAIL;
89 }
90
91private:
92 NATNetworkEventAdapter *m_pNAT;
93};
94typedef ListenerImpl<NATNetworkListener, NATNetworkEventAdapter*> NATNetworkListenerImpl;
95
96# ifdef VBOX_WITH_XPCOM
97class NS_CLASSINFO_NAME(NATNetworkListenerImpl);
98# endif
99
100typedef ComPtr<NATNetworkListenerImpl> ComNatListenerPtr;
101typedef com::SafeArray<VBoxEventType_T> ComEventTypeArray;
102
103/* XXX: const is commented out because of compilation erro on Windows host, but it's intended that this function
104 isn't modify event type array */
105int createNatListener(ComNatListenerPtr& listener, const ComVirtualBoxPtr& vboxptr,
106 NATNetworkEventAdapter *adapter, /* const */ ComEventTypeArray& events);
107int destroyNatListener(ComNatListenerPtr& listener, const ComVirtualBoxPtr& vboxptr);
108int createClientListener(ComNatListenerPtr& listener, const ComVirtualBoxClientPtr& vboxclientptr,
109 NATNetworkEventAdapter *adapter, /* const */ ComEventTypeArray& events);
110int destroyClientListener(ComNatListenerPtr& listener, const ComVirtualBoxClientPtr& vboxclientptr);
111
112#endif /* !VBOX_INCLUDED_SRC_NetLib_utils_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette