public TcpPacket HandleTcpPacket() { TcpPacket packet = new TcpPacket(); int source_port = HeaderParser.ToInt(this.Data, 0, 16); int dest_port = HeaderParser.ToInt(this.Data, 16, 16); int offset = HeaderParser.ToInt(this.Data, 96, 4) * 4; packet.Source = new IPEndPoint(this.Source, source_port); packet.Destination = new IPEndPoint(this.Destination, dest_port); packet.Sequence = HeaderParser.ToUInt(this.Data, 32, 32); packet.Acknowledgement = HeaderParser.ToUInt(this.Data, 64, 32); packet.DataOffset = offset; packet.Urgent = HeaderParser.ToByte(this.Data, 106, 1) != 0; packet.Ack = HeaderParser.ToByte(this.Data, 107, 1) != 0; packet.Push = HeaderParser.ToByte(this.Data, 108, 1) != 0; packet.Reset = HeaderParser.ToByte(this.Data, 109, 1) != 0; packet.Syn = HeaderParser.ToByte(this.Data, 110, 1) != 0; packet.Fin = HeaderParser.ToByte(this.Data, 111, 1) != 0; packet.WindowSize = HeaderParser.ToInt(this.Data, 112, 16); packet.Checksum = HeaderParser.ToInt(this.Data, 128, 16); packet.UrgentPointer = HeaderParser.ToInt(this.Data, 144, 16); if (offset > 20) { packet.SetData(this.Data, 20, offset - 20); } packet.SetData(this.Data, offset, this.Data.Length - offset); return(packet); }
public bool SetFields(Byte[] buffer) { if (buffer.Length >= this.HeaderLength_) { int [] x = new int[2]; for (int i = 0; i < Keys_.Count; i++) { x = (int[])FieldLengths_[Keys_[i]]; if (x[1] <= 8) { Fields_.Add(Keys_[i], HeaderParser.ToByte(buffer, x[0], x[1])); } else if (x[1] <= 16) { Fields_.Add(Keys_[i], HeaderParser.ToInt(buffer, x[0], x[1])); } else if (x[1] <= 32) { Fields_.Add(Keys_[i], HeaderParser.ToUInt(buffer, x[0], x[1])); } } this.SetData(buffer, this.HeaderLength_, buffer.Length - this.HeaderLength_); Length_ = buffer.Length; return(true); } return(false); }
public int CheckNextFields(byte [] data) { int ret = 0; switch (this.Type) { case 0: case 8: case 13: case 14: case 15: case 16: case 17: case 18: case 37: case 38: FieldNames_ = new ArrayList(); FieldLength_ = new ArrayList(); FieldValues_ = new Hashtable(); this.FieldLength_.Add(16); this.FieldNames_.Add("Identifier"); this.FieldValues_.Add("Identifier", HeaderParser.ToUInt(data, 32, 16)); this.FieldLength_.Add(16); this.FieldNames_.Add("Sequence Number"); this.FieldValues_.Add("Sequence Number", HeaderParser.ToUInt(data, 48, 16)); ret = 8; this.dataIsIp = false; break; case 4: case 11: FieldNames_ = new ArrayList(); FieldLength_ = new ArrayList(); FieldValues_ = new Hashtable(); this.FieldLength_.Add(32); this.FieldNames_.Add("Reserved"); this.FieldValues_.Add("Reserved", HeaderParser.ToUInt(data, 32, 32)); ret = 8; this.dataIsIp = true; break; case 10: FieldNames_ = new ArrayList(); FieldLength_ = new ArrayList(); FieldValues_ = new Hashtable(); this.FieldLength_.Add(32); this.FieldNames_.Add("Reserved"); this.FieldValues_.Add("Reserved", HeaderParser.ToUInt(data, 32, 32)); ret = 8; this.dataIsIp = false; break; case 3: FieldNames_ = new ArrayList(); FieldLength_ = new ArrayList(); FieldValues_ = new Hashtable(); this.FieldLength_.Add(16); this.FieldNames_.Add("Unused"); this.FieldValues_.Add("Unused", HeaderParser.ToUInt(data, 32, 16)); this.FieldLength_.Add(16); this.FieldNames_.Add("Next Hop MTU"); this.FieldValues_.Add("Next Hop MTU", HeaderParser.ToUInt(data, 48, 16)); ret = 8; this.dataIsIp = true; break; case 5: FieldNames_ = new ArrayList(); FieldLength_ = new ArrayList(); FieldValues_ = new Hashtable(); this.FieldLength_.Add(32); this.FieldNames_.Add("IP Address"); this.FieldValues_.Add("IP Address", HeaderParser.ToUInt(data, 32, 32)); ret = 8; this.dataIsIp = true; break; case 31: FieldNames_ = new ArrayList(); FieldLength_ = new ArrayList(); FieldValues_ = new Hashtable(); this.FieldLength_.Add(32); this.FieldNames_.Add("Offset"); this.FieldValues_.Add("Offset", HeaderParser.ToUInt(data, 32, 32)); ret = 8; this.dataIsIp = false; break; case 12: FieldNames_ = new ArrayList(); FieldLength_ = new ArrayList(); FieldValues_ = new Hashtable(); this.FieldLength_.Add(8); this.FieldNames_.Add("Pointer"); this.FieldValues_.Add("Pointer", HeaderParser.ToUInt(data, 32, 8)); this.FieldLength_.Add(24); this.FieldNames_.Add("Unused"); this.FieldValues_.Add("Unused", HeaderParser.ToUInt(data, 40, 24)); ret = 8; this.dataIsIp = true; break; case 9: FieldNames_ = new ArrayList(); FieldLength_ = new ArrayList(); FieldValues_ = new Hashtable(); this.FieldLength_.Add(8); this.FieldNames_.Add("Advertisement Count"); this.FieldValues_.Add("Advertisement Count", HeaderParser.ToUInt(data, 32, 8)); this.FieldLength_.Add(8); this.FieldNames_.Add("Address Entry Size"); this.FieldValues_.Add("Address Entry Size", HeaderParser.ToUInt(data, 40, 8)); this.FieldLength_.Add(16); this.FieldNames_.Add("Life Time"); this.FieldValues_.Add("Life Time", HeaderParser.ToUInt(data, 48, 16)); ret = 8; this.dataIsIp = false; break; case 30: FieldNames_ = new ArrayList(); FieldLength_ = new ArrayList(); FieldValues_ = new Hashtable(); this.FieldLength_.Add(16); this.FieldNames_.Add("Identifier"); this.FieldValues_.Add("Identifier", HeaderParser.ToUInt(data, 32, 16)); this.FieldLength_.Add(16); this.FieldNames_.Add("Unused"); this.FieldValues_.Add("Unused", HeaderParser.ToUInt(data, 48, 16)); this.FieldLength_.Add(16); this.FieldNames_.Add("Out Bount Hop Count"); this.FieldValues_.Add("Out Bount Hop Count", HeaderParser.ToUInt(data, 64, 16)); this.FieldLength_.Add(16); this.FieldNames_.Add("Return Hop Count"); this.FieldValues_.Add("Return Hop Count", HeaderParser.ToUInt(data, 80, 16)); this.FieldLength_.Add(32); this.FieldNames_.Add("Output Link Speed"); this.FieldValues_.Add("Output Link Speed", HeaderParser.ToUInt(data, 96, 32)); this.FieldLength_.Add(32); this.FieldNames_.Add("Output Link MTU"); this.FieldValues_.Add("Output Link MTU", HeaderParser.ToUInt(data, 128, 32)); ret = 20; this.dataIsIp = false; break; case 40: FieldNames_ = new ArrayList(); FieldLength_ = new ArrayList(); FieldValues_ = new Hashtable(); this.FieldLength_.Add(16); this.FieldNames_.Add("Reserved"); this.FieldValues_.Add("Reserved", HeaderParser.ToUInt(data, 32, 16)); this.FieldLength_.Add(16); this.FieldNames_.Add("Pointer"); this.FieldValues_.Add("Pointer", HeaderParser.ToUInt(data, 48, 16)); ret = 8; this.dataIsIp = false; break; default: break; } return(ret); }