Esempio n. 1
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var buffer = new StringBuilder();

            buffer.Append(base.ToString(outputFormat));
            return(buffer.ToString());
        }
Esempio n. 2
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override String ToString(StringOutputType outputFormat)
        {
            var buffer = new StringBuilder();
            var color  = "";


            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color = Color;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[GREPacket: Type={1}",
                                    color,
                                    Protocol);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                var unused = new Dictionary <String, String>
                {
                    { "Protocol ", Protocol + " (0x" + Protocol.ToString("x") + ")" }
                };
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 3
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override String ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            String color       = "";
            String colorEscape = "";


            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = this.Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[GREPacket: Type={2}",
                                    color,
                                    colorEscape, this.Protocol);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary <String, String> properties = new Dictionary <String, String>();
                properties.Add("Protocol ", this.Protocol + " (0x" + this.Protocol.ToString("x") + ")");
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 4
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var buffer      = new StringBuilder();
            var color       = "";
            var colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = this.Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[IPv6Packet: SourceAddress={2}, DestinationAddress={3}, NextHeader={4}]{1}", color, colorEscape, this.SourceAddress, this.DestinationAddress,
                                    this.NextHeader);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                var properties = new Dictionary <string, string>();
                var ipVersion  = Convert.ToString((int)this.Version, 2).PadLeft(4, '0');
                properties.Add("version", ipVersion + " .... .... .... .... .... .... .... = " + (int)this.Version);
                var trafficClass = Convert.ToString(this.TrafficClass, 2).PadLeft(8, '0').Insert(4, " ");
                properties.Add("traffic class", ".... " + trafficClass + " .... .... .... .... .... = 0x" + this.TrafficClass.ToString("x").PadLeft(8, '0'));
                var flowLabel = Convert.ToString(this.FlowLabel, 2).PadLeft(20, '0').Insert(16, " ").Insert(12, " ").Insert(8, " ").Insert(4, " ");
                properties.Add("flow label", ".... .... .... " + flowLabel + " = 0x" + this.FlowLabel.ToString("x").PadLeft(8, '0'));
                properties.Add("payload length", this.PayloadLength.ToString());
                properties.Add("next header", this.NextHeader + " (0x" + this.NextHeader.ToString("x") + ")");
                properties.Add("hop limit", this.HopLimit.ToString());
                properties.Add("source", this.SourceAddress.ToString());
                properties.Add("destination", this.DestinationAddress.ToString());

                // calculate the padding needed to right-justify the property names
                var padLength = RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("IP:  ******* IP - \"Internet Protocol (Version 6)\" - offset=? length=" + this.TotalPacketLength);
                buffer.AppendLine("IP:");
                foreach (var property in properties)
                {
                    if (property.Key.Trim() != "")
                    {
                        buffer.AppendLine("IP: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                    }
                    else
                    {
                        buffer.AppendLine("IP: " + property.Key.PadLeft(padLength) + "   " + property.Value);
                    }
                }
                buffer.AppendLine("IP");
            }

            // append the base class output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 5
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override String ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            String color       = "";
            String colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = this.Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }
            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[DrdaDDMPacket: Length={2}, Magic=0x{3:x2}, Format=0x{4:x2}, CorrelId={5}, Length2={6}, CodePoint={7}]{1}",
                                    color,
                                    colorEscape, this.Length, this.Magic, this.Format, this.CorrelId, this.Length2, this.CodePoint);
                buffer.Append(" Paramters:{");
                foreach (var paramter in this.Parameters)
                {
                    buffer.AppendFormat("{0}[DrdaDDMParameter: Length={2}, CodePoint={3}, Data='{4}']{1}",
                                        color,
                                        colorEscape,
                                        paramter.Length,
                                        paramter.DrdaCodepoint,
                                        paramter.Data);
                }
                buffer.Append("}");
            }

            return(buffer.ToString());
        }
Esempio n. 6
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override String ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            String color       = "";
            String colorEscape = "";


            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[L2TPPacket",
                                    color,
                                    colorEscape);
            }


            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 7
0
        public override String ToString(StringOutputType outputFormat)
        {
            var buffer = new StringBuilder();

            buffer.Append("[MyEthernetPacket]");
            buffer.Append(base.ToString(outputFormat));
            return(buffer.ToString());
        }
Esempio n. 8
0
 /// <summary cref="Packet.ToString()">
 /// Output the packet information in the specified format
 /// Normal - outputs the packet info to a single line
 /// Colored - outputs the packet info to a single line with coloring
 /// Verbose - outputs detailed info about the packet
 /// VerboseColored - outputs detailed info about the packet with coloring
 /// </summary>
 /// <param name="outputFormat">
 ///     <see cref="T:PacketDotNet.StringOutputType" />
 /// </param>
 public virtual string ToString(StringOutputType outputFormat)
 {
     if (this.payloadPacketOrData.Type == PayloadType.Packet)
     {
         return(this.payloadPacketOrData.ThePacket.ToString(outputFormat));
     }
     return(string.Empty);
 }
Esempio n. 9
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var buffer      = new StringBuilder();
            var color       = "";
            var colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = this.Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[PPPoEPacket: Version={2}, Type={3}, Code={4}, SessionId={5}, Length={6}]{1}", color, colorEscape, this.Version, this.Type, this.Code,
                                    this.SessionId, this.Length);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                var properties = new Dictionary <string, string>();
                // FIXME: The version output is incorrect
                properties.Add("", Convert.ToString(this.Version, 2).PadLeft(4, '0') + " .... = version: " + this.Version);
                properties.Add(" ", ".... " + Convert.ToString(this.Type, 2).PadLeft(4, '0') + " = type: " + this.Type);
                // FIXME: The Code output is incorrect
                properties.Add("code", this.Code + " (0x" + this.Code.ToString("x") + ")");
                properties.Add("session id", "0x" + this.SessionId.ToString("x"));
                // TODO: Implement a PayloadLength property for PPPoE
                //properties.Add("payload length", PayloadLength.ToString());

                // calculate the padding needed to right-justify the property names
                var padLength = RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("PPPoE:  ******* PPPoE - \"Point-to-Point Protocol over Ethernet\" - offset=? length=" + this.TotalPacketLength);
                buffer.AppendLine("PPPoE:");
                foreach (var property in properties)
                {
                    if (property.Key.Trim() != "")
                    {
                        buffer.AppendLine("PPPoE: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                    }
                    else
                    {
                        buffer.AppendLine("PPPoE: " + property.Key.PadLeft(padLength) + "   " + property.Value);
                    }
                }
                buffer.AppendLine("PPPoE:");
            }

            // append the base output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 10
0
            /// <summary cref="Packet.ToString(StringOutputType)" />
            public override string ToString(StringOutputType outputFormat)
            {
                var    buffer      = new StringBuilder();
                string color       = "";
                string colorEscape = "";

                if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
                {
                    color       = Color;
                    colorEscape = AnsiEscapeSequences.Reset;
                }

                if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
                {
                    // build the output string
                    buffer.AppendFormat("{0}[Ieee80211RadioPacket: Version={2}, Length={3}, Present[0]=0x{4:x}]{1}",
                                        color,
                                        colorEscape,
                                        Version,
                                        Length,
                                        Present[0]);
                }

                if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
                {
                    // collect the properties and their value
                    Dictionary <string, string> properties = new Dictionary <string, string>();
                    properties.Add("version", Version.ToString());
                    properties.Add("length", Length.ToString());
                    properties.Add("present", " (0x" + Present[0].ToString("x") + ")");

                    var radioTapFields = this.RadioTapFields;

                    foreach (var r in radioTapFields)
                    {
                        properties.Add(r.Value.FieldType.ToString(),
                                       r.Value.ToString());
                    }

                    // calculate the padding needed to right-justify the property names
                    int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                    // build the output string
                    buffer.AppendLine("Ieee80211RadioPacket");
                    foreach (var property in properties)
                    {
                        buffer.AppendLine("TAP: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                    }
                    buffer.AppendLine("TAP:");
                }

                // append the base output
                buffer.Append(base.ToString(outputFormat));

                return(buffer.ToString());
            }
Esempio n. 11
0
 private void OutputPacket(Packet p, StringOutputType outputType)
 {
     Console.WriteLine(currentPacketDescription + " - " + outputType);
     Console.Write(p.ToString(outputType));
     if (outputType == StringOutputType.Verbose || outputType == StringOutputType.VerboseColored)
     {
         Console.Write(p.PrintHex());
     }
     Console.WriteLine();
 }
Esempio n. 12
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            string color       = "";
            string colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[ARPPacket: Operation={2}, SenderHardwareAddress={3}, TargetHardwareAddress={4}, SenderProtocolAddress={5}, TargetProtocolAddress={6}]{1}",
                                    color,
                                    colorEscape,
                                    Operation,
                                    HexPrinter.PrintMACAddress(SenderHardwareAddress),
                                    HexPrinter.PrintMACAddress(TargetHardwareAddress),
                                    SenderProtocolAddress,
                                    TargetProtocolAddress);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("hardware type", HardwareAddressType.ToString() + " (0x" + HardwareAddressType.ToString("x") + ")");
                properties.Add("protocol type", ProtocolAddressType.ToString() + " (0x" + ProtocolAddressType.ToString("x") + ")");
                properties.Add("operation", Operation.ToString() + " (0x" + Operation.ToString("x") + ")");
                properties.Add("source hardware address", HexPrinter.PrintMACAddress(SenderHardwareAddress));
                properties.Add("destination hardware address", HexPrinter.PrintMACAddress(TargetHardwareAddress));
                properties.Add("source protocol address", SenderProtocolAddress.ToString());
                properties.Add("destination protocol address", TargetProtocolAddress.ToString());

                // calculate the padding needed to right-justify the property names
                int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("ARP:  ******* ARP - \"Address Resolution Protocol\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("ARP:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("ARP: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }
                buffer.AppendLine("ARP:");
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 13
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            string color       = "";
            string colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("[{0}LinuxSLLPacket{1}: Type={2}, LinkLayerAddressType={3}, LinkLayerAddressLength={4}, Source={5}, ProtocolType={6}]",
                                    color,
                                    colorEscape,
                                    Type,
                                    LinkLayerAddressType,
                                    LinkLayerAddressLength,
                                    BitConverter.ToString(LinkLayerAddress, 0),
                                    EthernetProtocolType);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("type", Type.ToString() + " (" + ((int)Type).ToString() + ")");
                properties.Add("link layer address type", LinkLayerAddressType.ToString());
                properties.Add("link layer address length", LinkLayerAddressLength.ToString());
                properties.Add("source", BitConverter.ToString(LinkLayerAddress));
                properties.Add("protocol", EthernetProtocolType.ToString() + " (0x" + EthernetProtocolType.ToString("x") + ")");


                // calculate the padding needed to right-justify the property names
                int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("LCC:  ******* LinuxSLL - \"Linux Cooked Capture\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("LCC:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("LCC: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }
                buffer.AppendLine("LCC:");
            }

            // append the base output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 14
0
 public void SetStringOutput(StringOutputType outputType)
 {
     this._callbacks[0] = Marshal.GetFunctionPointerForDelegate(((InteropOutputType)((jt, type, output) => {
         string o = null;
         if (null != output && IntPtr.Zero != output)
         {
             byte[] bo = this.BytesFromPtr(output);
             o = Encoding.UTF8.GetString(bo);
         }
         outputType(type, o);
     })));
 }
Esempio n. 15
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            string color       = "";
            string colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the string of tlvs
                string tlvs = "{";
                var    r    = new Regex(@"[^(\.)]([^\.]*)$");
                foreach (TLV tlv in TlvCollection)
                {
                    // regex trim the parent namespaces from the class type
                    //   (ex. "PacketDotNet.LLDP.TimeToLive" becomes "TimeToLive")
                    var m = r.Match(tlv.GetType().ToString());
                    tlvs += m.Groups[0].Value + "|";
                }
                tlvs  = tlvs.TrimEnd('|');
                tlvs += "}";

                // build the output string
                buffer.AppendFormat("{0}[LLDPPacket: TLVs={2}]{1}",
                                    color,
                                    colorEscape,
                                    tlvs);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // build the output string
                buffer.AppendLine("LLDP:  ******* LLDP - \"Link Layer Discovery Protocol\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("LLDP:");
                foreach (var tlv in TlvCollection)
                {
                    buffer.AppendLine("LLDP:" + tlv.ToString());
                }
                buffer.AppendLine("LLDP:");
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            string color       = "";
            string colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[IGMPv2Packet: Type={2}, MaxResponseTime={3}, GroupAddress={4}]{1}",
                                    color,
                                    colorEscape,
                                    Type,
                                    String.Format("{0:0.0}", (MaxResponseTime / 10)),
                                    GroupAddress);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("type", Type + " (0x" + Type.ToString("x") + ")");
                properties.Add("max response time", String.Format("{0:0.0}", MaxResponseTime / 10) + " sec (0x" + MaxResponseTime.ToString("x") + ")");
                // TODO: Implement checksum validation for IGMPv2
                properties.Add("header checksum", "0x" + Checksum.ToString("x"));
                properties.Add("group address", GroupAddress.ToString());

                // calculate the padding needed to right-justify the property names
                int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("IGMP:  ******* IGMPv2 - \"Internet Group Management Protocol (Version 2)\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("IGMP:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("IGMP: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }
                buffer.AppendLine("IGMP:");
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 17
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            string color       = "";
            string colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[ICMPPacket: Type={2}, Code={3}]{1}",
                                    color,
                                    colorEscape,
                                    Type,
                                    Code);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("type", Type.ToString() + " (" + (int)Type + ")");
                properties.Add("code", Code.ToString());
                // TODO: Implement a checksum verification for ICMPv6
                properties.Add("checksum", "0x" + Checksum.ToString("x"));
                // TODO: Implement ICMPv6 Option fields here?

                // calculate the padding needed to right-justify the property names
                int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("ICMP:  ******* ICMPv6 - \"Internet Control Message Protocol (Version 6)\"- offset=? length=" + TotalPacketLength);
                buffer.AppendLine("ICMP:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("ICMP: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }
                buffer.AppendLine("ICMP:");
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 18
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            string color       = "";
            string colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[Ieee8021QPacket: PriorityControlPoint={2}, CanonicalFormatIndicator={3}, Type={4}]{1}",
                                    color,
                                    colorEscape,
                                    PriorityControlPoint,
                                    CanonicalFormatIndicator,
                                    Type);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("priority", PriorityControlPoint + " (0x" + PriorityControlPoint.ToString("x") + ")");
                properties.Add("canonical format indicator", CanonicalFormatIndicator.ToString());
                properties.Add("type", Type.ToString() + " (0x" + Type.ToString("x") + ")");
                properties.Add("VLANIdentifier", VLANIdentifier.ToString() + " (0x" + VLANIdentifier.ToString("x") + ")");

                // calculate the padding needed to right-justify the property names
                int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("Ieee802.1Q:  ******* Ieee802.1Q - \"VLan tag\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("Ieee802.1Q:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("Ieee802.1Q: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }
                buffer.AppendLine("Ieee802.1Q:");
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 19
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            string color       = "";
            string colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[EthernetPacket: SourceHwAddress={2}, DestinationHwAddress={3}, Type={4}]{1}",
                                    color,
                                    colorEscape,
                                    HexPrinter.PrintMACAddress(SourceHwAddress),
                                    HexPrinter.PrintMACAddress(DestinationHwAddress),
                                    Type.ToString());
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("destination", HexPrinter.PrintMACAddress(DestinationHwAddress));
                properties.Add("source", HexPrinter.PrintMACAddress(SourceHwAddress));
                properties.Add("type", Type.ToString() + " (0x" + Type.ToString("x") + ")");

                // calculate the padding needed to right-justify the property names
                int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("Eth:  ******* Ethernet - \"Ethernet\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("Eth:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("Eth: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }
                buffer.AppendLine("Eth:");
            }

            // append the base output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 20
0
            /// <summary cref="Packet.ToString(StringOutputType)" />
            public override string ToString(StringOutputType outputFormat)
            {
                var buffer      = new StringBuilder();
                var color       = "";
                var colorEscape = "";

                if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
                {
                    color       = this.Color;
                    colorEscape = AnsiEscapeSequences.Reset;
                }

                if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
                {
                    // build the output string
                    buffer.AppendFormat("{0}[Ieee80211PpiPacket: Version={2}, Length={3}, {1}", color, colorEscape, this.Version, this.Length);
                }

                if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
                {
                    // collect the properties and their value
                    var properties = new Dictionary <string, string>();
                    properties.Add("version", this.Version.ToString());
                    properties.Add("length", this.Length.ToString());

                    var ppiField = this.PpiFields;

                    foreach (var r in ppiField)
                    {
                        properties.Add(r.FieldType.ToString(), r.ToString());
                    }

                    // calculate the padding needed to right-justify the property names
                    var padLength = RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                    // build the output string
                    buffer.AppendLine("Ieee80211PpiPacket");
                    foreach (var property in properties)
                    {
                        buffer.AppendLine("PPI: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                    }
                    buffer.AppendLine("PPI:");
                }

                // append the base output
                buffer.Append(base.ToString(outputFormat));

                return(buffer.ToString());
            }
Esempio n. 21
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var buffer      = new StringBuilder();
            var color       = "";
            var colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[RawPacket: Protocol={2}]{1}",
                                    color,
                                    colorEscape,
                                    Protocol);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                var properties = new Dictionary <string, string>
                {
                    { "protocol", Protocol + " (0x" + Protocol.ToString("x") + ")" }
                };

                // calculate the padding needed to right-justify the property names
                var padLength = RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("Raw:  ******* Raw - \"Raw IP Packet\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("Raw:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("Raw: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }

                buffer.AppendLine("Raw:");
            }

            // append the base output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 22
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            string color       = "";
            string colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                buffer.AppendFormat("{0}[UDPPacket: SourcePort={2}, DestinationPort={3}]{1}",
                                    color,
                                    colorEscape,
                                    SourcePort,
                                    DestinationPort);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("source", SourcePort.ToString());
                properties.Add("destination", DestinationPort.ToString());
                properties.Add("length", Length.ToString());
                properties.Add("checksum", "0x" + Checksum.ToString("x") + " [" + (ValidUDPChecksum ? "valid" : "invalid") + "]");

                // calculate the padding needed to right-justify the property names
                int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("UDP:  ******* UDP - \"User Datagram Protocol\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("UDP:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("UDP: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }
                buffer.AppendLine("UDP:");
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 23
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var buffer      = new StringBuilder();
            var color       = "";
            var colorEscape = "";

            if ((outputFormat == StringOutputType.Colored) || (outputFormat == StringOutputType.VerboseColored))
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if ((outputFormat == StringOutputType.Normal) || (outputFormat == StringOutputType.Colored))
            {
                buffer.AppendFormat("[{0}WakeOnLanPacket{1}: DestinationAddress={2}]",
                                    color,
                                    colorEscape,
                                    DestinationAddress);
            }

            if ((outputFormat == StringOutputType.Verbose) || (outputFormat == StringOutputType.VerboseColored))
            {
                // collect the properties and their value
                var properties = new Dictionary <string, string>
                {
                    { "destination", HexPrinter.PrintMACAddress(DestinationAddress) }
                };

                // calculate the padding needed to right-justify the property names
                var padLength = RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("WOL:  ******* WOL - \"Wake-On-Lan\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("WOL:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("WOL: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }

                buffer.AppendLine("WOL:");
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
        public override string ToString(StringOutputType outputFormat)
        {
            StringBuilder stringBuilder = new StringBuilder();
            string        str1          = "";
            string        str2          = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                str1 = this.Color;
                str2 = AnsiEscapeSequences.Reset;
            }
            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                stringBuilder.AppendFormat("{0}[SctpUnsupportedChunk: Type={2}, Flags={3}, Length={4}, TSN={5}]{1}", (object)str1, (object)str2, (object)this.Type, (object)this.Flags.ToString("X2"), (object)this.Length, (object)this.TransmissionSequenceNumber);
            }
            return(stringBuilder.ToString());
        }
Esempio n. 25
0
        public override string ToString(StringOutputType outputFormat)
        {
            StringBuilder stringBuilder = new StringBuilder();
            string        str1          = "";
            string        str2          = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                str1 = this.Color;
                str2 = AnsiEscapeSequences.Reset;
            }
            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                stringBuilder.AppendFormat("{0}[SctpSackChunk: ParameterType={2}, ParameterLength={3}]{1}", (object)str1, (object)str2, (object)this.ParameterType, (object)this.ParameterLength);
            }
            return(stringBuilder.ToString());
        }
Esempio n. 26
0
        public override string ToString(StringOutputType outputFormat)
        {
            StringBuilder stringBuilder = new StringBuilder();
            string        str1          = "";
            string        str2          = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                str1 = this.Color;
                str2 = AnsiEscapeSequences.Reset;
            }
            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                stringBuilder.AppendFormat("{0}[SctpSackChunk: Type={2}, Flags={3}, Length={4}, TSN={5}, Advertised Receiver Window Creadit={6}, Gap Ack Blocks={7}, Duplicated TSNs={8}]{1}", (object)str1, (object)str2, (object)this.Type, (object)this.Flags.ToString("X2"), (object)this.Length, (object)this.TransmissionSequenceNumber, (object)this.AdvertisedReceiverWindowCreadit, (object)this.GapAckBlocks, (object)this.DuplicatedTSNs);
            }
            return(stringBuilder.ToString());
        }
Esempio n. 27
0
        public override string ToString(StringOutputType outputFormat)
        {
            StringBuilder stringBuilder = new StringBuilder();
            string        str1          = "";
            string        str2          = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                str1 = this.Color;
                str2 = AnsiEscapeSequences.Reset;
            }
            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                stringBuilder.AppendFormat("{0}[SctpPacket: SourcePort={2}, DestinationPort={3}, VerificationTag={4}, Checksum={5}, Chunks={6}]{1}", (object)str1, (object)str2, (object)this.SourcePort, (object)this.DestinationPort, (object)this.VerificationTag, (object)this.Checksum, (object)this.PayloadChunks.Count);
            }
            return(stringBuilder.ToString());
        }
Esempio n. 28
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var buffer = new StringBuilder();
            var color  = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color = Color;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[L2tpPacket",
                                    color);
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 29
0
 private void OutputPacket(Packet p, StringOutputType outputType)
 {
     Console.WriteLine(currentPacketDescription + " - " + outputType);
     Console.Write(p.ToString(outputType));
     if(outputType == StringOutputType.Verbose || outputType == StringOutputType.VerboseColored)
         Console.Write(p.PrintHex());
     Console.WriteLine();
 }
            /// <summary cref="Packet.ToString(StringOutputType)" />
            public override string ToString (StringOutputType outputFormat)
            {
                var buffer = new StringBuilder ();
                string color = "";
                string colorEscape = "";

                if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
                {
                    color = Color;
                    colorEscape = AnsiEscapeSequences.Reset;
                }

                if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
                {
                    // build the output string
                    buffer.AppendFormat ("{0}[Ieee80211PpiPacket: Version={2}, Length={3}, {1}",
                    color,
                    colorEscape,
                    Version,
                    Length
                    );
                }

                if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
                {
                    // collect the properties and their value
                    var properties = new Dictionary<string, string> ();
                    properties.Add ("version", Version.ToString ());
                    properties.Add ("length", Length.ToString ());

                    var ppiField = this.PpiFields;

                    foreach (var r in ppiField)
                    {
                        properties.Add (r.FieldType.ToString (),
                                   r.ToString ());
                    }

                    // calculate the padding needed to right-justify the property names
                    int padLength = RandomUtils.LongestStringLength (new List<string> (properties.Keys));

                    // build the output string
                    buffer.AppendLine ("Ieee80211PpiPacket");
                    foreach (var property in properties)
                    {
                        buffer.AppendLine ("PPI: " + property.Key.PadLeft (padLength) + " = " + property.Value);
                    }
                    buffer.AppendLine ("PPI:");
                }

                // append the base output
                buffer.Append (base.ToString (outputFormat));

                return buffer.ToString ();
            }
Esempio n. 31
0
		/// <summary cref="Packet.ToString(StringOutputType)" />
		public override string ToString(StringOutputType outputFormat) {
			var buffer = new StringBuilder();
			string color = "";
			string colorEscape = "";

			if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored) {
				color = Color;
				colorEscape = AnsiEscapeSequences.Reset;
			}

			if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored) {
				// build the output string
				buffer.AppendFormat("{0}[IGMPv2Packet: Type={2}, MaxResponseTime={3}, GroupAddress={4}]{1}",
					color,
					colorEscape,
					Type,
					String.Format("{0:0.0}", (MaxResponseTime / 10)),
					GroupAddress);
			}

			if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored) {
				// collect the properties and their value
				Dictionary<string, string> properties = new Dictionary<string, string>();
				properties.Add("type", Type + " (0x" + Type.ToString("x") + ")");
				properties.Add("max response time", String.Format("{0:0.0}", MaxResponseTime / 10) + " sec (0x" + MaxResponseTime.ToString("x") + ")");
				// TODO: Implement checksum validation for IGMPv2
				properties.Add("header checksum", "0x" + Checksum.ToString("x"));
				properties.Add("group address", GroupAddress.ToString());

				// calculate the padding needed to right-justify the property names
				int padLength = Utils.RandomUtils.LongestStringLength(new List<string>(properties.Keys));

				// build the output string
				buffer.AppendLine("IGMP:  ******* IGMPv2 - \"Internet Group Management Protocol (Version 2)\" - offset=? length=" + TotalPacketLength);
				buffer.AppendLine("IGMP:");
				foreach (var property in properties) {
					buffer.AppendLine("IGMP: " + property.Key.PadLeft(padLength) + " = " + property.Value);
				}
				buffer.AppendLine("IGMP:");
			}

			// append the base string output
			buffer.Append(base.ToString(outputFormat));

			return buffer.ToString();
		}
Esempio n. 32
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var buffer      = new StringBuilder();
            var color       = "";
            var colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = this.Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[IPv4Packet: SourceAddress={2}, DestinationAddress={3}, HeaderLength={4}, Protocol={5}, TimeToLive={6}]{1}", color, colorEscape,
                                    this.SourceAddress, this.DestinationAddress, this.HeaderLength, this.Protocol, this.TimeToLive);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                var properties = new Dictionary <string, string>();
                properties.Add("version", this.Version.ToString());
                // FIXME: Header length output is incorrect
                properties.Add("header length", this.HeaderLength + " bytes");
                var diffServices = Convert.ToString(this.DifferentiatedServices, 2).PadLeft(8, '0').Insert(4, " ");
                properties.Add("differentiated services", "0x" + this.DifferentiatedServices.ToString("x").PadLeft(2, '0'));
                properties.Add("", diffServices.Substring(0, 7) + ".. = [" + (this.DifferentiatedServices >> 2) + "] code point");
                properties.Add(" ", ".... .." + diffServices[6] + ". = [" + diffServices[6] + "] ECN");
                properties.Add("  ", ".... ..." + diffServices[7] + " = [" + diffServices[7] + "] ECE");
                properties.Add("total length", this.TotalLength.ToString());
                properties.Add("identification", "0x" + this.Id.ToString("x") + " (" + this.Id + ")");
                var flags = Convert.ToString(this.FragmentFlags, 2).PadLeft(8, '0').Substring(5, 3);
                properties.Add("flags", "0x" + this.FragmentFlags.ToString("x").PadLeft(2, '0'));
                properties.Add("   ", flags[0] + ".. = [" + flags[0] + "] reserved");
                properties.Add("    ", "." + flags[1] + ". = [" + flags[1] + "] don't fragment");
                properties.Add("     ", ".." + flags[2] + " = [" + flags[2] + "] more fragments");
                properties.Add("fragment offset", this.FragmentOffset.ToString());
                properties.Add("time to live", this.TimeToLive.ToString());
                properties.Add("protocol", this.Protocol + " (0x" + this.Protocol.ToString("x") + ")");
                properties.Add("header checksum", "0x" + this.Checksum.ToString("x") + " [" + (this.ValidChecksum? "valid" : "invalid") + "]");
                properties.Add("source", this.SourceAddress.ToString());
                properties.Add("destination", this.DestinationAddress.ToString());

                // calculate the padding needed to right-justify the property names
                var padLength = RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("IP:  ******* IPv4 - \"Internet Protocol (Version 4)\" - offset=? length=" + this.TotalPacketLength);
                buffer.AppendLine("IP:");
                foreach (var property in properties)
                {
                    if (property.Key.Trim() != "")
                    {
                        buffer.AppendLine("IP: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                    }
                    else
                    {
                        buffer.AppendLine("IP: " + property.Key.PadLeft(padLength) + "   " + property.Value);
                    }
                }
                buffer.AppendLine("IP:");
            }

            // append the base class output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 33
0
		/// <summary cref="Packet.ToString(StringOutputType)" />
		public override string ToString(StringOutputType outputFormat) {
			var buffer = new StringBuilder();
			string color = "";
			string colorEscape = "";

			if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored) {
				color = Color;
				colorEscape = AnsiEscapeSequences.Reset;
			}

			if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored) {
				// build the output string
				buffer.AppendFormat("[{0}LinuxSLLPacket{1}: Type={2}, LinkLayerAddressType={3}, LinkLayerAddressLength={4}, Source={5}, ProtocolType={6}]",
					color,
					colorEscape,
					Type,
					LinkLayerAddressType,
					LinkLayerAddressLength,
					BitConverter.ToString(LinkLayerAddress, 0),
					EthernetProtocolType);
			}

			if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored) {
				// collect the properties and their value
				Dictionary<string, string> properties = new Dictionary<string, string>();
				properties.Add("type", Type.ToString() + " (" + ((int)Type).ToString() + ")");
				properties.Add("link layer address type", LinkLayerAddressType.ToString());
				properties.Add("link layer address length", LinkLayerAddressLength.ToString());
				properties.Add("source", BitConverter.ToString(LinkLayerAddress));
				properties.Add("protocol", EthernetProtocolType.ToString() + " (0x" + EthernetProtocolType.ToString("x") + ")");


				// calculate the padding needed to right-justify the property names
				int padLength = Utils.RandomUtils.LongestStringLength(new List<string>(properties.Keys));

				// build the output string
				buffer.AppendLine("LCC:  ******* LinuxSLL - \"Linux Cooked Capture\" - offset=? length=" + TotalPacketLength);
				buffer.AppendLine("LCC:");
				foreach (var property in properties) {
					buffer.AppendLine("LCC: " + property.Key.PadLeft(padLength) + " = " + property.Value);
				}
				buffer.AppendLine("LCC:");
			}

			// append the base output
			buffer.Append(base.ToString(outputFormat));

			return buffer.ToString();
		}
Esempio n. 34
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var buffer = new StringBuilder();
            string color = "";
            string colorEscape = "";

            if(outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if(outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[Ieee8021QPacket: PriorityControlPoint={2}, CanonicalFormatIndicator={3}, Type={4}]{1}",
                    color,
                    colorEscape,
                    PriorityControlPoint,
                    CanonicalFormatIndicator,
                    Type);
            }

            if(outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary<string,string> properties = new Dictionary<string,string>();
                properties.Add("priority", PriorityControlPoint + " (0x" + PriorityControlPoint.ToString("x") + ")");
                properties.Add("canonical format indicator", CanonicalFormatIndicator.ToString());
                properties.Add("type", Type.ToString() + " (0x" + Type.ToString("x") + ")");
                properties.Add ("VLANIdentifier", VLANIdentifier.ToString () + " (0x" + VLANIdentifier.ToString ("x") + ")");

                // calculate the padding needed to right-justify the property names
                int padLength = Utils.RandomUtils.LongestStringLength(new List<string>(properties.Keys));

                // build the output string
                buffer.AppendLine("Ieee802.1Q:  ******* Ieee802.1Q - \"VLan tag\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("Ieee802.1Q:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("Ieee802.1Q: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }
                buffer.AppendLine("Ieee802.1Q:");
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return buffer.ToString();
        }
Esempio n. 35
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="outputFormat"></param>
 /// <returns></returns>
 public override String ToString(StringOutputType outputFormat)
 {
     return(base.ToString(outputFormat));
 }