tcpdump mailing list archives

pcap_compile() causes a segmentation fault on Ubuntu


From: Selçuk Cevher <cevhers () gmail com>
Date: Tue, 14 Dec 2010 11:05:31 +0200

Hi All,

The following code fragment causes a segmentation fault in Ubuntu when
pcap_compile() is executed in setupFilterExpression():

*int main()
{
    char errbuf[PCAP_ERRBUF_SIZE];

    vector<string> devNames;
    listAllDevices(devNames, errbuf);//list the device names

    pcap_t* handle;//sniffing session handle
    bpf_u_int32 netMask;//net mask of the device to be opened
    bpf_u_int32 ipAddress;//ip address of the device to be opened
    openNetworkDevice(handle, devNames, &netMask, &ipAddress, errbuf);//open
the device for sniffing

    string exp("ip");
    struct bpf_program fp;//the compiled filter expression

    if( setupFilterExpression(handle, exp, &fp, netMask) == -1 )//set up
filter expression for packets
    {
        cout << "Could not set up filter expression" << endl;
        return(-1);
    }

    return(0);
}*

*int setupFilterExpression(pcap_t* handle, string exp, struct bpf_program*
fp, bpf_u_int32& netMask)
{
    if(pcap_compile(handle, fp, exp.c_str(), 0, netMask) == -1)
<<<<<<-------------- segmentation fault
    {
        cout << "Couldn't parse filter " << exp << ":" <<
pcap_geterr(handle) <<endl;
        return -1;
    }

    if(pcap_setfilter(handle, fp) == -1)
    {
        cout << "Couldn't install filter " << exp << ":" <<
pcap_geterr(handle) <<endl;
        return -1;
    }

    cout << "Succesfull setup of filter expression: " << exp << endl;
    return 0;
}*

If  you need to see the sources for listAllDevices() and openNetworkDevice()
as well, I can post them.

What may cause pcap_compile() to crash ?

I am using Ubuntu 10.04, and, as far as I know, this filtering mechanism may
not be supported in some kernels.

Thanks.
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: