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); } }