Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 25th, 2006, 9:55 PM   #1
Intimidat0r
Hobbyist Programmer
 
Intimidat0r's Avatar
 
Join Date: May 2005
Location: Don't know, but the padded walls are a nice touch.
Posts: 126
Rep Power: 0 Intimidat0r is an unknown quantity at this point
Send a message via ICQ to Intimidat0r Send a message via AIM to Intimidat0r Send a message via MSN to Intimidat0r Send a message via Yahoo to Intimidat0r
Trying to make a simple packet sniffer

So this is my first time out with libpcap. And sadly this is not compiling:

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

#define NUM_PACKETS 10

void pcap_handler_cb(u_char *user, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data)
{
	printf("Got packet: %d bytes captured:", pkt_header->caplen);
	if (pkt_header->caplen > 2)
		printf("%02X %02X ... \n", pkt_data[0], pkt_data[1]);
	else
		printf("...\n");
}

int main(int argc, char *argv[])
{
	char errbuf[PCAP_ERRBUF_SIZE];
	char *default_device;
	pcap_t* ph;
	default_device = pcap_lookupdev(errbuf);
	if (!default_device)
	{
		fprintf(stderr, "%s\n", errbuf);
		exit(1);
	}
	printf("Opening %s\n", default_device);
	ph = pcap_open_live(default_device, BUFSIZ, 1, 0, errbuf);
	printf("Capturing on %s\n", default_device);
	pcap_loop(ph, NUM_PACKETS, pcap_handler_cb, NULL);
	printf("Done.\n");
	return 0;
}

And when I try to compile it I get this:

Quote:
Originally Posted by my terminal
intimidat0r@gibson:~$ cc simpsniff.c
simpsniff.c: In function ‘main’:
simpsniff.c:24: warning: incompatible implicit declaration of built-in function ‘exit’
/tmp/ccCQpoev.o: In function `main':simpsniff.c.text+0x89): undefined reference to `pcap_lookupdev'
:simpsniff.c.text+0xfe): undefined reference to `pcap_open_live'
:simpsniff.c.text+0x137): undefined reference to `pcap_loop'
collect2: ld returned 1 exit status
intimidat0r@gibson:~$
I used to get a lot more errors until I installed libpcap0.8 and libpcap0.8-dev.

Now I only get these. Any idea how to fix 'er?

Thanks.
__________________
Children in the dark cause accidents, and accidents in the dark cause children.

http://www.ronincoders.org
Intimidat0r is offline   Reply With Quote
Old Sep 25th, 2006, 10:12 PM   #2
niteice
Programmer
 
niteice's Avatar
 
Join Date: Aug 2005
Posts: 98
Rep Power: 4 niteice is on a distinguished road
Send a message via AIM to niteice
cc simpsnif.c -o simpsnif -l pcap
niteice is offline   Reply With Quote
Old Sep 25th, 2006, 10:18 PM   #3
Intimidat0r
Hobbyist Programmer
 
Intimidat0r's Avatar
 
Join Date: May 2005
Location: Don't know, but the padded walls are a nice touch.
Posts: 126
Rep Power: 0 Intimidat0r is an unknown quantity at this point
Send a message via ICQ to Intimidat0r Send a message via AIM to Intimidat0r Send a message via MSN to Intimidat0r Send a message via Yahoo to Intimidat0r
Thank you, that worked perfectly.
__________________
Children in the dark cause accidents, and accidents in the dark cause children.

http://www.ronincoders.org
Intimidat0r is offline   Reply With Quote
Old Sep 26th, 2006, 10:25 AM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
keep us informed of your progress (if you are going to continue development), cause i am interested in stuff like this :-)
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
very simple question. make button change number in edit box nickm Delphi 2 Apr 29th, 2006 11:47 PM
How would I make a simple macro Xero Other Programming Languages 3 Jan 28th, 2006 1:53 PM
Newbie: How to make simple Timer programe smith000monday Assembly 0 May 17th, 2005 3:54 AM
How do I make this work? simple problem gardon C++ 5 Feb 15th, 2005 8:34 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC