Padding to Ethernet Layer of TCP Packet

46 views
Skip to first unread message

kdun...@gmail.com

unread,
May 3, 2019, 8:10:41 AM5/3/19
to Pcap.Net Q&A
I am building and sending a packet like this


EthernetLayer ethernetLayer = new EthernetLayer
{
Source = SourceMac,
Destination = DestinationMac,
};

// IPv4 Layer
IpV4Layer ipV4Layer = new IpV4Layer
{
Source = SourceIpv4Add,
CurrentDestination = DestinationIpv4Add,
Ttl = 128,
Fragmentation = new IpV4Fragmentation(IpV4FragmentationOptions.DoNotFragment, 0),
Identification = 12,
};


// TCP Layer
TcpLayer tcpLayer = new TcpLayer
{
SourcePort = _sourcePort,
DestinationPort = _destinationPort,
SequenceNumber = _seqNumber,
ControlBits = TcpControlBits.Synchronize,

Window = _windowSize,
};

PayloadLayer payloadlayer = new PayloadLayer
{
Data = new Datagram(Encoding.ASCII.GetBytes("Hello Donnie"))
};


Packet syn = PacketBuilder.Build(DateTime.Now, ethernetLayer, ipV4Layer, tcpLayer, payloadlayer);

communicator.SendPacket(syn);

This packet has a total length of 58 bytes but I need to add 2 bytes of padding to the Ethernet layer so that the packet length is 60 bytes. How would I accomplish this in Pcap.net

Boaz Brickner

unread,
Jun 21, 2019, 2:23:23 AM6/21/19
to Pcap.Net Q&A
The padding is added implicitly when you send the packet over the wire.
Let me know if something doesn't work as expected.
Reply all
Reply to author
Forward
0 new messages