⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htc.c

📁 穿越防火墙技术代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*htc.cCopyright (C) 1999 Lars Brinkhoff.  See COPYING for terms and conditions.htc is the client half of httptunnel.  httptunnel creates a virtualtwo-way data path tunneled in HTTP requests.*/#include <stdio.h>#include <stdlib.h>#include <unistd_.h>#include <signal.h>#include <sys/poll_.h>#include <sys/time.h>#include <sys/stat.h>#include "common.h"#include "base64.h"#define DEFAULT_PROXY_PORT 8080#define DEFAULT_PROXY_BUFFER_TIMEOUT 500 /* milliseconds */typedef struct{  char *me;  char *device;  char *host_name;  int host_port;  char *proxy_name;  int proxy_port;  size_t proxy_buffer_size;  int proxy_buffer_timeout;  size_t content_length;  int forward_port;  int strict_content_length;  int keep_alive;  int max_connection_age;  char *proxy_authorization;  char *user_agent;} Arguments;#define NO_PROXY_BUFFER 0#define NO_PROXY (NULL)int debug_level = 0;FILE *debug_file = NULL;static voidusage (FILE *f, const char *me){  fprintf (f,"Usage: %s [OPTION]... HOST[:PORT]\n""Set up a httptunnel connection to PORT at HOST (default port is %d).\n""When a connection is made, I/O is redirected from the source specified\n""by the --device or --forward-port switch to the tunnel.\n""\n""  -A, --proxy-authorization USER:PASSWORD  proxy authorization\n""  --proxy-authorization-file FILE          proxy authorization file\n""  -B, --proxy-buffer-size BYTES  assume a proxy buffer size of BYTES bytes\n""                                 (k, M, and G postfixes recognized)\n""  -c, --content-length BYTES     use HTTP PUT requests of BYTES size\n""                                 (k, M, and G postfixes recognized)\n""  -d, --device DEVICE            use DEVICE for input and output\n"#ifdef DEBUG_MODE"  -D, --debug [LEVEL]            enable debugging mode\n"#endif"  -F, --forward-port PORT        use TCP port PORT for input and output\n""  -h, --help                     display this help and exit\n""  -k, --keep-alive SECONDS       send keepalive bytes every SECONDS seconds\n""                                 (default is %d)\n"#ifdef DEBUG_MODE"  -l, --logfile FILE             specify file for debugging output\n"#endif"  -M, --max-connection-age SEC   maximum time a connection will stay\n""                                 open is SEC seconds (default is %d)\n""  -P, --proxy HOSTNAME[:PORT]    use a HTTP proxy (default port is %d)\n""  -S, --strict-content-length    always write Content-Length bytes in requests\n""  -T, --timeout TIME             timeout, in milliseconds, before sending\n""                                 padding to a buffering proxy\n""  -U, --user-agent STRING        specify User-Agent value in HTTP requests\n""  -V, --version                  output version information and exit\n""\n""Report bugs to %s.\n",	   me, DEFAULT_HOST_PORT, DEFAULT_KEEP_ALIVE,	   DEFAULT_MAX_CONNECTION_AGE, DEFAULT_PROXY_PORT,	   BUG_REPORT_EMAIL);}static intwait_for_connection_on_socket (int s){  struct sockaddr addr;  socklen_t len;  int t;  len = sizeof addr;  t = accept (s, &addr, &len);  if (t == -1)    return -1;  return t;}static voidparse_arguments (int argc, char **argv, Arguments *arg){  int c;  /* defaults */  arg->me = argv[0];  arg->device = NULL;  arg->forward_port = -1;  arg->host_name = NULL;  arg->host_port = DEFAULT_HOST_PORT;  arg->proxy_name = NO_PROXY;  arg->proxy_port = DEFAULT_PROXY_PORT;  arg->proxy_buffer_size = NO_PROXY_BUFFER;  arg->proxy_buffer_timeout = -1;  arg->content_length = DEFAULT_CONTENT_LENGTH;  arg->strict_content_length = FALSE;  arg->keep_alive = DEFAULT_KEEP_ALIVE;  arg->max_connection_age = DEFAULT_CONNECTION_MAX_TIME;  arg->proxy_authorization = NULL;  arg->user_agent = NULL;    for (;;)    {      int option_index = 0;      static struct option long_options[] =      {	{ "help", no_argument, 0, 'h' },	{ "version", no_argument, 0, 'V' },#ifdef DEBUG_MODE	{ "debug", required_argument, 0, 'D' },	{ "logfile", required_argument, 0, 'l' },#endif	{ "proxy", required_argument, 0, 'P' },	{ "device", required_argument, 0, 'd' },	{ "timeout", required_argument, 0, 'T' },	{ "keep-alive", required_argument, 0, 'k' },	{ "user-agent", required_argument, 0, 'U' },	{ "forward-port", required_argument, 0, 'F' },	{ "content-length", required_argument, 0, 'c' },	{ "strict-content-length", no_argument, 0, 'S' },	{ "proxy-buffer-size", required_argument, 0, 'B' },	{ "proxy-authorization", required_argument, 0, 'A' },	{ "max-connection-age", required_argument, 0, 'M' },	{ "proxy-authorization-file", required_argument, 0, 'z' },	{ 0, 0, 0, 0 }      };      static const char *short_options = "A:B:c:d:F:hk:M:P:ST:U:Vz:"#ifdef DEBUG_MODE	"D:l:"#endif	;      c = getopt_long (argc, argv, short_options,		       long_options, &option_index);      if (c == -1)	break;      switch (c)	{	case 0:	  printf ("option %s", long_options[option_index].name);	  if (optarg)	    printf (" with arg %s", optarg);	  printf ("\n");	  break;	case 'A':	  arg->proxy_authorization = optarg;	  break;	case 'B':	  arg->proxy_buffer_size = atoi_with_postfix (optarg);	  break;	case 'c':	  arg->content_length = atoi_with_postfix (optarg);	  break;	case 'd':	  arg->device = optarg;	  break;#ifdef DEBUG_MODE	case 'D':	  if (optarg)	    debug_level = atoi (optarg);	  else	    debug_level = 1;	  break;	case 'l':	  debug_file = fopen (optarg, "w");	  if (debug_file == NULL)	    {	      fprintf (stderr, "%s: couldn't open file %s for writing\n",		       arg->me, optarg);	      exit (1);	    }	  break;#endif	case 'F':	  arg->forward_port = atoi (optarg);	  break;	case 'k':	  arg->keep_alive = atoi (optarg);	  break;	case 'M':	  arg->max_connection_age = atoi (optarg);	  break;	case 'h':	  usage (stdout, arg->me);	  exit (0);	case 'P':	  name_and_port (optarg, &arg->proxy_name, &arg->proxy_port);	  if (arg->proxy_port == -1)	    arg->proxy_port = DEFAULT_PROXY_PORT;	  if (arg->proxy_buffer_timeout == -1)	    arg->proxy_buffer_timeout = DEFAULT_PROXY_BUFFER_TIMEOUT;	  break;	case 'S':	  arg->strict_content_length = TRUE;	  break;	case 'T':	  arg->proxy_buffer_timeout = atoi (optarg);	  break;	case 'U':	  arg->user_agent = optarg;	  break;	case 'V':	  printf ("htc (%s) %s\n", PACKAGE, VERSION);	  exit (0);	case 'z':	  {	    struct stat s;	    char *auth;	    int f;	    f = open (optarg, O_RDONLY);	    if (f == -1)	      {		printf ("couldn't open %s: %s\n", optarg, strerror (errno));		exit (1);	      }	    if (fstat (f, &s) == -1)	      {		printf ("error fstating %s: %s\n", optarg, strerror (errno));		exit (1);	      }	    auth = malloc (s.st_size + 1);	    if (auth == NULL)	      {		printf ("out of memory whilst allocating"			"authentication string\n");		exit (1);	      }	    if (read_all (f, auth, s.st_size) == -1)	      {		printf ("error reading %s: %s\n", optarg, strerror (errno));		exit (1);	      }	    /*	     * If file ends with a "\r\n" or "\n", chop them off.	     */	    if (s.st_size >= 1 && auth[s.st_size - 1] == '\n')	      {		s.st_size -=		  (s.st_size >= 2 && auth[s.st_size - 2] == '\r') ? 2 : 1;	      }	    auth[s.st_size] = 0;	    arg->proxy_authorization = auth;	  }	  break;	case '?':	  break;	default:	  printf ("?? getopt returned character code 0%o ??\n", c);	}    }  if (optind == argc - 1)    {      name_and_port (argv[optind], &arg->host_name, &arg->host_port);      if (arg->host_port == -1)	arg->host_port = DEFAULT_HOST_PORT;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -