summaryrefslogtreecommitdiff
path: root/other/fizzbounce/network.h
diff options
context:
space:
mode:
Diffstat (limited to 'other/fizzbounce/network.h')
-rw-r--r--other/fizzbounce/network.h205
1 files changed, 205 insertions, 0 deletions
diff --git a/other/fizzbounce/network.h b/other/fizzbounce/network.h
new file mode 100644
index 0000000..0fcaa06
--- /dev/null
+++ b/other/fizzbounce/network.h
@@ -0,0 +1,205 @@
1/* scut's leet network library ;)
2 * 1999 (c) scut
3 *
4 * networking code
5 */
6
7#include <sys/socket.h>
8#include <net/if.h>
9#include <netinet/in.h>
10#include <stdio.h>
11
12#ifndef _NETWORK_H
13#define _NETWORK_H
14
15#define NET_READTIMEOUT 180
16#define NET_CONNTIMEOUT 60
17#define NET_IDENTTIMEOUT 15
18
19#define IFI_NAME 16
20#define IFI_HADDR 8
21
22/* pointer to this struct list returned by net_get_ifi
23 */
24struct ifi_info {
25 char ifi_name[IFI_NAME];
26 u_char ifi_haddr[IFI_HADDR];
27 u_short ifi_hlen;
28 short ifi_flags;
29 short ifi_myflags;
30 struct sockaddr *ifi_addr;
31 struct in_addr ifi_saddr;
32 struct ifi_info *ifi_next;
33};
34
35#define IFI_ALIAS 1
36
37typedef struct bound {
38 int bs; /* bound socket */
39 unsigned short port; /* port we bound to */
40 struct sockaddr bsa; /* bs_in */
41} bound;
42
43extern int net_readtimeout;
44extern int net_conntimeout;
45extern int net_identtimeout;
46
47/* net_socks_connect
48 *
49 * relays through an open socks 5 server (NO AUTH type)
50 * returns a socket descriptor which is already connected
51 */
52
53int net_socks_connect (char *socks, unsigned short int sport, char *server, unsigned short int port, int sec);
54
55/* net_socks_put_s5info
56 *
57 * inserts socks 5 compatible relay information into socket s5s,
58 * used to relay over more then just one socks server
59 */
60
61int net_socks_put_s5info (int s5s, char *server, unsigned short int port, int sec);
62
63/* net_parseip
64 *
65 * reads an ip in the format "1.1.1.1:299" or "blabla:481" into
66 * the char pointer *ip and into the port *port
67 *
68 * returns 0 on failure
69 * returns 1 on success
70 */
71int net_parseip (char *inp, char **ip, unsigned short int *port);
72
73/* net_getlocalip
74 *
75 * returns the local IP address as string on success
76 * returns NULL on failure
77 */
78
79char *net_getlocalip (void);
80
81/* net_descriptify
82 *
83 * descriptifies a socket ;)
84 * returns -1 on failure
85 * returns file descriptor on success
86 */
87
88FILE *net_descriptify (int socket);
89
90/* net_ident
91 *
92 * idents a connection identified by the host:port pairs on both sides,
93 * returning the ident in *ident
94 *
95 * returns 1 on success
96 * returns -1 on failure
97 */
98
99int net_ident (char **ident, struct sockaddr_in *locals, unsigned short int localport,
100 struct sockaddr_in *remotes, unsigned short int remoteport);
101
102/* net_accept
103 * accepts a connection from socket s, and stores the connection
104 * into cs.
105 * wait a maximum amount of maxsec seconds for connections
106 * maxsec can also be zero (infinite wait, until connection)
107 *
108 * returns 0 if no connection has been made within maxsec seconds
109 * returns -1 if an error appears
110 * returns the socket number if a connection has been made
111 */
112
113int net_accept (int s, struct sockaddr_in *cs, int maxsec);
114
115/* net_get_ifi
116 * get interface information
117 * returns NULL on failure
118 * returns a pointer to a linked list structure ifi_info (see above)
119 */
120
121struct ifi_info *net_ifi_get (int family, int doaliases);
122void net_ifi_free (struct ifi_info *tf);
123
124/* net_testvip
125 * tests if virtual ip/hostname is available for use on the local machine,
126 * returns 1 if the ip can be used
127 * 0 if the ip/host is not available
128 */
129int net_testvip (char *ip);
130
131/* net_bind
132 * binds a socket to an ip:port on the local machine,
133 * ip can be either NULL (bind to all IP's on the host), or a pointer
134 * to a virtual host name, or a real IP, or "*" for any.
135 * port can be either 0 (ephemeral port), or any free port.
136 *
137 * returns NULL on failure
138 * pointer to bound structure on success
139 */
140bound *net_bind (char *ip, unsigned short int port);
141void net_boundfree (bound *bf);
142
143/* net_resolve
144 * resolves host into s_addr
145 */
146unsigned long int net_resolve(char *host);
147
148/* net_connect
149 * connects to the given server and port with a max timeout of sec
150 * initializes the sockaddr_in struct correctly (ipv4), accepts any
151 * ip "123.123.123.123" or hostname "localhost", "www.yahoo.de" as hostname
152 * creates a new socket and returns either -1 if failed or
153 * the socket if connection has been established within the timeout limit
154 * routine is still IPv4 biased :-/
155 *
156 * returns -1 on failure
157 * returns socket if success
158 */
159int net_connect(struct sockaddr_in *cs, char *server, unsigned short int port, int sec);
160
161/* net_rtimeout
162 * waits max <sec> seconds for fd to become readable
163 * returns -1 on error (errno set)
164 * returns 1 on readability
165 */
166int net_rtimeout(int fd, int sec);
167
168/* net_rbuf
169 * allocates memory and reads to *dst until connection close
170 * returns n if success (n = number of bytes read)
171 * returns -1 if failed
172 */
173long int net_rbuf(int fd, char **dst);
174#define NET_BSIZE 4096
175
176/* net_rbuft
177 * reads dsize bytes into dst from fd, with timeout
178 * returns 1 on success
179 * returns -1 on failure
180 */
181int net_rbuft(int fd, char *dst, unsigned long int dsize);
182
183/* net_rlinet
184 * reads a line from socket descriptor with timeout to buffer
185 * if sec = 0, then only a continuous stream of data is required, not
186 * an overall timeout.
187 * returns -1 on timeout
188 * returns 0 on connection close
189 * returns length of readen line (including '\n')
190 */
191int net_rlinet(int fd, char *buf, int bufsize, int sec);
192
193/* net_tline
194 * returns length if string contains '\n'
195 * returns -1 if no '\n' in string
196 */
197int net_tline(char *buf, int bufsize);
198
199/* net_write
200 * prints a formatted string to a socket
201 */
202void net_write(int fd, const char *str, ...);
203
204#endif
205