2
* Copyright (c) 1997, 1998, 1999, 2000, 2001
3
* Inferno Nettverk A/S, Norway. All rights reserved.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. The above copyright notice, this list of conditions and the following
9
* disclaimer must appear in all copies of the software, derivative works
10
* or modified versions, and any portions thereof, aswell as in all
11
* supporting documentation.
12
* 2. All advertising materials mentioning features or use of this software
13
* must display the following acknowledgement:
14
* This product includes software developed by
15
* Inferno Nettverk A/S, Norway.
16
* 3. The name of the author may not be used to endorse or promote products
17
* derived from this software without specific prior written permission.
19
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
* Inferno Nettverk A/S requests users of this software to return to
32
* Software Distribution Coordinator or sdc@inet.no
33
* Inferno Nettverk A/S
39
* any improvements or extensions that they make and grant Inferno Nettverk A/S
40
* the rights to redistribute these changes.
44
/* $Id: socks.h,v 1.164 2001/10/06 12:37:11 karls Exp $ */
48
#endif /* ! _SOCKS_H_ */
51
extern const int lintnoloop_socks_h;
53
#define lintnoloop_socks_h 0
56
#ifndef HAVE_OSF_OLDSTYLE
57
#define HAVE_OSF_OLDSTYLE 0
58
#endif /* !HAVE_OSF_OLDSTYLE */
60
#if SOCKSLIBRARY_DYNAMIC
65
#if HAVE_EXTRA_OSF_SYMBOLS
66
#define accept(s, addr, addrlen) sys_Eaccept(s, addr, addrlen)
68
#define accept(s, addr, addrlen) sys_accept(s, addr, addrlen)
69
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
74
#define bind(s, name, namelen) sys_bind(s, name, namelen)
78
#endif /* bindresvport */
79
#define bindresvport(sd, sin) sys_bindresvport(sd, sin)
84
#define connect(s, name, namelen) sys_connect(s, name, namelen)
88
#endif /* gethostbyname */
89
#if HAVE_GETHOSTBYNAME2
91
* a little tricky ... we need it to be at the bottom of the stack,
94
#define gethostbyname(name) sys_gethostbyname2(name, AF_INET)
96
#define gethostbyname(name) sys_gethostbyname(name)
100
#undef gethostbyname2
101
#endif /* gethostbyname2 */
102
#define gethostbyname2(name, af) sys_gethostbyname2(name, af)
106
#endif /* getpeername */
107
#if HAVE_EXTRA_OSF_SYMBOLS
108
#define getpeername(s, name, namelen) sys_Egetpeername(s, name, namelen)
110
#define getpeername(s, name, namelen) sys_getpeername(s, name, namelen)
111
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
115
#endif /* getsockname */
116
#if HAVE_EXTRA_OSF_SYMBOLS
117
#define getsockname(s, name, namelen) sys_Egetsockname(s, name, namelen)
119
#define getsockname(s, name, namelen) sys_getsockname(s, name, namelen)
120
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
125
#define read(d, buf, nbytes) sys_read(d, buf, nbytes)
130
#if HAVE_EXTRA_OSF_SYMBOLS
131
#define readv(d, iov, iovcnt) sys_Ereadv(d, iov, iovcnt)
133
#define readv(d, iov, iovcnt) sys_readv(d, iov, iovcnt)
134
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
139
#define recv(s, msg, len, flags) sys_recv(s, msg, len, flags)
143
#endif /* recvfrom */
144
#if HAVE_EXTRA_OSF_SYMBOLS
145
#define recvfrom(s, buf, len, flags, from, fromlen) \
146
sys_Erecvfrom(s, buf, len, flags, from, fromlen)
148
#define recvfrom(s, buf, len, flags, from, fromlen) \
149
sys_recvfrom(s, buf, len, flags, from, fromlen)
151
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
156
#if HAVE_EXTRA_OSF_SYMBOLS
157
#define recvmsg(s, msg, flags) sys_Erecvmsg(s, msg, flags)
159
#define recvmsg(s, msg, flags) sys_recvmsg(s, msg, flags)
160
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
164
#endif /* rresvport */
165
#define rresvport(port) sys_rresvport(port)
170
#define sendto(s, msg, len, flags, to, tolen) \
171
sys_sendto(s, msg, len, flags, to, tolen)
176
#define write(d, buf, nbytes) sys_write(d, buf, nbytes)
181
#if HAVE_EXTRA_OSF_SYMBOLS
182
#define writev(d, iov, iovcnt) sys_Ewritev(d, iov, iovcnt)
184
#define writev(d, iov, iovcnt) sys_writev(d, iov, iovcnt)
185
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
190
#define send(s, msg, len, flags) sys_send(s, msg, len, flags)
195
#if HAVE_EXTRA_OSF_SYMBOLS
196
#define sendmsg(s, msg, flags) sys_Esendmsg(s, msg, flags)
198
#define sendmsg(s, msg, flags) sys_sendmsg(s, msg, flags)
199
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
201
#endif /* SOCKSLIBRARY_DYNAMIC */
203
struct configstate_t {
206
struct sockaddr lastconnect; /* address we last connected to. */
213
char *configfile; /* name of current configfile. */
214
unsigned lbuf:1; /* linebuffered output? */
221
pid_t connectchild; /* connect process. */
222
int connect_s; /* socket to child. */
223
char domain[MAXHOSTNAMELEN]; /* localdomain. */
224
struct logtype_t log; /* where to log. */
225
struct option_t option; /* misc. options. */
226
struct configstate_t state;
227
int resolveprotocol; /* resolveprotocol. */
228
struct route_t *route; /* linked list of routes*/
231
struct childpacket_t {
232
struct sockshost_t src;
233
struct sockshost_t dst;
234
struct socks_t packet;
241
* libsocks function declarations
245
clientinit __P((void));
247
* initialises clientstate, reads configfile, etc.
251
#if !HAVE_OSF_OLDSTYLE
252
int Raccept __P((int, struct sockaddr *, socklen_t *));
253
int Rconnect __P((int, const struct sockaddr *, socklen_t));
254
int Rgetsockname __P((int, struct sockaddr *, socklen_t *));
255
int Rgetpeername __P((int, struct sockaddr *, socklen_t *));
256
ssize_t Rsendto __P((int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen));
257
ssize_t Rrecvfrom __P((int s, void *buf, size_t len, int flags, struct sockaddr * from, socklen_t *fromlen));
258
ssize_t Rsendmsg __P((int s, const struct msghdr *msg, int flags));
259
ssize_t Rrecvmsg __P((int s, struct msghdr *msg, int flags));
260
int Rbind __P((int, const struct sockaddr *, socklen_t));
261
#endif /* !HAVE_OSF_OLDSTYLE */
263
int Rbindresvport __P((int, struct sockaddr_in *));
264
int Rrresvport __P((int *));
265
struct hostent *Rgethostbyname __P((const char *));
266
struct hostent *Rgethostbyname2 __P((const char *, int af));
267
ssize_t Rwrite __P((int d, const void *buf, size_t nbytes));
268
ssize_t Rwritev __P((int d, const struct iovec *iov, int iovcnt));
269
ssize_t Rsend __P((int s, const void *msg, size_t len, int flags));
270
ssize_t Rread __P((int d, void *buf, size_t nbytes));
271
ssize_t Rreadv __P((int d, const struct iovec *iov, int iovcnt));
272
ssize_t Rrecv __P((int s, void *msg, size_t len, int flags));
274
int SOCKSinit __P((char *));
275
int Rlisten __P((int, int));
276
int Rselect __P((int, fd_set *, fd_set *, fd_set *, struct timeval *));
278
* unused functions needed to compile programs with support for other
279
* socks implementations.
284
udpsetup __P((int s, const struct sockaddr *to, int type));
286
* sets up udp relaying between address of "s" and "to" by connecting
288
* If relaying is already set up the function returns with success.
289
* Type is the type of connection setup, SOCKS_SEND or SOCKS_RECV.
290
* At the moment only SOCKS_SEND is supported.
298
negotiate_method __P((int s, struct socks_t *packet));
300
* Negotiates a method to be used when talking with the server connected
301
* to "s". "packet" is the packet that will later be sent to server,
302
* only the "auth" element in it will be set but other elements are needed
311
socks_sendrequest __P((int s, const struct request_t *request));
313
* Sends the request "request" to the socksserver connected to "s".
320
socks_recvresponse __P((int s, struct response_t *response, int version));
322
* Receives a socks response from the "s". "response" is filled in with
324
* "version" is the protocolversion negotiated.
332
socks_negotiate __P((int s, int control, struct socks_t *packet,
333
struct route_t *route));
335
* "s" is the socket data will flow over.
336
* "control" is the control connection to the socks server.
337
* "packet" is a socks packet containing the request.
338
* "route" is the connected route.
339
* Negotiates method and fills the response to the request into packet->res.
341
* On success: 0 (server replied to our request).
348
socks_nbconnectroute __P((int s, int control, struct socks_t *packet,
349
const struct sockshost_t *src,
350
const struct sockshost_t *dst));
352
* The non-blocking version of socks_connectroute(), only used by client.
353
* Takes one additional argument, "s", which is the socket to connect
354
* and not necessarily the same as "control" (msproxy case).
358
socks_badroute __P((struct route_t *route));
360
* Marks route "route" as bad.
364
recv_sockshost __P((int s, struct sockshost_t *host, int version,
365
struct authmethod_t *auth));
367
* Fills "host" based on data read from "s". "version" is the version
368
* the remote peer is expected to send data in.
377
* Misc. functions to help keep track of our connection(s) to the server.
381
socks_addaddr __P((unsigned int clientfd, struct socksfd_t *socksaddress));
383
* "clientfd" is associated with the structure "socksfd".
384
* The function duplicates all arguments in it's own form and does
385
* not access the memory referenced by them afterwards.
387
* The function checks the state of all filedescriptors on each call and
388
* removes those that are no longer open.
391
* On success: pointer to the added socksfd_t structure.
392
* On failure: exits. (memory exhausted and process grew descriptor size.)
397
socks_getaddr __P((unsigned int fd));
400
* On success: the socketaddress associated with filedescriptor "fd".
401
* On failure: NULL. (no socketaddress associated with "fd").
406
socks_rmaddr __P((unsigned int s));
408
* removes the association for the socket "s", also closes the server
409
* connection. If "s" is not registered the request is ignored.
413
socksfddup __P((const struct socksfd_t *old, struct socksfd_t *new));
415
* Duplicates "old", in "new".
418
* On failure: NULL (resource shortage).
423
socks_addrcontrol __P((const struct sockaddr *local,
424
const struct sockaddr *remote));
426
* Goes through all addresses registered and tries to find one where
427
* the control socket has a local address of "local" and peer address
428
* of "remote". If either of "local" or "remote" is NULL, that
429
* endpoint is not checked against.
431
* On success: the descriptor the socksfd struct was registered with.
436
socks_addrmatch __P((const struct sockaddr *local,
437
const struct sockaddr *remote,
438
const struct socksstate_t *state));
440
* Goes through all addresses registered and tries to find one where
441
* all arguments match.
442
* Arguments that are NULL or have "illegal" values are ignored.
444
* On success: the descriptor the socksfd with matching arguments was
445
* registered with (>= 0).
451
socks_isaddr __P((unsigned int fd));
453
* Returns true if there is a address registered for the socket "fd", false
459
socks_addrisok __P((unsigned int s));
461
* Compares the current address of "s" to the registered address.
462
* If there is a mismatch, the function will try to correct it if possible.
464
* If current address found to match registered: true.
469
socks_addfd __P((unsigned int fd));
471
* adds the filedescriptor "fd" to an internal table.
472
* If it is already in the table the request is ignored.
479
socks_isfd __P((unsigned int fd));
481
* returns 1 if "fd" is a filedescriptor in our internal table, 0 if not.
485
socks_rmfd __P((unsigned int fd));
487
* removes the filedescriptor "fd" from our internal table.
492
fdisopen __P((int fd));
494
* returns 1 if the filedescriptor "fd" currently references a open object.
495
* returns 0 otherwise.
500
clientmethod_uname __P((int s, const struct sockshost_t *host, int version));
502
* Enters username/password negotiation with the socksserver connected to
504
* "host" gives the name of the server.
505
* "version" gives the socksversion established to use.
508
* On failure: whatever the remote socksserver returned as status.
513
socks_getusername __P((const struct sockshost_t *host, char *buf,
516
* Tries to determine the username of the current user, to be used
517
* when negotiating with the server "host".
518
* The NUL-terminated username is written to "buf", which is of size
521
* On success: pointer to "buf" with the username.
526
socks_getpassword __P((const struct sockshost_t *host, const char *user,
527
char *buf, size_t buflen));
529
* Tries to determine the password of user "user", to be used
530
* when negotiating with the server "host".
531
* The NUL-terminated password is written to "buf", which is of length
534
* On success: pointer to "buf" with the password.
540
serverreplyisok __P((int version, int reply, struct route_t *route));
542
* "replycode" is the reply code returned by a socksserver of version
544
* "route" is the route that was used for the socksserver. If
545
* the errorcode indicates a serverfailure, it might be "badrouted".
546
* Returns true if the reply indicates request succeeded, false otherwise
547
* and sets errno accordingly.
551
msproxy_negotiate __P((int s, int control, struct socks_t *packet));
553
* Negotiates with the msproxy server connected to "control".
554
* "s" gives the socket to be used for dataflow.
555
* "packet" contains the request and on return from the function
556
* contains the response.
558
* On success: 0 (server replied to our request).
564
send_msprequest __P((int s, struct msproxy_state_t *state,
565
struct msproxy_request_t *packet));
567
* Sends a msproxy request to "s".
568
* "state" is the current state of the connection to "s",
569
* "packet" is the request to send.
573
recv_mspresponse __P((int s, struct msproxy_state_t *state,
574
struct msproxy_response_t *packet));
576
* Receives a msproxy response from "s".
577
* "state" is the current state of the connection to "s",
578
* "packet" is the memory the response is read into.
582
msproxy_sigio __P((int s));
584
* Must be called on sockets where we expect the connection to be forwarded
585
* by the msproxy server.
586
* "s" is the socket and must have been added with socks_addaddr() beforehand.
593
msproxy_init __P((void));
595
* inits things for using a msproxyserver.
601
httpproxy_negotiate __P((int control, struct socks_t *packet));
603
* Negotiates a method to be used when talking with the server connected
604
* to "s". "packet" is the packet that will later be sent to server.
605
* packet->res.reply will be set depending on the result of negotiation.
607
* On success: 0 (server replied to our request).
613
cc_socksfdv(int sig);
615
* consistencycheck on socksfdv.
620
#if SOCKSLIBRARY_DYNAMIC
622
int sys_rresvport __P((int *));
623
int sys_bindresvport __P((int, struct sockaddr_in *));
625
HAVE_PROT_READ_0 sys_read
626
__P((HAVE_PROT_READ_1, HAVE_PROT_READ_2, HAVE_PROT_READ_3));
627
HAVE_PROT_READV_0 sys_readv
628
__P((HAVE_PROT_READV_1, HAVE_PROT_READV_2, HAVE_PROT_READV_3));
629
HAVE_PROT_RECV_0 sys_recv
630
__P((HAVE_PROT_RECV_1, HAVE_PROT_RECV_2, HAVE_PROT_RECV_3, HAVE_PROT_RECV_4));
631
HAVE_PROT_RECVMSG_0 sys_recvmsg
632
__P((HAVE_PROT_RECVMSG_1, HAVE_PROT_RECVMSG_2, HAVE_PROT_RECVMSG_3));
633
HAVE_PROT_SEND_0 sys_send
634
__P((HAVE_PROT_SEND_1 , HAVE_PROT_SEND_2, HAVE_PROT_SEND_3, HAVE_PROT_SEND_4));
635
HAVE_PROT_WRITE_0 sys_write
636
__P((HAVE_PROT_WRITE_1, HAVE_PROT_WRITE_2, HAVE_PROT_WRITE_3));
638
#if HAVE_OSF_OLDSTYLE
639
int sys_accept __P((int, struct sockaddr *, int *));
641
HAVE_PROT_ACCEPT_0 sys_accept
642
__P((HAVE_PROT_ACCEPT_1, HAVE_PROT_ACCEPT_2, HAVE_PROT_ACCEPT_3));
643
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
645
#if HAVE_OSF_OLDSTYLE
646
int sys_bind __P((int, const struct sockaddr *, int));
648
HAVE_PROT_BIND_0 sys_bind
649
__P((HAVE_PROT_BIND_1, HAVE_PROT_BIND_2, HAVE_PROT_BIND_3));
650
#endif /* !HAVE_OSF_OLDSTYLE */
652
#if HAVE_OSF_OLDSTYLE
653
int sys_connect __P((int, const struct sockaddr *, int));
655
HAVE_PROT_CONNECT_0 sys_connect
656
__P((HAVE_PROT_CONNECT_1, HAVE_PROT_CONNECT_2, HAVE_PROT_CONNECT_3));
657
#endif /* HAVE_OSF_OLDSTYLE */
659
#if HAVE_OSF_OLDSTYLE
660
int sys_getpeername __P((int, struct sockaddr *, int *));
662
HAVE_PROT_GETPEERNAME_0 sys_getpeername
663
__P((HAVE_PROT_GETPEERNAME_1, HAVE_PROT_GETPEERNAME_2, HAVE_PROT_GETPEERNAME_3));
664
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
666
#if HAVE_OSF_OLDSTYLE
667
int sys_getsockname __P((int, struct sockaddr *, int *));
669
HAVE_PROT_GETSOCKNAME_0 sys_getsockname
670
__P((HAVE_PROT_GETSOCKNAME_1, HAVE_PROT_GETSOCKNAME_2, HAVE_PROT_GETSOCKNAME_3));
671
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
673
#if HAVE_OSF_OLDSTYLE
674
int sys_recvfrom __P((int, void*, int, int, struct sockaddr *, int *));
676
HAVE_PROT_RECVFROM_0 sys_recvfrom
677
__P((HAVE_PROT_RECVFROM_1, HAVE_PROT_RECVFROM_2, HAVE_PROT_RECVFROM_3, HAVE_PROT_RECVFROM_4, HAVE_PROT_RECVFROM_5, HAVE_PROT_RECVFROM_6));
680
#if HAVE_OSF_OLDSTYLE
681
ssize_t sys_writev __P((int, const struct iovec *, int));
683
HAVE_PROT_WRITEV_0 sys_writev
684
__P((HAVE_PROT_WRITEV_1, HAVE_PROT_WRITEV_2, HAVE_PROT_WRITEV_3));
687
#if HAVE_OSF_OLDSTYLE
688
ssize_t sys_sendmsg __P((int, struct msghdr *, int));
690
HAVE_PROT_SENDMSG_0 sys_sendmsg
691
__P((HAVE_PROT_SENDMSG_1, HAVE_PROT_SENDMSG_2, HAVE_PROT_SENDMSG_3));
694
#if HAVE_OSF_OLDSTYLE
695
int sys_sendto __P((int, const void *, int, int, const struct sockaddr *, socklen_t));
697
HAVE_PROT_SENDTO_0 sys_sendto
698
__P((HAVE_PROT_SENDTO_1, HAVE_PROT_SENDTO_2, HAVE_PROT_SENDTO_3, HAVE_PROT_SENDTO_4, HAVE_PROT_SENDTO_5, HAVE_PROT_SENDTO_6));
699
#endif /* !HAVE_OSF_OLDSTYLE */
701
#if HAVE_EXTRA_OSF_SYMBOLS
702
int sys_Eaccept __P((int, struct sockaddr *, socklen_t *));
703
int sys_Egetpeername __P((int, struct sockaddr *, socklen_t *));
704
int sys_Egetsockname __P((int, struct sockaddr *, socklen_t *));
705
ssize_t sys_Ereadv __P((int, const struct iovec *, int));
706
int sys_Erecvfrom __P((int, void *, size_t, int, struct sockaddr *, size_t *));
707
ssize_t sys_Erecvmsg __P((int, struct msghdr *, int));
708
ssize_t sys_Esendmsg __P((int, const struct msghdr *, int));
709
ssize_t sys_Ewritev __P((int, const struct iovec *, int));
711
int sys_naccept __P((int, struct sockaddr *, socklen_t *));
712
int sys_ngetpeername __P((int, struct sockaddr *, socklen_t *));
713
int sys_ngetsockname __P((int, struct sockaddr *, socklen_t *));
714
int sys_nrecvfrom __P((int, void *, size_t, int, struct sockaddr *, size_t *));
715
ssize_t sys_nrecvmsg __P((int, struct msghdr *, int));
716
ssize_t sys_nsendmsg __P((int, const struct msghdr *, int));
718
#endif /* HAVE_EXTRA_OSF_SYMBOLS */
720
#endif /* SOCKSLIBRARY_DYNAMIC */