예제 #1
0
        internal static void WriteQueryVersion3(byte[] buffer, int offset, TimeSpan maxResponseTime, IpV4Address groupAddress, bool isSuppressRouterSideProcessing, byte queryRobustnessVariable, TimeSpan queryInterval, IEnumerable <IpV4Address> sourceAddresses)
        {
            ByteArrayExtensions.Write(buffer, offset, (byte)17);
            if (maxResponseTime < TimeSpan.Zero || maxResponseTime > IgmpDatagram.MaxVersion3MaxResponseTime)
            {
                throw new ArgumentOutOfRangeException("maxResponseTime", (object)maxResponseTime, "must be in the range [" + (object)TimeSpan.Zero + ", " + (string)(object)IgmpDatagram.MaxVersion3MaxResponseTime + "]");
            }
            double num1 = maxResponseTime.TotalSeconds * 10.0;
            byte   num2 = num1 < 128.0 ? (byte)num1 : (byte)(double)IgmpDatagram.ValueToCode((int)num1);

            ByteArrayExtensions.Write(buffer, offset + 1, num2);
            ByteArrayExtensions.Write(buffer, offset + 4, groupAddress, Endianity.Big);
            if ((int)queryRobustnessVariable > 7)
            {
                throw new ArgumentOutOfRangeException("queryRobustnessVariable", (object)queryRobustnessVariable, "must be in range [0, 7]");
            }
            ByteArrayExtensions.Write(buffer, offset + 8, (byte)((int)queryRobustnessVariable | (isSuppressRouterSideProcessing ? 8 : 0)));
            if (queryInterval < TimeSpan.Zero || queryInterval > IgmpDatagram.MaxQueryInterval)
            {
                throw new ArgumentOutOfRangeException("queryInterval", (object)maxResponseTime, "must be in the range [" + (object)TimeSpan.Zero + ", " + (string)(object)IgmpDatagram.MaxQueryInterval + "]");
            }
            double totalSeconds = queryInterval.TotalSeconds;
            byte   num3         = totalSeconds < 128.0 ? (byte)totalSeconds : (byte)(double)IgmpDatagram.ValueToCode((int)totalSeconds);

            ByteArrayExtensions.Write(buffer, offset + 9, num3);
            int num4 = 0;

            foreach (IpV4Address ipV4Address in sourceAddresses)
            {
                ByteArrayExtensions.Write(buffer, offset + 12 + 4 * num4, ipV4Address, Endianity.Big);
                ++num4;
            }
            ByteArrayExtensions.Write(buffer, offset + 10, (ushort)num4, Endianity.Big);
            IgmpDatagram.WriteChecksum(buffer, offset, 12 + 4 * num4);
        }
예제 #2
0
        internal static void WriteHeader(byte[] buffer, int offset, IgmpMessageType igmpMessageType, TimeSpan maxResponseTime, IpV4Address groupAddress)
        {
            ByteArrayExtensions.Write(buffer, offset, (byte)igmpMessageType);
            double num = maxResponseTime.TotalSeconds * 10.0;

            if (num >= 256.0 || num < 0.0)
            {
                throw new ArgumentOutOfRangeException("maxResponseTime", (object)maxResponseTime, "must be in the range [" + (object)TimeSpan.Zero + ", " + (string)(object)TimeSpan.FromSeconds(25.5) + "]");
            }
            ByteArrayExtensions.Write(buffer, offset + 1, (byte)num);
            ByteArrayExtensions.Write(buffer, offset + 4, groupAddress, Endianity.Big);
            IgmpDatagram.WriteChecksum(buffer, offset, 8);
        }
예제 #3
0
        internal static void WriteReportVersion3(byte[] buffer, int offset, IEnumerable <IgmpGroupRecord> groupRecords)
        {
            ByteArrayExtensions.Write(buffer, offset, (byte)34);
            ushort num     = (ushort)0;
            int    offset1 = offset + 8;

            foreach (IgmpGroupRecord igmpGroupRecord in groupRecords)
            {
                IgmpGroupRecordDatagram.Write(buffer, ref offset1, igmpGroupRecord.RecordType, igmpGroupRecord.AuxiliaryData, igmpGroupRecord.MulticastAddress, igmpGroupRecord.SourceAddresses);
                ++num;
            }
            ByteArrayExtensions.Write(buffer, offset + 6, num, Endianity.Big);
            IgmpDatagram.WriteChecksum(buffer, offset, offset1 - offset);
        }
예제 #4
0
        protected override bool CalculateIsValid()
        {
            if (this.Length < 8 || !this.IsChecksumCorrect)
            {
                return(false);
            }
            switch (this.MessageType)
            {
            case IgmpMessageType.MembershipQuery:
                switch (this.QueryVersion)
                {
                case IgmpQueryVersion.Version1:
                case IgmpQueryVersion.Version2:
                    return(this.Length == 8);

                case IgmpQueryVersion.Version3:
                    return(this.Length == IgmpDatagram.GetQueryVersion3Length((int)this.NumberOfSources));

                default:
                    return(false);
                }

            case IgmpMessageType.MembershipReportVersion1:
                if (this.Length == 8)
                {
                    return((int)this.MaxResponseCode == 0);
                }
                return(false);

            case IgmpMessageType.MembershipReportVersion2:
            case IgmpMessageType.LeaveGroupVersion2:
                return(this.Length == 8);

            case IgmpMessageType.MembershipReportVersion3:
                if ((int)this.MaxResponseCode == 0 && this.Length == 8 + Enumerable.Sum <IgmpGroupRecordDatagram>((IEnumerable <IgmpGroupRecordDatagram>) this.GroupRecords, (Func <IgmpGroupRecordDatagram, int>)(record => record.Length)))
                {
                    return(Enumerable.All <IgmpGroupRecordDatagram>((IEnumerable <IgmpGroupRecordDatagram>) this.GroupRecords, (Func <IgmpGroupRecordDatagram, bool>)(record => record.IsValid)));
                }
                return(false);

            default:
                return(false);
            }
        }
 protected override void Write(byte[] buffer, int offset)
 {
     IgmpDatagram.WriteReportVersion3(buffer, offset, (IEnumerable <IgmpGroupRecord>) this.GroupRecords);
 }
예제 #6
0
 /// <summary>
 /// Writes the layer to the buffer.
 /// This method ignores the payload length, and the previous and next layers.
 /// </summary>
 /// <param name="buffer">The buffer to write the layer to.</param>
 /// <param name="offset">The offset in the buffer to start writing the layer at.</param>
 protected override void Write(byte[] buffer, int offset)
 {
     IgmpDatagram.WriteQueryVersion3(buffer, offset,
                                     MaxResponseTime, GroupAddress, IsSuppressRouterSideProcessing, QueryRobustnessVariable,
                                     QueryInterval, SourceAddresses);
 }
예제 #7
0
 /// <summary>
 /// Writes the layer to the buffer.
 /// This method ignores the payload length, and the previous and next layers.
 /// </summary>
 /// <param name="buffer">The buffer to write the layer to.</param>
 /// <param name="offset">The offset in the buffer to start writing the layer at.</param>
 protected override void Write(byte[] buffer, int offset)
 {
     IgmpDatagram.WriteReportVersion3(buffer, offset, GroupRecords);
 }
예제 #8
0
 /// <summary>
 /// Writes the layer to the buffer.
 /// This method ignores the payload length, and the previous and next layers.
 /// </summary>
 /// <param name="buffer">The buffer to write the layer to.</param>
 /// <param name="offset">The offset in the buffer to start writing the layer at.</param>
 protected override void Write(byte[] buffer, int offset)
 {
     IgmpDatagram.WriteVersion0Header(buffer, offset, MessageTypeValue, CodeValue, IdentifierValue, GroupAddressValue, AccessKeyValue);
 }
예제 #9
0
 protected override void Write(byte[] buffer, int offset)
 {
     IgmpDatagram.WriteQueryVersion3(buffer, offset, this.MaxResponseTime, this.GroupAddress, this.IsSuppressRouterSideProcessing, this.QueryRobustnessVariable, this.QueryInterval, (IEnumerable <IpV4Address>) this.SourceAddresses);
 }
 /// <summary>
 /// Writes the layer to the buffer.
 /// This method ignores the payload length, and the previous and next layers.
 /// </summary>
 /// <param name="buffer">The buffer to write the layer to.</param>
 /// <param name="offset">The offset in the buffer to start writing the layer at.</param>
 protected sealed override void Write(byte[] buffer, int offset)
 {
     IgmpDatagram.WriteVersion1PlusSimpleHeader(buffer, offset,
                                                MessageTypeValue, MaxResponseTimeValue, GroupAddress);
 }
예제 #11
0
 protected override sealed void Write(byte[] buffer, int offset)
 {
     IgmpDatagram.WriteHeader(buffer, offset, this.MessageType, this.MaxResponseTimeValue, this.GroupAddress);
 }