public override PacketData GetBytes(IHeader header, PacketData packetData) { var udpHeader = (UdpHeader)header; var currentData = new List<byte>(); currentData.AddRange(GetBytes(udpHeader.SourcePort)); currentData.AddRange(GetBytes(udpHeader.DestinationPort)); currentData.AddRange(GetBytes((ushort)(UdpHeaderProperty.Size + packetData.Data.Count))); currentData.AddRange(new byte[] { 0, 0 }); //+ crc List<byte> crcData = GetPseudoHeaderBytes(udpHeader, (uint)(packetData.Data.Count + UdpHeaderProperty.Size)); crcData.AddRange(currentData); crcData.AddRange(packetData.Data); if (crcData.Count % 2 == 1) { crcData.Add(0); } byte[] crc = Checksum.GetCrc(crcData.ToArray()); currentData[6] = crc[1]; currentData[7] = crc[0]; //+ currentData.AddRange(packetData.Data); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { var ipHeader = (IPHeader)header; var currentData = new List<byte>(); currentData.Add((byte)((ipHeader.VersionIHL << 4) | 5)); currentData.Add(ipHeader.TypeOfService); //currentData.AddRange(GetBytes((UInt16)(packetData.Data.Count + 20))); currentData.AddRange(GetBytes(ipHeader.TotalLength)); currentData.AddRange(GetBytes(ipHeader.Identification)); //++ flags (3 bits-- left to right) //Bit 0: reserved, must be zero //Bit 1: (DF) 0 = May Fragment, 1 = Don't Fragment. //Bit 2: (MF) 0 = Last Fragment, 1 = More Fragments. //++ offset (13 bits) currentData.AddRange(GetBytes(ipHeader.FlagsFragmentOffset)); currentData.Add(ipHeader.TTL); currentData.Add(ipHeader.Protocol); currentData.AddRange(new byte[] { 0, 0 }); currentData.AddRange(ipHeader.SourceAddress.GetBytes()); currentData.AddRange(ipHeader.DestinationAddress.GetBytes()); byte[] crc = GetCrc(currentData.ToArray()); currentData[10] = crc[1]; currentData[11] = crc[0]; currentData.AddRange(packetData.Data); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { var imageHeader = (ImageHeader)header; var currentData = new List<byte>(); currentData.Add(imageHeader.Operation); currentData.AddRange(imageHeader.Data); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { var icmpEchoHeader = (IcmpEchoHeader)header; var currentData = new List<byte>(); currentData.AddRange(GetBytes(icmpEchoHeader.Identifier)); currentData.AddRange(GetBytes(icmpEchoHeader.SequenceNumber)); currentData.AddRange(icmpEchoHeader.Data); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { var ethernetHeader = (EthernetHeader)header; var currentData = new List<byte>(); currentData.AddRange(ethernetHeader.Destination.GetBytes()); currentData.AddRange(ethernetHeader.Source.GetBytes()); currentData.AddRange(ethernetHeader.TypeOrLength.GetBytes()); currentData.AddRange(packetData.Data); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { return packetData; var ipv6_header = (IPv6Header)header; var currentData = new List<byte>(); //++ more here currentData.AddRange(ipv6_header.SourceAddress.GetBytes()); currentData.AddRange(ipv6_header.DestinationAddress.GetBytes()); currentData.AddRange(packetData.Data); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { var icmpHeader = (IcmpHeader)header; var currentData = new List<byte>(); currentData.AddRange(GetBytes(icmpHeader.Type)); currentData.AddRange(GetBytes(icmpHeader.Code)); currentData.AddRange(new byte[] { 0, 0 }); currentData.AddRange(packetData.Data); byte[] crc = Checksum.GetCrc(currentData.ToArray()); currentData[2] = crc[1]; currentData[3] = crc[0]; return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { if (!Collection.IsNullOrEmpty(packetData.Data)) { //TODO: if this becomes iterative, this will have to change throw new InvalidOperationException("There should never be data after the TLV area of an OSPF LLS data block"); } var ospfLlsDataBlockTlv = (OspfLlsDataBlockTlv)header; var currentData = new List<byte>(); currentData.AddRange(GetBytes(ospfLlsDataBlockTlv.Type)); currentData.AddRange(GetBytes(ospfLlsDataBlockTlv.Length)); currentData.AddRange(ospfLlsDataBlockTlv.Value); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { var ripPreambleHeader = (RipPreambleHeader)header; var currentData = new List<byte>(); currentData.Add(ripPreambleHeader.command); currentData.Add(ripPreambleHeader.Version); currentData.AddRange(GetBytes(ripPreambleHeader.Domain)); foreach (var ripDataHeader in ripPreambleHeader.DataArray) { currentData.AddRange(GetBytes(ripDataHeader.AddressFamily)); currentData.AddRange(GetBytes(ripDataHeader.RouteTag)); currentData.AddRange(ripDataHeader.Network.GetBytes()); currentData.AddRange(ripDataHeader.Mask.GetBytes()); currentData.AddRange(ripDataHeader.NextHop.GetBytes()); currentData.AddRange(GetBytes(ripDataHeader.Metric)); } return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { var ospfDBDHeader = (OspfDbdHeader)header; if (ospfDBDHeader.LsaList != null) { foreach (var ospfLsaHeader in ospfDBDHeader.LsaList) { packetData = Controller.GetSingletonHandler("OSPFLSA").GetBytes(ospfLsaHeader, packetData); } } var currentData = new List<byte>(); currentData.AddRange(GetBytes(ospfDBDHeader.Mtu)); currentData.AddRange(GetBytes(ospfDBDHeader.Options)); currentData.AddRange(GetBytes(ospfDBDHeader.Flags)); currentData.AddRange(GetBytes(ospfDBDHeader.SequenceNumber)); currentData.AddRange(packetData.Data); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { var arpHeader = (ArpHeader)header; var currentData = new List<byte>(); currentData.AddRange(GetBytes(arpHeader.HardwareType)); currentData.AddRange(GetBytes(arpHeader.ProtocolType)); currentData.Add(arpHeader.HardwareSize); currentData.Add(arpHeader.ProtocolSize); currentData.AddRange(GetBytes(arpHeader.Operation)); currentData.AddRange(arpHeader.SourceMacAddress.GetBytes()); currentData.AddRange(arpHeader.SourceIPAddress.GetBytes()); currentData.AddRange(arpHeader.DestinationMacAddress.GetBytes()); currentData.AddRange(arpHeader.DestinationIPAddress.GetBytes()); currentData.AddRange(packetData.Data); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { ushort size = (ushort)packetData.Data.Count; var ospfLsaHeader = (OspfLsaHeader)header; var currentData = new List<byte>(); currentData.AddRange(GetBytes(ospfLsaHeader.LSAge)); currentData.AddRange(GetBytes(ospfLsaHeader.Options)); currentData.AddRange(GetBytes(ospfLsaHeader.LSType)); currentData.AddRange(ospfLsaHeader.LSID.GetBytes()); currentData.AddRange(ospfLsaHeader.AdvertisingRouter.GetBytes()); currentData.AddRange(GetBytes(ospfLsaHeader.SequenceNumber)); currentData.AddRange(new byte[] { 0, 0 }); currentData.AddRange(GetBytes((ushort)(20 + size))); byte[] crc = Nalarium.Checksum.GetCrc(currentData.ToArray()); currentData[16] = crc[1]; currentData[17] = crc[0]; currentData.AddRange(packetData.Data); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { var ospfHelloHeader = (OspfHelloHeader)header; var currentData = new List<byte>(); currentData.AddRange(GetNotReversedBytes(ospfHelloHeader.Mask)); currentData.AddRange(GetBytes(ospfHelloHeader.Interval)); currentData.Add(ospfHelloHeader.Options); currentData.Add(ospfHelloHeader.RouterPriority); currentData.AddRange(GetBytes(ospfHelloHeader.RouterDeadInterval)); currentData.AddRange(ospfHelloHeader.Dr.GetBytes()); currentData.AddRange(ospfHelloHeader.Bdr.GetBytes()); if (ospfHelloHeader.Neighbor != null) { foreach (IPAddress neighbor in ospfHelloHeader.Neighbor) { currentData.AddRange(neighbor.GetBytes()); } } currentData.AddRange(packetData.Data); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { var ospfLlsDataBlockHeader = (OspfLlsDataBlockHeader)header; var currentData = new List<byte>(); currentData.AddRange(new byte[] { 0, 0 }); var size = (ushort)(packetData.Data.Count + 4); packetData.AddProperty("OspfLlsDataBlockHeaderSize", size); currentData.AddRange(GetBytes((ushort)(size / 4))); byte[] crc = Checksum.GetCrc(currentData.ToArray()); currentData[0] = 0xff; currentData[1] = 0xf6; //foreach (var ospfLlsDataBlockTlv in OspfLlsDataBlockHeader.OspfLlsDataBlockTlv) //{ // var subData = new List<byte>(); // Controller.GetSingletonHandler("OSPFLLSDATABLOCKTLV").GetBytes(ospfLlsDataBlockTlv, subData); // currentData.AddRange(subData); //} currentData.AddRange(packetData.Data); return packetData.UpdateData(currentData); }
public override PacketData GetBytes(IHeader header, PacketData packetData) { var ospfHeader = (OspfHeader)header; var currentData = new List<byte>(); currentData.Add(ospfHeader.Version); currentData.Add(ospfHeader.Type); byte[] array = GetBytes((UInt16)(packetData.Data.Count + 24 - packetData.GetProperty<ushort>("OspfLlsDataBlockHeaderSize"))); currentData.AddRange(array); currentData.AddRange(GetNotReversedBytes(ospfHeader.RouterID)); currentData.AddRange(GetBytes(ospfHeader.AreaID)); //currentData.AddRange(new byte[] { 1, 2 }); //currentData.AddRange(new byte[] { 3, 4 }); //currentData.AddRange(new byte[] { 5, 6, 7, 8 }); //currentData.AddRange(new byte[] { 9, 0xa, 0xb, 0xc }); currentData.AddRange(new byte[] { 0, 0 }); currentData.AddRange(new byte[] { 0, 0 }); currentData.AddRange(new byte[] { 0, 0, 0, 0 }); currentData.AddRange(new byte[] { 0, 0, 0, 0 }); currentData.AddRange(packetData.Data); byte[] crc = Checksum.GetCrc(currentData.ToArray()); currentData[12] = crc[1]; currentData[13] = crc[0]; return packetData.UpdateData(currentData); }