libpcap programming issues
libpcap programming issues
- Subject: libpcap programming issues
- From: Syphor <email@hidden>
- Date: Fri, 29 Aug 2003 21:10:17 +1000
Dear list,
Can you all help me out with the following code. I can't figure out
whats wrong.. I'm just trying to print out the ether type... though I
always get a BUS ERROR when i run the program. I compile the following
with this command:
cc main.c -o run -lpcap
Anyway here is the code:
#include <stdio.h>
#include <pcap.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/ip.h>
#include <net/ethernet.h>
int main( int argc, char* argv ) {
char *dev; /* The device */
char errbuf[PCAP_ERRBUF_SIZE]; /* The error buffer for pcap */
pcap_t *sess; /* The pcap session */
struct pcap_pkthdr header; /* The header that pcap gives us */
const u_char *packet; /* The actual packet */
struct ether_header *ethernet;
/* Define the device */
dev = "ppp0";
/* Open the device in promiscuous mode */
if ( (sess = pcap_open_live( dev, BUFSIZ, 1, 1, errbuf )) == NULL )
{
printf("%s\n", errbuf);
exit(1);
}
/* Get a packet */
packet = pcap_next(sess, &header);
ethernet = (struct ether_header*)(packet);
printf("%i", ethernet->ether_type);
return(0);
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.