Note that there are some explanatory texts on larger screens.

plurals
  1. POerror running a simple libpcap example
    text
    copied!<p>I am trying to compile a simple libpcap example, </p> <pre><code>#include&lt;stdio.h&gt; #include&lt;pcap.h&gt; int main(int argc, char *argv[]) { char *dev; char errbuf[PCAP_ERRBUF_SIZE]; struct bpf_program fp; char filter_exp[] = "port 23"; bpf_u_int32 mask; bpf_u_int32 net; dev = pcap_lookupdev(errbuf); if (dev == NULL ) { fprintf(stderr, "couldn't find default device: %s\n", errbuf); return (2); } printf("Device: %s\n", dev); //LOOKUP NETMASK and IP if (pcap_lookupnet(dev, &amp;net, &amp;mask, errbuf) == -1) { fprintf(stderr, "can't get netmask for device %s\n", dev); net = 0; mask = 0; } printf("lookup\n"); pcap_t *handle; printf("handle defined\n"); handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf); printf("opened\n"); if (handle = NULL ) { fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf); return (2); } printf("pcap_open\n"); if ((pcap_compile(handle, &amp;fp, filter_exp, 1, net)) == -1) { printf("compile error block entered\n"); fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle)); return (2); } printf("compiled\n"); if (pcap_setfilter(handle, &amp;fp) == -1) { fprintf(stderr, "couldn't install filter %s: %s\n", filter_exp, pcap_geterr(handle)); return (2); } printf("after filter\n"); return (0); } </code></pre> <p>It compiles without error, but when I try to run it, I'm getting segmentation fault message or if I try to run it with root permission, I don't get the message but the program stops after printing </p> <pre><code>Device: eth0 lookup handle defined opened pcap_open </code></pre> <p>Can you please help me with this, I'm confused as to why this error happens. Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload