LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2005, 02:18 AM   #1
cynthia_thomas
LQ Newbie
 
Registered: Oct 2005
Posts: 28

Rep: Reputation: 15
in gcc compiler error: parse error before string constsnt


hi,
I got the following error when compiling a packet capture program. I checked it out with lot of people I not getting the problem.please help me .This is the first step in my project work.

[root@CORE-2-02 bin]# gcc testcap2.c
testcap2.c:3: parse error before string constant
testcap2.c:4:29: warning: extra tokens at end of #include directive
In file included from /usr/include/pcap.h:41,
from testcap2.c:4:
/usr/include/sys/time.h:62: parse error before '}' token

this is the code I am trying to complile.I have all the header files installed.

#include <stdio.h>
#include <stdlib.h>
extern "C" {
#include <pcap.h> }
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/if_ether.h>

int main(int argc, char **argv)
{
int i;
char *dev;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t* descr;
const u_char *packet;
struct pcap_pkthdr hdr;
struct ether_header *eptr;

u_char *ptr;


dev = pcap_lookupdev(errbuf);

if(dev == NULL)
{
printf("%s\n",errbuf);
exit(1);
}

printf("DEV: %s\n",dev);



descr = pcap_open_live(dev,BUFSIZ,0,-1,errbuf);


if(descr == NULL)
{
printf("pcap_open_live(): %s\n",errbuf);
exit(1);
}



packet = pcap_next(descr,&hdr);

if(packet == NULL)
{
printf("Didn't grab packet\n");
exit(1);
}



printf("Grabbed packet of length %d\n",hdr.len);
printf("Recieved at ..... %s\n",ctime((const time_t*)&hdr.ts.tv_sec));
printf("Ethernet address length is %d\n",ETHER_HDR_LEN);


eptr = (struct ether_header *) packet;


if (ntohs (eptr->ether_type) == ETHERTYPE_IP)
{
printf("Ethernet type hex:%x dec:%d is an IP packet\n",
ntohs(eptr->ether_type),
ntohs(eptr->ether_type));
}else if (ntohs (eptr->ether_type) == ETHERTYPE_ARP)
{
printf("Ethernet type hex:%x dec:%d is an ARP packet\n",
ntohs(eptr->ether_type),
ntohs(eptr->ether_type));
}else {
printf("Ethernet type %x not IP", ntohs(eptr->ether_type));
exit(1);
}


ptr = eptr->ether_dhost;
i = ETHER_ADDR_LEN;
printf(" Destination Address: ");
do{
printf("%s%x",(i == ETHER_ADDR_LEN) ? " " : ":",*ptr++);
}while(--i>0);
printf("\n");

ptr = eptr->ether_shost;
i = ETHER_ADDR_LEN;
printf(" Source Address: ");
do{
printf("%s%x",(i == ETHER_ADDR_LEN) ? " " : ":",*ptr++);
}while(--i>0);
printf("\n");

return 0;
}

thanks
regards
cynthia
 
Old 10-20-2005, 02:29 AM   #2
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Remove the extern "C" { before the include of pcap.h and the } after.

When compiling your program, add the option -lpcap to tell gcc to link your program with the pcap library.

Last edited by zhangmaike; 10-20-2005 at 02:30 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
gcc compiler error maheshbmane Programming 3 09-02-2005 10:23 PM
How do I fix this assignment problem C++ compiler error in GCC? Erik_the_Red Programming 4 07-12-2005 10:36 AM
Problem with gcc: configure: error: C compiler cannot create executable abefroman SUSE / openSUSE 4 05-11-2005 07:12 PM
Gcc compiler error Yoda Sabre Linux - Software 9 08-16-2004 04:53 PM
gcc compiler error / linux headers install help SciYro Linux - Software 2 12-07-2003 02:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:38 PM.

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