[Click] Stupid question: Crafting packets with correct checksums...
Nicholas Weaver
nweaver at ICSI.Berkeley.EDU
Fri May 16 17:12:18 EDT 2008
I'm doing a little hacking where I'm crafting raw TCP packets.
Things seem to be going well looking at the data received on the other
side looking at TCPdump, except I can't seem to generate proper TCP
checksums, either with raw code or a pipeline of
SetTCPChecksum->SetIPChecksum
or with code in the file. If it helps, this is on OS-X. I feel like
I'm doing something incredibly stupid here, and I'm just missing
something obvious.
Suggestions?
I'm using the following code (taken from SetTCPChecksum and
SetIPChecksum), where
dst_iph and dst_tcph as appropriate are pointing into a buffer of
bytes I'm using to construct the packet.
dst_iph->ip_len = htons(strlen(reply_string) + (dst_tcph->th_off
<< 2) +
(dst_iph->ip_hl << 2));
unsigned plen, csum;
dst_tcph->th_sum = 0;
plen = ntohs(dst_iph->ip_len) - (dst_iph->ip_hl << 2);
csum = click_in_cksum((unsigned char *) tcph, plen);
dst_tcph->th_sum = click_in_cksum_pseudohdr(csum, dst_iph, plen);
dst_iph->ip_sum = 0;
dst_iph->ip_sum = click_in_cksum((unsigned char *)dst_iph,
dst_iph->ip_hl << 2);
WritablePacket * dst = Packet::make(data, ntohs(dst_iph->ip_len)
+ 14);
dst->set_ip_header(dst_iph, dst_iph->ip_hl << 2);
output(0).push(dst);
More information about the click
mailing list