Register a domain and help support LQ
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-26-2003, 01:07 PM   #1
LQ Newbie
Registered: Nov 2003
Location: Thailand
Posts: 4

Rep: Reputation: 0
problem to print source address and destination address

Please look my code below

#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/spinlock.h>
#include <linux/icmp.h>
#include <linux/udp.h>
#include <linux/tcp.h>
#include <linux/netfilter_ipv4/ip_tables.h>

int init_module(struct sk_buff *skb)
struct iphdr *iph;
int i;
printk("SRC : %u.%u.%u.%u \n",NIPQUAD(iph->saddr));
printk("DST : %u.%u.%u.%u \n",NIPQUAD(iph->daddr));
return 0;

void cleanup_module()

That code print source & destination address in /var/log/message below


I don't understand ,what is ip ? and Where it come from ?
Old 11-26-2003, 02:16 PM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
 struct iphdr *iph;
/* ... */
printk("SRC : %u.%u.%u.%u \n",NIPQUAD(iph->saddr));
I'm not familiar with programming af kernel modules, but seems to me that iph is a dangling pointer. So you are syslogging random data from an unknown place in memory.
Old 11-26-2003, 03:24 PM   #3
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
it would be nice if u read the replies to ur posts b4 asking again. people dont like typing out replies twice.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
API for mapping Physical Address to Virtual Address Lakshman_smt Linux - Software 2 10-15-2006 09:08 PM
dhcp no ip address and netmask dont match route address pengy666 Linux - Wireless Networking 1 05-08-2005 09:33 AM
how to get ip address, broadcast address, mac address of a machine sumeshstar Programming 2 03-12-2005 04:33 AM
DHCP Server MAC Address found, IP address not assigned wmburke Linux - Wireless Networking 17 11-17-2004 10:33 AM
userspace program for forwarding packets after amendment of the destination address becky_starr Linux - Software 0 01-12-2004 06:22 AM

All times are GMT -5. The time now is 11:24 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration