/// <summary>
        /// Converts the string representation of an IPv4 address (1.2.3.4) to its IPv4 address equivalent.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="value">A string containing the IPv4 address to convert (1.2.3.4).</param>
        /// <param name="result">
        /// When this method returns, contains the IPv4 address value equivalent of the IPv4 address contained in s, if the conversion succeeded,
        /// or zero IPv4 address if the conversion failed.
        /// The conversion fails if the s parameter is null or String.Empty or is not of the correct format. This parameter is passed uninitialized.
        /// </param>
        /// <returns>True iff parsing was successful.</returns>
        public static bool TryParse(string value, out IpV4Address result)
        {
            if (value == null)
            {
                result = Zero;
                return(false);
            }

            string[] valuesStrings = value.Split('.');
            if (valuesStrings.Length != 4)
            {
                result = Zero;
                return(false);
            }

            byte[] values = new byte[4];
            for (int i = 0; i != 4; ++i)
            {
                if (!byte.TryParse(valuesStrings[i], NumberStyles.None, CultureInfo.InvariantCulture, out values[i]))
                {
                    result = Zero;
                    return(false);
                }
            }

            result = new IpV4Address(BitSequence.Merge(values[0], values[1], values[2], values[3]));
            return(true);
        }
예제 #2
0
 /// <summary>
 /// A hash code out of the combination of the authentication prohibited, confidentiality prohibited, experimental, user associated, IPSec, email,
 /// name type, signatory, protocol, algorithm, flags extension and public key fields.
 /// </summary>
 public override int GetHashCode()
 {
     return(Sequence.GetHashCode(
                BitSequence.Merge(BitSequence.Merge(AuthenticationProhibited, ConfidentialityProhibited, Experimental, UserAssociated, IpSec, Email),
                                  (byte)NameType, (byte)Signatory, (byte)Protocol),
                BitSequence.Merge((byte)Algorithm, (ushort)(FlagsExtension.HasValue ? FlagsExtension.Value : 0)),
                PublicKey));
 }
예제 #3
0
 public IpV4Address(string value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     string[] strArray = value.Split('.');
     this._value = BitSequence.Merge(byte.Parse(strArray[0], (IFormatProvider)CultureInfo.InvariantCulture), byte.Parse(strArray[1], (IFormatProvider)CultureInfo.InvariantCulture), byte.Parse(strArray[2], (IFormatProvider)CultureInfo.InvariantCulture), byte.Parse(strArray[3], (IFormatProvider)CultureInfo.InvariantCulture));
 }
예제 #4
0
 /// <summary>
 /// Returns a hash code for the layer.
 /// The hash code is a XOR of a combination of the protocol type and operation and the hash codes of the layer length and data link.
 /// </summary>
 public override int GetHashCode()
 {
     return(base.GetHashCode() ^
            BitSequence.Merge((ushort)ProtocolType, (ushort)Operation).GetHashCode() ^
            SenderHardwareAddress.BytesSequenceGetHashCode() ^
            SenderProtocolAddress.BytesSequenceGetHashCode() ^
            TargetHardwareAddress.BytesSequenceGetHashCode() ^
            TargetProtocolAddress.BytesSequenceGetHashCode());
 }
        /// <summary>
        /// Creates an address from an address string (1.2.3.4).
        /// </summary>
        public IpV4Address(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            string[] values = value.Split('.');
            _value = BitSequence.Merge(byte.Parse(values[0], CultureInfo.InvariantCulture),
                                       byte.Parse(values[1], CultureInfo.InvariantCulture),
                                       byte.Parse(values[2], CultureInfo.InvariantCulture),
                                       byte.Parse(values[3], CultureInfo.InvariantCulture));
        }
예제 #6
0
 public MacAddress(string address)
 {
     if (address == null)
     {
         throw new ArgumentNullException("address");
     }
     string[] strArray = address.Split(':');
     if (strArray.Length != 6)
     {
         throw new ArgumentException("Failed parsing " + (object)address + " as mac address. Expected 6 hexes and got " + (string)(object)strArray.Length + " hexes", "address");
     }
     this._value = BitSequence.Merge(Convert.ToByte(strArray[0], 16), Convert.ToByte(strArray[1], 16), Convert.ToByte(strArray[2], 16), Convert.ToByte(strArray[3], 16), Convert.ToByte(strArray[4], 16), Convert.ToByte(strArray[5], 16));
 }
예제 #7
0
        /// <summary>
        /// Create the address from a string in the format XX:XX:XX:XX:XX:XX.
        /// </summary>
        /// <param name="address">The string value in hexadecimal format. Every two digits are separated by a colon.</param>
        public MacAddress(string address)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            string[] hexes = address.Split(':');
            if (hexes.Length != 6)
            {
                throw new ArgumentException("Failed parsing " + address + " as mac address. Expected 6 hexes and got " + hexes.Length + " hexes", "address");
            }

            _value = BitSequence.Merge(Convert.ToByte(hexes[0], 16), Convert.ToByte(hexes[1], 16), Convert.ToByte(hexes[2], 16),
                                       Convert.ToByte(hexes[3], 16), Convert.ToByte(hexes[4], 16), Convert.ToByte(hexes[5], 16));
        }
예제 #8
0
        public void Merge8BoolRandomTest()
        {
            Random random = new Random();

            for (int i = 0; i != 10; ++i)
            {
                byte   expectedResult = 0;
                bool[] input          = new bool[8];
                for (int bit = 0; bit != 8; ++bit)
                {
                    bool bitValue = random.NextBool();
                    input[bit]       = bitValue;
                    expectedResult <<= 1;
                    if (bitValue)
                    {
                        ++expectedResult;
                    }
                }

                Assert.AreEqual(expectedResult, BitSequence.Merge(input[0], input[1], input[2], input[3], input[4], input[5], input[6], input[7]));
            }
        }
 /// <summary>
 /// A hash code of the combination of the priority, weight, port and target fields.
 /// </summary>
 public override int GetHashCode()
 {
     return(Sequence.GetHashCode(BitSequence.Merge(Priority, Weight), Port, Target));
 }
 internal override int GetDataHashCode()
 {
     return(Sequence.GetHashCode(BitSequence.Merge((byte)Status, Priority, BindingId), SimultaneousHomeAndForeignBinding, IpV4CareOfAddress,
                                 IpV6CareOfAddress));
 }
예제 #11
0
 internal override int DataGetHashCode()
 {
     return(Sequence.GetHashCode(BitSequence.Merge(Version, (ushort)OpCode), ErrorCode, Id, LeaseLife));
 }
 public override int GetHashCode()
 {
     return(base.GetHashCode() ^ BitSequence.Merge(this.IsStart, this.IsEnd).GetHashCode());
 }
 /// <summary>
 /// A hash code based on the algorithm, fingerprint type and fingerprint fields.
 /// </summary>
 public override int GetHashCode()
 {
     return(Sequence.GetHashCode(BitSequence.Merge((byte)Algorithm, (byte)FingerprintType), Fingerprint));
 }
예제 #14
0
 /// <summary>
 /// Returns a hash code for the layer.
 /// The hash code is a XOR of the layer length, data link, message type and code, checksum and variable.
 /// </summary>
 public sealed override int GetHashCode()
 {
     return(base.GetHashCode() ^
            Sequence.GetHashCode(BitSequence.Merge((ushort)MessageTypeAndCode, Checksum ?? 0), Variable));
 }
 public DnsOptResourceRecord(DnsDomainName domainName, ushort sendersUdpPayloadSize, byte extendedReturnCode, DnsOptVersion version, DnsOptFlags flags, DnsResourceDataOptions data)
     : this(domainName, (DnsClass)sendersUdpPayloadSize, (int)BitSequence.Merge(extendedReturnCode, (byte)version, (ushort)flags), (DnsResourceData)data)
 {
 }
예제 #16
0
 internal override int GetDataHashCode()
 {
     return(Sequence.GetHashCode(BitSequence.Merge(FragmentOffset, MoreFragments.ToByte()), Identification));
 }
예제 #17
0
 public override int GetHashCode()
 {
     return(Sequence.GetHashCode((object)BitSequence.Merge(this.Order, this.Preference), (object)this.Flags, (object)this.Services, (object)this.RegularExpression, (object)this.Replacement));
 }
 internal sealed override int GetDataHashCode()
 {
     return(Sequence.GetHashCode(BitSequence.Merge(Checksum, (byte)MobilityHeaderType), MobilityOptions, GetMessageDataHashCode()));
 }
 /// <summary>
 /// A hash code of the combination of the precedence, gateway, algorithm and public key fields.
 /// </summary>
 public override int GetHashCode()
 {
     return(Sequence.GetHashCode(BitSequence.Merge(Precedence, (byte)Algorithm), Gateway, PublicKey));
 }
예제 #20
0
 /// <summary>
 /// Sets the key according to the payload length and call id.
 /// </summary>
 /// <param name="keyPayloadLength">(High 2 octets of Key) Size of the payload, not including the GRE header.</param>
 /// <param name="keyCallId">(Low 2 octets of Key) Contains the Peer's Call ID for the session to which this packet belongs.</param>
 public void SetKey(ushort keyPayloadLength, ushort keyCallId)
 {
     Key = BitSequence.Merge(keyPayloadLength, keyCallId);
 }
예제 #21
0
 /// <summary>
 /// Returns a hash code for the layer.
 /// The hash code is a XOR of the hash codes of the layer length, data link, TagControlInformation and the ethernet type.
 /// </summary>
 public override int GetHashCode()
 {
     return(base.GetHashCode() ^
            BitSequence.Merge(TagControlInformation, (ushort)EtherType).GetHashCode());
 }
 public override int GetHashCode()
 {
     return(base.GetHashCode() ^ Sequence.GetHashCode((object)BitSequence.Merge((byte)this.TimestampType, this.Overflow), (object)this.PointedIndex));
 }
 internal int GetHashCodeParameters()
 {
     return(Sequence.GetHashCode((object)BitSequence.Merge(this.Iterations, (byte)this.HashAlgorithm, (byte)this.Flags), (object)this.Salt));
 }
예제 #24
0
 /// <summary>
 /// Xor of the combination of the IsSuppressRouterSideProcessing and QueryRobustnessVariable fields with
 /// the hash codes of the layer length, datalink, message type, query version, group address and all the source addresses.
 /// </summary>
 public override int GetHashCode()
 {
     return(base.GetHashCode() ^
            Sequence.GetHashCode(GroupAddress, BitSequence.Merge(IsSuppressRouterSideProcessing.ToByte(), QueryRobustnessVariable)) ^
            SourceAddresses.SequenceGetHashCode());
 }
 /// <summary>
 /// A hash code of the combination of the type covered, algorithm, labels, original TTL, signature expiration, signature inception, key tag,
 /// signer's name and signature fields
 /// </summary>
 public override int GetHashCode()
 {
     return(Sequence.GetHashCode(BitSequence.Merge((ushort)TypeCovered, (byte)Algorithm, Labels), OriginalTtl, SignatureExpiration, SignatureInception,
                                 KeyTag, SignersName, Signature));
 }
 /// <summary>
 /// A hash code of the combination of the order, preference, flags, services, regular expression and replacement fields.
 /// </summary>
 public override int GetHashCode()
 {
     return(Sequence.GetHashCode(BitSequence.Merge(Order, Preference), Flags, Services, RegularExpression, Replacement));
 }
예제 #27
0
 /// <summary>
 /// Returns a hash code for the layer.
 /// The hash code is a XOR of the combination of the source and destination ports and the hash codes of the layer length, data link and checksum.
 /// </summary>
 public sealed override int GetHashCode()
 {
     return(base.GetHashCode() ^
            Checksum.GetHashCode() ^ BitSequence.Merge(SourcePort, DestinationPort).GetHashCode());
 }
예제 #28
0
 internal int GetHashCodeBase()
 {
     return(Sequence.GetHashCode(DomainName, BitSequence.Merge((ushort)DnsType, (ushort)DnsClass)));
 }
 public override int GetHashCode()
 {
     return(BitSequence.Merge(this.Priority, this.Weight).GetHashCode() ^ IEnumerableExtensions.SequenceGetHashCode <DataSegment>((IEnumerable <DataSegment>) this.Target));
 }
예제 #30
0
 /// <summary>
 /// A hash code of the combination of the certificate type, key tag, algorithm and certificate fields.
 /// </summary>
 public override int GetHashCode()
 {
     return(Sequence.GetHashCode(BitSequence.Merge((ushort)CertificateType, KeyTag), Algorithm, Certificate));
 }