X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/2184a5d91ffbcf2de2f730c83dda2d9443035f50..9dc625f0ca85b2272a4dda1150c5c178c91729ea:/portfwd.c diff --git a/portfwd.c b/portfwd.c index 732bfc5b..e1499de9 100644 --- a/portfwd.c +++ b/portfwd.c @@ -1,4 +1,3 @@ -#include #include #include @@ -61,6 +60,8 @@ struct PFwdPrivate { struct plug_function_table *fn; /* the above variable absolutely *must* be the first in this structure */ void *c; /* (channel) data used by ssh.c */ + void *backhandle; /* instance of SSH backend itself */ + /* Note that backhandle need not be filled in if c is non-NULL */ Socket s; char hostname[128]; int throttled, throttle_override; @@ -69,8 +70,6 @@ struct PFwdPrivate { struct pfwd_queue *waiting; }; -void pfd_close(Socket s); - static int pfd_closing(Plug plug, char *error_msg, int error_code, int calling_back) @@ -109,7 +108,8 @@ static void pfd_sent(Plug plug, int bufsize) /* * Called when receiving a PORT OPEN from the server */ -char *pfd_newconnect(Socket *s, char *hostname, int port, void *c) +char *pfd_newconnect(Socket *s, char *hostname, int port, void *c, + const Config *cfg) { static struct plug_function_table fn_table = { pfd_closing, @@ -125,8 +125,8 @@ char *pfd_newconnect(Socket *s, char *hostname, int port, void *c) /* * Try to find host. */ - addr = sk_namelookup(hostname, &dummy_realhost); - if ((err = sk_addr_error(addr))) + addr = name_lookup(hostname, port, &dummy_realhost, cfg); + if ((err = sk_addr_error(addr)) != NULL) return err; /* @@ -137,9 +137,11 @@ char *pfd_newconnect(Socket *s, char *hostname, int port, void *c) pr->throttled = pr->throttle_override = 0; pr->ready = 1; pr->c = c; + pr->backhandle = NULL; /* we shouldn't need this */ - pr->s = *s = sk_new(addr, port, 0, 1, 0, (Plug) pr); - if ((err = sk_socket_error(*s))) { + pr->s = *s = new_connection(addr, dummy_realhost, port, + 0, 1, 0, (Plug) pr, cfg); + if ((err = sk_socket_error(*s)) != NULL) { sfree(pr); return err; } @@ -170,14 +172,15 @@ static int pfd_accepting(Plug p, void *sock) pr->fn = &fn_table; pr->c = NULL; + pr->backhandle = org->backhandle; pr->s = s = sk_register(sock, (Plug) pr); - if ((err = sk_socket_error(s))) { + if ((err = sk_socket_error(s)) != NULL) { sfree(pr); return err != NULL; } - pr->c = new_sock_channel(s); + pr->c = new_sock_channel(org->backhandle, s); strcpy(pr->hostname, org->hostname); pr->port = org->port; @@ -200,9 +203,10 @@ static int pfd_accepting(Plug p, void *sock) /* Add a new forwarding from port -> desthost:destport - sets up a listener on the local machine on port + sets up a listener on the local machine on (srcaddr:)port */ -char *pfd_addforward(char *desthost, int destport, int port) +char *pfd_addforward(char *desthost, int destport, char *srcaddr, int port, + void *backhandle, const Config *cfg) { static struct plug_function_table fn_table = { pfd_closing, @@ -226,9 +230,11 @@ char *pfd_addforward(char *desthost, int destport, int port) pr->throttled = pr->throttle_override = 0; pr->ready = 0; pr->waiting = NULL; + pr->backhandle = backhandle; - pr->s = s = sk_newlistener(port, (Plug) pr, !cfg.lport_acceptall); - if ((err = sk_socket_error(s))) { + pr->s = s = new_listener(srcaddr, port, (Plug) pr, + !cfg->lport_acceptall, cfg); + if ((err = sk_socket_error(s)) != NULL) { sfree(pr); return err; }