tcpdump mailing list archives

Re: Re: compile failed when using pcap, "undefined reference t


From: "Arthur Chen" <iamarthur60 () hotmail com>
Date: Sat, 29 Nov 2003 00:21:51 +0000

Alex and Jan,
    Thanks a lot for your kindly reply.
    I have solved the problem, that's because of link problem.
Redhat 9.0 will install libpcap to /usr/lib as both shared library object(libpcap.so files) and static archive(libpcap.a), Nevertheless, when you want to install a new pcap version, it will only create a static archive. When I compile my test program with gcc as, 'gcc -lpcap -o pcap_test.o pcap_test.c', it will link to the shared library.Therefore, although the new created libpcap.a will replace the old one of redhat, but the link step can not pass because it still using the old version pcaplib.so file. so we must tell the the gcc to compile and link to the new static archive file libpcap.a. The correct way to do this is: gcc -c pcap_test.c --------->compile and create a object file pcap_test.o gcc -o pcaptest pcap_test.o libpcap.a ----->tell gcc to link pcap_test.o to the libpcap.a, and create a exe file called 'pcaptest'

I am very curious that why we don't write these things into the tutorial of pcap, AND MAKE IT BECOMES SO TRICKY?


From: alex medvedev <alexm () pycckue org>
To: Arthur Chen <iamarthur60 () hotmail com>
CC: tcpdump-workers () tcpdump org
Subject: Re: [tcpdump-workers] Re: compile failed when using pcap, "undefined reference to `pcap_set_datalink"
Date: Fri, 28 Nov 2003 14:51:00 -0600 (CST)

hallo,

# nm libpcap.a | grep -i datalink

and see if it is compiled in (exported[?])
it may not be in your pcap library.
:)

for example, pcap_set_datalink is not on my debian.

-alexm
14:49 28/11/2003

On Fri, 28 Nov 2003, Arthur Chen wrote:

> Hi all,
>     now I have found part of the error.
> 1) my system is redhat 9.0, and I installed pcap with these steps:
>                 root# ./configure
>                 root# ./make
>                 root# ./make install
> with these steps, in the Makefile's item 'install:', it showed out these
> things to do
>            (a) copy libpcap.a to /usr/local/lib,
>            (b)copy pcap.h, pcap-named.h pcap-bpf.h to /usr/local/include
> 2) It seems the 'configure' shell is wrong,
> (a) copy libpcap.a to /usr/local/lib,----this should be copy to
> /usr/lib
>            (b)copy pcap.h, pcap-named.h pcap-bpf.h to
> /usr/local/include-----this is wrong, should be copy to /usr/include
>
> 3)But after I copied them to the correct place, I still can not compile, the
> error is still be:
> "undefined reference to 'pcap_set_datalink'"
> I have noticed that under the directory /usr/lib, there are several shared
> library files called libpcap.so,
> libpcap.so.0,libpcap.so.0.6,libpcap.so.0.6.2 , they might be the key
> problem---because when I make and instal the new PCAP library, I didn't see
> that there were any of these files be createdl:
>
> ----anybody help me!
>
>
>
>
>
>
> >From: "Arthur Chen" <iamarthur60 () hotmail com>
> >To: tcpdump-workers () tcpdump org
> >Subject: [tcpdump-workers] small program compile failed when using pcap,
> >"undefined reference to `pcap_set"
> >Date: Thu, 27 Nov 2003 23:00:02 +0000
> >
> >this small trying program can not compile, It said undefined reference to > >`pcap_set_datalink', but this function prototype was included in pcap.h and
> >was implemented in pcap.c! Any idea?
> >
> >     This is the error message:
> >
> >[root@ arthur]# gcc -lpcap -o pcap_test.o pcap_test.c
> >/tmp/ccViVFVU.o(.text+0xbb): In function `main':
> >: undefined reference to `pcap_set_datalink'
> >collect2: ld returned 1 exit status
> >[root@ arthur]#
> >
> >
> >      the source file is:
> >
> >#include <stdio.h>
> >#include <pcap.h>
> >//#include <pcap_int.h>
> >extern int     pcap_set_datalink(pcap_t *, int);
> >    int main()
> >    {
> >        pcap_t *handle;                       /* Session handle */
> >// char *dev; /* The device to sniff on */
> >        char errbuf[PCAP_ERRBUF_SIZE];        /* Error string */
> >        struct bpf_program filter;            /* The compiled filter */
> >// char filter_app[] = "port 23"; /* The filter expression */
> >        char filter_app[] = "ether[11]=0xcb || (ether[5]=0xcb)";
> >        bpf_u_int32 mask;                     /* Our netmask */
> >        bpf_u_int32 net;                      /* Our IP */
> > struct pcap_pkthdr header; /* The header that pcap gives
> >us */
> >        const u_char *packet;                 /* The actual packet */
> >        /* Define the device */
> >//        dev = pcap_lookupdev(errbuf);
> >char dev[]="eth0";
> >int errCode=0;
> >
> >bpf_u_int32 counter=0;
> >printf("the dev=%s\n",dev);
> >
> >        /* Find the properties for the device */
> >        pcap_lookupnet(dev, &net, &mask, errbuf);
> >       /* Open the session in promiscuous mode */
> >        handle = pcap_open_live(dev, BUFSIZ, 1, 0, errbuf);
> >       //printf("The data link is %d",(pcap_datalink(handle)));
> >pcap_set_datalink(handle, DLT_PPP_ETHER);
> >
> >if (errCode)
> >       printf("Set data link failed, error code=%d",errCode);
> >else
> >       printf("Set data link succeeded, ");
> >
> >       /* Compile and apply the filter */
> >//        pcap_compile(handle, &filter, filter_app, 0, net);
> >        pcap_compile(handle, &filter, filter_app, 0, net);
> >       pcap_setfilter(handle, &filter);
> >        /* Grab a packet */
> >
> >       packet = pcap_next(handle, &header);
> >        /* Print its length */
> >        printf("Jacked a packet with length of [%d]\n", header.len);
> >        /* And close the session */
> >for (; counter<header.len; counter++)
> >       printf("%3x", *(packet+counter));
> >
> >       pcap_close(handle);
> >
> >        return(0);
> >    }
> >
> >_________________________________________________________________
> >Help STOP SPAM with the new MSN 8 and get 2 months FREE*
> >http://join.msn.com/?page=features/junkmail
> >
> >-
> >This is the TCPDUMP workers list. It is archived at
> >http://www.tcpdump.org/lists/workers/index.html
> >To unsubscribe use
> >mailto:tcpdump-workers-request () tcpdump org?body=unsubscribe
>
> _________________________________________________________________
> The new MSN 8: advanced junk mail protection and 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
> -
> This is the TCPDUMP workers list. It is archived at
> http://www.tcpdump.org/lists/workers/index.html
> To unsubscribe use mailto:tcpdump-workers-request () tcpdump org?body=unsubscribe
>

-
This is the TCPDUMP workers list. It is archived at
http://www.tcpdump.org/lists/workers/index.html
To unsubscribe use mailto:tcpdump-workers-request () tcpdump org?body=unsubscribe

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus

-
This is the TCPDUMP workers list. It is archived at
http://www.tcpdump.org/lists/workers/index.html
To unsubscribe use mailto:tcpdump-workers-request () tcpdump org?body=unsubscribe


Current thread: