libiproute: make rt_addr_n2a() and format_host() return auto strings
function old new delta rt_addr_n2a 56 53 -3 print_addrinfo 1227 1178 -49 print_neigh 933 881 -52 print_rule 689 617 -72 print_tunnel 640 560 -80 print_route 1727 1588 -139 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-395) Total: -395 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
@@ -276,20 +276,21 @@ int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits)
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *rt_addr_n2a(int af,
|
||||
void *addr, char *buf, int buflen)
|
||||
const char *rt_addr_n2a(int af, void *addr)
|
||||
{
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
case AF_INET6:
|
||||
return inet_ntop(af, addr, buf, buflen);
|
||||
return inet_ntop(af, addr,
|
||||
auto_string(xzalloc(INET6_ADDRSTRLEN)), INET6_ADDRSTRLEN
|
||||
);
|
||||
default:
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef RESOLVE_HOSTNAMES
|
||||
const char *format_host(int af, int len, void *addr, char *buf, int buflen)
|
||||
const char *format_host(int af, int len, void *addr)
|
||||
{
|
||||
if (resolve_hosts) {
|
||||
struct hostent *h_ent;
|
||||
@@ -308,11 +309,10 @@ const char *format_host(int af, int len, void *addr, char *buf, int buflen)
|
||||
if (len > 0) {
|
||||
h_ent = gethostbyaddr(addr, len, af);
|
||||
if (h_ent != NULL) {
|
||||
safe_strncpy(buf, h_ent->h_name, buflen);
|
||||
return buf;
|
||||
return auto_string(xstrdup(h_ent->h_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
return rt_addr_n2a(af, addr, buf, buflen);
|
||||
return rt_addr_n2a(af, addr);
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user