Skip to contentSkip to conversation

figuring out the udp port number (in linux >= 2.6.22)

DISCUSSION Marty Leisner 2 participants 2 messages Mar 16, 2008 netfilter

lore
Share & tools
lore
#0 lore raw

Obviously I'm doing something wrong...My UDP port numbers look all wrong (I took at them raw and ran them through ntohs to see if anything looked right) *They're a type __be16 -- which is network byte order?)

BTW, the IP addresses look fine, I wrote my own inet_ntoa_r...

I'm running wireshark alongside my module to see if I can get it to agree..

Here's my code:
static unsigned int main_hook(unsigned int hooknum,
struct sk_buff **skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff*))

{
        struct sk_buff *sock_buff;
        struct udphdr *udp_header;
        struct iphdr *ip_header;
        char address1[20];
        char address2[20];

        sock_buff = *skb;
        if(!sock_buff)
                return NF_ACCEPT;

        ip_header = ip_hdr(sock_buff);
        if(ip_header->protocol != IPPROTO_UDP)
                return NF_ACCEPT;
        udp_header =  udp_hdr(sock_buff);
        printk("udp source = %s dest %s\n", inet_ntoa_r(*(struct in_addr *) &ip_header->saddr, address1),
                                            inet_ntoa_r(*(struct in_addr *) &ip_header->daddr, address2));
        printk("udp packet = source port = %d, dest port = %d\n",ntohs(udp_header->source),
                                                        ntohs(udp_header->dest));
        printk("no ntohs: udp packet = source port = %, dest port = %d\n",udp_header->source,
                        udp_header->dest);

        return NF_ACCEPT;
#1 lore raw
Quoted 5 lines · Marty Leisner

Obviously I'm doing something wrong...My UDP port numbers look all wrong (I took at them raw and ran them through ntohs to see if anything looked right) *They're a type __be16 -- which is network byte order?)

__be16 is an annotated tag. It is still unsigned short internally, but is there to indicate big-endian encoding is used.

Quoted 1 line

BTW, the IP addresses look fine, I wrote my own inet_ntoa_r...

But what for?

printk("Addr: " NIP_FMT "\n", NIPQUAD(some struct in_addr));