Hi,
The changelog for libpcap 0.7.1 seems to indicate that pcap_compile is
reentrant.  I tested it on a RH 7.2 box (2.4.18-5 kernel,
glibc-2.2.5-39) and found it segfaulting about half the time when
using pthreads.  Is this a known issue?  How much of libpcap isn't
thread safe? I'm most concerned with pcap_dispatch...

Thanks,
david

---segfaulting program----
#include <pthread.h>
#include <stdio.h>
#include <pcap.h>

pcap_t *p;
bpf_u_int32 mask;
bpf_u_int32 net;

void *foo(void *null)
{
 char perr[PCAP_ERRBUF_SIZE];
 char textfilter[1024];
 struct bpf_program filter;

 printf("Thread %d starting\n", pthread_self());
 sprintf(textfilter, "tcp and port %d\n", pthread_self() & 0xffff);
 pcap_compile(p, &filter, textfilter, 1, net);

 printf("Thread %d ending\n", pthread_self());
 fflush(stdout);
}
void main()
{
 pthread_t t[100];
 char perr[PCAP_ERRBUF_SIZE];
 int i;

 p = pcap_open_live("eth0", 1600, 1, 0, perr);
 if(p == NULL){
   printf("%s\n", perr);
 }
 pcap_lookupnet("eth0", &net, &mask, perr);

 for(i = 0; i< 100; i++){
   if(pthread_create(&(t[i]), NULL, foo, NULL) != 0){
     perror("pthread_create()\n");
   }
 }
 for(i = 0; i < 100; i++){
   pthread_join(t[i], NULL);
 }
 printf("DONE\n");
}

-
This is the TCPDUMP workers list. It is archived at
http://www.tcpdump.org/lists/workers/index.html
To unsubscribe use mailto:[EMAIL PROTECTED]?body=unsubscribe

Reply via email to