Description: Solve problems with connecting to localhost. Forwarded: no Author: Emilio López Last-Update: 2009-03-03 --- proxychains-3.1.orig/proxychains/libproxychains.c 2006-03-16 05:16:59.000000000 +1300 +++ proxychains-3.1/proxychains/libproxychains.c 2007-04-18 15:31:24.000000000 +1200 @@ -42,6 +42,30 @@ #define SOCKFAMILY(x) (satosin(x)->sin_family) #define MAX_CHAIN 30*1024 +#ifdef PTRUE +#undef PTRUE +#endif +#define PTRUE 1 + +#ifdef PFALSE +#undef PFALSE +#endif +#define PFALSE 0 + +/* total number of available slots for subnets */ +#define MAX_LOCAL_NETS 20 + +/* structur for representing networks to be excluded */ +typedef struct +{ + int valid; + unsigned int subnetwork; + unsigned int subnetmask; +} my_network; + +my_network localnet[MAX_LOCAL_NETS]; /* array of sub nets */ + + int tcp_read_time_out; int tcp_connect_time_out; chain_type proxychains_ct; @@ -55,14 +79,15 @@ static inline void get_chain_data( proxy_data *pd, unsigned int *proxy_count, - chain_type *ct); + chain_type *ct, + my_network *subnets); static void init_lib() { // proxychains_write_log("ProxyChains-"VERSION -// " (http://proxychains.sf.net)\n"); - - get_chain_data(proxychains_pd,&proxychains_proxy_count,&proxychains_ct); +// " (http://proxychains.sf.net)\n"); + get_chain_data(proxychains_pd,&proxychains_proxy_count,&proxychains_ct,localnet); + true_connect = (connect_t) dlsym(RTLD_NEXT, "connect"); if (!true_connect) { @@ -140,11 +165,12 @@ static inline void get_chain_data( proxy_data *pd, unsigned int *proxy_count, - chain_type *ct) + chain_type *ct, + my_network *subnets) { - int count=0,port_n=0,list=0; + int count=0,port_n=0,list=0,subcount=0; char buff[1024],type[1024],host[1024],user[1024]; FILE* file; @@ -170,7 +196,11 @@ if(buff[strspn(buff," ")]!='#') { if(list) { bzero(&pd[count], sizeof(proxy_data)); - pd[count].ps=PLAY_STATE; + + bzero(&subnets[subcount], sizeof(my_network)); + + pd[count].ps=PLAY_STATE; + port_n=0; sscanf(buff,"%s %s %d %s %s", type,host,&port_n, pd[count].user,pd[count].pass); @@ -182,6 +212,12 @@ pd[count].pt=SOCKS4_TYPE; }else if(!strcmp(type,"socks5")) { pd[count].pt=SOCKS5_TYPE; + } else if(!strcmp(type,"localnet")) { + subnets[subcount].subnetwork=inet_addr(host); + subnets[subcount].subnetmask=inet_addr(pd[count].user); + subnets[subcount].valid=PTRUE; + subnets[subcount + 1].valid=PFALSE; + subcount++; }else continue; if( pd[count].ip && pd[count].ip!=-1 && port_n) @@ -223,13 +259,23 @@ int connect (int sock, const struct sockaddr *addr, unsigned int len) { int socktype=0,optlen=0,flags=0,ret=0; - + int lnnum=0; if(!init_l) init_lib(); optlen=sizeof(socktype); getsockopt(sock,SOL_SOCKET,SO_TYPE,&socktype,&optlen); if (! (SOCKFAMILY(*addr)==AF_INET && socktype==SOCK_STREAM)) return true_connect(sock,addr,len); + + get_chain_data(proxychains_pd,&proxychains_proxy_count,&proxychains_ct,localnet); + for (lnnum = 0; localnet[lnnum].valid == PTRUE; lnnum++) + { + if (( satosin(*addr)->sin_addr.s_addr & localnet[lnnum].subnetmask) == localnet[lnnum].subnetwork) + { + return true_connect(sock,addr,len); + } + } + flags=fcntl(sock, F_GETFL, 0); if(flags & O_NONBLOCK) fcntl(sock, F_SETFL, !O_NONBLOCK);