mirror of
https://github.com/haad/proxychains
synced 2026-06-08 14:30:41 +00:00
Compare commits
38 Commits
testing
...
rofl0r-master
| Author | SHA1 | Date | |
|---|---|---|---|
| efa5738a6a | |||
| 8547764a82 | |||
| 40bb78b53f | |||
| a4f3dd0538 | |||
| 80e58726e2 | |||
| 3c7fcc7507 | |||
| ab3ca31871 | |||
| 6f56956715 | |||
| 037edbcb8e | |||
| 40edf758ee | |||
| 4b999cdae7 | |||
| 71e15e2edd | |||
| e5e87c8f22 | |||
| fafeaf5936 | |||
| fba5f5694c | |||
| 1a02b9f82f | |||
| 3004240462 | |||
| 364c785970 | |||
| 1fc7e38ee0 | |||
| eb0db7221a | |||
| 2c9c4d9da7 | |||
| d95ef42d48 | |||
| e991cabb94 | |||
| d28cf03c61 | |||
| 952a039801 | |||
| 8d9bb5545c | |||
| f512779539 | |||
| f53119773a | |||
| 2f9a9cf0b0 | |||
| cdec339f11 | |||
| fe8672eab6 | |||
| d9341a8c74 | |||
| af5163bccf | |||
| 1471c5756f | |||
| 15d4d5a669 | |||
| 865dc76c08 | |||
| 9a29a4c0d1 | |||
| ca599cbc86 |
@@ -1,5 +1,16 @@
|
|||||||
|
original code
|
||||||
N3E7CR34TUR3.
|
N3E7CR34TUR3.
|
||||||
|
http://proxychains.sourceforge.net
|
||||||
|
netcreature@users.sourceforge.net
|
||||||
|
|
||||||
web site: proxychains.sourceforge.net
|
main.c, remote-dns, thread safety, bugfixes, build system, cleanups
|
||||||
email: netcreature@users.sourceforge.net
|
rofl0r.
|
||||||
|
https://github.com/rofl0r/proxychains
|
||||||
|
|
||||||
|
localnet, bugfixes
|
||||||
|
adam hamsik.
|
||||||
|
https://github.com/haad/proxychains
|
||||||
|
|
||||||
|
localnet-port, bugfixes
|
||||||
|
jianing yang.
|
||||||
|
https://github.com/jianingy/proxychains
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
ProxyChains ver 3.1 Installation
|
|
||||||
=======================
|
|
||||||
|
|
||||||
If you have installed other ver of proxychains "make uninstall" before installing this distribution
|
|
||||||
|
|
||||||
unpack the .tar.gz , 'cd' to distribution directory and
|
|
||||||
run following commands (as root)
|
|
||||||
-------------------------------------
|
|
||||||
./configure
|
|
||||||
make
|
|
||||||
make install
|
|
||||||
-------------------------------------
|
|
||||||
that's all
|
|
||||||
@@ -5,19 +5,19 @@
|
|||||||
# Do not make changes here.
|
# Do not make changes here.
|
||||||
#
|
#
|
||||||
|
|
||||||
exec_prefix = /usr/local
|
prefix = /usr/local
|
||||||
bindir = $(exec_prefix)/bin
|
|
||||||
|
|
||||||
prefix = /usr/local/
|
|
||||||
includedir = $(prefix)/include
|
includedir = $(prefix)/include
|
||||||
libdir = $(prefix)/lib
|
libdir = $(prefix)/lib
|
||||||
sysconfdir=$(prefix)/etc
|
confdir = $(prefix)/etc
|
||||||
|
|
||||||
|
exec_prefix = $(prefix)
|
||||||
|
bindir = $(exec_prefix)/bin
|
||||||
|
|
||||||
SRCS = $(sort $(wildcard src/*.c))
|
SRCS = $(sort $(wildcard src/*.c))
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
LOBJS = src/core.o src/libproxychains.o
|
LOBJS = src/core.o src/common.o src/libproxychains.o
|
||||||
|
|
||||||
CFLAGS += -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE
|
CCFLAGS = -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror
|
||||||
LDFLAGS = -shared -fPIC -ldl -lpthread
|
LDFLAGS = -shared -fPIC -ldl -lpthread
|
||||||
INC =
|
INC =
|
||||||
PIC = -fPIC
|
PIC = -fPIC
|
||||||
@@ -39,17 +39,19 @@ ALL_TOOLS = $(PXCHAINS)
|
|||||||
|
|
||||||
|
|
||||||
CFLAGS+=$(USER_CFLAGS) $(MAC_CFLAGS)
|
CFLAGS+=$(USER_CFLAGS) $(MAC_CFLAGS)
|
||||||
CFLAGS_MAIN=-DLIB_DIR=\"$(libdir)\" -DSYSCONFDIR=\"$(sysconfdir)\" -DDLL_NAME=\"$(LDSO_PATHNAME)\"
|
CFLAGS_MAIN=-DLIB_DIR=\"$(libdir)\" -DSYSCONFDIR=\"$(confdir)\" -DDLL_NAME=\"$(LDSO_PATHNAME)\"
|
||||||
|
|
||||||
|
|
||||||
all: $(ALL_LIBS) $(ALL_TOOLS)
|
all: $(ALL_LIBS) $(ALL_TOOLS)
|
||||||
|
|
||||||
#install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(DESTDIR)$(LDSO_PATHNAME)
|
install-config:
|
||||||
|
install -d $(DESTDIR)/$(confdir)
|
||||||
|
install $(INSTALL_FLAGS) 644 src/proxychains.conf $(DESTDIR)/$(confdir)/
|
||||||
|
|
||||||
install:
|
install:
|
||||||
install -d $(DESTDIR)/$(bindir)/ $(DESTDIR)/$(libdir)/ $(DESTDIR)/$(sysconfdir)
|
install -d $(DESTDIR)/$(bindir)/ $(DESTDIR)/$(libdir)/
|
||||||
install $(INSTALL_FLAGS) 755 $(ALL_TOOLS) $(DESTDIR)/$(bindir)/
|
install $(INSTALL_FLAGS) 755 $(ALL_TOOLS) $(DESTDIR)/$(bindir)/
|
||||||
install $(INSTALL_FLAGS) 644 $(ALL_LIBS) $(DESTDIR)/$(libdir)/
|
install $(INSTALL_FLAGS) 644 $(ALL_LIBS) $(DESTDIR)/$(libdir)/
|
||||||
install $(INSTALL_FLAGS) 644 src/proxychains.conf $(DESTDIR)/$(sysconfdir)/
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(ALL_LIBS)
|
rm -f $(ALL_LIBS)
|
||||||
@@ -57,13 +59,13 @@ clean:
|
|||||||
rm -f $(OBJS)
|
rm -f $(OBJS)
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) $(CFLAGS) $(CFLAGS_MAIN) $(INC) $(PIC) -c -o $@ $<
|
$(CC) $(CCFLAGS) $(CFLAGS_MAIN) $(INC) $(PIC) -c -o $@ $<
|
||||||
|
|
||||||
$(LDSO_PATHNAME): $(LOBJS)
|
$(LDSO_PATHNAME): $(LOBJS)
|
||||||
$(CC) $(LDFLAGS) $(LD_SET_SONAME)$(LDSO_PATHNAME) -o $@ $(LOBJS)
|
$(CC) $(LDFLAGS) $(LD_SET_SONAME)$(LDSO_PATHNAME) -o $@ $(LOBJS)
|
||||||
|
|
||||||
$(ALL_TOOLS): $(OBJS)
|
$(ALL_TOOLS): $(OBJS)
|
||||||
$(CC) src/main.o -o $(PXCHAINS)
|
$(CC) src/main.o src/common.o -o $(PXCHAINS)
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all clean install
|
.PHONY: all clean install
|
||||||
|
|||||||
@@ -1,23 +1,43 @@
|
|||||||
ProxyChains ver 4.0 README
|
ProxyChains ver 4.0 README
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
|
ProxyChains is a UNIX program, that hooks network-related libc functions
|
||||||
|
in dynamically linked programs via a preloaded DLL and redirects the
|
||||||
|
connections through SOCKS4a/5 or HTTP proxies.
|
||||||
|
|
||||||
*********** ATTENTION ***********
|
*********** ATTENTION ***********
|
||||||
|
|
||||||
this program works only on dynamically linked programs.
|
this program works only on dynamically linked programs.
|
||||||
also both proxychains and the program to call must use
|
also both proxychains and the program to call must use
|
||||||
the same dynamic linker (i.e. same libc)
|
the same dynamic linker (i.e. same libc)
|
||||||
|
|
||||||
*********************************
|
*********************************
|
||||||
|
|
||||||
|
*** Known limitations of the current version: ***
|
||||||
|
|
||||||
This is Unix version only.
|
when a process forks, does a DNS lookup in the child, and then uses
|
||||||
|
the ip in the parent, the corresponding ip mapping will not be found.
|
||||||
|
this is because the fork can't write back into the parents mapping table.
|
||||||
|
IRSSI shows this behaviour, so you have to pass the resolved ip address
|
||||||
|
to it. (you can use the proxyresolv script (requires "dig") to do so)
|
||||||
|
|
||||||
How to mess with sources - How to Install : read INSTALL !!!!!!
|
this means that you can't currently use tor onion urls for irssi.
|
||||||
|
to solve this issue, an external data store (file, pipe, ...) has to
|
||||||
|
manage the dns <-> ip mapping. of course there has to be proper locking.
|
||||||
|
shm_open, mkstemp, are possible candidates for a file based approach,
|
||||||
|
the other option is to spawn some kind of server process that manages the
|
||||||
|
map lookups. since connect() etc are hooked, this must not be a TCP server.
|
||||||
|
|
||||||
This program forces any tcp connection made by any given tcp client
|
I am reluctant on doing this change, because the described behaviour
|
||||||
to follow through proxy (or proxy chain). It is a kind of proxifier.
|
seems pretty idiotic (doing a fork only for a DNS lookup), and irssi
|
||||||
It acts like sockscap / permeo / eborder driver ( intercepts TCP calls )
|
is currently the only known affected program.
|
||||||
It is FREE.
|
|
||||||
|
*** Installation ***
|
||||||
|
|
||||||
|
# needs a working C compiler, preferably gcc
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
----------
|
----------
|
||||||
@@ -74,21 +94,21 @@ proxychains looks for config file in following order:
|
|||||||
|
|
||||||
Usage Example:
|
Usage Example:
|
||||||
|
|
||||||
bash$ proxychains telnet targethost.com
|
$ proxychains telnet targethost.com
|
||||||
|
|
||||||
in this example it will run telnet through proxy(or chained proxies)
|
in this example it will run telnet through proxy(or chained proxies)
|
||||||
specified by proxychains.conf
|
specified by proxychains.conf
|
||||||
|
|
||||||
Usage Example:
|
Usage Example:
|
||||||
|
|
||||||
bash$ proxychains -f /etc/proxychains-other.conf targethost2.com
|
$ proxychains -f /etc/proxychains-other.conf targethost2.com
|
||||||
|
|
||||||
in this example it will use different configuration file then proxychains.conf
|
in this example it will use different configuration file then proxychains.conf
|
||||||
to connect to targethost2.com host.
|
to connect to targethost2.com host.
|
||||||
|
|
||||||
Usage Example:
|
Usage Example:
|
||||||
|
|
||||||
bash$ proxyresolv targethost.com
|
$ proxyresolv targethost.com
|
||||||
|
|
||||||
in this example it will resolve targethost.com through proxy(or chained proxies)
|
in this example it will resolve targethost.com through proxy(or chained proxies)
|
||||||
specified by proxychains.conf
|
specified by proxychains.conf
|
||||||
|
|||||||
@@ -2,6 +2,18 @@
|
|||||||
|
|
||||||
prefix=/usr/local
|
prefix=/usr/local
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "supported arguments"
|
||||||
|
echo "--prefix=/path default: $prefix"
|
||||||
|
echo "--exec_prefix=/path default: $prefix/bin"
|
||||||
|
echo "--bindir=/path default: $prefix/bin"
|
||||||
|
echo "--libdir=/path default: $prefix/lib"
|
||||||
|
echo "--includedir=/path default: $prefix/include"
|
||||||
|
echo "--sysconfdir=/path default: $prefix/etc"
|
||||||
|
echo "--help : show this text"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
spliteq() {
|
spliteq() {
|
||||||
arg=$1
|
arg=$1
|
||||||
echo "${arg#*=}"
|
echo "${arg#*=}"
|
||||||
@@ -17,6 +29,7 @@ parsearg() {
|
|||||||
--libdir=*) libdir=`spliteq $1`;;
|
--libdir=*) libdir=`spliteq $1`;;
|
||||||
--includedir=*) includedir=`spliteq $1`;;
|
--includedir=*) includedir=`spliteq $1`;;
|
||||||
--sysconfdir=*) sysconfdir=`spliteq $1`;;
|
--sysconfdir=*) sysconfdir=`spliteq $1`;;
|
||||||
|
--help) usage;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
Begin3
|
|
||||||
Title: ProxyChains
|
|
||||||
Version: 3.0
|
|
||||||
Entered-date:
|
|
||||||
Description:
|
|
||||||
Keywords:
|
|
||||||
Author: <N37CR347UR3>
|
|
||||||
Maintained-by: <NetCreature>
|
|
||||||
Primary-site:
|
|
||||||
Home-page: http://proxychains.sourceforge.net
|
|
||||||
Original-site:
|
|
||||||
Platforms: Linux and other Unices
|
|
||||||
Copying-policy: GNU Public License
|
|
||||||
End
|
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
#include "common.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
static int check_path(char *path) {
|
||||||
|
if(!path)
|
||||||
|
return 0;
|
||||||
|
return access(path, R_OK) != -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *get_config_path(char* default_path, char* pbuf, size_t bufsize) {
|
||||||
|
char buf[512];
|
||||||
|
// top priority: user defined path
|
||||||
|
char *path = default_path;
|
||||||
|
if(check_path(path))
|
||||||
|
goto have;
|
||||||
|
|
||||||
|
// priority 1: env var PROXYCHAINS_CONF_FILE
|
||||||
|
path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
||||||
|
if(check_path(path))
|
||||||
|
goto have;
|
||||||
|
|
||||||
|
// priority 2; proxychains conf in actual dir
|
||||||
|
path = getcwd(buf, sizeof(buf));
|
||||||
|
snprintf(pbuf, bufsize, "%s/%s", path, PROXYCHAINS_CONF_FILE);
|
||||||
|
path = pbuf;
|
||||||
|
if(check_path(path))
|
||||||
|
goto have;
|
||||||
|
|
||||||
|
// priority 3; $HOME/.proxychains/proxychains.conf
|
||||||
|
path = getenv("HOME");
|
||||||
|
snprintf(pbuf, bufsize, "%s/.proxychains/%s", path, PROXYCHAINS_CONF_FILE);
|
||||||
|
path = pbuf;
|
||||||
|
if(check_path(path))
|
||||||
|
goto have;
|
||||||
|
|
||||||
|
// priority 4: $SYSCONFDIR/proxychains.conf
|
||||||
|
path = SYSCONFDIR "/" PROXYCHAINS_CONF_FILE;
|
||||||
|
if(check_path(path))
|
||||||
|
goto have;
|
||||||
|
|
||||||
|
// priority 5: /etc/proxychains.conf
|
||||||
|
path = "/etc/" PROXYCHAINS_CONF_FILE;
|
||||||
|
if(check_path(path))
|
||||||
|
goto have;
|
||||||
|
|
||||||
|
perror("couldnt find configuration file");
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
have:
|
||||||
|
return path;
|
||||||
|
}
|
||||||
@@ -2,3 +2,7 @@
|
|||||||
#define PROXYCHAINS_QUIET_MODE_ENV_VAR "PROXYCHAINS_QUIET_MODE"
|
#define PROXYCHAINS_QUIET_MODE_ENV_VAR "PROXYCHAINS_QUIET_MODE"
|
||||||
#define PROXYCHAINS_CONF_FILE "proxychains.conf"
|
#define PROXYCHAINS_CONF_FILE "proxychains.conf"
|
||||||
#define LOG_PREFIX "[proxychains] "
|
#define LOG_PREFIX "[proxychains] "
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
char *get_config_path(char* default_path, char* pbuf, size_t bufsize);
|
||||||
+94
-116
@@ -14,6 +14,7 @@
|
|||||||
* (at your option) any later version. *
|
* (at your option) any later version. *
|
||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -25,7 +26,6 @@
|
|||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@@ -33,6 +33,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <assert.h>
|
||||||
#ifdef THREAD_SAFE
|
#ifdef THREAD_SAFE
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
pthread_mutex_t internal_ips_lock;
|
pthread_mutex_t internal_ips_lock;
|
||||||
@@ -48,7 +49,6 @@ extern unsigned int remote_dns_subnet;
|
|||||||
|
|
||||||
internal_ip_lookup_table internal_ips = { 0, 0, NULL };
|
internal_ip_lookup_table internal_ips = { 0, 0, NULL };
|
||||||
|
|
||||||
|
|
||||||
uint32_t dalias_hash(char *s0) {
|
uint32_t dalias_hash(char *s0) {
|
||||||
unsigned char *s = (void *) s0;
|
unsigned char *s = (void *) s0;
|
||||||
uint_fast32_t h = 0;
|
uint_fast32_t h = 0;
|
||||||
@@ -89,33 +89,10 @@ in_addr_t make_internal_ip(uint32_t index) {
|
|||||||
return (in_addr_t) ret.as_int;
|
return (in_addr_t) ret.as_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stolen from libulz (C) rofl0r
|
|
||||||
void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes) {
|
|
||||||
unsigned char *p;
|
|
||||||
char *o = outbuf_16_bytes;
|
|
||||||
unsigned char n;
|
|
||||||
for(p = ip_buf_4_bytes; p < ip_buf_4_bytes + 4; p++) {
|
|
||||||
n = *p;
|
|
||||||
if(*p >= 100) {
|
|
||||||
if(*p >= 200)
|
|
||||||
*(o++) = '2';
|
|
||||||
else
|
|
||||||
*(o++) = '1';
|
|
||||||
n %= 100;
|
|
||||||
}
|
|
||||||
if(*p >= 10) {
|
|
||||||
*(o++) = (n / 10) + '0';
|
|
||||||
n %= 10;
|
|
||||||
}
|
|
||||||
*(o++) = n + '0';
|
|
||||||
*(o++) = '.';
|
|
||||||
}
|
|
||||||
o[-1] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
|
||||||
static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout) {
|
static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int time_remain = timeout;
|
int time_remain = timeout;
|
||||||
int time_elapsed = 0;
|
int time_elapsed = 0;
|
||||||
@@ -175,21 +152,16 @@ static void encode_base_64(char *src, char *dest, int max_len) {
|
|||||||
*dest++ = 0;
|
*dest++ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOG_BUFF 1024*20
|
void proxychains_write_log(char *str, ...) {
|
||||||
|
char buff[1024*20];
|
||||||
int proxychains_write_log(char *str, ...) {
|
|
||||||
char buff[LOG_BUFF];
|
|
||||||
va_list arglist;
|
va_list arglist;
|
||||||
FILE *log_file;
|
|
||||||
log_file = stderr;
|
|
||||||
if(!proxychains_quiet_mode) {
|
if(!proxychains_quiet_mode) {
|
||||||
va_start(arglist, str);
|
va_start(arglist, str);
|
||||||
vsprintf(buff, str, arglist);
|
vsnprintf(buff, sizeof(buff), str, arglist);
|
||||||
va_end(arglist);
|
va_end(arglist);
|
||||||
fprintf(log_file, "%s", buff);
|
fprintf(stderr, "%s", buff);
|
||||||
fflush(log_file);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_n_bytes(int fd, char *buff, size_t size) {
|
static int write_n_bytes(int fd, char *buff, size_t size) {
|
||||||
@@ -230,26 +202,15 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
|||||||
pfd[0].events = POLLOUT;
|
pfd[0].events = POLLOUT;
|
||||||
fcntl(sock, F_SETFL, O_NONBLOCK);
|
fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||||
ret = true_connect(sock, addr, len);
|
ret = true_connect(sock, addr, len);
|
||||||
#ifdef DEBUG
|
PDEBUG("\nconnect ret=%d\n", ret);
|
||||||
if(ret == -1)
|
|
||||||
perror("true_connect");
|
|
||||||
printf("\nconnect ret=%d\n", ret);
|
|
||||||
|
|
||||||
fflush(stdout);
|
|
||||||
#endif
|
|
||||||
if(ret == -1 && errno == EINPROGRESS) {
|
if(ret == -1 && errno == EINPROGRESS) {
|
||||||
ret = poll_retry(pfd, 1, tcp_connect_time_out);
|
ret = poll_retry(pfd, 1, tcp_connect_time_out);
|
||||||
#ifdef DEBUG
|
PDEBUG("\npoll ret=%d\n", ret);
|
||||||
printf("\npoll ret=%d\n", ret);
|
|
||||||
fflush(stdout);
|
|
||||||
#endif
|
|
||||||
if(ret == 1) {
|
if(ret == 1) {
|
||||||
value_len = sizeof(socklen_t);
|
value_len = sizeof(socklen_t);
|
||||||
getsockopt(sock, SOL_SOCKET, SO_ERROR, &value, &value_len);
|
getsockopt(sock, SOL_SOCKET, SO_ERROR, &value, &value_len);
|
||||||
#ifdef DEBUG
|
PDEBUG("\nvalue=%d\n", value);
|
||||||
printf("\nvalue=%d\n", value);
|
|
||||||
fflush(stdout);
|
|
||||||
#endif
|
|
||||||
if(!value)
|
if(!value)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
else
|
else
|
||||||
@@ -258,6 +219,10 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
if(ret == -1)
|
||||||
|
perror("true_connect");
|
||||||
|
#endif
|
||||||
if(ret != 0)
|
if(ret != 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
@@ -268,6 +233,8 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
|||||||
|
|
||||||
|
|
||||||
#define INVALID_INDEX 0xFFFFFFFFU
|
#define INVALID_INDEX 0xFFFFFFFFU
|
||||||
|
#define HTTP_AUTH_MAX ((0xFF * 2) + 1 + 1)
|
||||||
|
|
||||||
static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, char *user, char *pass) {
|
static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, char *user, char *pass) {
|
||||||
char *dns_name = NULL;
|
char *dns_name = NULL;
|
||||||
size_t dns_len = 0;
|
size_t dns_len = 0;
|
||||||
@@ -286,6 +253,8 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
if(!dns_len)
|
if(!dns_len)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PDEBUG("host dns %s\n", dns_name ? dns_name : "<NULL>");
|
||||||
|
|
||||||
size_t ulen = strlen(user);
|
size_t ulen = strlen(user);
|
||||||
size_t passlen = strlen(pass);
|
size_t passlen = strlen(pass);
|
||||||
@@ -304,7 +273,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
switch (pt) {
|
switch (pt) {
|
||||||
case HTTP_TYPE:{
|
case HTTP_TYPE:{
|
||||||
if(!dns_len) {
|
if(!dns_len) {
|
||||||
pc_stringfromipv4(&ip.octet[0], ip_buf);
|
inet_ntop(AF_INET, &ip.octet[0], ip_buf, sizeof(ip_buf));
|
||||||
dns_name = ip_buf;
|
dns_name = ip_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +281,6 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
ntohs(port));
|
ntohs(port));
|
||||||
|
|
||||||
if(user[0]) {
|
if(user[0]) {
|
||||||
#define HTTP_AUTH_MAX ((0xFF * 2) + 1 + 1)
|
|
||||||
// 2 * 0xff: username and pass, plus 1 for ':' and 1 for zero terminator.
|
// 2 * 0xff: username and pass, plus 1 for ':' and 1 for zero terminator.
|
||||||
char src[HTTP_AUTH_MAX];
|
char src[HTTP_AUTH_MAX];
|
||||||
char dst[(4 * HTTP_AUTH_MAX)];
|
char dst[(4 * HTTP_AUTH_MAX)];
|
||||||
@@ -516,8 +484,8 @@ static int start_chain(int *fd, proxy_data * pd, char *begin_mark) {
|
|||||||
*fd = socket(PF_INET, SOCK_STREAM, 0);
|
*fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
if(*fd == -1)
|
if(*fd == -1)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
pc_stringfromipv4(&pd->ip.octet[0], ip_buf);
|
inet_ntop(AF_INET, &pd->ip.octet[0], ip_buf, sizeof(ip_buf));
|
||||||
proxychains_write_log(LOG_PREFIX "%s " TP " %s:%d ",
|
proxychains_write_log(LOG_PREFIX "%s " TP " %s:%d ",
|
||||||
begin_mark, ip_buf, htons(pd->port));
|
begin_mark, ip_buf, htons(pd->port));
|
||||||
pd->ps = PLAY_STATE;
|
pd->ps = PLAY_STATE;
|
||||||
@@ -539,8 +507,10 @@ static int start_chain(int *fd, proxy_data * pd, char *begin_mark) {
|
|||||||
return SOCKET_ERROR;
|
return SOCKET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int proxy_count, unsigned int *offset) {
|
static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int proxy_count, unsigned int *offset) {
|
||||||
unsigned int i = 0, k = 0;
|
unsigned int i = 0, k = 0;
|
||||||
|
|
||||||
if(*offset >= proxy_count)
|
if(*offset >= proxy_count)
|
||||||
return NULL;
|
return NULL;
|
||||||
switch (how) {
|
switch (how) {
|
||||||
@@ -592,7 +562,6 @@ static unsigned int calc_alive(proxy_data * pd, unsigned int proxy_count) {
|
|||||||
return alive_count;
|
return alive_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
||||||
int retcode = -1;
|
int retcode = -1;
|
||||||
char *hostname;
|
char *hostname;
|
||||||
@@ -606,7 +575,7 @@ static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
|||||||
goto usenumericip;
|
goto usenumericip;
|
||||||
} else {
|
} else {
|
||||||
usenumericip:
|
usenumericip:
|
||||||
pc_stringfromipv4(&pto->ip.octet[0], ip_buf);
|
inet_ntop(AF_INET, &pto->ip.octet[0], ip_buf, sizeof(ip_buf));
|
||||||
hostname = ip_buf;
|
hostname = ip_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -623,7 +592,7 @@ static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
|||||||
break;
|
break;
|
||||||
case SOCKET_ERROR:
|
case SOCKET_ERROR:
|
||||||
pto->ps = DOWN_STATE;
|
pto->ps = DOWN_STATE;
|
||||||
proxychains_write_log("<--timeout\n");
|
proxychains_write_log("<--socket error or timeout!\n");
|
||||||
close(ns);
|
close(ns);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -721,7 +690,6 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
p3->port = target_port;
|
p3->port = target_port;
|
||||||
if(SUCCESS != chain_step(ns, p1, p3))
|
if(SUCCESS != chain_step(ns, p1, p3))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proxychains_write_log(TP " OK\n");
|
proxychains_write_log(TP " OK\n");
|
||||||
@@ -746,35 +714,30 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: all those buffers aren't threadsafe, but since no memory allocation happens there shouldnt be any segfaults
|
|
||||||
static struct hostent hostent_space;
|
|
||||||
static in_addr_t resolved_addr;
|
|
||||||
static char *resolved_addr_p[2];
|
|
||||||
static char addr_name[1024 * 8];
|
|
||||||
static const ip_type local_host = { {127, 0, 0, 1} };
|
static const ip_type local_host = { {127, 0, 0, 1} };
|
||||||
struct hostent *proxy_gethostbyname(const char *name) {
|
|
||||||
|
struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data* data) {
|
||||||
char buff[256];
|
char buff[256];
|
||||||
uint32_t i, hash;
|
uint32_t i, hash;
|
||||||
// yep, new_mem never gets freed. once you passed a fake ip to the client, you can't "retreat" it
|
// yep, new_mem never gets freed. once you passed a fake ip to the client, you can't "retreat" it
|
||||||
void *new_mem;
|
void *new_mem;
|
||||||
size_t l;
|
size_t l;
|
||||||
|
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
|
|
||||||
resolved_addr_p[0] = (char *) &resolved_addr;
|
data->resolved_addr_p[0] = (char *) &data->resolved_addr;
|
||||||
resolved_addr_p[1] = NULL;
|
data->resolved_addr_p[1] = NULL;
|
||||||
|
|
||||||
hostent_space.h_addr_list = resolved_addr_p;
|
data->hostent_space.h_addr_list = data->resolved_addr_p;
|
||||||
|
|
||||||
resolved_addr = 0;
|
data->resolved_addr = 0;
|
||||||
|
|
||||||
gethostname(buff, sizeof(buff));
|
gethostname(buff, sizeof(buff));
|
||||||
|
|
||||||
if(!strcmp(buff, name)) {
|
if(!strcmp(buff, name)) {
|
||||||
resolved_addr = inet_addr(buff);
|
data->resolved_addr = inet_addr(buff);
|
||||||
if(resolved_addr == (in_addr_t) (-1))
|
if(data->resolved_addr == (in_addr_t) (-1))
|
||||||
resolved_addr = (in_addr_t) (local_host.as_int);
|
data->resolved_addr = (in_addr_t) (local_host.as_int);
|
||||||
return &hostent_space;
|
return &data->hostent_space;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(buff, 0, sizeof(buff));
|
memset(buff, 0, sizeof(buff));
|
||||||
@@ -783,7 +746,6 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
|||||||
if(!strcmp(hp->h_name, name))
|
if(!strcmp(hp->h_name, name))
|
||||||
return hp;
|
return hp;
|
||||||
|
|
||||||
|
|
||||||
hash = dalias_hash((char *) name);
|
hash = dalias_hash((char *) name);
|
||||||
|
|
||||||
MUTEX_LOCK(&internal_ips_lock);
|
MUTEX_LOCK(&internal_ips_lock);
|
||||||
@@ -792,12 +754,13 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
|||||||
if(internal_ips.counter) {
|
if(internal_ips.counter) {
|
||||||
for(i = 0; i < internal_ips.counter; i++) {
|
for(i = 0; i < internal_ips.counter; i++) {
|
||||||
if(internal_ips.list[i]->hash == hash && !strcmp(name, internal_ips.list[i]->string)) {
|
if(internal_ips.list[i]->hash == hash && !strcmp(name, internal_ips.list[i]->string)) {
|
||||||
resolved_addr = make_internal_ip(i);
|
data->resolved_addr = make_internal_ip(i);
|
||||||
PDEBUG("got cached ip for %s\n", name);
|
PDEBUG("got cached ip for %s\n", name);
|
||||||
goto have_ip;
|
goto have_ip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// grow list if needed.
|
// grow list if needed.
|
||||||
if(internal_ips.capa < internal_ips.counter + 1) {
|
if(internal_ips.capa < internal_ips.counter + 1) {
|
||||||
PDEBUG("realloc\n");
|
PDEBUG("realloc\n");
|
||||||
@@ -812,8 +775,8 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resolved_addr = make_internal_ip(internal_ips.counter);
|
data->resolved_addr = make_internal_ip(internal_ips.counter);
|
||||||
if(resolved_addr == (in_addr_t) - 1)
|
if(data->resolved_addr == (in_addr_t) - 1)
|
||||||
goto err_plus_unlock;
|
goto err_plus_unlock;
|
||||||
|
|
||||||
l = strlen(name);
|
l = strlen(name);
|
||||||
@@ -825,6 +788,7 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
|||||||
|
|
||||||
internal_ips.list[internal_ips.counter] = new_mem;
|
internal_ips.list[internal_ips.counter] = new_mem;
|
||||||
internal_ips.list[internal_ips.counter]->hash = hash;
|
internal_ips.list[internal_ips.counter]->hash = hash;
|
||||||
|
|
||||||
internal_ips.list[internal_ips.counter]->string = (char *) new_mem + sizeof(string_hash_tuple);
|
internal_ips.list[internal_ips.counter]->string = (char *) new_mem + sizeof(string_hash_tuple);
|
||||||
|
|
||||||
memcpy(internal_ips.list[internal_ips.counter]->string, name, l + 1);
|
memcpy(internal_ips.list[internal_ips.counter]->string, name, l + 1);
|
||||||
@@ -835,63 +799,77 @@ struct hostent *proxy_gethostbyname(const char *name) {
|
|||||||
|
|
||||||
MUTEX_UNLOCK(&internal_ips_lock);
|
MUTEX_UNLOCK(&internal_ips_lock);
|
||||||
|
|
||||||
strncpy(addr_name, name, sizeof(addr_name));
|
strncpy(data->addr_name, name, sizeof(data->addr_name));
|
||||||
|
|
||||||
hostent_space.h_name = addr_name;
|
data->hostent_space.h_name = data->addr_name;
|
||||||
hostent_space.h_length = sizeof(in_addr_t);
|
data->hostent_space.h_length = sizeof(in_addr_t);
|
||||||
return &hostent_space;
|
return &data->hostent_space;
|
||||||
|
|
||||||
err_plus_unlock:
|
err_plus_unlock:
|
||||||
MUTEX_UNLOCK(&internal_ips_lock);
|
MUTEX_UNLOCK(&internal_ips_lock);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct addrinfo_data {
|
||||||
|
struct addrinfo addrinfo_space;
|
||||||
|
struct sockaddr sockaddr_space;
|
||||||
|
char addr_name[256];
|
||||||
|
};
|
||||||
|
|
||||||
|
void proxy_freeaddrinfo(struct addrinfo *res) {
|
||||||
|
free(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
|
int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
|
||||||
|
struct gethostbyname_data ghdata;
|
||||||
|
struct addrinfo_data *space;
|
||||||
struct servent *se = NULL;
|
struct servent *se = NULL;
|
||||||
struct hostent *hp = NULL;
|
struct hostent *hp = NULL;
|
||||||
struct sockaddr *sockaddr_space = NULL;
|
struct servent se_buf;
|
||||||
struct addrinfo *addrinfo_space = NULL;
|
struct addrinfo *p;
|
||||||
|
char buf[1024];
|
||||||
|
int port;
|
||||||
|
|
||||||
// printf("proxy_getaddrinfo node %s service %s\n",node,service);
|
// printf("proxy_getaddrinfo node %s service %s\n",node,service);
|
||||||
addrinfo_space = malloc(sizeof(struct addrinfo));
|
space = calloc(1, sizeof(struct addrinfo_data));
|
||||||
if(!addrinfo_space)
|
if(!space) goto err1;
|
||||||
goto err1;
|
|
||||||
sockaddr_space = malloc(sizeof(struct sockaddr));
|
if(node && !inet_aton(node, &((struct sockaddr_in *) &space->sockaddr_space)->sin_addr)) {
|
||||||
if(!sockaddr_space)
|
hp = proxy_gethostbyname(node, &ghdata);
|
||||||
goto err2;
|
|
||||||
memset(sockaddr_space, 0, sizeof(*sockaddr_space));
|
|
||||||
memset(addrinfo_space, 0, sizeof(*addrinfo_space));
|
|
||||||
if(node && !inet_aton(node, &((struct sockaddr_in *) sockaddr_space)->sin_addr)) {
|
|
||||||
hp = proxy_gethostbyname(node);
|
|
||||||
if(hp)
|
if(hp)
|
||||||
memcpy(&((struct sockaddr_in *) sockaddr_space)->sin_addr,
|
memcpy(&((struct sockaddr_in *) &space->sockaddr_space)->sin_addr,
|
||||||
*(hp->h_addr_list), sizeof(in_addr_t));
|
*(hp->h_addr_list), sizeof(in_addr_t));
|
||||||
else
|
else
|
||||||
goto err3;
|
goto err2;
|
||||||
}
|
}
|
||||||
if(service)
|
if(service) getservbyname_r(service, NULL, &se_buf, buf, sizeof(buf), &se);
|
||||||
se = getservbyname(service, NULL);
|
|
||||||
|
|
||||||
if(!se) {
|
port = se ? se->s_port : htons(atoi(service ? service : "0"));
|
||||||
((struct sockaddr_in *) sockaddr_space)->sin_port = htons(atoi(service ? : "0"));
|
((struct sockaddr_in *) &space->sockaddr_space)->sin_port = port;
|
||||||
} else
|
|
||||||
((struct sockaddr_in *) sockaddr_space)->sin_port = se->s_port;
|
|
||||||
|
|
||||||
*res = addrinfo_space;
|
*res = p = &space->addrinfo_space;
|
||||||
(*res)->ai_addr = sockaddr_space;
|
assert((size_t)p == (size_t) space);
|
||||||
|
|
||||||
|
p->ai_addr = &space->sockaddr_space;
|
||||||
if(node)
|
if(node)
|
||||||
strcpy(addr_name, node);
|
strncpy(space->addr_name, node, sizeof(space->addr_name));
|
||||||
(*res)->ai_canonname = addr_name;
|
p->ai_canonname = space->addr_name;
|
||||||
(*res)->ai_next = NULL;
|
p->ai_next = NULL;
|
||||||
(*res)->ai_family = sockaddr_space->sa_family = AF_INET;
|
p->ai_family = space->sockaddr_space.sa_family = AF_INET;
|
||||||
(*res)->ai_socktype = hints->ai_socktype;
|
p->ai_addrlen = sizeof(space->sockaddr_space);
|
||||||
(*res)->ai_flags = hints->ai_flags;
|
|
||||||
(*res)->ai_protocol = hints->ai_protocol;
|
if(hints) {
|
||||||
(*res)->ai_addrlen = sizeof(*sockaddr_space);
|
p->ai_socktype = hints->ai_socktype;
|
||||||
|
p->ai_flags = hints->ai_flags;
|
||||||
|
p->ai_protocol = hints->ai_protocol;
|
||||||
|
} else {
|
||||||
|
p->ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
goto out;
|
goto out;
|
||||||
err3:
|
|
||||||
free(sockaddr_space);
|
|
||||||
err2:
|
err2:
|
||||||
free(addrinfo_space);
|
free(space);
|
||||||
err1:
|
err1:
|
||||||
return 1;
|
return 1;
|
||||||
out:
|
out:
|
||||||
|
|||||||
+32
-30
@@ -4,10 +4,8 @@
|
|||||||
begin : Tue May 14 2002
|
begin : Tue May 14 2002
|
||||||
copyright : netcreature (C) 2002
|
copyright : netcreature (C) 2002
|
||||||
email : netcreature@users.sourceforge.net
|
email : netcreature@users.sourceforge.net
|
||||||
***************************************************************************/
|
***************************************************************************
|
||||||
#include <stdint.h>
|
***************************************************************************
|
||||||
/* GPL */
|
|
||||||
/***************************************************************************
|
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@@ -15,6 +13,9 @@
|
|||||||
* (at your option) any later version. *
|
* (at your option) any later version. *
|
||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef __CORE_HEADER
|
#ifndef __CORE_HEADER
|
||||||
#define __CORE_HEADER
|
#define __CORE_HEADER
|
||||||
#define BUFF_SIZE 8*1024 // used to read responses from proxies.
|
#define BUFF_SIZE 8*1024 // used to read responses from proxies.
|
||||||
@@ -37,9 +38,10 @@ typedef struct {
|
|||||||
} internal_ip_lookup_table;
|
} internal_ip_lookup_table;
|
||||||
|
|
||||||
extern internal_ip_lookup_table internal_ips;
|
extern internal_ip_lookup_table internal_ips;
|
||||||
|
|
||||||
#ifdef THREAD_SAFE
|
#ifdef THREAD_SAFE
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
extern pthread_mutex_t internal_ips_lock;
|
pthread_mutex_t internal_ips_lock;
|
||||||
# define MUTEX_LOCK(x) pthread_mutex_lock(x)
|
# define MUTEX_LOCK(x) pthread_mutex_lock(x)
|
||||||
# define MUTEX_UNLOCK(x) pthread_mutex_unlock(x)
|
# define MUTEX_UNLOCK(x) pthread_mutex_unlock(x)
|
||||||
# define MUTEX_INIT(x,y) pthread_mutex_init(x, y)
|
# define MUTEX_INIT(x,y) pthread_mutex_init(x, y)
|
||||||
@@ -101,42 +103,42 @@ int connect_proxy_chain (int sock, ip_type target_ip, unsigned short target_port
|
|||||||
proxy_data * pd, unsigned int proxy_count, chain_type ct,
|
proxy_data * pd, unsigned int proxy_count, chain_type ct,
|
||||||
unsigned int max_chain );
|
unsigned int max_chain );
|
||||||
|
|
||||||
int proxychains_write_log(char *str,...);
|
void proxychains_write_log(char *str, ...);
|
||||||
|
|
||||||
typedef int (*connect_t)(int, const struct sockaddr *, socklen_t);
|
typedef int (*connect_t)(int, const struct sockaddr *, socklen_t);
|
||||||
connect_t true_connect;
|
|
||||||
|
|
||||||
typedef struct hostent* (*gethostbyname_t)(const char *);
|
typedef struct hostent* (*gethostbyname_t)(const char *);
|
||||||
gethostbyname_t true_gethostbyname;
|
|
||||||
|
|
||||||
typedef int (*getaddrinfo_t)(const char *, const char *,
|
|
||||||
const struct addrinfo *,
|
|
||||||
struct addrinfo **);
|
|
||||||
getaddrinfo_t true_getaddrinfo;
|
|
||||||
|
|
||||||
typedef int (*freeaddrinfo_t)(struct addrinfo *);
|
typedef int (*freeaddrinfo_t)(struct addrinfo *);
|
||||||
freeaddrinfo_t true_freeaddrinfo;
|
|
||||||
|
|
||||||
typedef int (*getnameinfo_t) (const struct sockaddr *,
|
|
||||||
socklen_t, char *,
|
|
||||||
socklen_t, char *,
|
|
||||||
socklen_t, int);
|
|
||||||
getnameinfo_t true_getnameinfo;
|
|
||||||
|
|
||||||
typedef struct hostent *(*gethostbyaddr_t) (const void *, socklen_t, int);
|
typedef struct hostent *(*gethostbyaddr_t) (const void *, socklen_t, int);
|
||||||
gethostbyaddr_t true_gethostbyaddr;
|
|
||||||
|
|
||||||
struct hostent* proxy_gethostbyname(const char *name);
|
typedef int (*getaddrinfo_t)(const char *, const char *, const struct addrinfo *,
|
||||||
|
struct addrinfo **);
|
||||||
|
|
||||||
int proxy_getaddrinfo(const char *node, const char *service,
|
typedef int (*getnameinfo_t) (const struct sockaddr *, socklen_t, char *,
|
||||||
const struct addrinfo *hints,
|
socklen_t, char *, socklen_t, int);
|
||||||
struct addrinfo **res);
|
|
||||||
|
|
||||||
|
|
||||||
void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes);
|
extern connect_t true_connect;
|
||||||
|
extern gethostbyname_t true_gethostbyname;
|
||||||
|
extern getaddrinfo_t true_getaddrinfo;
|
||||||
|
extern freeaddrinfo_t true_freeaddrinfo;
|
||||||
|
extern getnameinfo_t true_getnameinfo;
|
||||||
|
extern gethostbyaddr_t true_gethostbyaddr;
|
||||||
|
|
||||||
|
struct gethostbyname_data {
|
||||||
|
struct hostent hostent_space;
|
||||||
|
in_addr_t resolved_addr;
|
||||||
|
char *resolved_addr_p[2];
|
||||||
|
char addr_name[1024 * 8];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct hostent* proxy_gethostbyname(const char *name, struct gethostbyname_data *data);
|
||||||
|
|
||||||
|
int proxy_getaddrinfo(const char *node, const char *service,
|
||||||
|
const struct addrinfo *hints, struct addrinfo **res);
|
||||||
|
void proxy_freeaddrinfo(struct addrinfo *res);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# define PDEBUG(fmt, args...) fprintf(stderr,"DEBUG:"fmt, ## args)
|
# define PDEBUG(fmt, args...) do { fprintf(stderr,"DEBUG:"fmt, ## args); fflush(stderr); } while(0)
|
||||||
#else
|
#else
|
||||||
# define PDEBUG(fmt, args...) do {} while (0)
|
# define PDEBUG(fmt, args...) do {} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+43
-60
@@ -18,20 +18,20 @@
|
|||||||
#undef _GNU_SOURCE
|
#undef _GNU_SOURCE
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <netdb.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <unistd.h>
|
||||||
#include <netdb.h>
|
|
||||||
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@@ -43,18 +43,23 @@
|
|||||||
#define SOCKFAMILY(x) (satosin(x)->sin_family)
|
#define SOCKFAMILY(x) (satosin(x)->sin_family)
|
||||||
#define MAX_CHAIN 512
|
#define MAX_CHAIN 512
|
||||||
|
|
||||||
|
connect_t true_connect;
|
||||||
|
gethostbyname_t true_gethostbyname;
|
||||||
|
getaddrinfo_t true_getaddrinfo;
|
||||||
|
freeaddrinfo_t true_freeaddrinfo;
|
||||||
|
getnameinfo_t true_getnameinfo;
|
||||||
|
gethostbyaddr_t true_gethostbyaddr;
|
||||||
|
|
||||||
int tcp_read_time_out;
|
int tcp_read_time_out;
|
||||||
int tcp_connect_time_out;
|
int tcp_connect_time_out;
|
||||||
chain_type proxychains_ct;
|
|
||||||
proxy_data proxychains_pd[MAX_CHAIN];
|
|
||||||
unsigned int proxychains_proxy_count = 0;
|
|
||||||
int proxychains_got_chain_data = 0;
|
int proxychains_got_chain_data = 0;
|
||||||
unsigned int proxychains_max_chain = 1;
|
|
||||||
int proxychains_quiet_mode = 0;
|
int proxychains_quiet_mode = 0;
|
||||||
int proxychains_resolver = 0;
|
int proxychains_resolver = 0;
|
||||||
localaddr_arg localnet_addr[MAX_LOCALNET];
|
localaddr_arg localnet_addr[MAX_LOCALNET];
|
||||||
|
chain_type proxychains_ct;
|
||||||
|
proxy_data proxychains_pd[MAX_CHAIN];
|
||||||
|
|
||||||
size_t num_localnet_addr = 0;
|
size_t num_localnet_addr = 0;
|
||||||
unsigned int remote_dns_subnet = 224;
|
|
||||||
|
|
||||||
#ifdef THREAD_SAFE
|
#ifdef THREAD_SAFE
|
||||||
pthread_once_t init_once = PTHREAD_ONCE_INIT;
|
pthread_once_t init_once = PTHREAD_ONCE_INIT;
|
||||||
@@ -63,49 +68,41 @@ static int init_l = 0;
|
|||||||
|
|
||||||
static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
|
static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
|
||||||
|
|
||||||
static void load_sym(void** funcptr, char* symname, void* proxyfunc) {
|
static void* load_sym(char* symname, void* proxyfunc) {
|
||||||
|
|
||||||
*funcptr = dlsym(RTLD_NEXT, symname);
|
void *funcptr = dlsym(RTLD_NEXT, symname);
|
||||||
|
|
||||||
if(!(*funcptr)) {
|
if(!funcptr) {
|
||||||
fprintf(stderr, "Cannot load symbol '%s' %s\n", symname, dlerror());
|
fprintf(stderr, "Cannot load symbol '%s' %s\n", symname, dlerror());
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
PDEBUG("loaded symbol '%s'" " real addr %p wrapped addr %p\n", symname, (*funcptr), proxyfunc);
|
PDEBUG("loaded symbol '%s'" " real addr %p wrapped addr %p\n", symname, funcptr, proxyfunc);
|
||||||
}
|
}
|
||||||
if((*funcptr) == proxyfunc) {
|
if(funcptr == proxyfunc) {
|
||||||
PDEBUG("circular reference detected, aborting!\n");
|
PDEBUG("circular reference detected, aborting!\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
return funcptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define INIT() init_lib_wrapper(__FUNCTION__)
|
#define INIT() init_lib_wrapper(__FUNCTION__)
|
||||||
|
|
||||||
|
#define SETUP_SYM(X) do { true_ ## X = load_sym( # X, X ); } while(0)
|
||||||
|
|
||||||
static void do_init(void) {
|
static void do_init(void) {
|
||||||
static const struct override_info {
|
|
||||||
void* funcptr;
|
|
||||||
char* symname;
|
|
||||||
void* proxyfunc;
|
|
||||||
} override_symbols[] = {
|
|
||||||
#define SYM_ENTRY(X) { .funcptr = &true_ ## X, .symname = # X, .proxyfunc = X,}
|
|
||||||
SYM_ENTRY(connect),
|
|
||||||
SYM_ENTRY(gethostbyname),
|
|
||||||
SYM_ENTRY(getaddrinfo),
|
|
||||||
SYM_ENTRY(freeaddrinfo),
|
|
||||||
SYM_ENTRY(gethostbyaddr),
|
|
||||||
SYM_ENTRY(getnameinfo),
|
|
||||||
#undef SYM_ENTRY
|
|
||||||
};
|
|
||||||
unsigned i;
|
|
||||||
MUTEX_INIT(&internal_ips_lock, NULL);
|
MUTEX_INIT(&internal_ips_lock, NULL);
|
||||||
/* read the config file */
|
/* read the config file */
|
||||||
get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
|
get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
|
||||||
|
|
||||||
proxychains_write_log(LOG_PREFIX "DLL init\n");
|
proxychains_write_log(LOG_PREFIX "DLL init\n");
|
||||||
|
|
||||||
for (i = 0; i < (sizeof(override_symbols) / sizeof(override_symbols[0])); i++) {
|
SETUP_SYM(connect);
|
||||||
load_sym(override_symbols[i].funcptr, override_symbols[i].symname, override_symbols[i].proxyfunc);
|
SETUP_SYM(gethostbyname);
|
||||||
}
|
SETUP_SYM(getaddrinfo);
|
||||||
|
SETUP_SYM(freeaddrinfo);
|
||||||
|
SETUP_SYM(gethostbyaddr);
|
||||||
|
SETUP_SYM(getnameinfo);
|
||||||
|
|
||||||
init_l = 1;
|
init_l = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +139,7 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
|
|||||||
char *env;
|
char *env;
|
||||||
char local_in_addr_port[32];
|
char local_in_addr_port[32];
|
||||||
char local_in_addr[32], local_in_port[32], local_netmask[32];
|
char local_in_addr[32], local_in_port[32], local_netmask[32];
|
||||||
FILE *file;
|
FILE *file = NULL;
|
||||||
|
|
||||||
if(proxychains_got_chain_data)
|
if(proxychains_got_chain_data)
|
||||||
return;
|
return;
|
||||||
@@ -151,22 +148,9 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
|
|||||||
tcp_read_time_out = 4 * 1000;
|
tcp_read_time_out = 4 * 1000;
|
||||||
tcp_connect_time_out = 10 * 1000;
|
tcp_connect_time_out = 10 * 1000;
|
||||||
*ct = DYNAMIC_TYPE;
|
*ct = DYNAMIC_TYPE;
|
||||||
|
|
||||||
/*
|
env = get_config_path(getenv(PROXYCHAINS_CONF_FILE_ENV_VAR), buff, sizeof(buff));
|
||||||
* Get path to configuration file from env this file has priority
|
file = fopen(env, "r");
|
||||||
* if it's defined.
|
|
||||||
*/
|
|
||||||
env = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
|
||||||
|
|
||||||
snprintf(buff, 256, "%s/.proxychains/proxychains.conf", getenv("HOME"));
|
|
||||||
|
|
||||||
if(!env || (!(file = fopen(env, "r"))))
|
|
||||||
if(!(file = fopen("./proxychains.conf", "r")))
|
|
||||||
if(!(file = fopen(buff, "r")))
|
|
||||||
if(!(file = fopen("/etc/proxychains.conf", "r"))) {
|
|
||||||
perror("Can't locate proxychains.conf");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
env = getenv(PROXYCHAINS_QUIET_MODE_ENV_VAR);
|
env = getenv(PROXYCHAINS_QUIET_MODE_ENV_VAR);
|
||||||
if(env && *env == '1')
|
if(env && *env == '1')
|
||||||
@@ -339,13 +323,14 @@ int connect(int sock, const struct sockaddr *addr, unsigned int len) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct gethostbyname_data ghbndata;
|
||||||
struct hostent *gethostbyname(const char *name) {
|
struct hostent *gethostbyname(const char *name) {
|
||||||
INIT();
|
INIT();
|
||||||
|
|
||||||
PDEBUG("gethostbyname: %s\n", name);
|
PDEBUG("gethostbyname: %s\n", name);
|
||||||
|
|
||||||
if(proxychains_resolver)
|
if(proxychains_resolver)
|
||||||
return proxy_gethostbyname(name);
|
return proxy_gethostbyname(name, &ghbndata);
|
||||||
else
|
else
|
||||||
return true_gethostbyname(name);
|
return true_gethostbyname(name);
|
||||||
|
|
||||||
@@ -374,10 +359,8 @@ void freeaddrinfo(struct addrinfo *res) {
|
|||||||
|
|
||||||
if(!proxychains_resolver)
|
if(!proxychains_resolver)
|
||||||
true_freeaddrinfo(res);
|
true_freeaddrinfo(res);
|
||||||
else {
|
else
|
||||||
free(res->ai_addr);
|
proxy_freeaddrinfo(res);
|
||||||
free(res);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +385,7 @@ int getnameinfo(const struct sockaddr *sa,
|
|||||||
ret = true_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
|
ret = true_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
|
||||||
} else {
|
} else {
|
||||||
if(hostlen) {
|
if(hostlen) {
|
||||||
pc_stringfromipv4((unsigned char*) &(SOCKADDR_2(*sa)), ip_buf);
|
inet_ntop(AF_INET, (unsigned char*) &(SOCKADDR_2(*sa)), ip_buf, sizeof(ip_buf));
|
||||||
strncpy(host, ip_buf, hostlen);
|
strncpy(host, ip_buf, hostlen);
|
||||||
}
|
}
|
||||||
if(servlen)
|
if(servlen)
|
||||||
@@ -436,7 +419,7 @@ struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
|
|||||||
he.h_addrtype = AF_INET;
|
he.h_addrtype = AF_INET;
|
||||||
he.h_aliases = NULL;
|
he.h_aliases = NULL;
|
||||||
he.h_length = 4;
|
he.h_length = 4;
|
||||||
pc_stringfromipv4((unsigned char *) addr, buf);
|
inet_ntop(AF_INET, addr, buf, sizeof(buf));
|
||||||
return &he;
|
return &he;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
+15
-57
@@ -1,12 +1,4 @@
|
|||||||
/***************************************************************************
|
/* (C) 2011, 2012 rofl0r
|
||||||
main.c - description
|
|
||||||
|
|
||||||
begin : Tue May 14 2002
|
|
||||||
copyright : netcreature (C) 2002
|
|
||||||
email : netcreature@users.sourceforge.net
|
|
||||||
***************************************************************************/
|
|
||||||
/* GPL */
|
|
||||||
/***************************************************************************
|
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@@ -14,16 +6,21 @@
|
|||||||
* (at your option) any later version. *
|
* (at your option) any later version. *
|
||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#undef _POSIX_C_SOURCE
|
#undef _POSIX_C_SOURCE
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#undef _XOPEN_SOURCE
|
#undef _XOPEN_SOURCE
|
||||||
#define _XOPEN_SOURCE 700
|
#define _XOPEN_SOURCE 700
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@@ -36,12 +33,6 @@ static int usage(char **argv) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_path(char *path) {
|
|
||||||
if(!path)
|
|
||||||
return 0;
|
|
||||||
return access(path, R_OK) != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *dll_name = DLL_NAME;
|
static const char *dll_name = DLL_NAME;
|
||||||
|
|
||||||
static char own_dir[256];
|
static char own_dir[256];
|
||||||
@@ -72,11 +63,12 @@ static void set_own_dir(const char *argv0) {
|
|||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
char buf[256];
|
char buf[PATH_MAX];
|
||||||
char pbuf[256];
|
char pbuf[PATH_MAX];
|
||||||
int start_argv = 1;
|
int start_argv = 1;
|
||||||
int quiet = 0;
|
int quiet = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
const char *prefix = NULL;
|
const char *prefix = NULL;
|
||||||
|
|
||||||
for(i = 0; i < MAX_COMMANDLINE_FLAGS; i++) {
|
for(i = 0; i < MAX_COMMANDLINE_FLAGS; i++) {
|
||||||
@@ -101,41 +93,8 @@ int main(int argc, char *argv[]) {
|
|||||||
return usage(argv);
|
return usage(argv);
|
||||||
|
|
||||||
/* check if path of config file has not been passed via command line */
|
/* check if path of config file has not been passed via command line */
|
||||||
if(!path) {
|
path = get_config_path(path, pbuf, sizeof(pbuf));
|
||||||
// priority 1: env var PROXYCHAINS_CONF_FILE
|
|
||||||
path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
|
||||||
if(check_path(path))
|
|
||||||
goto have;
|
|
||||||
|
|
||||||
// priority 2; proxychains conf in actual dir
|
|
||||||
path = getcwd(buf, sizeof(buf));
|
|
||||||
snprintf(pbuf, sizeof(pbuf), "%s/%s", path, PROXYCHAINS_CONF_FILE);
|
|
||||||
path = pbuf;
|
|
||||||
if(check_path(path))
|
|
||||||
goto have;
|
|
||||||
|
|
||||||
// priority 3; $HOME/.proxychains/proxychains.conf
|
|
||||||
path = getenv("HOME");
|
|
||||||
snprintf(pbuf, sizeof(pbuf), "%s/.proxychains/%s", path, PROXYCHAINS_CONF_FILE);
|
|
||||||
path = pbuf;
|
|
||||||
if(check_path(path))
|
|
||||||
goto have;
|
|
||||||
|
|
||||||
// priority 4: $SYSCONFDIR/proxychains.conf
|
|
||||||
path = SYSCONFDIR "/" PROXYCHAINS_CONF_FILE;
|
|
||||||
if(check_path(path))
|
|
||||||
goto have;
|
|
||||||
|
|
||||||
// priority 5: /etc/proxychains.conf
|
|
||||||
path = "/etc/" PROXYCHAINS_CONF_FILE;
|
|
||||||
if(check_path(path))
|
|
||||||
goto have;
|
|
||||||
perror("couldnt find configuration file");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
have:
|
|
||||||
|
|
||||||
if(!quiet)
|
if(!quiet)
|
||||||
fprintf(stderr, LOG_PREFIX "config file found: %s\n", path);
|
fprintf(stderr, LOG_PREFIX "config file found: %s\n", path);
|
||||||
|
|
||||||
@@ -145,9 +104,7 @@ int main(int argc, char *argv[]) {
|
|||||||
if(quiet)
|
if(quiet)
|
||||||
setenv(PROXYCHAINS_QUIET_MODE_ENV_VAR, "1", 1);
|
setenv(PROXYCHAINS_QUIET_MODE_ENV_VAR, "1", 1);
|
||||||
|
|
||||||
|
|
||||||
// search DLL
|
// search DLL
|
||||||
|
|
||||||
set_own_dir(argv[0]);
|
set_own_dir(argv[0]);
|
||||||
|
|
||||||
while(dll_dirs[i]) {
|
while(dll_dirs[i]) {
|
||||||
@@ -163,6 +120,7 @@ int main(int argc, char *argv[]) {
|
|||||||
fprintf(stderr, "couldnt locate %s\n", dll_name);
|
fprintf(stderr, "couldnt locate %s\n", dll_name);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!quiet)
|
if(!quiet)
|
||||||
fprintf(stderr, LOG_PREFIX "preloading %s/%s\n", prefix, dll_name);
|
fprintf(stderr, LOG_PREFIX "preloading %s/%s\n", prefix, dll_name);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#ifndef NI_MAXHOST
|
||||||
|
#define NI_MAXHOST 1025
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct addrinfo *result;
|
||||||
|
struct addrinfo *res;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
/* resolve the domain name into a list of addresses */
|
||||||
|
error = getaddrinfo("www.example.com", NULL, NULL, &result);
|
||||||
|
if (error != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* loop over all returned results and do inverse lookup */
|
||||||
|
for (res = result; res != NULL; res = res->ai_next)
|
||||||
|
{
|
||||||
|
char hostname[NI_MAXHOST] = "";
|
||||||
|
|
||||||
|
error = getnameinfo(res->ai_addr, res->ai_addrlen, hostname, NI_MAXHOST, NULL, 0, 0);
|
||||||
|
if (error != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "error in getnameinfo: %s\n", gai_strerror(error));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (*hostname != '\0')
|
||||||
|
printf("hostname: %s\n", hostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
freeaddrinfo(result);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user