Exemple #1
0
/*
 * Resolve a hostname through Tor and set the ip address in the given pointer.
 *
 * Return 0 on success else a negative value and the result addr is untouched.
 */
int tsocks_tor_resolve_ptr(const char *addr, char **ip, int af)
{
	int ret;
	struct connection conn;
	uint8_t socks5_method;

	assert(addr);
	assert(ip);

	DBG("Resolving %" PRIu32 " on the Tor network", addr);

	conn.fd = tsocks_libc_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (conn.fd < 0) {
		PERROR("socket");
		ret = -errno;
		goto error;
	}
	conn.dest_addr.domain = CONNECTION_DOMAIN_INET;

	/* Is this configuration is set to use SOCKS5 authentication. */
	if (tsocks_config.socks5_use_auth) {
		socks5_method = SOCKS5_USER_PASS_METHOD;
	} else {
		socks5_method = SOCKS5_NO_AUTH_METHOD;
	}

	ret = setup_tor_connection(&conn, socks5_method);
	if (ret < 0) {
		goto end_close;
	}

	/* For the user/pass method, send the request before resolve ptr. */
	if (socks5_method == SOCKS5_USER_PASS_METHOD) {
		ret = auth_socks5(&conn);
		if (ret < 0) {
			goto end_close;
		}
	}

	ret = socks5_send_resolve_ptr_request(&conn, addr, af);
	if (ret < 0) {
		goto end_close;
	}

	/* Force IPv4 resolution for now. */
	ret = socks5_recv_resolve_ptr_reply(&conn, ip);
	if (ret < 0) {
		goto end_close;
	}

end_close:
	if (tsocks_libc_close(conn.fd) < 0) {
		PERROR("close");
	}

error:
	return ret;
}
Exemple #2
0
/*
 * Resolve a hostname through Tor and set the ip address in the given pointer.
 *
 * Return 0 on success else a negative value and the result addr is untouched.
 */
int tsocks_tor_resolve_ptr(const char *addr, char **ip, int af)
{
	int ret;
	struct connection conn;

	assert(addr);
	assert(ip);

	DBG("Resolving %" PRIu32 " on the Tor network", addr);

	conn.fd = tsocks_libc_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (conn.fd < 0) {
		PERROR("socket");
		ret = -errno;
		goto error;
	}
	conn.dest_addr.domain = CONNECTION_DOMAIN_INET;

	ret = setup_tor_connection(&conn, SOCKS5_NO_AUTH_METHOD);
	if (ret < 0) {
		goto end_close;
	}

	ret = socks5_send_resolve_ptr_request(&conn, addr, af);
	if (ret < 0) {
		goto end_close;
	}

	/* Force IPv4 resolution for now. */
	ret = socks5_recv_resolve_ptr_reply(&conn, ip);
	if (ret < 0) {
		goto end_close;
	}

end_close:
	if (tsocks_libc_close(conn.fd) < 0) {
		PERROR("close");
	}

error:
	return ret;
}
Exemple #3
0
/*
 * Resolve a hostname through Tor and set the ip address in the given pointer.
 *
 * Return 0 on success else a negative value and the result addr is untouched.
 */
int tsocks_tor_resolve_ptr(const char *addr, char **ip, int af)
{
	int ret;
	struct connection conn;

	assert(addr);
	assert(ip);

	DBG("Resolving %" PRIu32 " on the Tor network", addr);

	conn.fd = tsocks_libc_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (conn.fd < 0) {
		PERROR("socket");
		ret = -errno;
		goto error;
	}

	ret = setup_tor_connection(&conn);
	if (ret < 0) {
		goto error;
	}

	ret = socks5_send_resolve_ptr_request(addr, &conn);
	if (ret < 0) {
		goto error;
	}

	/* Force IPv4 resolution for now. */
	ret = socks5_recv_resolve_ptr_reply(&conn, ip);
	if (ret < 0) {
		goto error;
	}

	ret = close(conn.fd);
	if (ret < 0) {
		PERROR("close");
	}

error:
	return ret;
}