I need assistance in understanding how to implement fragmentation logic using Libnet for UDP packets. Despite setting the "More Fragments (MF)" flag, the packets are not being fragmented as expected.
I believe there may be issues with how I'm building the packets using Libnet. I need guidance on the correct sequence of calls and settings required to create fragmented UDP packets.
char payload[32];
int payload_size = 32;
memset(payload, 'A', payload_size);
libnet_build_udp(
src_port,
dest_port,
LIBNET_UDP_H + payload_size,
0,
(unsigned char *)payload,
payload_size,
l,
0
);
libnet_build_ipv4(
LIBNET_IPV4_H + LIBNET_UDP_H + payload_size,
0,
255,
htons(0x2000), //fragment flag
128,
IPPROTO_UDP,
0,
libnet_name2addr4(l, source_ip, LIBNET_RESOLVE),
libnet_name2addr4(l, dest_ip, LIBNET_RESOLVE),
NULL,
0,
l,
0
);
When i set fragment flag to 0 i am able to send udp data to my server.
I've set the MF (More Fragments) flag in the IP header to indicate that more fragments are expected. I've adjusted the payload size to exceed the Maximum Transmission Unit (MTU) of the network (e.g., 1500 bytes) to force fragmentation. I've verified that other types of packets (TCP, UDP) can be sent successfully using Libnet.
libnet version 1.2