comparison tcp-connect.c @ 62:20563735e8b5

just checkpointing
author Matt Johnston <matt@ucc.asn.au>
date Tue, 10 Aug 2004 17:09:52 +0000
parents
children dcc43965928f
comparison
equal deleted inserted replaced
61:3a4f0ef1e8c3 62:20563735e8b5
1 #include "includes.h"
2 #include "session.h"
3 #include "dbutil.h"
4 #include "channel.h"
5 #include "tcp-connect.h"
6 #include "runopts.h"
7
8 #ifndef DISABLE_TCP_CONNECT
9
10 /* Called upon creating a new direct tcp channel (ie we connect out to an
11 * address */
12 int newtcpdirect(struct Channel * channel) {
13
14 unsigned char* desthost = NULL;
15 unsigned int destport;
16 unsigned char* orighost = NULL;
17 unsigned int origport;
18 char portstring[6];
19 int sock;
20 int len;
21 int ret = DROPBEAR_FAILURE;
22
23 if (opts.nolocaltcp) {
24 TRACE(("leave newtcpdirect: local tcp forwarding disabled"));
25 goto out;
26 }
27
28 desthost = buf_getstring(ses.payload, &len);
29 if (len > MAX_HOST_LEN) {
30 TRACE(("leave newtcpdirect: desthost too long"));
31 goto out;
32 }
33
34 destport = buf_getint(ses.payload);
35
36 orighost = buf_getstring(ses.payload, &len);
37 if (len > MAX_HOST_LEN) {
38 TRACE(("leave newtcpdirect: orighost too long"));
39 goto out;
40 }
41
42 origport = buf_getint(ses.payload);
43
44 /* best be sure */
45 if (origport > 65535 || destport > 65535) {
46 TRACE(("leave newtcpdirect: port > 65535"));
47 goto out;
48 }
49
50 snprintf(portstring, sizeof(portstring), "%d", destport);
51 sock = connect_remote(desthost, portstring, 1, NULL);
52 if (sock < 0) {
53 TRACE(("leave newtcpdirect: sock failed"));
54 goto out;
55 }
56
57 ses.maxfd = MAX(ses.maxfd, sock);
58
59 /* Note that infd is actually the "outgoing" direction on the
60 * tcp connection, vice versa for outfd.
61 * We don't set outfd, that will get set after the connection's
62 * progress succeeds */
63 channel->infd = sock;
64 channel->initconn = 1;
65
66 ret = DROPBEAR_SUCCESS;
67
68 out:
69 m_free(desthost);
70 m_free(orighost);
71 TRACE(("leave newtcpdirect: ret %d", ret));
72 return ret;
73 }
74
75 #endif /* DISABLE_TCPFWD_DIRECT */