PDA

View Full Version : [Solved] Recalculate udp checksum


yavuzg
January 26th, 2010, 10:18
Hi all,

I want to re-calculate checksum of an udp packet,
When I grep freebsd code I found below line:


(/usr/src/sys/netinet/udp_usrreq.c)

uh_sum = in_cksum(m, len + sizeof (struct ip));


When try to use above method in my userland code I got linker error:

yavuzg# gcc -o out divert_out.c
/var/tmp//cczSfAd4.o(.text+0x266): In function `main':
: undefined reference to `in_cksum_skip'


How can I use in_cksum method in my userland code?

thanks in advance,
yavuz

DutchDaemon
January 26th, 2010, 13:53
That reference is in ip_output.c (same directory).

yavuzg
January 26th, 2010, 15:01
you mean this line?

csum = in_cksum_skip(m, ip->ip_len, offset);

this is an example usage of the method but my problem is different. I can not compile my code if I use below piece of code

uh_sum = in_cksum(m, len + sizeof (struct ip));



yavuzg# gcc -o out divert_out.c
/var/tmp//cczSfAd4.o(.text+0x266): In function `main':
: undefined reference to `in_cksum_skip'

gordon@
January 27th, 2010, 07:00
You can't recalculate a UDP checksum in userland (I don't believe). What are you trying to do?

yavuzg
January 27th, 2010, 07:49
I am trying to change udp packet payload via a divert socket.

expl
January 27th, 2010, 18:15
When try to use above method in my userland code I got linker error:

yavuzg# gcc -o out divert_out.c
/var/tmp//cczSfAd4.o(.text+0x266): In function `main':
: undefined reference to `in_cksum_skip'


How can I use in_cksum method in my userland code?


in_cksum_skip is a kernel function (located in sys/i386/i386/in_cksum.c) not part of libc. What you want to do is port it to your userland app then link together.

Btw these in_cksum implementations are optimized for specific platforms so porting this to userland and staying portable might be bit dirty work.