[SOLVED] printk incorrect output from ntohs(tcp_hdr(skb)->source)
Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
printk incorrect output from ntohs(tcp_hdr(skb)->source)
I am messing around with linux kernel modules while I learn C. I wrote a LKM that has sucessfully been sniffing IP Packets Source/Destination, and writing that to /var/log/messages with printk, but when I try to access the TCP header source/dest, and write it to the log I am not getting the correct values.
The dest should be 80(http), but the log is saying 40. Is there some other conversion of "tcp_hdr(skb)->dest" I need to do for it to print the correct value? I know the value should be 80 so I expect that the source value I am getting is also incorrect, but have not used Wireshark to deteremine that its actual value is.
Hehe ;^) Nice code, but...
Looks like it does the same thing to me. Doesn't tcp_hdr(skb) also pull data from the skb?
Anyways that's the results I'm getting.
Just FYI (I know the thread is old, but, still ;^)
I'm working in the sch_red.ko module. On the host PC tcp_hdr(skb) works as expected. On the router it always seems to generate the same (wrong) source and dest port. Your neat little piece of code does the same thing.
I suspect that my router is doing something funny ;^)
tcp_hdr(skb) should pull the correct data but the linux kernel I was using at the time it would not work. All my development was with CentOS 5 being based on RHEL its a little behind when it comes to the latest linux kernel.
You can see I am still using my original method in the userspace daemon to map the pointer to the correct tcp_header. I could probably try using the simpler tcp_hdr(skb) and see if it works. http://opennop.svn.sourceforge.net/v...73&view=markup
Netfilter hook blog? Could you shoot me a link to that? For a networking scientist I know embarrassingly little about netfilter hooks and the proper way of doing things in the kernel. I just sort of found the kernel code and started messing around with it's brains. It might be worthwhile for me to learn how everybody else does things ;^)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.