printk and skb->data

Submitted by Anonymous
on August 27, 2007 - 1:15pm

I'm relatively new to kernel hacking and am working on a netfilter module. I'm trying to look at the contents of skb->data and am using this logging statement:

printk(KERN_INFO "==> before copy bits data %x\n\n", skb->data);

but I'm only getting what looks like the memory address, i.e. c672f5a0. How can I print this in ASCII?

Unprintable ASCII

on
August 27, 2007 - 5:56pm

What do u mean - 0xc6 is not a printable character, and so is 0xf5, and 0xa0.

printk and skb->data

on
August 27, 2007 - 8:27pm

Hi,

Have you tried to change %x to %p ?

Regards,
Douglas Landgraf

pointers

on
August 27, 2007 - 10:29pm

you really don't know how to dereference a pointer?

you may want to read the manual page of printf(). %x of course prints the value passed as argument (like %d or %c) and does not dereference it (like %s). how would printk() know the length of the data array anyway? you may want to preformat the data into a temporary string and print that with %s.

printing skb->data

on
August 28, 2007 - 4:42pm

why not just follow the way it is done in some parts of the linux kernel source code, eg,

in the drivers/net/macb.c:

For the pointer value:

printk("%x", skb->data);

For the data itself:

for(i=0;i<16;i++) printk("%02x", skb->data[i]);

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.