Reputation: 25287
I'm using Pcap to build network tcp packages:
private static Packet BuildTcpPacket()
{
EthernetLayer ethernetLayer =
new EthernetLayer
{
Source = new MacAddress("01:01:01:01:01:01"),
Destination = new MacAddress("02:02:02:02:02:02"),
EtherType = EthernetType.None, // Will be filled automatically.
};
IpV4Layer ipV4Layer =
new IpV4Layer
{
Source = new IpV4Address("1.2.3.4"),
CurrentDestination = new IpV4Address("11.22.33.44"),
Fragmentation = IpV4Fragmentation.None,
HeaderChecksum = null, // Will be filled automatically.
Identification = 123,
Options = IpV4Options.None,
Protocol = null, // Will be filled automatically.
Ttl = 100,
TypeOfService = 0,
};
TcpLayer tcpLayer =
new TcpLayer
{
SourcePort = 4050,
DestinationPort = 25,
Checksum = null, // Will be filled automatically.
SequenceNumber = 100,
AcknowledgmentNumber = 50,
ControlBits = TcpControlBits.Acknowledgment,
Window = 100,
UrgentPointer = 0,
Options = TcpOptions.None,
};
PayloadLayer payloadLayer =
new PayloadLayer
{
Data = new Datagram(Encoding.ASCII.GetBytes("hello world")),
};
PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, tcpLayer, payloadLayer);
return builder.Build(DateTime.Now);
}
Because the package is sent over ethernet, maximum total package size is limited to 1500 bytes. Is there any method, which I could use to check the size of the pachage headers so I know how much space is left for the actual data?
Also, If I need to send more than 1500 bytes of data, do I just split it up, or are any other rules which I need to observe?
Upvotes: 2
Views: 318
Reputation: 6585
Yes.
You can use ILayer.Length property to get each of the layers' lengths.
You can split the packets using IP fragmentation or just using regular TCP (which is what most applications do).
Upvotes: 2