title: How to access data/payload from tcphdr (sk_buff) struct on debian 64 bits?
body: <p>I'm working on a small firewall, i had to retrieve the datas from each tcp packet from port 80 (http) for parsing them. This code works well on a debian 32 bits virtual machine, i'm able to print the headers of each web page, but when i try to load my kernel module and to transfer some datas through the http port, it prints no datas.</p>
  
  <p>When i compile, it shows those warnings only on my 64bits computer :</p>
  
  <pre><code>/home/dev3/C/FIREWALL/firewall.c: In function ‘hook_func’:
  /home/dev3/C/FIREWALL/firewall.c:179: warning: cast from pointer to integer of different size
  /home/dev3/C/FIREWALL/firewall.c:179: warning: cast to pointer from integer of different size
  </code></pre>
  
  <p>Anyone got any ideas, please ?</p>
  
  <p>Thanks.</p>
  
  <p>Code :</p>
  
  <pre><code>#include &lt;linux/module.h&gt;
  #include &lt;linux/kernel.h&gt;
  #include &lt;linux/netfilter.h&gt;
  
  #undef __KERNEL__
  #include &lt;linux/netfilter_ipv4.h&gt;
  #define __KERNEL__
  
  #include &lt;linux/ip.h&gt;
  #include &lt;linux/tcp.h&gt;
  
  static struct nf_hook_ops nfho;
  
  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 *))
  {
      struct iphdr    * iph;
      struct tcphdr   * tcph;
      unsigned char   * http_port = "\x00\x50";
      char            * data;
  
      if (skb)
      {
          iph = ip_hdr(skb);
  
          if (iph &amp;&amp; iph-&gt;protocol &amp;&amp; (iph-&gt;protocol == IPPROTO_TCP))
          {
              tcph = (struct tcphdr *)((__u32 *)iph + iph-&gt;ihl);
  
              if ((tcph-&gt;source) == *(unsigned short *)http_port)
              {
                  data    = (char *)((int)tcph + (int)(tcph-&gt;doff * 4));
  
                  printk(KERN_DEBUG "TCP source : %hu, TCP  dest : %hu\n", ntohs(tcph-&gt;source), ntohs(tcph-&gt;dest));
                  printk(KERN_DEBUG "TCP seq : %u, TCP ack_seq : %u\n", ntohl(tcph-&gt;seq), ntohl(tcph-&gt;ack_seq));
                  printk(KERN_DEBUG "TCP doff : %hu, TCP window : %hu\n", ntohs(tcph-&gt;doff), ntohs(tcph-&gt;window));
                  printk(KERN_DEBUG "TCP check : 0x%hx, TCP urg_ptr : %hu\n", ntohs(tcph-&gt;check), ntohs(tcph-&gt;urg_ptr));
                  printk(KERN_DEBUG "FLAGS=%c%c%c%c%c%c\n\n",
                          tcph-&gt;urg ? 'U' : '-',
                          tcph-&gt;ack ? 'A' : '-',
                          tcph-&gt;psh ? 'P' : '-',
                          tcph-&gt;rst ? 'R' : '-',
                          tcph-&gt;syn ? 'S' : '-',
                          tcph-&gt;fin ? 'F' : '-');
                  //printk(KERN_DEBUG "sending packet to : %pI4\n", &amp;iph-&gt;daddr);
                  printk(KERN_DEBUG "data len : %d\ndata : \n", (int) strlen(data));
                  printk(KERN_DEBUG "%s\n", data);
              }
          }
      }
  
      return NF_ACCEPT;
  }
  
  int init_module()
  {
      int result;
  
      nfho.hook   = (nf_hookfn *) hook_func;
      nfho.hooknum    = NF_IP_POST_ROUTING;
      nfho.pf     = PF_INET;
      nfho.priority   = NF_IP_PRI_FIRST;
  
      result = nf_register_hook(&amp;nfho);
  
      if(result)
      {
          printk(KERN_DEBUG "firewall : erreur nf_register_hook !\n");
          return 1;
      }
  
      printk(KERN_DEBUG "firewall : module charge.\n");
  
      return 0;
  }
  
  void cleanup_module()
  {
      nf_unregister_hook(&amp;nfho);
      printk(KERN_DEBUG "firewall : module decharge.\n");
  }
  </code></pre>