LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How can I Write a sniffer program in System Programming (https://www.linuxquestions.org/questions/programming-9/how-can-i-write-a-sniffer-program-in-system-programming-422434/)

touqeeransar 03-07-2006 07:09 AM

How can I Write a sniffer program in System Programming
 
Hi guys can you help me How can I build a sniffer program.

Wim Sturkenboom 03-07-2006 09:44 AM

a generic google on sniffer c program

I did not specifically search for rs232 sniffing, network sniffing or whatever, only tried to find some c-code.

touqeeransar 03-07-2006 11:39 AM

I am talking about Network Sniffing

nx5000 03-07-2006 11:51 AM

Use libcap. It uses Berkeley packet filter

Code:

#include <pcap.h>
#include <net/if.h>
#include <netinet/in.h>

Use pcap_lookupdev to choose the interface
Use pcap_open_live to get a packet capture descriptor
Use pcap_lookupnet to get network information from interface
Use pcap_compile to transform your filter text into a BPF filter
Use pcap_setfilter to apply the filter
Use pcap_loop to set a function that will be called on every packet matching the filter
Compile with -lpcap

man pcap will give you more information

The other solution would be to redo everything but I don't think its interesting to reinvent the wheel..

Have fun


All times are GMT -5. The time now is 04:07 AM.