当前位置: 首页>>代码示例>>C#>>正文


C# XElement.Fields方法代码示例

本文整理汇总了C#中System.Xml.Linq.XElement.Fields方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.Fields方法的具体用法?C# XElement.Fields怎么用?C# XElement.Fields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.Fields方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompareField

        protected override bool CompareField(XElement field, Datagram parentDatagram, Datagram datagram)
        {
            IpDatagram ipDatagram = (IpDatagram)parentDatagram;
            UdpDatagram udpDatagram = (UdpDatagram)datagram;

            switch (field.Name())
            {
                case "udp.srcport":
                    field.AssertShowDecimal(udpDatagram.SourcePort);
                    break;

                case "udp.dstport":
                    field.AssertShowDecimal(udpDatagram.DestinationPort);
                    break;

                case "udp.port":
                    Assert.IsTrue(ushort.Parse(field.Show()) == udpDatagram.SourcePort ||
                                  ushort.Parse(field.Show()) == udpDatagram.DestinationPort);
                    break;

                case "udp.length":
                    field.AssertShowDecimal(udpDatagram.TotalLength);
                    break;

                case "udp.checksum":
                    field.AssertShowDecimal(udpDatagram.Checksum);
                    if (udpDatagram.Checksum != 0)
                    {
                        foreach (var checksumField in field.Fields())
                        {
                            switch (checksumField.Name())
                            {
                                case "udp.checksum_good":
                                    checksumField.AssertShowDecimal(ipDatagram.IsTransportChecksumCorrect);
                                    break;

                                case "udp.checksum_bad":
                                    if (checksumField.Show() == "1")
                                        Assert.IsFalse(ipDatagram.IsTransportChecksumCorrect);
                                    else
                                        checksumField.AssertShowDecimal(0);
                                    break;
                            }
                        }
                    }
                    break;

                case "udp.checksum_coverage":
                    field.AssertShowDecimal(udpDatagram.TotalLength);
                    break;

                case "udp.stream":
                    break;

                default:
                    throw new InvalidOperationException("Invalid udp field " + field.Name());
            }

            return true;
        }
开发者ID:amitla,项目名称:Pcap.Net,代码行数:60,代码来源:WiresharkDatagramComparerUdp.cs

示例2: CompareEthernetAddress

        private static void CompareEthernetAddress(XElement element, MacAddress address)
        {
            foreach (var field in element.Fields())
            {
                switch (field.Name())
                {
                    case "eth.addr":
                    case "eth.dst_resolved":
                    case "eth.addr_resolved":
                    case "eth.src_resolved":
                        field.AssertShow(address.ToString().ToLower());
                        field.AssertNoFields();
                        break;

                    case "eth.ig":
                    case "eth.lg":
                        field.AssertNoFields();
                        break;

                    case "_ws.expert":
                        field.AssertNumFields(4);
                        break;

                    default:
                        throw new InvalidOperationException("Invalid ethernet address field " + field.Name());
                }
            }
        }
开发者ID:JackWangCUMT,项目名称:WiFiSpy,代码行数:28,代码来源:WiresharkDatagramComparerEthernet.cs

示例3: CompareDatagram

        protected void CompareDatagram(XElement layer, Datagram parentDatagram, Datagram datagram)
        {
            foreach (var field in layer.Fields())
            {
                if (!CompareField(field, parentDatagram, datagram))
                    break;
            }

            WiresharkCompareTests.CompareProtocols(datagram, layer);
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:10,代码来源:WiresharkDatagramComparer.cs

示例4: CompareDatagram

        protected bool CompareDatagram(XElement layer, Datagram parentDatagram, Datagram datagram)
        {
            bool success = true;
            foreach (var element in layer.Fields())
            {
                if (!CompareField(element, parentDatagram, datagram))
                {
                    success = false;
                    break;
                }
            }

            WiresharkCompareTests.CompareProtocols(datagram, layer, success);
            return success;
        }
开发者ID:preyea,项目名称:Pcap.Net,代码行数:15,代码来源:WiresharkDatagramComparer.cs

示例5: CompareDatagram

        protected bool CompareDatagram(XElement layer, Datagram parentDatagram, Datagram datagram)
        {
            bool success = true;
            foreach (var element in layer.Fields())
            {
                // TODO: Remove this hack when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=11802 is fixed.
                IpV6Datagram ipV6ParentDatagram = parentDatagram as IpV6Datagram;
                if (ipV6ParentDatagram != null && (ipV6ParentDatagram.NextHeader == IpV4Protocol.IsoIp || ipV6ParentDatagram.ExtensionHeaders.NextHeader == IpV4Protocol.IsoIp))
                    return false;
                if (!CompareField(element, parentDatagram, datagram))
                {
                    success = false;
                    break;
                }
            }

            WiresharkCompareTests.CompareProtocols(datagram, layer, success);
            return success;
        }
开发者ID:yanggis,项目名称:Pcap.Net,代码行数:19,代码来源:WiresharkDatagramComparer.cs

示例6: CompareField

        protected override bool CompareField(XElement field, Datagram datagram)
        {
            GreDatagram greDatagram = (GreDatagram)datagram;
            switch (field.Name())
            {
                case "gre.flags_and_version":
                    XElement[] innerFields = field.Fields().ToArray();
                    MoreAssert.IsInRange(8, 9, innerFields.Length);

                    int currentInnerFieldIndex = 0;
                    innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.ChecksumPresent);
                    innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.RoutingPresent);
                    innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.KeyPresent);
                    innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.SequenceNumberPresent);
                    innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.StrictSourceRoute);
                    innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.RecursionControl);
                    if (innerFields.Length == 9)
                    {
                        innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.AcknowledgmentSequenceNumberPresent);
                        innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.FutureUseBits);
                    }
                    else
                    {
                        byte futureUseBitsValue = (byte)((greDatagram.AcknowledgmentSequenceNumberPresent.ToInt() << 4) | greDatagram.FutureUseBits);
                        innerFields[currentInnerFieldIndex++].AssertShowDecimal(futureUseBitsValue);
                    }
                    innerFields[currentInnerFieldIndex].AssertShowDecimal((byte)greDatagram.Version);
                    break;

                case "data.len":
                    field.AssertShowDecimal(
                        greDatagram.Payload.Length + (greDatagram.AcknowledgmentSequenceNumberPresent &&
                                                      (greDatagram.Version != GreVersion.EnhancedGre || !greDatagram.SequenceNumberPresent)
                                                          ? 4
                                                          : 0), "GRE data.len");
                    field.AssertNoFields();
                    break;

                case "gre.checksum":
                    field.AssertShowDecimal(greDatagram.Checksum);
                    field.AssertNoFields();
                    break;

                case "gre.key.payload_length":
                    field.AssertShowDecimal(greDatagram.KeyPayloadLength);
                    field.AssertNoFields();
                    break;

                case "gre.key.call_id":
                    field.AssertShowDecimal(greDatagram.KeyCallId);
                    field.AssertNoFields();
                    break;

                case "gre.ack_number":
                    field.AssertShowDecimal(greDatagram.AcknowledgmentSequenceNumber);
                    field.AssertNoFields();
                    break;

                case "gre.sequence_number":
                    field.AssertShowDecimal(greDatagram.SequenceNumber);
                    field.AssertNoFields();
                    break;

                case "gre.offset":
                    field.AssertShowDecimal(greDatagram.RoutingOffset);
                    field.AssertNoFields();
                    break;

                case "gre.routing":
                    field.AssertShow("");
                    field.AssertNoFields();
                    break;

                case "gre.routing.address_family":
                    if (_routingEntryIndex == greDatagram.Routing.Count)
                        field.AssertShowDecimal(0);
                    else
                        field.AssertShowDecimal((ushort)greDatagram.Routing[_routingEntryIndex].AddressFamily);
                    field.AssertNoFields();
                    break;

                case "gre.routing.sre_offset":
                    if (_routingEntryIndex == greDatagram.Routing.Count)
                        field.AssertShowDecimal(0);
                    else
                        field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadOffset);
                    field.AssertNoFields();
                    break;

                case "gre.routing.src_length":
                    if (_routingEntryIndex == greDatagram.Routing.Count)
                        field.AssertShowDecimal(0);
                    else
                        field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadLength);
                    field.AssertNoFields();
                    break;

                case "gre.routing.information":
                    if (_routingEntryIndex != greDatagram.Routing.Count)
                    {
//.........这里部分代码省略.........
开发者ID:JackWangCUMT,项目名称:WiFiSpy,代码行数:101,代码来源:WiresharkDatagramComparerGre.cs

示例7: CompareField

        protected override bool CompareField(XElement field, Datagram datagram)
        {
            VLanTaggedFrameDatagram vLanTaggedFrameDatagram = (VLanTaggedFrameDatagram)datagram;
            switch (field.Name())
            {
                case "vlan.priority":
                    field.AssertNoFields();
                    field.AssertShowDecimal((byte)vLanTaggedFrameDatagram.PriorityCodePoint);
                    break;

                case "vlan.cfi":
                    field.AssertNoFields();
                    field.AssertShowDecimal(vLanTaggedFrameDatagram.CanonicalFormatIndicator);
                    break;

                case "vlan.id":
                    field.AssertNoFields();
                    field.AssertShowDecimal(vLanTaggedFrameDatagram.VLanIdentifier);
                    break;

                case "vlan.etype":
                    field.AssertNoFields();
                    field.AssertShowDecimal((ushort)vLanTaggedFrameDatagram.EtherType);
                    break;

                case "vlan.len":
                    field.AssertShowDecimal((ushort)vLanTaggedFrameDatagram.EtherType);
                    if (field.Fields().Any())
                    {
                        field.AssertNumFields(1);
                        field.Fields().First().AssertName("_ws.expert");
                    }
                    break;

                case "vlan.trailer":
                    field.AssertNoFields();
                    if (!new[]
                             {
                                 (EthernetType)1,
                                 (EthernetType)5,
                                 (EthernetType)12,
                                 (EthernetType)17,
                                 (EthernetType)29,
                                 (EthernetType)30,
                                 (EthernetType)43,
                                 (EthernetType)50,
                                 EthernetType.ReverseArp, // TODO: Support RARP
                                 EthernetType.ExtensibleAuthenticationProtocolOverLan, // TODO: Support this protocol.
                             }.Contains(
                                 vLanTaggedFrameDatagram.EtherType))
                    {
                        field.AssertValue(vLanTaggedFrameDatagram.ExtraData);
                    }
                    break;

                case "eth.padding":
                    field.AssertNoFields();
                    if (!new[]
                             {
                                 EthernetType.ExtensibleAuthenticationProtocolOverLan, // TODO: Support this protocol.
                             }.Contains(
                                 vLanTaggedFrameDatagram.EtherType))
                    {
                        field.AssertValue(vLanTaggedFrameDatagram.Trailer);
                    }
                    break;

                default:
                    throw new InvalidOperationException("Invalid VLanTaggedFrame field " + field.Name());
            }

            return true;
        }
开发者ID:yanggis,项目名称:Pcap.Net,代码行数:73,代码来源:WiresharkDatagramComparerVLanTaggedFrame.cs

示例8: CompareField

        protected override bool CompareField(XElement field, Datagram datagram)
        {
            IpV4Datagram ipV4Datagram = (IpV4Datagram)datagram;
            switch (field.Name())
            {
                case "ip.version":
                    field.AssertShowDecimal(ipV4Datagram.Version);
                    field.AssertNoFields();
                    break;

                case "ip.hdr_len":
                    field.AssertShowDecimal(ipV4Datagram.HeaderLength);
                    field.AssertNoFields();
                    break;

                case "ip.dsfield":
                    field.AssertShowDecimal((int)ipV4Datagram.TypeOfService);
                    // TODO: Parse TypeOfService to Differentiated Services and ECN.
                    break;

                case "ip.len":
                    field.AssertShowDecimal(ipV4Datagram.TotalLength);
                    field.AssertNoFields();
                    break;

                case "ip.id":
                    field.AssertShowDecimal(ipV4Datagram.Identification);
                    field.AssertNoFields();
                    break;

                case "ip.flags":
                    field.AssertShowDecimal(((ushort)ipV4Datagram.Fragmentation.Options >> 13));
                    foreach (XElement subfield in field.Fields())
                    {
                        subfield.AssertNoFields();
                        switch (subfield.Name())
                        {
                            case "ip.flags.rb":
                                break;

                            case "ip.flags.df":
                                subfield.AssertShowDecimal((ipV4Datagram.Fragmentation.Options & IpV4FragmentationOptions.DoNotFragment) ==
                                                           IpV4FragmentationOptions.DoNotFragment);
                                break;

                            case "ip.flags.mf":
                                subfield.AssertShowDecimal((ipV4Datagram.Fragmentation.Options & IpV4FragmentationOptions.MoreFragments) ==
                                                           IpV4FragmentationOptions.MoreFragments);
                                break;

                            default:
                                throw new InvalidOperationException(string.Format("Invalid ip flags subfield {0}", subfield.Name()));
                        }
                    }
                    break;

                case "ip.frag_offset":
                    field.AssertShowDecimal(ipV4Datagram.Fragmentation.Offset);
                    field.AssertNoFields();
                    break;

                case "ip.ttl":
                    field.AssertShowDecimal(ipV4Datagram.Ttl);
                    foreach (XElement subfield in field.Fields())
                    {
                        switch (subfield.Name())
                        {
                            case "_ws.expert":
                                break;

                            default:
                                subfield.AssertNoFields();
                                throw new InvalidOperationException(string.Format("Invalid ip subfield {0}", subfield.Name()));
                        }
                    }
                    break;

                case "ip.proto":
                    field.AssertShowDecimal((byte)ipV4Datagram.Protocol);
                    field.AssertNoFields();
                    break;

                case "ip.checksum":
                    field.AssertShowDecimal(ipV4Datagram.HeaderChecksum);
                    if (field.Showname().EndsWith(" [not all data available]"))
                    {
                        Assert.IsFalse(ipV4Datagram.IsValid);
                        break;
                    }
                    foreach (var checksumField in field.Fields())
                    {
                        switch (checksumField.Name())
                        {
                            case "ip.checksum_good":
                                checksumField.AssertNoFields();
                                // TODO: Remove this case when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10579 is fixed.
                                if (field.Showname().EndsWith(" [in ICMP error packet]"))
                                    break;
                                checksumField.AssertShowDecimal(ipV4Datagram.IsHeaderChecksumCorrect);
                                break;
//.........这里部分代码省略.........
开发者ID:amitla,项目名称:Pcap.Net,代码行数:101,代码来源:WiresharkDatagramComparerIpV4.cs

示例9: CompareFrame

        private static void CompareFrame(XElement frame, Packet packet)
        {
            foreach (var field in frame.Fields())
            {
                switch (field.Name())
                {
//                    case "frame.time":
//                        string fieldShow = field.Show();
//                        if (fieldShow == "Not representable")
//                            break;
//                        fieldShow = fieldShow.Substring(0, fieldShow.Length - 2);
//                        DateTime fieldTimestamp = fieldShow[4] == ' '
//                                                      ? DateTime.ParseExact(fieldShow, "MMM  d, yyyy HH:mm:ss.fffffff", CultureInfo.InvariantCulture)
//                                                      : DateTime.ParseExact(fieldShow, "MMM dd, yyyy HH:mm:ss.fffffff", CultureInfo.InvariantCulture);
//                        MoreAssert.IsInRange(fieldTimestamp.AddSeconds(-2), fieldTimestamp.AddSeconds(2), packet.Timestamp, "Timestamp");
//                        break;

                    case "frame.time_epoch":
                        double timeEpoch = double.Parse(field.Show(), CultureInfo.InvariantCulture);
                        DateTime fieldTimestamp = new DateTime(1970, 1, 1).AddSeconds(timeEpoch);
                        MoreAssert.IsInRange(fieldTimestamp.AddMilliseconds(-1), fieldTimestamp.AddMilliseconds(1), packet.Timestamp.ToUniversalTime(), "Timestamp");
                        break;

                    case "frame.cap_len":
                        field.AssertShowDecimal(packet.Length);
                        break;
                }
            }
        }
开发者ID:rokugasenpai,项目名称:Pcap.Net,代码行数:29,代码来源:WiresharkCompareTests.cs

示例10: CompareField

        protected override bool CompareField(XElement field, Datagram datagram)
        {
            IpV4Datagram ipV4Datagram = (IpV4Datagram)datagram;
            switch (field.Name())
            {
                case "ip.version":
                    field.AssertShowDecimal(ipV4Datagram.Version);
                    break;

                case "ip.hdr_len":
                    field.AssertShowDecimal(ipV4Datagram.HeaderLength);
                    break;

                case "ip.dsfield":
                    field.AssertShowDecimal((int)ipV4Datagram.TypeOfService);
                    break;

                case "ip.len":
                    field.AssertShowDecimal(ipV4Datagram.TotalLength);
                    break;

                case "ip.id":
                    field.AssertShowHex(ipV4Datagram.Identification);
                    break;

                case "ip.flags":
                    field.AssertShowHex((byte)((ushort)ipV4Datagram.Fragmentation.Options >> 13));
                    break;

                case "ip.frag_offset":
                    field.AssertShowDecimal(ipV4Datagram.Fragmentation.Offset);
                    break;

                case "ip.ttl":
                    field.AssertShowDecimal(ipV4Datagram.Ttl);
                    break;

                case "ip.proto":
                    field.AssertShowDecimal((byte)ipV4Datagram.Protocol);
                    break;

                case "ip.checksum":
                    field.AssertShowHex(ipV4Datagram.HeaderChecksum);
                    foreach (var checksumField in field.Fields())
                    {
                        switch (checksumField.Name())
                        {
                            case "ip.checksum_good":
                                checksumField.AssertShowDecimal(ipV4Datagram.IsHeaderChecksumCorrect);
                                break;

                            case "ip.checksum_bad":
                                if (ipV4Datagram.Length < IpV4Datagram.HeaderMinimumLength ||
                                    ipV4Datagram.Length < ipV4Datagram.HeaderLength)
                                    break;

                                checksumField.AssertShowDecimal(!ipV4Datagram.IsHeaderChecksumCorrect);
                                break;
                        }
                    }
                    break;

                case "ip.src":
                case "ip.src_host":
                    field.AssertShow(ipV4Datagram.Source.ToString());
                    break;

                case "ip.dst":
                case "ip.dst_host":
                    if (field.Show() != ipV4Datagram.Destination.ToString())
                    {
                        // TODO: Remove this fallback once https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7043 is fixed.
                        field.AssertShow(ipV4Datagram.CurrentDestination.ToString());
                        Assert.IsTrue(ipV4Datagram.Options.IsBadForWireshark(),
                                      string.Format("Expected destination: {0}. Destination: {1}. Current destination: {2}.", field.Show(),
                                                    ipV4Datagram.Destination, ipV4Datagram.CurrentDestination));
                    }
                    break;

                case "ip.addr":
                case "ip.host":
                    Assert.IsTrue(field.Show() == ipV4Datagram.Source.ToString() ||
                                  field.Show() == ipV4Datagram.Destination.ToString() ||
                                  // TODO: Remove this fallback once https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7043 is fixed.
                                  field.Show() == ipV4Datagram.CurrentDestination.ToString() && ipV4Datagram.Options.IsBadForWireshark(),
                                  string.Format("Expected ip: {0}. ", field.Show()) +
                                  (ipV4Datagram.IsValid
                                       ? string.Format("Source: {0}. Destination: {1}. Current destination: {2}.", ipV4Datagram.Source,
                                                       ipV4Datagram.Destination, ipV4Datagram.CurrentDestination)
                                       : ""));
                    break;

                case "":
                    CompareIpV4Options(field, ipV4Datagram.Options);
                    break;

                default:
                    throw new InvalidOperationException("Invalid ip field " + field.Name());
            }

//.........这里部分代码省略.........
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:101,代码来源:WiresharkDatagramComparerIpV4.cs

示例11: CompareIpV4Options

        private static void CompareIpV4Options(XElement element, IpV4Datagram ipV4Datagram, IpV4Options options)
        {
            int currentOptionIndex = 0;
            foreach (var field in element.Fields())
            {
                if (currentOptionIndex >= options.Count)
                {
                    Assert.IsFalse(options.IsValid);
                    Assert.IsTrue(field.Show() == "Commercial IP security option" ||
                                  field.Show() == "Loose source route (length byte past end of options)" ||
                                  field.Show() == "Time stamp:" ||
                                  field.Show().StartsWith("Unknown") ||
                                  field.Show().StartsWith("Security") ||
                                  field.Show().StartsWith("Router Alert (with option length = ") ||
                                  field.Show().StartsWith("Stream ID (with option length = ") ||
                                  field.Show().Contains("with too") ||
                                  field.Show().Contains(" bytes says option goes past end of options") ||
                                  field.Show().Contains("(length byte past end of options)") ||
                                  XElementExtensions.Show(field.Fields().First()).StartsWith("Pointer: ") && XElementExtensions.Show(field.Fields().First()).EndsWith(" (points to middle of address)") ||
                                  field.Fields().Where(value => value.Show() == "(suboption would go past end of option)").Count() != 0, field.Show());
                    break;
                }
                IpV4Option option = options[currentOptionIndex++];

                switch (option.OptionType)
                {
                    case IpV4OptionType.NoOperation:
                    case IpV4OptionType.EndOfOptionList:
                        field.AssertShow(option.OptionType == IpV4OptionType.EndOfOptionList ? "End of Options List (EOL)" : "No Operation (NOP)");
                        foreach (var subfield in field.Fields())
                        {
                            if (HandleCommonOptionSubfield(subfield, option))
                                continue;
                            switch (subfield.Name())
                            {
                                default:
                                    throw new InvalidOperationException("Invalid subfield " + subfield.Name());
                            }
                        }
                        break;

                    case IpV4OptionType.BasicSecurity:
                        field.AssertShow("Security (" + option.Length + " bytes)");
                        var basicSecurity = (IpV4OptionBasicSecurity)option;
                        int basicSecurityFlagsIndex = 0;
                        foreach (var subfield in field.Fields())
                        {
                            if (HandleCommonOptionSubfield(subfield, option))
                                continue;
                            switch (subfield.Name())
                            {
                                case "ip.opt.sec_cl":
                                    subfield.AssertNoFields();
                                    subfield.AssertShowDecimal((byte)basicSecurity.ClassificationLevel);
                                    break;

                                case "ip.opt.sec_prot_auth_flags":
                                    foreach (XElement flagField in subfield.Fields())
                                    {
                                        flagField.AssertNoFields();
                                        switch (flagField.Name())
                                        {
                                            case "ip.opt.sec_prot_auth_genser":
                                                flagField.AssertShowDecimal((basicSecurity.ProtectionAuthorities &
                                                                             IpV4OptionSecurityProtectionAuthorities.Genser) ==
                                                                            IpV4OptionSecurityProtectionAuthorities.Genser);
                                                break;

                                            case "ip.opt.sec_prot_auth_siop_esi":
                                                flagField.AssertShowDecimal((basicSecurity.ProtectionAuthorities &
                                                                             IpV4OptionSecurityProtectionAuthorities.
                                                                                 SingleIntegrationOptionalPlanExtremelySensitiveInformation) ==
                                                                            IpV4OptionSecurityProtectionAuthorities.
                                                                                SingleIntegrationOptionalPlanExtremelySensitiveInformation);
                                                break;

                                            case "ip.opt.sec_prot_auth_sci":
                                                flagField.AssertShowDecimal((basicSecurity.ProtectionAuthorities &
                                                                             IpV4OptionSecurityProtectionAuthorities.SensitiveCompartmentedInformation) ==
                                                                            IpV4OptionSecurityProtectionAuthorities.SensitiveCompartmentedInformation);
                                                break;

                                            case "ip.opt.sec_prot_auth_nsa":
                                                flagField.AssertShowDecimal((basicSecurity.ProtectionAuthorities & IpV4OptionSecurityProtectionAuthorities.Nsa) ==
                                                                            IpV4OptionSecurityProtectionAuthorities.Nsa);
                                                break;

                                            case "ip.opt.sec_prot_auth_doe":
                                                flagField.AssertShowDecimal((basicSecurity.ProtectionAuthorities &
                                                                             IpV4OptionSecurityProtectionAuthorities.DepartmentOfEnergy) ==
                                                                            IpV4OptionSecurityProtectionAuthorities.DepartmentOfEnergy);
                                                break;

                                            case "ip.opt.sec_prot_auth_unassigned":
                                                flagField.AssertShowDecimal(0);
                                                break;

                                            case "ip.opt.sec_prot_auth_fti":
                                                flagField.AssertShowDecimal(basicSecurity.Length - basicSecurityFlagsIndex > 4);
                                                break;
//.........这里部分代码省略.........
开发者ID:amitla,项目名称:Pcap.Net,代码行数:101,代码来源:WiresharkDatagramComparerIpV4.cs

示例12: CompareResourceRecordData

        private void CompareResourceRecordData(XElement dataField, DnsResourceRecord resourceRecord)
        {
            var data = resourceRecord.Data;
            string dataFieldName = dataField.Name();
            string dataFieldShow = dataField.Show();
            string dataFieldShowUntilColon = dataFieldShow.Split(':')[0];
            switch (resourceRecord.DnsType)
            {
                case DnsType.A:
                    switch (dataFieldName)
                    {
                        case "dns.resp.addr":
                            dataField.AssertShow(((DnsResourceDataIpV4)data).Data.ToString());
                            break;

                        default:
                            throw new InvalidOperationException("Invalid DNS data field name " + dataFieldName);
                    }
                    break;

                case DnsType.Ns:
                    dataField.AssertName("dns.resp.ns");
                    dataField.AssertShow(GetWiresharkDomainName(((DnsResourceDataDomainName)data).Data));
                    dataField.AssertNoFields();
                    break;

                case DnsType.Md:            // 3.
                case DnsType.MailForwarder: // 4.
                case DnsType.Mailbox:       // 7.
                case DnsType.MailGroup:     // 8.
                case DnsType.MailRename:    // 9.
                    dataField.AssertName("");
                    dataField.AssertShow("Host: " + GetWiresharkDomainName(((DnsResourceDataDomainName)data).Data));
                    dataField.AssertNoFields();
                    break;

                case DnsType.CName:
                    dataField.AssertName("dns.resp.primaryname");
                    dataField.AssertShow(GetWiresharkDomainName(((DnsResourceDataDomainName)data).Data));
                    dataField.AssertNoFields();
                    break;

                case DnsType.StartOfAuthority:
                    dataField.AssertName("");
                    var soaData = (DnsResourceDataStartOfAuthority)data;
                    switch (dataFieldShowUntilColon)
                    {
                        case "Primary name server":
                            dataField.AssertShow(dataFieldShowUntilColon + ": " + GetWiresharkDomainName(soaData.MainNameServer));
                            break;

                        case "Responsible authority's mailbox":
                            dataField.AssertShow(dataFieldShowUntilColon + ": " + GetWiresharkDomainName(soaData.ResponsibleMailbox));
                            break;

                        case "Serial number":
                            dataField.AssertShow(dataFieldShowUntilColon + ": " + soaData.Serial);
                            break;

                        case "Refresh interval":
                            dataField.AssertValue(soaData.Refresh);
                            break;

                        case "Retry interval":
                            dataField.AssertValue(soaData.Retry);
                            break;

                        case "Expiration limit":
                            dataField.AssertValue(soaData.Expire);
                            break;

                        case "Minimum TTL":
                            dataField.AssertValue(soaData.MinimumTtl);
                            break;

                        default:
                            throw new InvalidOperationException("Invalid DNS data field " + dataFieldShow);
                    }
                    dataField.AssertNoFields();
                    break;
                    
                case DnsType.Wks:
                    dataField.AssertName("");
                    var wksData = (DnsResourceDataWellKnownService)data;
                    switch (dataFieldShowUntilColon)
                    {
                        case "Addr":
                            dataField.AssertShow(dataFieldShowUntilColon + ": " + wksData.Address);
                            break;

                        case "Protocol":
                            dataField.AssertValue((byte)wksData.Protocol);
                            break;

                        case "Bits":
                            while (wksData.Bitmap[_wksBitmapIndex] == 0x00)
                                ++_wksBitmapIndex;
                            dataField.AssertValue(wksData.Bitmap[_wksBitmapIndex++]);
                            break;

//.........这里部分代码省略.........
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:101,代码来源:WiresharkDatagramComparerDns.cs

示例13: CompareField


//.........这里部分代码省略.........
                            protocol == IpV4Protocol.IntermediateSystemToIntermediateSystemOverIpV4 ||
                            protocol == IpV4Protocol.ComputerProtocolNetworkExecutive ||
                            protocol == IpV4Protocol.EncapsulationHeader ||
                            protocol == IpV4Protocol.GatewayToGateway ||
                            protocol == IpV4Protocol.SatMon ||
                            protocol == IpV4Protocol.VersatileMessageTransactionProtocol ||
                            protocol == IpV4Protocol.ReliableDatagramProtocol ||
                            protocol == IpV4Protocol.InternetReliableTransactionProtocol ||
                            protocol == IpV4Protocol.MeritInternodalProtocol ||
                            protocol == IpV4Protocol.Skip ||
                            protocol == IpV4Protocol.BurroughsNetworkArchitecture ||
                            protocol == IpV4Protocol.InterDomainRoutingProtocol ||
                            protocol == IpV4Protocol.ActiveNetworks ||
                            protocol == IpV4Protocol.SpectraLinkRadioProtocol ||
                            protocol == IpV4Protocol.MobileAdHocNetwork ||
                            protocol == IpV4Protocol.DissimilarGatewayProtocol ||
                            protocol == IpV4Protocol.SpriteRpc ||
                            protocol == IpV4Protocol.CombatRadioUserDatagram ||
                            protocol == IpV4Protocol.Gmtp ||
                            protocol == IpV4Protocol.MobileHostRoutingProtocol ||
                            protocol == IpV4Protocol.Shim6 ||  // TODO: Implement Shim6.
                            protocol == IpV4Protocol.RemoteVirtualDiskProtocol))
                return false;

            int currentExtensionHeaderIndex = ipV6Datagram.ExtensionHeaders.TakeWhile(extensionHeader => extensionHeader.Protocol != IpV4Protocol.MobilityHeader).Count();
            if (currentExtensionHeaderIndex >= ipV6Datagram.ExtensionHeaders.Headers.Count && !ipV6Datagram.IsValid)
                return false;
            IpV6ExtensionHeaderMobility mobilityHeader = (IpV6ExtensionHeaderMobility)ipV6Datagram.ExtensionHeaders[currentExtensionHeaderIndex];

            switch (field.Name())
            {
                case "mip6.proto":
                    field.AssertShowDecimal((byte)mobilityHeader.NextHeader);
                    field.AssertNoFields();
                    break;

                case "mip6.hlen":
                    if (mobilityHeader.IsValid)
                        field.AssertShowDecimal(mobilityHeader.Length / 8 - 1);
                    field.AssertNoFields();
                    break;

                case "mip6.mhtype":
                    field.AssertShowDecimal((byte)mobilityHeader.MobilityHeaderType);
                    break;

                case "mip6.reserved":
                    field.AssertShowDecimal(0);
                    field.AssertNoFields();
                    break;

                case "mip6.csum":
                    field.AssertShowDecimal(mobilityHeader.Checksum);
                    break;

                case "mip6.em.data":
                    IpV6ExtensionHeaderMobilityExperimental experimentalHeader = (IpV6ExtensionHeaderMobilityExperimental)mobilityHeader;
                    field.AssertValue(experimentalHeader.MessageData);
                    break;

                case "":
                    switch (field.Show())
                    {
                        case "Binding Refresh Request":
                            Assert.AreEqual(IpV6MobilityHeaderType.BindingRefreshRequest, mobilityHeader.MobilityHeaderType);
                            field.AssertNoFields();
开发者ID:yanggis,项目名称:Pcap.Net,代码行数:67,代码来源:WiresharkDatagramComparerIpV6MobilityHeader.cs

示例14: CompareTcpOptions

        private static void CompareTcpOptions(XElement element, TcpOptions options)
        {
            int currentOptionIndex = 0;
            foreach (var field in element.Fields())
            {
                if (field.Name() == "_ws.expert")
                    continue;
                if (currentOptionIndex >= options.Count)
                {
                    Assert.IsFalse(options.IsValid, "Options IsValid");
                    Assert.IsTrue(
                        field.Show().StartsWith("Unknown (0x09) ") || // Unknown in Wireshark but known (and invalid) in Pcap.Net.
                        field.Show().StartsWith("Unknown (0x0a) ") || // Unknown in Wireshark but known (and invalid) in Pcap.Net.
                        field.Show().StartsWith("Unknown (0x19) ") || // Unknown in Wireshark but known (and invalid) in Pcap.Net.
                        field.Show().StartsWith("Unknown (0x2d) ") || // Unknown in Wireshark and unknown and invalid in Pcap.Net.
                        field.Show().StartsWith("Unknown (0xa9) ") || // Unknown in Wireshark and unknown and invalid in Pcap.Net.
                        field.Show().StartsWith("Echo reply (with option length = ") ||
                        field.Show().Contains("bytes says option goes past end of options") ||
                        field.Show().Contains(") (with too-short option length = ") ||
                        field.Show().EndsWith(" (length byte past end of options)"),
                        "Options show: " + field.Show());
                    Assert.AreEqual(options.Count, currentOptionIndex, "Options Count");
                    return;
                }

                TcpOption option = options[currentOptionIndex];
                switch (field.Name())
                {
                    case "":
                        switch (option.OptionType)
                        {
                            case TcpOptionType.WindowScale:
                                TcpOptionWindowScale windowScale = (TcpOptionWindowScale)option;
                                byte scaleFactorLog = windowScale.ScaleFactorLog;
                                field.AssertShow(string.Format("Window scale: {0} (multiply by {1})", scaleFactorLog, (1L << (scaleFactorLog % 32))));
                                foreach (var subField in field.Fields())
                                {
                                    if (HandleOptionCommonFields(subField, option))
                                        continue;
                                    switch (subField.Name())
                                    {
                                        case "tcp.options.wscale.shift":
                                            subField.AssertShowDecimal(windowScale.ScaleFactorLog);
                                            break;

                                        case "tcp.options.wscale.multiplier":
                                            subField.AssertShowDecimal(1L << (windowScale.ScaleFactorLog % 32));
                                            break;

                                        default:
                                            throw new InvalidOperationException("Invalid tcp option subfield " + subField.Name());
                                    }
                                }
                                break;

                            case TcpOptionType.SelectiveAcknowledgment:
                                var selectiveAcknowledgmentOption = (TcpOptionSelectiveAcknowledgment)option;
                                IEnumerable<TcpOptionSelectiveAcknowledgmentBlock> blocks = selectiveAcknowledgmentOption.Blocks;
                                field.AssertShow("SACK:" + (blocks.Count() == 0
                                                                ? string.Empty
                                                                : ((TcpOptionSelectiveAcknowledgment)option).Blocks.SequenceToString(" ", " ")));
                                int blockIndex = 0;
                                foreach (var subField in field.Fields())
                                {
                                    if (HandleOptionCommonFields(subField, option))
                                        continue;
                                    subField.AssertNoFields();
                                    switch (subField.Name())
                                    {
                                        case "tcp.options.sack":
                                            subField.AssertShowDecimal(true);
                                            break;

                                        case "tcp.options.sack_le":
                                            subField.AssertShowDecimal(selectiveAcknowledgmentOption.Blocks[blockIndex].LeftEdge);
                                            break;

                                        case "tcp.options.sack_re":
                                            subField.AssertShowDecimal(selectiveAcknowledgmentOption.Blocks[blockIndex].RightEdge);
                                            ++blockIndex;
                                            break;

                                        case "tcp.options.sack.count":
                                            subField.AssertShowDecimal(selectiveAcknowledgmentOption.Blocks.Count);
                                            break;

                                        default:
                                            throw new InvalidOperationException("Invalid tcp option subfield " + subField.Name());
                                    }
                                }
                                break;

                            case TcpOptionType.Timestamp:
                                var timestampOption = (TcpOptionTimestamp)option;
                                field.AssertShow("Timestamps: TSval " + timestampOption.TimestampValue + ", TSecr " + timestampOption.TimestampEchoReply);
                                foreach (var subField in field.Fields())
                                {
                                    if (HandleOptionCommonFields(subField, option))
                                        continue;
                                    subField.AssertNoFields();
//.........这里部分代码省略.........
开发者ID:amitla,项目名称:Pcap.Net,代码行数:101,代码来源:WiresharkDatagramComparerTcp.cs

示例15: CompareOptions

        private void CompareOptions(XElement field, ref int optionsIndex, IpV6Datagram ipV6Datagram, IpV6ExtensionHeaderOptions header)
        {
            foreach (var headerField in field.Fields())
            {
                switch (headerField.Name())
                {
                    case "ipv6.nxt":
                        headerField.AssertNoFields();
                        headerField.AssertShowDecimal((byte)header.NextHeader);
                        break;

                    case "ipv6.opt.length":
                        headerField.AssertNoFields();
                        headerField.AssertShowDecimal((header.Length - 8) / 8);
                        break;

                    case "ipv6.opt":
                        foreach (XElement headerSubfield in headerField.Fields())
                        {
                            IpV6Option option = header.Options[optionsIndex];
                            var optionCalipso = option as IpV6OptionCalipso;
                            var optionQuickStart = option as IpV6OptionQuickStart;
                            switch (headerSubfield.Name())
                            {
                                case "ipv6.opt.type":
                                    headerSubfield.AssertNoFields();
                                    headerSubfield.AssertShowDecimal((byte)option.OptionType);
                                    break;

                                case "ipv6.opt.length":
                                    headerSubfield.AssertNoFields();
                                    headerSubfield.AssertShowDecimal(option.Length - 2);
                                    break;

                                case "ipv6.opt.tel":
                                    headerSubfield.AssertNoFields();
                                    IpV6OptionTunnelEncapsulationLimit optionTunnelEncapsulationLimit = (IpV6OptionTunnelEncapsulationLimit)option;
                                    headerSubfield.AssertShowDecimal(optionTunnelEncapsulationLimit.TunnelEncapsulationLimit);
                                    ++optionsIndex;
                                    break;

                                case "ipv6.opt.rpl.flag":
                                    IpV6OptionRoutingProtocolLowPowerAndLossyNetworks optionRoutingProtocolLowPowerAndLossyNetworks =
                                        (IpV6OptionRoutingProtocolLowPowerAndLossyNetworks)option;
                                    foreach (XElement optionSubfield in headerSubfield.Fields())
                                    {
                                        optionSubfield.AssertNoFields();
                                        switch (optionSubfield.Name())
                                        {
                                            case "ipv6.opt.rpl.flag.o":
                                                optionSubfield.AssertShowDecimal(optionRoutingProtocolLowPowerAndLossyNetworks.Down);
                                                break;

                                            case "ipv6.opt.rpl.flag.r":
                                                optionSubfield.AssertShowDecimal(optionRoutingProtocolLowPowerAndLossyNetworks.RankError);
                                                break;

                                            case "ipv6.opt.rpl.flag.f":
                                                optionSubfield.AssertShowDecimal(optionRoutingProtocolLowPowerAndLossyNetworks.ForwardingError);
                                                break;

                                            case "ipv6.opt.rpl.flag.rsv":
                                                optionSubfield.AssertShowDecimal(0);
                                                break;

                                            case "ipv6.opt.rpl.instance_id":
                                                optionSubfield.AssertShowDecimal(
                                                    optionRoutingProtocolLowPowerAndLossyNetworks.RoutingProtocolLowPowerAndLossyNetworksInstanceId);
                                                break;

                                            case "ipv6.opt.rpl.sender_rank":
                                                optionSubfield.AssertShowDecimal(optionRoutingProtocolLowPowerAndLossyNetworks.SenderRank);
                                                break;

                                            default:
                                                throw new InvalidOperationException("Invalid ipv6 option subfield " + optionSubfield.Name());
                                        }
                                    }
                                    ++optionsIndex;
                                    // TODO: change to break; after https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10559 is fixed.
                                    return;

                                case "ipv6.opt.calipso.doi":
                                    headerSubfield.AssertNoFields();
                                    headerSubfield.AssertShowDecimal((uint)optionCalipso.DomainOfInterpretation);
                                    break;

                                case "ipv6.opt.calipso.cmpt.length":
                                    headerSubfield.AssertNoFields();
                                    headerSubfield.AssertShowDecimal(optionCalipso.CompartmentLength);
                                    break;

                                case "ipv6.opt.calipso.sens_level":
                                    headerSubfield.AssertNoFields();
                                    headerSubfield.AssertShowDecimal(optionCalipso.SensitivityLevel);
                                    break;

                                case "ipv6.opt.calipso.checksum":
                                    headerSubfield.AssertNoFields();
                                    headerSubfield.AssertShowDecimal(optionCalipso.Checksum);
//.........这里部分代码省略.........
开发者ID:JackWangCUMT,项目名称:WiFiSpy,代码行数:101,代码来源:WiresharkDatagramComparerIpV6.cs


注:本文中的System.Xml.Linq.XElement.Fields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。