tcpdump mailing list archives
SV: segfault in pcap_snapshot
From: Karl Sjödahl <karlsjod01 () student kau se>
Date: Mon, 23 Feb 2004 00:21:08 +0100
Hi.
Ok it snuk in an error in my code when i wrote it in the mail (mailbox
aint same as the codebox..).
The line is as u said and checks if p = null.
p is an pcap_t *p.
Here is the code more specific:
pcap_t *p;
<snip>
p = pcap_open_live(device, BUFSIZ, PROMISC, 0, errbuf);
if(p = NULL)
{
fprintf(stderr, "pcap_open_live() failed: %s\n",
errbuf);
exit(EXIT_FAILURE);
}
if(pcap_lookupnet(device, &local_net, &netmask, errbuf) == ERROR)
{
fprintf(stderr, "pcap_lookupnet() failed: %s\n",
errbuf);
pcap_close(p);
exit(EXIT_FAILURE);
}
if(pcap_compile(p, &filter_code, TESTFILTER, 0, netmask) == ERROR)
{
fprintf(stderr, "pcap_compile() failed: %s\n",
pcap_geterr(p));
pcap_close(p);
exit(EXIT_FAILURE);
}
printf("After pcap_compile()n");
/* here the segfault is */
if(pcap_setfilter(p, &filter_code) == ERROR)
{
fprintf(stderr, "pcap_setfilter() failed: %s\n", pcap_geterr(p));
pcap_close(p);
exit(EXIT_FAILURE);
}
....
// Dunceor
-----Ursprungligt meddelande-----
Från: owner-tcpdump-workers () sandelman ottawa on ca
[mailto:owner-tcpdump-workers () sandelman ottawa on ca] För Guy Harris
Skickat: den 22 februari 2004 23:58
Till: Karl Sjödahl
Kopia: tcpdump-workers () tcpdump org
Ämne: Re: [tcpdump-workers] segfault in pcap_snapshot
On Sun, Feb 22, 2004 at 11:35:21PM +0100, Karl Sjödahl wrote:
if(pcap_open_live(device, BUFSIZ, PROMISC, 0, errbuf) == -1)
{
error handling
}
"pcap_open_live()" doesn't return an integer, it returns a "pcap_t *" on
success, and NULL on failure; the "pcap_t *" is what you have to use in
subsequent calls to "pcap_compile()", "pcap_setfilter()",
"pcap_dispatch()"/"pcap_loop()"/"pcap_next()", etc..
Thus, that call should be
p = pcap_open_live(device, BUFSIZ, PROMISC, 0, errbuf);
if (p == NULL
{
error handling
}
and that "p" (which should be a "pcap_t *") is what should be used in
subsequent calls such as
if(pcap_compile(p, &filter_code, TESTFILTER, 0, netmask) == -1)
{
error handling
}
if(pcap_setfilter(p, &filter_code) == -1)
{
error handling
}
- 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 --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.593 / Virus Database: 376 - Release Date: 2004-02-20 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.593 / Virus Database: 376 - Release Date: 2004-02-20 - 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:
- segfault in pcap_snapshot Karl Sjödahl (Feb 22)
- Re: segfault in pcap_snapshot Guy Harris (Feb 22)
- SV: segfault in pcap_snapshot Karl Sjödahl (Feb 22)
- Re: segfault in pcap_snapshot Guy Harris (Feb 22)
