我正在编写一个模块来管理与该模块所在的服务位于同一位置的 DHCP 服务器。
我使用DHCP 服务器 API编写了代码,该 API能够创建子网并添加 DHCP 预留。我似乎无法做的实际上是启用/激活子网范围。
我曾假设可以DhcpSetSubnetInfo( )
将结构SubnetState
字段DHCP_SUBNET_INFO
设置为,DhcpSubnetEnabled
但这似乎没有效果。
扫描 DHCP 服务器 API 的其余部分,我看不到任何其他配置子网/范围的方法。
有没有人设法做到这一点?
谢谢你的帮助。
缺口。
编辑:
static bool enableSubnet(
const std::wstring& server,
DWORD dwSubnet
)
{
LPDHCP_SUBNET_INFO pInfo = NULL;
DWORD res = DhcpGetSubnetInfo(
server.c_str( ),
dwSubnet,
&pInfo
);
if ( res != ERROR_SUCCESS )
{
DhcpRpcFreeMemory( pInfo );
return false;
}
if ( pInfo->SubnetState == DhcpSubnetEnabled )
{
DhcpRpcFreeMemory( pInfo );
return true;
}
DHCP_SUBNET_INFO info( *pInfo );
info.SubnetState = DhcpSubnetDisabled;
res = DhcpCreateSubnet( server.c_str( ), dwSubnet, &info );
DhcpRpcFreeMemory( pInfo );
if ( res != ERROR_SUCCESS )
{
return false;
}
res = DhcpGetSubnetInfo(
server.c_str( ),
dwSubnet,
&pInfo
);
if ( res != ERROR_SUCCESS )
{
DhcpRpcFreeMemory( pInfo );
return false;
}
bool retVal = ( pInfo->SubnetState == DhcpSubnetEnabled );
if ( !retVal )
{
std::wcerr << L"Failed to enable subnet";
}
DhcpRpcFreeMemory( pInfo );
return retVal;
}
调试代码,所有DhcpXX函数都通过了,但是检查时函数返回false:
bool retVal = ( pInfo->SubnetState == DhcpSubnetEnabled );