LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 05-23-2007, 09:03 PM   #1
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Rep: Reputation: 32
writing sniffer in linux


Hi,

I need to write a sniffer in linux can you guys please help me that

1) which is the best IDE should I use
2) which libraries will help me in writing a sniffer
3) what are the things I should consider before start programming
4) I want to use command line interface so which library e.g; ncurses will be best for it?

Regards,
Imran
 
Old 05-23-2007, 10:00 PM   #2
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
When you say "sniffer" do you mean a packet sniffer? You haven't mentioned what language you wish to code in? This will influence the answers to the rest of the questions.
 
Old 05-23-2007, 11:11 PM   #3
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
Sorry for that,
yeah I mean packet sniffer and the language that I would like to use is C (gcc).
 
Old 05-23-2007, 11:23 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

You definitely want to look here:
http://sourceforge.net/projects/libpcap/

Before you dive in, however, definitely familiarize yourself with these resources:

http://www.cet.nau.edu/~mc8/Socket/T.../section1.html

http://www.certforums.co.uk/forums/thread12166.html
http://www.certforums.co.uk/forums/thread12187.html
http://www.certforums.co.uk/forums/thread12493.html

'Hope that helps .. PSM
 
Old 05-24-2007, 07:17 AM   #5
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Rep: Reputation: 30
Also, look at the PF_PACKET socket type. This is a raw socket on the ethernet frame level.
 
Old 05-24-2007, 11:36 AM   #6
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
thanks alot guy, I would like if more people can give me more suggestions.
 
Old 05-24-2007, 04:07 PM   #7
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
Check ethereal project/sources.
 
Old 05-24-2007, 05:16 PM   #8
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by Alien_Hominid
Check ethereal project/sources.
Nowadays, it’s called wireshark (I think).

As for answering the OP questions,
  1. Whatever IDE you are most comfortable with.
  2. As has been stated, you can either use the pcap library (much of the work has been done for you here) or implement ethernet-level sockets (you do a lot of wheel-reinventing here).
  3. Is yet another packet sniffer really necessary? Why not help improve an already existing sniffer?
  4. If you want an interactive command line interface, you might use some form of curses. Personally, I would use normal I/O to and from stdout and stdin for a base program (if it might be interactive at all). I might write frontends in ncurses and perhaps a GUI toolkit.
 
Old 05-24-2007, 07:11 PM   #9
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
hi I got one more question to ask

when I try to execute the followin code in Anjuta IDE

#include <stdio.h>
#include <pcap.h>

int main(int argc, char *argv[])
{
char *dev, errbuf[PCAP_ERRBUF_SIZE];

dev = pcap_lookupdev(errbuf);
if (dev == NULL) {
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
return(2);
}
printf("Device: %s\n", dev);
return(0);
}


it gives me following error however I've install libpcap

/root/Projects/test/src/main.c:11: undefined reference to 'pcap_lookupdev'


I can't understand the problem.

regards,
Imran

thanks
 
Old 05-24-2007, 07:47 PM   #10
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
You’re not linking to libpcap. Change the linker option to include “-lpcap”.
 
Old 05-24-2007, 08:17 PM   #11
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
Dear Osor,

can you kindly give me the full syntax for gcc cause I'm a newbie in programming and this is my first programming script.

I'm so grateful to all of you guys for help.

Regards,
Imran

thanks
 
Old 05-24-2007, 08:20 PM   #12
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
as I've mentioned before that i'm using Anjuta and it shows me the following command

gcc -Wall -g -g -O2 -o Test main.0

where will -lpcap go?

thanks
 
Old 05-24-2007, 09:03 PM   #13
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by ilnli
where will -lpcap go?
It can go anywhere on that line except between the two tokens “-o Test”.
 
Old 05-26-2007, 06:47 PM   #14
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
Thanks a lot all of you, it working now
 
  


Reply



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
Wireless router with sniffer using Linux Sunshine_54 Linux - Wireless Networking 1 10-17-2006 07:06 PM
I need Linux sniffer olivila1 Linux - Software 4 09-14-2005 09:16 AM
I need Linux sniffer olivila1 Linux - Software 2 09-14-2005 08:26 AM
linux sniffer mgyildiz Linux - Software 10 04-07-2004 10:52 PM
where can i find sniffer program on Linux Babba Linux - Newbie 1 01-24-2003 02:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:50 AM.

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
Open Source Consulting | Domain Registration