Set Local Network Filter Example for C++
HRESULT SetLocalNetworkFilter(IltmsServer* server)
{
HRESULT hr;
CComPtr<IltmsIPFilters> filters;
CString ipfirst;
CString iplast;
// this routine will setup an IP filter that only allows local network connections
// retrieve a copy of the current filters
hr = server->GetIPFilters(&filters);
if(FAILED(hr))
goto error;
// create a full range blacklist
// equivalent to filters->Add(CComBSTR(L"0.0.0.0"), CComBSTR(L"255.255.255.255"), VARIANT_FALSE);
// create a full range whitelist
hr = filters->Reset();
if(FAILED(hr))
goto error;
// invert the single whitelist filter to create the blacklist
hr = filters->Remove(0);
if(FAILED(hr))
goto error;
{
// obtain the server IP address and create the filter range
CComPtr<IltmsNetworkProperties> props;
hr = server->GetNetworkProperties(&props);
if(FAILED(hr))
goto error;
CComBSTR v;
hr = props->get_ActualIPAddress(&v);
if(FAILED(hr))
goto error;
CString t(v);
t = t.Left(t.ReverseFind(_T('.')));
ipfirst = t + _T(".0");
iplast += t + _T(".255");
}
// now we will add a filter to allow for the local network IP range
hr = filters->Add(CComBSTR(ipfirst), CComBSTR(iplast), VARIANT_TRUE);
if(FAILED(hr))
goto error;
// copy the filters to the server
hr = server->SetIPFilters(filters);
if(FAILED(hr))
goto error;
error:
return hr;
}