1 /*
2  * Copyright (C) 2002-2006 Josh A. Beam
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *   1. Redistributions of source code must retain the above copyright
9  *      notice, this list of conditions and the following disclaimer.
10  *   2. Redistributions in binary form must reproduce the above copyright
11  *      notice, this list of conditions and the following disclaimer in the
12  *      documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21  * WHETHER IN CONTACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 /* flags */
27 #define PRT_VERBOSE 0x1
28 #define PRT_COLOR   0x2
29 #define PRT_DAEMON	0x4
30 #define PRT_IPV6    0x8
31 #define PRT_IRC_AUTOPONG 0x10
32 #define PRT_HTTP_1_0     0x20
33 
34 /* proxy types */
35 #define PRT_DIRECT     0
36 #define PRT_DIRECT6    1
37 #define PRT_HTTP       2
38 #define PRT_SOCKS5     3
39 
40 /* keep-alive types */
41 #define PRT_KEEPALIVE_TELNET 0
42 #define PRT_KEEPALIVE_CRLF   1
43 
44 #ifdef _WIN32
45 #	include <winsock2.h>
46 #	define SHUT_RDWR SD_BOTH
47 #	define close(s) closesocket(s)
48 #	define snprintf _snprintf
49 #else
50 #	include <unistd.h>
51 #	include <sys/time.h>
52 #	include <sys/socket.h>
53 #	include <netinet/in.h>
54 #	include <netdb.h>
55 #endif /* _WIN32 */
56 
57 struct prt_context {
58 	/* pointers to protocol-specific functions */
59 	int (*connect)(struct prt_context *context, char *hostname, unsigned short port, char *username, char *password, int server_timeout);
60 	void (*disconnect)(struct prt_context *context);
61 	int (*local_read)(struct prt_context *context, char *buf, int size);
62 	int (*local_send)(struct prt_context *context, char *buf, int size);
63 	int (*remote_read)(struct prt_context *context, char *buf, int size);
64 	int (*remote_send)(struct prt_context *context, char *buf, int size);
65 
66 	struct sockaddr_in sin;
67 #ifdef IPV6
68 	struct sockaddr_in6 sin6;
69 #endif /* IPV6 */
70 	unsigned int sockaddr_len;
71 
72 	int localfd; /* client socket */
73 	int remotefd; /* server socket */
74 	unsigned int bytes_sent;
75 	unsigned int bytes_rcvd;
76 	void *data; /* some protocols may require extra data, so we
77 	               include this pointer for them to keep track of it */
78 
79 	unsigned long keepalive_seconds;
80 };
81