我正在使用 Pcap 构建网络 tcp 包:
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);
}
因为包是通过以太网发送的,所以最大的包总大小限制为 1500 字节。有什么方法可以用来检查包头的大小,这样我就知道为实际数据留下了多少空间?
另外,如果我需要发送超过 1500 字节的数据,我是否只需将其拆分,还是需要遵守任何其他规则?