LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 11-26-2003, 02:07 PM   #1
jooboo
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()
{
printk("Goodbye\n");
}

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

SRC : 208.1.0.0
DST : 1.0.0.0

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

Rep: Reputation: 108Reputation: 108
Quote:
Code:
 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, 04:24 PM   #3
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
http://www.linuxquestions.org/questi...hreadid=119823
it would be nice if u read the replies to ur posts b4 asking again. people dont like typing out replies twice.
 
  


Reply


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 10:08 PM
dhcp no ip address and netmask dont match route address pengy666 Linux - Wireless Networking 1 05-08-2005 10:33 AM
how to get ip address, broadcast address, mac address of a machine sumeshstar Programming 2 03-12-2005 05:33 AM
DHCP Server MAC Address found, IP address not assigned wmburke Linux - Wireless Networking 17 11-17-2004 11:33 AM
userspace program for forwarding packets after amendment of the destination address becky_starr Linux - Software 0 01-12-2004 07:22 AM


All times are GMT -5. The time now is 06:07 PM.

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