public static DhcpInfo GetDhcpInfo(Guid networkAdapterId) { using (var wrapper = new DhcpWrapper()) { DHCPCAPI_PARAMS outParameters; if (!wrapper.TryExecuteRequest(networkAdapterId, OPTION.ROUTER_ADDRESS, out outParameters) || outParameters.nBytesData != 4u) { return null; } var gatewayAddress = GetAddress(outParameters.Data); if (!wrapper.TryExecuteRequest(networkAdapterId, OPTION.DOMAIN_NAME_SERVERS, out outParameters) || !IsValidAddressByteCount((int)outParameters.nBytesData)) { return null; } var dnsServerAddress = GetAddresses(outParameters.Data, (int)outParameters.nBytesData / 4).First(); if (!wrapper.TryExecuteRequest(networkAdapterId, OPTION.DOMAIN_NAME, out outParameters)) { return null; } var domainName = GetDomainName(outParameters.Data, (int)outParameters.nBytesData); var result = new DhcpInfo(gatewayAddress, dnsServerAddress, domainName); return result; } }
public static DhcpInfo GetDhcpInfo(Guid networkAdapterId) { using (var wrapper = new DhcpWrapper()) { DHCPCAPI_PARAMS outParameters; if (!wrapper.TryExecuteRequest(networkAdapterId, OPTION.ROUTER_ADDRESS, out outParameters) || outParameters.nBytesData != 4u) { return(null); } var gatewayAddress = GetAddress(outParameters.Data); if (!wrapper.TryExecuteRequest(networkAdapterId, OPTION.DOMAIN_NAME_SERVERS, out outParameters) || !IsValidAddressByteCount((int)outParameters.nBytesData)) { return(null); } var dnsServerAddress = GetAddresses(outParameters.Data, (int)outParameters.nBytesData / 4).First(); if (!wrapper.TryExecuteRequest(networkAdapterId, OPTION.DOMAIN_NAME, out outParameters)) { return(null); } var domainName = GetDomainName(outParameters.Data, (int)outParameters.nBytesData); var result = new DhcpInfo(gatewayAddress, dnsServerAddress, domainName); return(result); } }