aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-09-29 14:18:47 +0000
committerNick Mathewson <nickm@torproject.org>2008-09-29 14:18:47 +0000
commitee0078ead4d41dc87c080ab5d9ec955770aca3de (patch)
treebf3756384c5ca12a2ca2b999e0e1d461df7dc4fc
parent9678f166a8e5c48f9cd0e0b6a27dd41ce081e419 (diff)
downloadtor-ee0078ead4d41dc87c080ab5d9ec955770aca3de.tar
tor-ee0078ead4d41dc87c080ab5d9ec955770aca3de.tar.gz
Make tor-resolve take a -p port option in addition to the current host:port syntax.
svn:r17002
-rw-r--r--ChangeLog2
-rw-r--r--src/tools/tor-resolve.c37
2 files changed, 33 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 94a59ae55..8673a7b3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -60,6 +60,8 @@ Changes in version 0.2.1.6-alpha - 2008-09-29
single-hop circuits, and clients to use those servers to build
single-hop circuits when using a specialized controller. Patch
from Josh Albrecht. Resolves feature request 768.
+ - Add a -p option to tor-resolve for specifying the SOCKS port: some
+ people find host:port too confusing.
o Minor bugfixes:
- Fix compile on OpenBSD 4.4-current. Bugfix on 0.2.1.5-alpha.
diff --git a/src/tools/tor-resolve.c b/src/tools/tor-resolve.c
index 04822a15d..90f736df3 100644
--- a/src/tools/tor-resolve.c
+++ b/src/tools/tor-resolve.c
@@ -293,7 +293,7 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
static void
usage(void)
{
- puts("Syntax: tor-resolve [-4] [-v] [-x] [-F] "
+ puts("Syntax: tor-resolve [-4] [-v] [-x] [-F] [-p port] "
"hostname [sockshost:socksport]");
exit(1);
}
@@ -303,7 +303,7 @@ int
main(int argc, char **argv)
{
uint32_t sockshost;
- uint16_t socksport;
+ uint16_t socksport = 0, port_option = 0;
int isSocks4 = 0, isVerbose = 0, isReverse = 0, force = 0;
char **arg;
int n_args;
@@ -336,7 +336,21 @@ main(int argc, char **argv)
isReverse = 1;
else if (!strcmp("-F", arg[0]))
force = 1;
- else {
+ else if (!strcmp("-p", arg[0])) {
+ int p;
+ if (n_args < 2) {
+ fprintf(stderr, "No arguments given to -p\n");
+ usage();
+ }
+ p = atoi(arg[1]);
+ if (p<1 || p > 65535) {
+ fprintf(stderr, "-p requires a number between 1 and 65535\n");
+ usage();
+ }
+ port_option = (uint16_t) p;
+ ++arg; /* skip the port */
+ --n_args;
+ } else {
fprintf(stderr, "Unrecognized flag '%s'\n", arg[0]);
usage();
}
@@ -356,15 +370,26 @@ main(int argc, char **argv)
add_stream_log(s, "<stderr>", stderr);
if (n_args == 1) {
- log_debug(LD_CONFIG, "defaulting to localhost:9050");
+ log_debug(LD_CONFIG, "defaulting to localhost");
sockshost = 0x7f000001u; /* localhost */
- socksport = 9050; /* 9050 */
+ if (port_option) {
+ log_debug(LD_CONFIG, "Using port %d", (int)port_option);
+ socksport = port_option;
+ } else {
+ log_debug(LD_CONFIG, "defaulting to port 9050");
+ socksport = 9050; /* 9050 */
+ }
} else if (n_args == 2) {
if (parse_addr_port(LOG_WARN, arg[1], NULL, &sockshost, &socksport)<0) {
fprintf(stderr, "Couldn't parse/resolve address %s", arg[1]);
return 1;
}
- if (socksport == 0) {
+ if (socksport && port_option && socksport != port_option) {
+ log_warn(LD_CONFIG, "Conflicting ports; using %d, not %d",
+ (int)socksport, (int)port_option);
+ } else if (port_option) {
+ socksport = port_option;
+ } else {
log_debug(LD_CONFIG, "defaulting to port 9050");
socksport = 9050;
}