Recalculate udp checksum

Hi all,

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

Code:
(/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:
Code:
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
 
you mean this line?

Code:
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

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

Code:
yavuzg# gcc -o out divert_out.c
/var/tmp//cczSfAd4.o(.text+0x266): In function `main':
: undefined reference to `in_cksum_skip'
 
yavuzg said:
When try to use above method in my userland code I got linker error:
Code:
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.
 
Back
Top