コード例 #1
0
ファイル: DnsGateway.cs プロジェクト: pedoc/Pcap.Net
        internal static DnsGateway CreateInstance(DnsGatewayType gatewayType, DnsDatagram dns, int offsetInDns, int length)
        {
            switch (gatewayType)
            {
            case DnsGatewayType.None:
                return(None);

            case DnsGatewayType.IpV4:
                if (length < IpV4Address.SizeOf)
                {
                    return(null);
                }
                return(new DnsGatewayIpV4(dns.ReadIpV4Address(offsetInDns, Endianity.Big)));

            case DnsGatewayType.IpV6:
                if (length < IpV6Address.SizeOf)
                {
                    return(null);
                }
                return(new DnsGatewayIpV6(dns.ReadIpV6Address(offsetInDns, Endianity.Big)));

            case DnsGatewayType.DomainName:
                DnsDomainName domainName;
                int           numBytesRead;
                if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName, out numBytesRead))
                {
                    return(null);
                }
                return(new DnsGatewayDomainName(domainName));

            default:
                return(null);
            }
        }
コード例 #2
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < 3)
            {
                return((DnsResourceData)null);
            }
            byte                  precedence  = dns[offsetInDns];
            DnsGatewayType        gatewayType = (DnsGatewayType)dns[offsetInDns + 1];
            DnsPublicKeyAlgorithm algorithm   = (DnsPublicKeyAlgorithm)dns[offsetInDns + 2];
            DnsGateway            instance    = DnsGateway.CreateInstance(gatewayType, dns, offsetInDns + 3, length - 3);

            if (instance == null)
            {
                return((DnsResourceData)null);
            }
            DataSegment publicKey = dns.Subsegment(offsetInDns + 3 + instance.Length, length - 3 - instance.Length);

            return((DnsResourceData) new DnsResourceDataIpSecKey(precedence, instance, algorithm, publicKey));
        }
コード例 #3
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < ConstPartLength)
            {
                return(null);
            }

            byte                  precedence  = dns[offsetInDns + Offset.Precedence];
            DnsGatewayType        gatewayType = (DnsGatewayType)dns[offsetInDns + Offset.GatewayType];
            DnsPublicKeyAlgorithm algorithm   = (DnsPublicKeyAlgorithm)dns[offsetInDns + Offset.Algorithm];
            DnsGateway            gateway     = DnsGateway.CreateInstance(gatewayType, dns, offsetInDns + Offset.Gateway, length - ConstPartLength);

            if (gateway == null)
            {
                return(null);
            }
            DataSegment publicKey = dns.Subsegment(offsetInDns + ConstPartLength + gateway.Length, length - ConstPartLength - gateway.Length);

            return(new DnsResourceDataIpSecKey(precedence, gateway, algorithm, publicKey));
        }
コード例 #4
0
        public static DnsGateway NextDnsGateway(this Random random)
        {
            DnsGatewayType gatewayType = random.NextEnum <DnsGatewayType>();

            switch (gatewayType)
            {
            case DnsGatewayType.None:
                return(DnsGateway.None);

            case DnsGatewayType.IpV4:
                return(new DnsGatewayIpV4(random.NextIpV4Address()));

            case DnsGatewayType.IpV6:
                return(new DnsGatewayIpV6(random.NextIpV6Address()));

            case DnsGatewayType.DomainName:
                return(new DnsGatewayDomainName(random.NextDnsDomainName()));

            default:
                throw new InvalidOperationException(string.Format("Invalid gateway type: {0}", gatewayType));
            }
        }