title: How to solve "Segmentation fault (core dumped)"
body: <p>Here is my code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;pcap.h&gt;
  
  void pcapdump(u_char* argument,const struct pcap_pkthdr* packet_header,const u_char*   packet_content);
  
  int main()
  {
      int i=0, devid,ret;
      char errbuf[PCAP_ERRBUF_SIZE];
      pcap_t *handle;
      bpf_u_int32 mask;
      bpf_u_int32 net;
      int num_packets=500;
      pcap_dumper_t *p;
      pcap_if_t *alldevs;
      pcap_if_t *pdev; 
      const struct pcap_pkthdr *packet_header;
      const u_char *packet_content;
  
      ret=pcap_findalldevs(&amp;alldevs,errbuf);
      if(ret=-1)
      {
          printf("%s",errbuf);
      };
  
      for (pdev = alldevs;pdev;pdev=pdev-&gt;next)  
          printf("#%d: %s %s %s\n",++i,pdev-&gt;name,pdev-&gt;description,pdev-&gt;description);
  
      printf("select a device: "); 
      scanf("%d", &amp;devid);  
      pdev=alldevs; 
      while (--devid)
      pdev=pdev-&gt;next;  
      printf("Selected %s \n", pdev-&gt;name);  
  
  
     if (pcap_lookupnet(pdev-&gt;name,&amp;net,&amp;mask,errbuf)==-1)
     {
          printf("Couldn't get netmask for device %s: %s\n", pdev-&gt;name, errbuf);
          net = 0;
          mask = 0;
      };
  
      handle=pcap_open_live(pdev-&gt;name,BUFSIZ,1,0,errbuf);
      printf("Number of packets: %d\n", num_packets);
      pcap_dump_open(handle,"/home/jiangzhongbai/capturefiles/10.pcapng");
      pcap_loop(handle,num_packets,pcap_dump,NULL);
      pcap_dump_close(p);
      pcap_freealldevs(alldevs); 
      pcap_close(handle);
      printf("\nCapture complete.\n");
      return 0;
  }
  </code></pre>
  
  <p>The result is </p>
  
  <ul>
  <li>eth0 (null) (null)</li>
  <li>wlan0 (null) (null)</li>
  <li>nflog Linux netfilter log (NFLOG) interface Linux netfilter log (NFLOG) interface</li>
  <li>nfqueue Linux netfilter queue (NFQUEUE) interface Linux netfilter queue (NFQUEUE) interface</li>
  <li>any Pseudo-device that captures on all interfaces Pseudo-device that captures on all interfaces</li>
  <li>lo (null) (null)</li>
  </ul>
  
  <p>select a device: 2
  Selected wlan0 
  Number of packets: 500
  Segmentation fault (core dumped)</p>
  
  <p>I think there is something wrong with the functionpcap_dump_open.But I don't know how to solve the problem of Segmentation fault (core dumped).Please help me.</p>