Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
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.
SDN 101: An Introduction to Software Defined Networking
Discover the advantages of SDN.
SDN has quickly become one of the hottest trends in IT. But not all SDN solutions offer real software-defined functionality. As more enterprises consider SDN, they want to know, “What is SDN? And what are the real benefits?” If you're ready to explore the advantages of SDN, and want to know how it should be implemented within your enterprise, start by reading our introductory white paper.
Click Here to receive this Complete Guide absolutely free.
I am working on a kernel module that modifies the source port number of the TCP packets passing through the Netfilter hook. Currently, I am trying to print out the information about each TCP packet before I try to modify anything in the packets. My problem is that the port numbers the program captures are much different from what Ethereal (traffic monitor for those who are not familiar) shows. For instance, I constantly get 69 as the source port when I know for sure that it's something like 30573. After struggling for two whole days, I highly suspect that the use of a function called htons() is the key to the solution. According to the unix man page, htons does some conversion between different forms of addresses, but for some odd reason, it does not like being included in the module. My code, which compiles fine, shows the following as soon as I try to insert the module.
$>gcc -c modify.c
modify.o: unresolved symbol htons
Hint: You are trying to load a module without a GPL compatible license
and it has unresolved symbols. Contact the module supplier for
assistance, only they can help you.
My code follows.
#include <linux/init.h> // Needed for the macros
//generic.h includes htons()
/* This is the structure we shall use to register our function */
static struct nf_hook_ops nfho;
/* This is the hook function itself */
unsigned int hook_func(unsigned int hooknum,
struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
// the trouble makers start
// two lines below are supposed to show the source and the destination port
printk(KERN_ALERT "source port: %u\n",htons((*skb)->h.th->source));
printk(KERN_ALERT "destination port: %u\n",htons((*skb)->h.th->dest));
// the trouble makers end
/* Initialisation routine */
/* Fill in our hook structure */
nfho.hook = hook_func; /* Handler function */
nfho.hooknum = NF_IP_PRE_ROUTING; /* First hook for IPv4 */
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST; /* Make our function first */