Consistently format addresses in node_get_address_string

Also, don't write to a buffer with length zero.
This commit is contained in:
teor (Tim Wilson-Brown)
2016-01-20 13:17:08 +11:00
parent 772577b547
commit 4db5a35e66
+5 -5
View File
@@ -863,13 +863,13 @@ node_get_prim_addr_ipv4h(const node_t *node)
void
node_get_address_string(const node_t *node, char *buf, size_t len)
{
if (node->ri) {
strlcpy(buf, fmt_addr32(node->ri->addr), len);
} else if (node->rs) {
uint32_t ipv4_addr = node_get_prim_addr_ipv4h(node);
if (tor_addr_is_valid_ipv4h(ipv4_addr, 0)) {
tor_addr_t addr;
tor_addr_from_ipv4h(&addr, node->rs->addr);
tor_addr_from_ipv4h(&addr, ipv4_addr);
tor_addr_to_str(buf, &addr, len, 0);
} else {
} else if (len > 0) {
buf[0] = '\0';
}
}