Example #1
0
        public IpV4Header(byte[] byBuffer, int nReceived)
        {
            _dataGram = new BitArrayReader(byBuffer);
            try
            {
                // The first eight bits of the IP header contain the version and
                // header length so we read them.
                _version      = (int)_dataGram.ReadInt(4);
                _headerLength = (byte)(_dataGram.ReadByte(4) * 4);

                _dscp = _dataGram.ReadByte(6);
                _ecn  = _dataGram.ReadByte(2);

                _totalLength = _dataGram.ReadShort();

                _identification = _dataGram.ReadShort();
                _flags          = _dataGram.ReadByte(3);
                _fragmentOffset = _dataGram.ReadShort(13);
                _timeToLive     = _dataGram.ReadByte();
                _protocolType   = (Protocol)_dataGram.ReadByte();
                _checksum       = (short)_dataGram.ReadShort();
                _srcIP          = _dataGram.ReadInt().Reverse();
                _destIP         = _dataGram.ReadInt().Reverse();

                _dataGram.CurrentPositionInBytes = _headerLength;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Network Sniffer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
 public UdpHeader(BitArrayReader dataGram, int nReceived)
 {
     _dataGram = dataGram;
     // The first sixteen bits contain the source port.
     _sourcePort = _dataGram.ReadShort();
     // The next sixteen bits contain the destination port.
     _destinationPort = _dataGram.ReadShort();
     // The next sixteen bits contain the length of the UDP packet.
     _length = _dataGram.ReadShort();
     // The next sixteen bits contain the checksum.
     _checksum = (short)_dataGram.ReadShort();
     //_dataGram already in correct position
 }
Example #3
0
 public IcmpHeader(BitArrayReader dataGram, int nReceived)
 {
     // ICMP type
     _Type = dataGram.ReadByte();
     // ICMP subtype
     _Code = dataGram.ReadByte();
     // Error checking data, calculated from the ICMP header and data, with value 0 substituted for this field. The Internet Checksum is used, specified in RFC 1071
     _Checksum = dataGram.ReadShort();
     // Four-bytes field, contents vary based on the ICMP type and code.
     _Header = dataGram.ReadInt();
 }
Example #4
0
        public IgmpHeader(BitArrayReader dataGram, int nReceived)
        {
            // ICMP type
            _Type = dataGram.ReadByte();
            // ICMP subtype
            _MaxRespCode = dataGram.ReadByte();
            // Error checking data, calculated from the ICMP header and data, with value 0 substituted for this field. The Internet Checksum is used, specified in RFC 1071
            _Checksum = dataGram.ReadShort();

            _GroupAddress = new IPAddress(dataGram.ReadInt().Reverse());

            if (_Type == 0x11)
            {
                _Resv            = dataGram.ReadByte(4);
                _SFlag           = dataGram.ReadByte(1);
                _QRV             = dataGram.ReadByte(3);
                _QQIC            = dataGram.ReadByte();
                _NumberofSources = dataGram.ReadShort();
            }

            // Four-bytes field, contents vary based on the ICMP type and code.
            //_Header = (uint)IPAddress.NetworkToHostOrder(binaryReader.ReadInt32());
        }
Example #5
0
 public DnsHeader(BitArrayReader dataGram)
 {
     // First sixteen bits are for identification.
     _identification = dataGram.ReadShort();
     // Next sixteen contain the flags.
     _flags = dataGram.ReadShort();
     // Read the total numbers of questions in the quesion list.
     _totalQuestions = dataGram.ReadShort();
     // Read the total number of answers in the answer list.
     _totalAnswerRRs = dataGram.ReadShort();
     // Read the total number of entries in the authority list.
     _totalAuthorityRRs = dataGram.ReadShort();
     // Total number of entries in the additional resource record list.
     _totalAdditionalRRs = dataGram.ReadShort();
 }
Example #6
0
 public TcpHeader(BitArrayReader dataGram, int nReceived)
 {
     _dataGram = dataGram;
     try
     {
         // The first sixteen bits contain the source port.
         _sourcePort = _dataGram.ReadShort();
         // The next sixteen contain the destiination port.
         _destinationPort = _dataGram.ReadShort();
         // Next thirty two have the sequence number.
         _sequenceNumber = _dataGram.ReadInt();
         // Next thirty two have the acknowledgement number.
         _acknowledgementNumber = _dataGram.ReadInt();
         // The next sixteen bits hold the flags and the data offset.
         _headerLength = _dataGram.ReadByte(4);
         _dataGram.SkipBits(3);
         _nFlags = _dataGram.ReadShort(9);
         // The next sixteen contain the window size.
         _window = _dataGram.ReadShort();
         // In the next sixteen we have the checksum.
         _checksum = (short)_dataGram.ReadShort();
         // The following sixteen contain the urgent pointer.
         _urgentPointer = _dataGram.ReadShort();
         //// The data offset indicates where the data begins, so using it we
         //// calculate the header length.
         //_headerLength = (byte)(_dataOffset >> 12);
         _headerLength *= 4;
         //// Message length = Total length of the TCP packet - Header length.
         //_messageLength = (ushort)(nReceived - _headerLength);
         //// Copy the TCP data into the data buffer.
         //_nFlags = _dataOffset & 0x3F;
         _dataGram.CurrentPositionInBytes = _headerLength;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Network Sniffer" + (nReceived), MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }