public void SetPorts() { if (this.Protocol == 6 || this.Protocol == 17) { SPort = HeaderParser.ToInt(this.Data, 0, 16); DPort = HeaderParser.ToInt(this.Data, 16, 16); } }
public IcmpPacket HandleIcmpPacket() { IcmpPacket packet = new IcmpPacket(); packet.Source = new IPEndPoint(this.Source, 0); packet.Destination = new IPEndPoint(this.Destination, 0); packet.Type = HeaderParser.ToByte(this.Data, 0, 8); packet.Code = HeaderParser.ToByte(this.Data, 8, 8); packet.Checksum = HeaderParser.ToUShort(this.Data, 16, 16); packet.SetData(this.Data, 4, this.Data.Length - 4); return(packet); }
public UdpDatagram HandleUdpDatagram() { UdpDatagram packet = new UdpDatagram(); int source_port = HeaderParser.ToInt(this.Data, 0, 16); int dest_port = HeaderParser.ToInt(this.Data, 16, 16); int length = HeaderParser.ToInt(this.Data, 32, 16) - 8; packet.Source = new IPEndPoint(this.Source, source_port); packet.Destination = new IPEndPoint(this.Destination, dest_port); packet.SetData(this.Data, 8, length); return(packet); }
public int GetInnerDataLength() { switch (this.Protocol) { case 1: return(this.Data.Length - 8); case 6: return(this.Data.Length - HeaderParser.ToInt(this.Data, 96, 4) * 4); case 17: return(HeaderParser.ToInt(this.Data, 32, 16) - 8); default: return(0); } }
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); }