mirror of
https://github.com/rofl0r/proxychains-ng
synced 2026-05-13 17:03:07 +08:00
25afe98b20
this is in order to get irssi, which forks for DNS lookups, and similar programs, to work as intended. in a previous attempt i learned that shared memory created in a child process is not visible to the parent; in this attempt i spin off a thread from the parent which listens on a pipe and manages the shared memory allocation from the parent address-space. however this doesnt work as expected: memory allocated in the parent after the child forked is not visi- ble to the child as well. so what happens is: irssi starts a child process, the thread allocs memory and hands it to the child, the child attempts to write and segfaults. however irssi doesnt crash. since now the memory is already allocated, doing the dns lookup again will succeed. i.e. the dns lookup works now in irssi by luck. all but the first dns lookups will suceed. however this is not good enough for me to be satisfied, i commit this only for documentation purposes.
160 lines
4.3 KiB
C
160 lines
4.3 KiB
C
/***************************************************************************
|
|
core.h - description
|
|
-------------------
|
|
begin : Tue May 14 2002
|
|
copyright : netcreature (C) 2002
|
|
email : netcreature@users.sourceforge.net
|
|
***************************************************************************
|
|
***************************************************************************
|
|
* *
|
|
* 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 *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
***************************************************************************/
|
|
|
|
#include <unistd.h>
|
|
#include <stdint.h>
|
|
#include <netinet/in.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netdb.h>
|
|
|
|
#ifndef __CORE_HEADER
|
|
#define __CORE_HEADER
|
|
#define BUFF_SIZE 8*1024 // used to read responses from proxies.
|
|
#define MAX_LOCALNET 64
|
|
|
|
typedef union {
|
|
unsigned char octet[4];
|
|
uint32_t as_int;
|
|
} ip_type;
|
|
|
|
typedef struct {
|
|
uint32_t hash;
|
|
char* string;
|
|
} string_hash_tuple;
|
|
|
|
struct mallocinfo {
|
|
void * addr;
|
|
size_t oldsz;
|
|
size_t newsz;
|
|
};
|
|
|
|
typedef struct {
|
|
uint32_t counter;
|
|
uint32_t capa;
|
|
struct mallocinfo mi;
|
|
string_hash_tuple** list;
|
|
} internal_ip_lookup_table;
|
|
|
|
extern internal_ip_lookup_table *internal_ips;
|
|
#ifdef THREAD_SAFE
|
|
#include <pthread.h>
|
|
extern pthread_mutex_t internal_ips_lock;
|
|
extern pthread_mutex_t hostdb_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*/
|
|
typedef enum {
|
|
SUCCESS=0,
|
|
MEMORY_FAIL, // malloc failed
|
|
SOCKET_ERROR, // look errno for more
|
|
CHAIN_DOWN, // no proxy in chain responds to tcp
|
|
CHAIN_EMPTY, // if proxy_count = 0
|
|
BLOCKED // target's port blocked on last proxy in the chain
|
|
} ERR_CODE;
|
|
|
|
typedef enum {
|
|
HTTP_TYPE,
|
|
SOCKS4_TYPE,
|
|
SOCKS5_TYPE
|
|
} proxy_type;
|
|
|
|
typedef enum {
|
|
DYNAMIC_TYPE,
|
|
STRICT_TYPE,
|
|
RANDOM_TYPE}
|
|
chain_type;
|
|
|
|
typedef enum {
|
|
PLAY_STATE,
|
|
DOWN_STATE,
|
|
BLOCKED_STATE,
|
|
BUSY_STATE
|
|
} proxy_state;
|
|
|
|
typedef enum {
|
|
RANDOMLY,
|
|
FIFOLY
|
|
} select_type;
|
|
|
|
typedef struct {
|
|
struct in_addr in_addr, netmask;
|
|
unsigned short port;
|
|
} localaddr_arg;
|
|
|
|
typedef struct {
|
|
ip_type ip;
|
|
unsigned short port;
|
|
proxy_type pt;
|
|
proxy_state ps;
|
|
char user[256];
|
|
char pass[256];
|
|
} proxy_data;
|
|
|
|
int connect_proxy_chain (int sock, ip_type target_ip, unsigned short target_port,
|
|
proxy_data * pd, unsigned int proxy_count, chain_type ct,
|
|
unsigned int max_chain );
|
|
|
|
void proxychains_write_log(char *str, ...);
|
|
|
|
typedef int (*connect_t)(int, const struct sockaddr *, socklen_t);
|
|
typedef struct hostent* (*gethostbyname_t)(const char *);
|
|
typedef int (*freeaddrinfo_t)(struct addrinfo *);
|
|
typedef struct hostent *(*gethostbyaddr_t) (const void *, socklen_t, int);
|
|
|
|
typedef int (*getaddrinfo_t)(const char *, const char *, const struct addrinfo *,
|
|
struct addrinfo **);
|
|
|
|
typedef int (*getnameinfo_t) (const struct sockaddr *, socklen_t, char *,
|
|
socklen_t, char *, socklen_t, int);
|
|
|
|
|
|
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);
|
|
|
|
void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes);
|
|
|
|
#include "debug.h"
|
|
|
|
#endif
|
|
|
|
//RcB: DEP "core.c"
|
|
//RcB: DEP "libproxychains.c"
|
|
//RcB: LINK "-Wl,--no-as-needed -ldl -lpthread"
|