summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/tor-gencert.c24
-rw-r--r--src/tools/tor-resolve.c27
2 files changed, 28 insertions, 23 deletions
diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c
index ce032ed643..ff924152a6 100644
--- a/src/tools/tor-gencert.c
+++ b/src/tools/tor-gencert.c
@@ -38,10 +38,11 @@ ENABLE_GCC_WARNING(redundant-decls)
#include "lib/encoding/binascii.h"
#include "lib/encoding/time_fmt.h"
#include "lib/fs/files.h"
-#include "lib/log/torlog.h"
-#include "lib/malloc/util_malloc.h"
+#include "lib/log/log.h"
+#include "lib/malloc/malloc.h"
#include "lib/net/address.h"
-#include "lib/net/ipv4.h"
+#include "lib/net/inaddr.h"
+#include "lib/net/resolve.h"
#include "lib/string/compat_string.h"
#include "lib/string/printf.h"
@@ -170,19 +171,22 @@ parse_commandline(int argc, char **argv)
} else if (!strcmp(argv[i], "-v")) {
verbose = 1;
} else if (!strcmp(argv[i], "-a")) {
- uint32_t addr;
+ tor_addr_t addr;
uint16_t port;
- char b[INET_NTOA_BUF_LEN];
- struct in_addr in;
if (i+1>=argc) {
fprintf(stderr, "No argument to -a\n");
return 1;
}
- if (addr_port_lookup(LOG_ERR, argv[++i], NULL, &addr, &port)<0)
+ const char *addr_arg = argv[++i];
+ if (tor_addr_port_lookup(addr_arg, &addr, &port)<0) {
+ fprintf(stderr, "Can't resolve address/port for %s", addr_arg);
return 1;
- in.s_addr = htonl(addr);
- tor_inet_ntoa(&in, b, sizeof(b));
- tor_asprintf(&address, "%s:%d", b, (int)port);
+ }
+ if (tor_addr_family(&addr) != AF_INET) {
+ fprintf(stderr, "%s must resolve to an IPv4 address", addr_arg);
+ return 1;
+ }
+ address = tor_strdup(fmt_addrport(&addr, port));
} else if (!strcmp(argv[i], "--create-identity-key")) {
make_new_id = 1;
} else if (!strcmp(argv[i], "--passphrase-fd")) {
diff --git a/src/tools/tor-resolve.c b/src/tools/tor-resolve.c
index 1532d5f201..d5b4987832 100644
--- a/src/tools/tor-resolve.c
+++ b/src/tools/tor-resolve.c
@@ -6,8 +6,8 @@
#include "orconfig.h"
#include "lib/arch/bytes.h"
-#include "lib/log/torlog.h"
-#include "lib/malloc/util_malloc.h"
+#include "lib/log/log.h"
+#include "lib/malloc/malloc.h"
#include "lib/net/address.h"
#include "lib/net/resolve.h"
#include "lib/net/socket.h"
@@ -197,12 +197,14 @@ socks5_reason_to_string(char reason)
* address (in host order) into *<b>result_addr</b>.
*/
static int
-do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
+do_resolve(const char *hostname,
+ const tor_addr_t *sockshost, uint16_t socksport,
int reverse, int version,
tor_addr_t *result_addr, char **result_hostname)
{
int s = -1;
- struct sockaddr_in socksaddr;
+ struct sockaddr_storage ss;
+ socklen_t socklen;
char *req = NULL;
ssize_t len = 0;
@@ -219,11 +221,10 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
return -1;
}
- memset(&socksaddr, 0, sizeof(socksaddr));
- socksaddr.sin_family = AF_INET;
- socksaddr.sin_port = htons(socksport);
- socksaddr.sin_addr.s_addr = htonl(sockshost);
- if (connect(s, (struct sockaddr*)&socksaddr, sizeof(socksaddr))) {
+ socklen = tor_addr_to_sockaddr(sockshost, socksport,
+ (struct sockaddr *)&ss, sizeof(ss));
+
+ if (connect(s, (struct sockaddr*)&ss, sizeof(socklen))) {
log_sock_error("connecting to SOCKS host", s);
goto err;
}
@@ -346,7 +347,7 @@ usage(void)
int
main(int argc, char **argv)
{
- uint32_t sockshost;
+ tor_addr_t sockshost;
uint16_t socksport = 0, port_option = 0;
int isSocks4 = 0, isVerbose = 0, isReverse = 0;
char **arg;
@@ -414,7 +415,7 @@ main(int argc, char **argv)
if (n_args == 1) {
log_debug(LD_CONFIG, "defaulting to localhost");
- sockshost = 0x7f000001u; /* localhost */
+ tor_addr_from_ipv4h(&sockshost, 0x7f000001u); /* localhost */
if (port_option) {
log_debug(LD_CONFIG, "Using port %d", (int)port_option);
socksport = port_option;
@@ -423,7 +424,7 @@ main(int argc, char **argv)
socksport = 9050; /* 9050 */
}
} else if (n_args == 2) {
- if (addr_port_lookup(LOG_WARN, arg[1], NULL, &sockshost, &socksport)<0) {
+ if (tor_addr_port_lookup(arg[1], &sockshost, &socksport)<0) {
fprintf(stderr, "Couldn't parse/resolve address %s", arg[1]);
return 1;
}
@@ -445,7 +446,7 @@ main(int argc, char **argv)
return 1;
}
- if (do_resolve(arg[0], sockshost, socksport, isReverse,
+ if (do_resolve(arg[0], &sockshost, socksport, isReverse,
isSocks4 ? 4 : 5, &result,
&result_hostname))
return 1;