Commit c76f310f authored by teor's avatar teor
Browse files

routerinfo: Make router_get_orport() return an error status

Part of 33222.
parent 24099680
......@@ -21,9 +21,8 @@
* <b>family</b> into *<b>ap_out</b>.
*
* If the requested ORPort does not exist, sets *<b>ap_out</b> to the null
* address and port. You can check the returned value using
* tor_addr_port_is_valid_ap(ap_out, 0). */
void
* address and port, and returns -1. Otherwise, returns 0. */
int
router_get_orport(const routerinfo_t *router,
tor_addr_port_t *ap_out,
int family)
......@@ -32,15 +31,22 @@ router_get_orport(const routerinfo_t *router,
if (family == AF_INET) {
tor_addr_from_ipv4h(&ap_out->addr, router->addr);
ap_out->port = router->or_port;
return 0;
} else if (family == AF_INET6) {
/* If there is no IPv6 address, ipv6_addr will be the null address and
* port. */
tor_addr_copy(&ap_out->addr, &router->ipv6_addr);
ap_out->port = router->ipv6_orport;
/* IPv6 addresses are optional, so check if it is valid. */
if (tor_addr_port_is_valid(&router->ipv6_addr, router->ipv6_orport, 0)) {
tor_addr_copy(&ap_out->addr, &router->ipv6_addr);
ap_out->port = router->ipv6_orport;
return 0;
} else {
tor_addr_port_make_null_ap(ap_out, AF_INET6);
return -1;
}
} else {
/* Unsupported address family */
tor_assert_nonfatal_unreached();
tor_addr_port_make_null_ap(ap_out, AF_UNSPEC);
return -1;
}
}
......
......@@ -12,7 +12,7 @@
#ifndef TOR_ROUTERINFO_H
#define TOR_ROUTERINFO_H
void router_get_orport(const routerinfo_t *router,
int router_get_orport(const routerinfo_t *router,
tor_addr_port_t *addr_port_out,
int family);
int router_has_orport(const routerinfo_t *router,
......
......@@ -163,8 +163,7 @@ extend_info_from_router(const routerinfo_t *r, int family)
else
ed_id_key = NULL;
router_get_orport(r, &ap, family);
if (!tor_addr_port_is_valid_ap(&ap, 0)) {
if (router_get_orport(r, &ap, family) < 0) {
/* We don't have an ORPort for the requested family. */
return NULL;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment