diff options
Diffstat (limited to 'nametoaddr.c')
-rw-r--r-- | nametoaddr.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/nametoaddr.c b/nametoaddr.c index a746cb6d..67d31343 100644 --- a/nametoaddr.c +++ b/nametoaddr.c @@ -135,6 +135,8 @@ #include <pcap/namedb.h> #include "nametoaddr.h" +#include "thread-local.h" + #ifdef HAVE_OS_PROTO_H #include "os-proto.h" #endif @@ -465,40 +467,33 @@ pcap_nametoport(const char *name, int *port, int *proto) int pcap_nametoportrange(const char *name, int *port1, int *port2, int *proto) { - u_int p1, p2; char *off, *cpy; int save_proto; - if (sscanf(name, "%d-%d", &p1, &p2) != 2) { - if ((cpy = strdup(name)) == NULL) - return 0; + if ((cpy = strdup(name)) == NULL) + return 0; - if ((off = strchr(cpy, '-')) == NULL) { - free(cpy); - return 0; - } + if ((off = strchr(cpy, '-')) == NULL) { + free(cpy); + return 0; + } - *off = '\0'; + *off = '\0'; - if (pcap_nametoport(cpy, port1, proto) == 0) { - free(cpy); - return 0; - } - save_proto = *proto; + if (pcap_nametoport(cpy, port1, proto) == 0) { + free(cpy); + return 0; + } + save_proto = *proto; - if (pcap_nametoport(off + 1, port2, proto) == 0) { - free(cpy); - return 0; - } + if (pcap_nametoport(off + 1, port2, proto) == 0) { free(cpy); + return 0; + } + free(cpy); - if (*proto != save_proto) - *proto = PROTO_UNDEF; - } else { - *port1 = p1; - *port2 = p2; + if (*proto != save_proto) *proto = PROTO_UNDEF; - } return 1; } @@ -806,16 +801,18 @@ pcap_ether_aton(const char *s) #ifndef HAVE_ETHER_HOSTTON /* * Roll our own. - * XXX - not thread-safe, because pcap_next_etherent() isn't thread- - * safe! Needs a mutex or a thread-safe pcap_next_etherent(). + * + * This should be thread-safe, as we define the static variables + * we use to be thread-local, and as pcap_next_etherent() does so + * as well. */ u_char * pcap_ether_hostton(const char *name) { register struct pcap_etherent *ep; register u_char *ap; - static FILE *fp = NULL; - static int init = 0; + static thread_local FILE *fp = NULL; + static thread_local int init = 0; if (!init) { fp = fopen(PCAP_ETHERS_FILE, "r"); |