Netutil.cc
IP分片并发送函数解析
1、mtu是通信协议某一层上面所能通过的最大数据大小
2、分片过程:
将IP数据部分划分为fragment片,每片大小mtu,最后一片大小datalen % mtu(因为可能不足mtu)
划分好的每片长度fdatalen
fdatalen = (fragment * mtu <= datalen ? mtu : datalen % mtu);
3、ip包头中需要填充的字节:
需要填充的ip_off是相对数据部分的偏移,因此偏移字节为fragment - 1) * mtu ,又由于ip_off是以8字节为单位
ip->ip_off = htons((fragment - 1) * mtu / 8);
/* Create and send all fragments of a pre-built IPv4 packet
* Minimal MTU for IPv4 is 68 and maximal IPv4 header size is 60
* which gives us a right to cut TCP header after 8th byte
* (shouldn't we inflate the header to 60 bytes too?) */
int send_frag_ip_packet(int sd, const struct eth_nfo *eth,
const struct sockaddr_in *dst,
const u8 *packet, un