Variable in functions

Hi everyone,

I'm curently working on a FreeBSD module.
I have some experience in C programming, but not in kernel mode.

I have a strange behaviour, I need some explanation :).

The module I am writing uses mbufs to log connections thanks to ip_input hooking.

When I use :

printf("%s->%s",ip->ip_src, ip->ip_dst);

The output is the same for both variables.

But, If I make two printf, one for ip_src and one for ip_dst both are different.

Why ?
This behaviour appears on every function, not only printf.

The printf available in kernel modules is not the same as that in libc. Have a look at printf(9). Maybe there's a bug, because it's supposed to work as expected.
What data types are ip_src and ip_dst? If they are of struct in_addr, they are basically an uint32_t, for which you cannot use "%s" as a format specifier. If you look at printf(3) or printf(9), you can see what format specifier you should use.

It's really hard to see another source for the problem.
Here is my function :

struct ip *ip;
ip = mtod(m, struct ip *);

inet_ntoa() returns the dots-and-numbers string in a static buffer that is overwritten with each call to the function.
So, depending on the order of evaluation of the arguments to printf, it will either print ip_src or ip_dst in both places.
aragon said:
Don't mean to break your thunder, but do you know about divert(4)? It might be easier and safer.

It is too dependent on ipfw(8), need to load ipdivert etc.