Ejemplo n.º 1
0
        public void InvalidKindTest()
        {
            const DataLinkKind InvalidKind = (DataLinkKind)100;
            IDataLink          dataLink    = new PcapDataLink(InvalidKind);

            Assert.IsNotNull(dataLink);
            Assert.Fail();
        }
Ejemplo n.º 2
0
 private static int KindToValue(DataLinkKind kind)
 {
     if (kind == DataLinkKind.Ethernet)
     {
         return(1);
     }
     if (kind == DataLinkKind.IpV4)
     {
         return(12);
     }
     if (kind != DataLinkKind.Docsis)
     {
         throw new NotSupportedException(typeof(PcapDataLink).Name + " kind " + kind.ToString() + " is unsupported");
     }
     return(143);
 }
Ejemplo n.º 3
0
        public static Packet FromHexadecimalString(string value, DateTime timestamp, DataLinkKind dataLink)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            byte[] data       = new byte[value.Length / 2];
            int    startIndex = 0;

            while (startIndex < value.Length)
            {
                data[startIndex / 2] = Convert.ToByte(value.Substring(startIndex, 2), 16);
                startIndex          += 2;
            }
            return(new Packet(data, timestamp, dataLink));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Create a packet from an array of bytes.
 /// </summary>
 /// <param name="data">The bytes of the packet. This array should not be changed after creating the packet until the packet is no longer used.</param>
 /// <param name="timestamp">A timestamp of the packet - when it was captured.</param>
 /// <param name="dataLink">The type of the datalink of the packet.</param>
 public Packet(byte[] data, DateTime timestamp, DataLinkKind dataLink)
     : this(data, timestamp, new DataLink(dataLink))
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a packet from a string that represents bytes in a hexadecimal format.
 /// </summary>
 public static Packet FromHexadecimalString(string value, DateTime timestamp, DataLinkKind dataLink)
 {
     return(FromHexadecimalString(value, timestamp, new DataLink(dataLink)));
 }
Ejemplo n.º 6
0
 private static Packet HexToPacket(string hexString, DataLinkKind dataLinkKind)
 {
     return Packet.FromHexadecimalString(hexString, DateTime.MinValue, dataLinkKind);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Create a packet from an array of bytes, assuming original length is equal to the data size.
 /// </summary>
 /// <param name="data">The bytes of the packet. This array should not be changed after creating the packet until the packet is no longer used.</param>
 /// <param name="timestamp">A timestamp of the packet - when it was captured.</param>
 /// <param name="dataLink">The type of the datalink of the packet.</param>
 /// <param name="originalLength">
 /// Length this packet (off wire).
 /// If the value is less than the data size, it is ignored and the original length is considered to be equal to the data size.
 /// </param>
 public Packet(byte[] data, DateTime timestamp, DataLinkKind dataLink, uint originalLength)
     : this(data, timestamp, new DataLink(dataLink), originalLength)
 {
 }
Ejemplo n.º 8
0
        public static void Dump(string fileName, DataLinkKind dataLink, int snapshotLength, IEnumerable <Packet> packets)
        {
            PcapDataLink dataLink1 = new PcapDataLink(dataLink);

            PacketDumpFile.Dump(fileName, dataLink1, snapshotLength, packets);
        }
Ejemplo n.º 9
0
 private static Packet HexToPacket(string hexString, DataLinkKind dataLinkKind)
 {
     return(Packet.FromHexadecimalString(hexString, DateTime.MinValue, dataLinkKind));
 }
 public BerkeleyPacketFilter(string filterValue, int snapshotLength, DataLinkKind kind, IpV4SocketAddress netmask)
 {
     this.Initialize(filterValue, snapshotLength, kind, netmask);
 }
Ejemplo n.º 11
0
 public DataLink(DataLinkKind kind)
 {
     this._kind = kind;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Create the DataLink from a kind.
 /// </summary>
 public DataLink(DataLinkKind kind)
 {
     _kind = kind;
 }
Ejemplo n.º 13
0
 public PcapDataLink(DataLinkKind kind)
 {
     this._value = PcapDataLink.KindToValue(kind);
 }
Ejemplo n.º 14
0
 public Packet(byte[] data, DateTime timestamp, DataLinkKind dataLink)
     : this(data, timestamp, (IDataLink) new PcapDotNet.Packets.DataLink(dataLink))
 {
 }