mirror of
https://github.com/haad/proxychains.git
synced 2026-09-13 18:45:50 +05:00
Remove THREAD_SAFE ifdefs and use macros for it. Is there any reason to not require threads by default ?
This commit is contained in:
parent
fe8672eab6
commit
cdec339f11
32
src/core.c
32
src/core.c
@ -33,10 +33,6 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdarg.h>
|
||||
#ifdef THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
pthread_mutex_t internal_ips_lock;
|
||||
#endif
|
||||
|
||||
#include "core.h"
|
||||
#include "common.h"
|
||||
@ -48,7 +44,6 @@ extern unsigned int remote_dns_subnet;
|
||||
|
||||
internal_ip_lookup_table internal_ips = {0, 0, NULL};
|
||||
|
||||
|
||||
uint32_t dalias_hash(char* s0) {
|
||||
unsigned char* s = (void*) s0;
|
||||
uint_fast32_t h = 0;
|
||||
@ -69,16 +64,16 @@ uint32_t index_from_internal_ip(ip_type internalip) {
|
||||
|
||||
char* string_from_internal_ip(ip_type internalip) {
|
||||
char* res = NULL;
|
||||
#ifdef THREAD_SAFE
|
||||
pthread_mutex_lock(&internal_ips_lock);
|
||||
#endif
|
||||
|
||||
proxychains_mutex_lock(&internal_ips_lock);
|
||||
|
||||
uint32_t index = index_from_internal_ip(internalip);
|
||||
if(index < internal_ips.counter)
|
||||
res = internal_ips.list[index]->string;
|
||||
#ifdef THREAD_SAFE
|
||||
pthread_mutex_unlock(&internal_ips_lock);
|
||||
#endif
|
||||
return res;
|
||||
|
||||
proxychains_mutex_unlock(&internal_ips_lock);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
in_addr_t make_internal_ip(uint32_t index) {
|
||||
@ -788,9 +783,7 @@ struct hostent* proxy_gethostbyname(const char *name)
|
||||
|
||||
hash = dalias_hash((char*) name);
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
pthread_mutex_lock(&internal_ips_lock);
|
||||
#endif
|
||||
proxychains_mutex_lock(&internal_ips_lock);
|
||||
|
||||
// see if we already have this dns entry saved.
|
||||
if(internal_ips.counter) {
|
||||
@ -837,10 +830,7 @@ struct hostent* proxy_gethostbyname(const char *name)
|
||||
|
||||
have_ip:
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
pthread_mutex_unlock(&internal_ips_lock);
|
||||
#endif
|
||||
|
||||
proxychains_mutex_unlock(&internal_ips_lock);
|
||||
|
||||
strncpy(addr_name, name, sizeof(addr_name));
|
||||
|
||||
@ -849,9 +839,7 @@ struct hostent* proxy_gethostbyname(const char *name)
|
||||
return &hostent_space;
|
||||
|
||||
err_plus_unlock:
|
||||
#ifdef THREAD_SAFE
|
||||
pthread_mutex_unlock(&internal_ips_lock);
|
||||
#endif
|
||||
proxychains_mutex_unlock(&internal_ips_lock);
|
||||
return NULL;
|
||||
}
|
||||
int proxy_getaddrinfo(const char *node, const char *service,
|
||||
|
||||
17
src/core.h
17
src/core.h
@ -37,10 +37,6 @@ typedef struct {
|
||||
} internal_ip_lookup_table;
|
||||
|
||||
extern internal_ip_lookup_table internal_ips;
|
||||
#ifdef THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
extern pthread_mutex_t internal_ips_lock;
|
||||
#endif
|
||||
|
||||
/*error codes*/
|
||||
typedef enum {
|
||||
@ -147,4 +143,17 @@ struct hostent* proxy_gethostbyname(const char *name);
|
||||
# define PDEBUG(fmt, args...)
|
||||
#endif
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
pthread_mutex_t internal_ips_lock;
|
||||
|
||||
# define proxychains_mutex_lock(mutex) pthread_mutex_lock(mutex)
|
||||
# define proxychains_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
|
||||
# define proxychains_mutex_init(mutex) pthread_mutex_init(mutex, NULL)
|
||||
#else
|
||||
# define proxychains_mutex_lock()
|
||||
# define proxychains_mutex_unlock()
|
||||
# define proxychains_mutex_init()
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -53,13 +53,13 @@ static int init_l = 0;
|
||||
|
||||
unsigned int proxychains_proxy_count = 0;
|
||||
unsigned int proxychains_max_chain = 1;
|
||||
unsigned int remote_dns_subnet = 224;
|
||||
|
||||
localaddr_arg localnet_addr[MAX_LOCALNET];
|
||||
chain_type proxychains_ct;
|
||||
proxy_data proxychains_pd[MAX_CHAIN];
|
||||
|
||||
size_t num_localnet_addr = 0;
|
||||
unsigned int remote_dns_subnet = 224;
|
||||
|
||||
static inline void get_chain_data(proxy_data *pd, unsigned int *proxy_count,
|
||||
chain_type *ct);
|
||||
@ -68,12 +68,13 @@ static void init_lib(void);
|
||||
/*
|
||||
* Initialize libproxychains.
|
||||
*/
|
||||
static void init_lib(void)
|
||||
static void
|
||||
init_lib(void)
|
||||
{
|
||||
#ifdef THREAD_SAFE
|
||||
pthread_mutex_init(&internal_ips_lock, NULL);
|
||||
#endif
|
||||
/* read the config file */
|
||||
/* Initialize mutex for internal ip list */
|
||||
proxychains_mutex_init(&internal_ips_lock);
|
||||
|
||||
/* Read the config file */
|
||||
get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
|
||||
|
||||
proxychains_write_log(LOG_PREFIX "DLL init\n");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user