Hi all,

I'm actually working on a kernel module in order to create a sort of
kernel Firewall. (by hooking tcp_input etc.)
I'm used to write C programs, but not in kernel mode.

I have two problems about memory allocation :

1/
First of all, why my printf() function gave me same value for both
variable (line 85.) ?
I solved this issue by using two strcpy() before printf for saving
these variable in my char *

It's the same for every other function, when i use directly mbuf
variables in the same line, both are same every time

61 ip_input_hook(struct mbuf *m, int off)
62 {
64 struct ip *ip_mbuf;
65 int hlen = off;
66 char *ip_src, *ip_dst;
....
68 ip_mbuf = mtod(m, struct ip *);
....
85 printf("%s:%s",inet_ntoa(ip_mbuf-
>ip_src),inet_ntoa(ip_mbuf->ip_dst));



2/
I also want to save every connection in a data structure (in order to
monitor every connection)
Here is my function

41 void
42 add_connection(char *src, char *dst, int psrc, int pdst)
43 {
44 MALLOC(my_connections->ip_src, char*, sizeof(src), M_IPSRC,
M_WAITOK);
45 strncpy(my_connections->ip_src, src, sizeof(src));
46
47 MALLOC(my_connections->ip_dst, char*, sizeof(dst), M_IPDST,
M_WAITOK);
48 strncpy(my_connections->ip_dst, dst, sizeof(dst));
49
50 printf("src : %s, %s\n",src,my_connections->ip_src);
51 printf("dst : %s, %s\n",dst,my_connections->ip_dst);

I got a strange behaviour, in my printf()s.
Sometimes, both variables aren't the same like :

src: 10.0.0.9, 10.0.0.9a~
dst : 10.0.0.6, 10.0.0.6#eed

some chars are added in my structure. Where am I wrong ?
I think my strncpies are good, but I'm a newbie in kernel
programming.
If you have any good website/book for kernel programming don't
hesitate to redirect me on them

Thank you,

Cheers,
Jerem