xref: /reactos/dll/directx/msdvbnp/ipv4.cpp (revision d6eebaa4)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS BDA Proxy
4  * FILE:            dll/directx/msdvbnp/ipv4.cpp
5  * PURPOSE:         IBDA_IPV4Filter interface
6  *
7  * PROGRAMMERS:     Johannes Anderwald (johannes.anderwald@reactos.org)
8  */
9 #include "precomp.h"
10 
11 class CIPV4Filter : public IBDA_IPV4Filter
12 {
13 public:
14     STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
15     STDMETHODIMP_(ULONG) AddRef();
16     STDMETHODIMP_(ULONG) Release();
17 
18     //IBDA_IPV4Filter
19     HRESULT STDMETHODCALLTYPE GetMulticastListSize(ULONG *pulcbAddresses);
20     HRESULT STDMETHODCALLTYPE PutMulticastList(ULONG ulcbAddresses, BYTE * pAddressList);
21     HRESULT STDMETHODCALLTYPE GetMulticastList(ULONG *pulcbAddresses, BYTE *pAddressList);
22     HRESULT STDMETHODCALLTYPE PutMulticastMode(ULONG ulModeMask);
23     HRESULT STDMETHODCALLTYPE GetMulticastMode(ULONG *pulModeMask);
24 
25 
26     CIPV4Filter(IBDA_NetworkProvider * pNetworkProvider);
27     virtual ~CIPV4Filter();
28 
29 protected:
30     IBDA_NetworkProvider * m_pNetworkProvider;
31     ULONG m_ulcbAddresses;
32     BYTE * m_pAddressList;
33     ULONG m_ulModeMask;
34 };
35 
36 CIPV4Filter::CIPV4Filter(
37     IBDA_NetworkProvider * pNetworkProvider) : m_pNetworkProvider(pNetworkProvider),
38                                                m_ulcbAddresses(0),
39                                                m_pAddressList(0),
40                                                m_ulModeMask(0)
41 {
42 }
43 
44 CIPV4Filter::~CIPV4Filter()
45 {
46     if (m_pAddressList)
47         CoTaskMemFree(m_pAddressList);
48 }
49 
50 
51 HRESULT
52 STDMETHODCALLTYPE
53 CIPV4Filter::QueryInterface(
54     REFIID InterfaceId,
55     PVOID* Interface)
56 {
57     assert(m_pNetworkProvider);
58     return m_pNetworkProvider->QueryInterface(InterfaceId, Interface);
59 }
60 
61 ULONG
62 STDMETHODCALLTYPE
63 CIPV4Filter::AddRef()
64 {
65     assert(m_pNetworkProvider);
66     return m_pNetworkProvider->AddRef();
67 }
68 
69 ULONG
70 STDMETHODCALLTYPE
71 CIPV4Filter::Release()
72 {
73     assert(m_pNetworkProvider);
74     return m_pNetworkProvider->Release();
75 }
76 
77 //-------------------------------------------------------------------
78 //IBDA_IPV4Filter
79 //
80 
81 
82 HRESULT
83 STDMETHODCALLTYPE
84 CIPV4Filter::GetMulticastListSize(
85     ULONG *pulcbAddresses)
86 {
87     if (!pulcbAddresses)
88         return E_POINTER;
89 
90     *pulcbAddresses = 0;
91     return NOERROR;
92 }
93 
94 HRESULT
95 STDMETHODCALLTYPE
96 CIPV4Filter::PutMulticastList(
97     ULONG ulcbAddresses,
98     BYTE * pAddressList)
99 {
100     if (!ulcbAddresses || !pAddressList)
101         return E_POINTER;
102 
103     if (m_pAddressList)
104         CoTaskMemFree(m_pAddressList);
105 
106     m_pAddressList = (BYTE*)CoTaskMemAlloc(ulcbAddresses);
107     if (!m_pAddressList)
108         return E_OUTOFMEMORY;
109 
110     CopyMemory(m_pAddressList, pAddressList, ulcbAddresses);
111     m_ulcbAddresses = ulcbAddresses;
112     return NOERROR;
113 }
114 
115 HRESULT
116 STDMETHODCALLTYPE
117 CIPV4Filter::GetMulticastList(
118     ULONG *pulcbAddresses,
119     BYTE *pAddressList)
120 {
121     if (!pulcbAddresses || !pAddressList)
122         return E_POINTER;
123 
124     if (*pulcbAddresses < m_ulcbAddresses)
125         return E_OUTOFMEMORY;
126 
127     CopyMemory(pAddressList, m_pAddressList, m_ulcbAddresses);
128     *pulcbAddresses = m_ulcbAddresses;
129     return NOERROR;
130 }
131 
132 HRESULT
133 STDMETHODCALLTYPE
134 CIPV4Filter::PutMulticastMode(
135     ULONG ulModeMask)
136 {
137     m_ulModeMask = ulModeMask;
138     return NOERROR;
139 }
140 
141 HRESULT
142 STDMETHODCALLTYPE
143 CIPV4Filter::GetMulticastMode(
144     ULONG *pulModeMask)
145 {
146     *pulModeMask = m_ulModeMask;
147     return NOERROR;
148 }
149 
150 HRESULT
151 WINAPI
152 CIPV4Filter_fnConstructor(
153     IBDA_NetworkProvider * pNetworkProvider,
154     REFIID riid,
155     LPVOID * ppv)
156 {
157     CIPV4Filter * filter = new CIPV4Filter(pNetworkProvider);
158 
159     if (!filter)
160         return E_OUTOFMEMORY;
161 
162     if (FAILED(filter->QueryInterface(riid, ppv)))
163     {
164         /* not supported */
165         delete filter;
166         return E_NOINTERFACE;
167     }
168 
169     return NOERROR;
170 }
171