LinuxQuestions.org
Review your favorite Linux distribution.
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 06-24-2006, 04:54 AM   #1
Al-xkon
LQ Newbie
 
Registered: Jun 2006
Posts: 10

Rep: Reputation: 0
Sniffer implementation


Hi
Does anyone know the basics of what is needed in order to implement a sniffer in Linux.
I thinking f developing it in C and C++ but i can't find any information on how to start.
an help apprecited

Thanks in advance
 
Old 06-24-2006, 05:46 AM   #2
cupubboy
Member
 
Registered: May 2003
Location: Bucharest,Romania
Distribution: Fedora Core 7
Posts: 109

Rep: Reputation: 15
I think you should take a look at libpcap .. http://www.tcpdump.org/
 
Old 06-24-2006, 06:26 AM   #3
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
Just one question: what kind of sniffer ?
 
Old 06-25-2006, 01:15 PM   #4
fedora4002
Member
 
Registered: Mar 2004
Posts: 135

Rep: Reputation: 15
You can use perl or python package for libpcap and it is very easy to do it.
 
Old 06-27-2006, 07:21 AM   #5
alred
Member
 
Registered: Mar 2005
Location: singapore
Distribution: puppy and Ubuntu and ... erh ... redhat(sort of) :( ... + the venerable bsd and solaris ^_^
Posts: 658
Blog Entries: 8

Rep: Reputation: 31
if you are refering to networking stuffs and if you are going to use libpcap , heres something simple i collected from the net quite sometime ago , not sure whether its accurate but sometimes i use it just to make sure things are moving around at least ... its in c ...

Code:
//cc -o 00 pcap6.c -lpcap

#include <ctype.h> 
#include<stdio.h>
#include<pcap.h>
int main(int argc,char *argv[])
{
int i;
char errbuf[PCAP_ERRBUF_SIZE];
char dev[]="eth0"; // set the device to listen on lo or eth0
bpf_u_int32 mask;
bpf_u_int32 net;
pcap_t *descr;
const u_char *packet;
struct pcap_pkthdr hdr;
    
printf("\nOpen Device = %s\n\n",dev);
    
descr=pcap_open_live(dev,BUFSIZ,1,0,errbuf);  
  
for (;;){

 packet=(u_char *)pcap_next(descr,&hdr);
    
if (packet != NULL) {

 fprintf(stdout,"\n==================================================================================\n"); 
for (i=0; i <= hdr.len; i++) {
  if isgraph(*packet) printf("%c",*packet); else

    printf(".",*packet);
 //printf("%c",*packet);                          
 //    printf("%.2X",*packet);
          packet++;
}
   fprintf(stdout,"\n==================================================================================\n"); 
       
}
  printf("      capturing packet of length [%d] from device [%s] total of i run = %i\n",hdr.len,dev,i); 
}
 return(0); 
}
you need to take a look at tcpdump websites ...



//dont ask me how it actually works ^_^

.
 
Old 06-28-2006, 11:30 AM   #6
Al-xkon
LQ Newbie
 
Registered: Jun 2006
Posts: 10

Original Poster
Rep: Reputation: 0
well i found information on libcap and tcpdump but i was hoping i could develop my own methods in spite of using libcap.
I think i should use raw sockets in Linux in order to implement it. at least for developing a ping program i should use raw sockets.
something similar i think i have to do.
 
Old 06-28-2006, 12:33 PM   #7
cupubboy
Member
 
Registered: May 2003
Location: Bucharest,Romania
Distribution: Fedora Core 7
Posts: 109

Rep: Reputation: 15
I maybe way off .. but so is ping related to a sniffer
 
Old 06-29-2006, 10:41 AM   #8
fedora4002
Member
 
Registered: Mar 2004
Posts: 135

Rep: Reputation: 15
The Sniffer can catch everything passing along the wire including PING traffic.
 
Old 06-30-2006, 03:50 AM   #9
Al-xkon
LQ Newbie
 
Registered: Jun 2006
Posts: 10

Original Poster
Rep: Reputation: 0
well the only way i found in order to be able to analyze the network packets received is raw sockets.i can't find any other way of how to create it.
i mentioned ping because ping also analyzes packets an a version i found was created with sockets.
 
Old 06-30-2006, 08:53 AM   #10
fedora4002
Member
 
Registered: Mar 2004
Posts: 135

Rep: Reputation: 15
PING is a program created to test the "liveness" of a host. Basically, it creates ICMP query and reply traffic.
 
Old 07-06-2006, 05:45 AM   #11
Al-xkon
LQ Newbie
 
Registered: Jun 2006
Posts: 10

Original Poster
Rep: Reputation: 0
Finally i found how to create,and it seems it isvery simple.
the basin is that you create a socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL));
The rest i'm looking for them but this is the basic idea.
 
  


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
How to use a sniffer? Titanas25 Linux - Newbie 3 05-13-2006 10:41 AM
I need Linux sniffer olivila1 Linux - Software 2 09-14-2005 08:26 AM
Which is the best sniffer? abefroman Linux - Security 3 05-07-2005 03:56 AM
Packet sniffer lyonsd Linux - Networking 2 12-28-2004 09:45 AM
Port Sniffer sykkn Linux - Networking 1 10-01-2001 01:55 PM

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

All times are GMT -5. The time now is 11:31 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