From 361889a2d29414a0277bc2f606e29d9a2067066a Mon Sep 17 00:00:00 2001 From: Adam Hamsik Date: Sun, 5 Aug 2012 15:07:37 +0200 Subject: [PATCH] Add option to do a development build with --devel configure flag. Rename proxy_getserverbyname to proxy_getservbyname. --- Makefile | 2 +- configure | 7 +++++++ src/core.c | 15 ++++++--------- src/core.h | 2 ++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 9d5744c..422c0f7 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ SRCS = $(sort $(wildcard src/*.c)) OBJS = $(SRCS:.c=.o) LOBJS = src/core.o src/common.o src/libproxychains.o -CCFLAGS = -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror -Wextra -Wunused -Wuninitialized -Wconversion -fno-common +CCFLAGS = -Wall -O2 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror LDFLAGS = -shared -fPIC -ldl -lpthread INC = PIC = -fPIC diff --git a/configure b/configure index c838d4d..f99e008 100755 --- a/configure +++ b/configure @@ -1,6 +1,7 @@ #!/bin/sh prefix=/usr/local +develflg=0 usage() { echo "supported arguments" @@ -10,6 +11,7 @@ usage() { echo "--libdir=/path default: $prefix/lib" echo "--includedir=/path default: $prefix/include" echo "--sysconfdir=/path default: $prefix/etc" + echo "--devel default:no (set development mode)" echo "--help : show this text" exit 1 } @@ -29,6 +31,7 @@ parsearg() { --libdir=*) libdir=`spliteq $1`;; --includedir=*) includedir=`spliteq $1`;; --sysconfdir=*) sysconfdir=`spliteq $1`;; + --devel) develflg=1;; --help) usage;; esac } @@ -68,6 +71,10 @@ if [ -z "$CC" ] ; then CC=cc fi +if [ $develflg -eq 1 ]; then + CFLAGS="-Wextra -Wunused -Wuninitialized -Wconversion -fno-common -g -O0" +fi + echo CC?=$CC>config.mak [ -z "$CPPFLAGS" ] || echo CPPFLAGS?=$CPPFLAGS>>config.mak [ -z "$CFLAGS" ] || echo USER_CFLAGS?=$CFLAGS>>config.mak diff --git a/src/core.c b/src/core.c index 052f429..c248f4e 100644 --- a/src/core.c +++ b/src/core.c @@ -15,6 +15,7 @@ * * ***************************************************************************/ #include +#include #include #include @@ -400,11 +401,11 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c *cur++ = 1; // version c = ulen & 0xFF; *cur++ = (char)c; - memcpy(cur, user, c); + memcpy(cur, user, (size_t)c); cur += c; c = passlen & 0xFF; *cur++ = (char)c; - memcpy(cur, pass, c); + memcpy(cur, pass, (size_t)c); cur += c; if((size_t)(cur - out) != write_n_bytes(sock, out, (size_t) (cur - out))) @@ -825,8 +826,8 @@ void proxy_freeaddrinfo(struct addrinfo *res) { free(res); } -void proxy_getserverbyname(const char * service, struct servent *se_buf, - __unused char * buf, size_t buf_len, struct servent **se_result) +void proxy_getservbyname(const char * service, struct servent *se_buf, + char * buf, size_t buf_len, struct servent **se_result) { #ifdef __linux__ @@ -836,9 +837,7 @@ void proxy_getserverbyname(const char * service, struct servent *se_buf, #ifdef __APPLE__ struct servent *se; -#ifdef THREAD_SAFE MUTEX_LOCK(&internal_getsrvbyname_lock); -#endif if(service) { se = getservbyname(service, NULL); @@ -849,9 +848,7 @@ void proxy_getserverbyname(const char * service, struct servent *se_buf, *se_result = NULL; } } -#ifdef THREAD_SAFE MUTEX_UNLOCK(&internal_getsrvbyname_lock); -#endif #endif /* __APPLE__ */ } @@ -878,7 +875,7 @@ int proxy_getaddrinfo(const char *node, const char *service, const struct addrin goto err2; } if(service) - proxy_getserverbyname(service, &se_buf, buf, sizeof(buf), &se); + proxy_getservbyname(service, &se_buf, buf, sizeof(buf), &se); port = se ? se->s_port : htons(atoi(service ? service : "0")); ((struct sockaddr_in *) &space->sockaddr_space)->sin_port = (in_port_t)port; diff --git a/src/core.h b/src/core.h index 46a162e..60e14b0 100644 --- a/src/core.h +++ b/src/core.h @@ -135,6 +135,8 @@ struct gethostbyname_data { }; struct hostent* proxy_gethostbyname(const char *name, struct gethostbyname_data *data); +void proxy_getservbyname(const char * service, struct servent *se_buf, + char * buf, size_t buf_len, struct servent **se_result); int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);