From b10eefd47f979a339aaeb247bf47cc333aa7ba91 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Fri, 5 May 2023 04:32:51 -0700 Subject: Make some static variables thread-local. This should make some functions thread-safe, even if it doesn't make them fully-reentrant; at least some of them would requiree API changes to full reentrancy. This should fix #1174. --- nametoaddr.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'nametoaddr.c') diff --git a/nametoaddr.c b/nametoaddr.c index a746cb6d..6f1dafe9 100644 --- a/nametoaddr.c +++ b/nametoaddr.c @@ -135,6 +135,8 @@ #include #include "nametoaddr.h" +#include "thread-local.h" + #ifdef HAVE_OS_PROTO_H #include "os-proto.h" #endif @@ -806,16 +808,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"); -- cgit v1.2.3