mirror of
				https://github.com/rofl0r/proxychains-ng.git
				synced 2025-11-04 00:56:03 +00:00 
			
		
		
		
	use macros for mutex stuff
This commit is contained in:
		
							
								
								
									
										21
									
								
								src/core.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								src/core.c
									
									
									
									
									
								
							@@ -69,15 +69,11 @@ 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
 | 
			
		||||
	uint32_t index = index_from_internal_ip(internalip);
 | 
			
		||||
	MUTEX_LOCK(&internal_ips_lock);
 | 
			
		||||
	if(index < internal_ips.counter)
 | 
			
		||||
		res = internal_ips.list[index]->string;
 | 
			
		||||
#ifdef THREAD_SAFE
 | 
			
		||||
	pthread_mutex_unlock(&internal_ips_lock);
 | 
			
		||||
#endif
 | 
			
		||||
	MUTEX_UNLOCK(&internal_ips_lock);
 | 
			
		||||
	return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -790,9 +786,7 @@ struct hostent *proxy_gethostbyname(const char *name) {
 | 
			
		||||
 | 
			
		||||
	hash = dalias_hash((char *) name);
 | 
			
		||||
 | 
			
		||||
#ifdef THREAD_SAFE
 | 
			
		||||
	pthread_mutex_lock(&internal_ips_lock);
 | 
			
		||||
#endif
 | 
			
		||||
	MUTEX_LOCK(&internal_ips_lock);
 | 
			
		||||
 | 
			
		||||
	// see if we already have this dns entry saved.
 | 
			
		||||
	if(internal_ips.counter) {
 | 
			
		||||
@@ -839,10 +833,7 @@ struct hostent *proxy_gethostbyname(const char *name) {
 | 
			
		||||
 | 
			
		||||
	have_ip:
 | 
			
		||||
 | 
			
		||||
#ifdef THREAD_SAFE
 | 
			
		||||
	pthread_mutex_unlock(&internal_ips_lock);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	MUTEX_UNLOCK(&internal_ips_lock);
 | 
			
		||||
 | 
			
		||||
	strncpy(addr_name, name, sizeof(addr_name));
 | 
			
		||||
 | 
			
		||||
@@ -851,9 +842,7 @@ struct hostent *proxy_gethostbyname(const char *name) {
 | 
			
		||||
	return &hostent_space;
 | 
			
		||||
 | 
			
		||||
	err_plus_unlock:
 | 
			
		||||
#ifdef THREAD_SAFE
 | 
			
		||||
	pthread_mutex_unlock(&internal_ips_lock);
 | 
			
		||||
#endif
 | 
			
		||||
	MUTEX_UNLOCK(&internal_ips_lock);
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
 | 
			
		||||
 
 | 
			
		||||
@@ -40,6 +40,13 @@ extern internal_ip_lookup_table internal_ips;
 | 
			
		||||
#ifdef THREAD_SAFE
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
extern pthread_mutex_t internal_ips_lock;
 | 
			
		||||
# define MUTEX_LOCK(x) pthread_mutex_lock(x)
 | 
			
		||||
# define MUTEX_UNLOCK(x) pthread_mutex_unlock(x)
 | 
			
		||||
# define MUTEX_INIT(x,y) pthread_mutex_init(x, y)
 | 
			
		||||
#else
 | 
			
		||||
# define MUTEX_LOCK(x)
 | 
			
		||||
# define MUTEX_UNLOCK(x)
 | 
			
		||||
# define MUTEX_INIT(x,y)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*error codes*/
 | 
			
		||||
 
 | 
			
		||||
@@ -61,9 +61,7 @@ static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, ch
 | 
			
		||||
static void init_lib(void);
 | 
			
		||||
 | 
			
		||||
static void init_lib(void) {
 | 
			
		||||
#ifdef THREAD_SAFE
 | 
			
		||||
	pthread_mutex_init(&internal_ips_lock, NULL);
 | 
			
		||||
#endif
 | 
			
		||||
	MUTEX_INIT(&internal_ips_lock, NULL);
 | 
			
		||||
	/* read the config file */
 | 
			
		||||
	get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user