PDA

View Full Version : Compile problem


danathane
06-03-2008, 08:29 AM
Hello!!

I have a problem compiling my program.
It has warnings, and it doesn't make any link for pcap_open_offline and other pcap function. I have no lib missing error or other. So I d'ont understand.

complie command : gcc file.c
Here is my code :




#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <pcap.h>
#include <pcap-bpf.h>

#include <netinet/in.h>
#include <net/ethernet.h>
#include <netinet/ether.h>
#include <netinet/ip.h>


int main(int argn, char **argv)
{

pcap_t *desc;
const u_char *packet_1;
const u_char *packet_2;
struct pcap_pkthdr hdr;
char errbuf[PCAP_ERRBUF_SIZE];
struct bpf_program bp ;
char * buff =NULL;
struct ethhdr *EtherHdr_1;
struct ethhdr *EtherHdr_2;
bpf_u_int32 netmask=32;



FILE *fp=fopen("./fichier/adresses_ip_mac.htm","w");


if(fp==NULL)
printf("Ouverture de fichier impossible\n");

desc = pcap_open_offline("./fichier/fichiertest.pcap", errbuf);

if (desc == NULL)
printf("pcap_open_offline: %s\n", errbuf), exit(2);

packet_1 = pcap_next(desc,&hdr);
EtherHdr_1 = (struct etherhdr *)packet_1;

packet_2 = packet_1;
EtherHdr_2 = (struct etherhdr *)packet_2;

while (EtherHdr_1->h_source == EtherHdr_2->h_source && (packet_2=pcap_next(desc,&hdr)))
{
EtherHdr_2 = (struct etherhdr *)packet_2;
}

printf("Adresse Mac 1 :%s\n", ether_ntoa((struct ether_addr *)EtherHdr_1->h_dest));
fclose(fp);
pcap_close(desc);


system ("pause");


}




Solution : gcc file.c -o file -lpcap


If you have ideas. I take it.

luckyr13
06-04-2008, 07:57 AM
If u can tell me what are the compile problems (what kind of warnings do u have?) that u have maybe i could help a little more :) ... actually u post after your code:

Solution : gcc file.c -o file -lpcap

This means that you already find a solution? what do you want the programs do? ... i suggest the next links anyway... maybe could help:

http://www.tcpdump.org/pcap.htm
http://www.geocities.com/amit_saha_works/linux/html/sniff.html
http://linux.drivein-jim.net/128/saha.html
http://www.deepthought.org/~ngallaher/c/packet/section1.html