Mercurial > dropbear
annotate cli-main.c @ 63:dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
- still a checkpoint-ish commit
- sorted out listening on localhost only
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 11 Aug 2004 17:26:47 +0000 |
parents | b4874d772210 |
children | e3adf4cf5465 |
rev | line source |
---|---|
33 | 1 #include "includes.h" |
2 #include "dbutil.h" | |
3 #include "runopts.h" | |
4 #include "session.h" | |
26 | 5 |
33 | 6 static void cli_dropbear_exit(int exitcode, const char* format, va_list param); |
7 static void cli_dropbear_log(int priority, const char* format, va_list param); | |
8 | |
9 #if defined(DBMULTI_dbclient) || !defined(DROPBEAR_MULTI) | |
10 #if defined(DBMULTI_dbclient) && defined(DROPBEAR_MULTI) | |
11 int cli_main(int argc, char ** argv) { | |
12 #else | |
26 | 13 int main(int argc, char ** argv) { |
33 | 14 #endif |
26 | 15 |
16 int sock; | |
17 char* error = NULL; | |
18 char* hostandport; | |
19 int len; | |
20 | |
21 _dropbear_exit = cli_dropbear_exit; | |
22 _dropbear_log = cli_dropbear_log; | |
23 | |
24 cli_getopts(argc, argv); | |
25 | |
33 | 26 TRACE(("user='%s' host='%s' port='%s'", cli_opts.username, |
27 cli_opts.remotehost, cli_opts.remoteport)); | |
28 | |
26 | 29 sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport, |
30 0, &error); | |
31 | |
32 if (sock < 0) { | |
33 dropbear_exit("%s", error); | |
34 } | |
35 | |
36 /* Set up the host:port log */ | |
37 len = strlen(cli_opts.remotehost); | |
38 len += 10; /* 16 bit port and leeway*/ | |
39 hostandport = (char*)m_malloc(len); | |
33 | 40 snprintf(hostandport, len, "%s:%s", |
26 | 41 cli_opts.remotehost, cli_opts.remoteport); |
42 | |
43 cli_session(sock, hostandport); | |
44 | |
45 /* not reached */ | |
46 return -1; | |
47 } | |
33 | 48 #endif /* DBMULTI stuff */ |
49 | |
50 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { | |
51 | |
52 char fmtbuf[300]; | |
53 | |
54 if (!sessinitdone) { | |
55 snprintf(fmtbuf, sizeof(fmtbuf), "exited: %s", | |
56 format); | |
57 } else { | |
58 snprintf(fmtbuf, sizeof(fmtbuf), | |
59 "connection to %s@%s:%s exited: %s", | |
60 cli_opts.username, cli_opts.remotehost, | |
61 cli_opts.remoteport, format); | |
62 } | |
63 | |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
64 /* Do the cleanup first, since then the terminal will be reset */ |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
65 cli_session_cleanup(); |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
66 common_session_cleanup(); |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
67 |
33 | 68 _dropbear_log(LOG_INFO, fmtbuf, param); |
69 | |
70 exit(exitcode); | |
71 } | |
72 | |
73 static void cli_dropbear_log(int priority, const char* format, va_list param) { | |
74 | |
75 char printbuf[1024]; | |
76 | |
77 vsnprintf(printbuf, sizeof(printbuf), format, param); | |
78 | |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
79 fprintf(stderr, "%s: %s\n", cli_opts.progname, printbuf); |
33 | 80 |
81 } |