{
struct ifaddrmsg *ifa = NLMSG_DATA(n);
int len = n->nlmsg_len;
- struct rtattr * rta_tb[IFA_MAX+1];
- char abuf[256];
+ struct rtattr *rta_tb[IFA_MAX+1];
if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR)
return 0;
printf(" family %d ", ifa->ifa_family);
if (rta_tb[IFA_LOCAL]) {
- fputs(rt_addr_n2a(ifa->ifa_family,
- RTA_DATA(rta_tb[IFA_LOCAL]),
- abuf, sizeof(abuf)), stdout);
+ fputs(rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_LOCAL])),
+ stdout
+ );
if (rta_tb[IFA_ADDRESS] == NULL
|| memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0
printf("/%d ", ifa->ifa_prefixlen);
} else {
printf(" peer %s/%d ",
- rt_addr_n2a(ifa->ifa_family,
- RTA_DATA(rta_tb[IFA_ADDRESS]),
- abuf, sizeof(abuf)),
- ifa->ifa_prefixlen);
+ rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_ADDRESS])),
+ ifa->ifa_prefixlen
+ );
}
}
if (rta_tb[IFA_BROADCAST]) {
printf("brd %s ",
rt_addr_n2a(ifa->ifa_family,
- RTA_DATA(rta_tb[IFA_BROADCAST]),
- abuf, sizeof(abuf))
+ RTA_DATA(rta_tb[IFA_BROADCAST]))
);
}
if (rta_tb[IFA_ANYCAST]) {
printf("any %s ",
rt_addr_n2a(ifa->ifa_family,
- RTA_DATA(rta_tb[IFA_ANYCAST]),
- abuf, sizeof(abuf))
+ RTA_DATA(rta_tb[IFA_ANYCAST]))
);
}
printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope));
struct ndmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr *tb[NDA_MAX+1];
- char abuf[256];
if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) {
bb_error_msg_and_die("not RTM_NEWNEIGH: %08x %08x %08x",
printf("%s ",
format_host(r->ndm_family,
RTA_PAYLOAD(tb[NDA_DST]),
- RTA_DATA(tb[NDA_DST]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[NDA_DST]))
+ );
}
if (!G_filter.index && r->ndm_ifindex)
printf("dev %s ", ll_index_to_name(r->ndm_ifindex));
struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr *tb[RTA_MAX+1];
- char abuf[256];
inet_prefix dst;
inet_prefix src;
int host_len = -1;
if (tb[RTA_DST]) {
if (r->rtm_dst_len != host_len) {
- printf("%s/%u ", rt_addr_n2a(r->rtm_family,
- RTA_DATA(tb[RTA_DST]),
- abuf, sizeof(abuf)),
- r->rtm_dst_len
- );
+ printf("%s/%u ",
+ rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_DST])),
+ r->rtm_dst_len
+ );
} else {
printf("%s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_DST]),
- RTA_DATA(tb[RTA_DST]),
- abuf, sizeof(abuf))
- );
+ RTA_DATA(tb[RTA_DST]))
+ );
}
} else if (r->rtm_dst_len) {
printf("0/%d ", r->rtm_dst_len);
}
if (tb[RTA_SRC]) {
if (r->rtm_src_len != host_len) {
- printf("from %s/%u ", rt_addr_n2a(r->rtm_family,
- RTA_DATA(tb[RTA_SRC]),
- abuf, sizeof(abuf)),
- r->rtm_src_len
- );
+ printf("from %s/%u ",
+ rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_SRC])),
+ r->rtm_src_len
+ );
} else {
printf("from %s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_SRC]),
- RTA_DATA(tb[RTA_SRC]),
- abuf, sizeof(abuf))
- );
+ RTA_DATA(tb[RTA_SRC]))
+ );
}
} else if (r->rtm_src_len) {
printf("from 0/%u ", r->rtm_src_len);
if (tb[RTA_GATEWAY] && G_filter.rvia.bitlen != host_len) {
printf("via %s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_GATEWAY]),
- RTA_DATA(tb[RTA_GATEWAY]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[RTA_GATEWAY]))
+ );
}
if (tb[RTA_OIF]) {
printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF])));
and symbolic name will not be useful.
*/
printf(" src %s ", rt_addr_n2a(r->rtm_family,
- RTA_DATA(tb[RTA_PREFSRC]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[RTA_PREFSRC])));
}
if (tb[RTA_PRIORITY]) {
printf(" metric %d ", *(uint32_t*)RTA_DATA(tb[RTA_PRIORITY]));
int len = n->nlmsg_len;
int host_len = -1;
struct rtattr * tb[RTA_MAX+1];
- char abuf[256];
if (n->nlmsg_type != RTM_NEWRULE)
return 0;
printf("from ");
if (tb[RTA_SRC]) {
if (r->rtm_src_len != host_len) {
- printf("%s/%u", rt_addr_n2a(r->rtm_family,
- RTA_DATA(tb[RTA_SRC]),
- abuf, sizeof(abuf)),
+ printf("%s/%u",
+ rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_SRC])),
r->rtm_src_len
);
} else {
fputs(format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_SRC]),
- RTA_DATA(tb[RTA_SRC]),
- abuf, sizeof(abuf)),
+ RTA_DATA(tb[RTA_SRC])),
stdout
);
}
if (tb[RTA_DST]) {
if (r->rtm_dst_len != host_len) {
printf("to %s/%u ", rt_addr_n2a(r->rtm_family,
- RTA_DATA(tb[RTA_DST]),
- abuf, sizeof(abuf)),
+ RTA_DATA(tb[RTA_DST])),
r->rtm_dst_len
);
} else {
printf("to %s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_DST]),
- RTA_DATA(tb[RTA_DST]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[RTA_DST])));
}
} else if (r->rtm_dst_len) {
printf("to 0/%d ", r->rtm_dst_len);
printf("map-to %s ",
format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_GATEWAY]),
- RTA_DATA(tb[RTA_GATEWAY]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[RTA_GATEWAY]))
+ );
} else
printf("masquerade");
} else if (r->rtm_type != RTN_UNICAST)
static void print_tunnel(struct ip_tunnel_parm *p)
{
- char s1[256];
- char s2[256];
- char s3[64];
- char s4[64];
-
- format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1));
- format_host(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2));
- inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
- inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));
+ char s3[INET_ADDRSTRLEN];
+ char s4[INET_ADDRSTRLEN];
printf("%s: %s/ip remote %s local %s ",
- p->name,
- p->iph.protocol == IPPROTO_IPIP ? "ip" :
- (p->iph.protocol == IPPROTO_GRE ? "gre" :
- (p->iph.protocol == IPPROTO_IPV6 ? "ipv6" : "unknown")),
- p->iph.daddr ? s1 : "any", p->iph.saddr ? s2 : "any");
+ p->name,
+ p->iph.protocol == IPPROTO_IPIP ? "ip" :
+ p->iph.protocol == IPPROTO_GRE ? "gre" :
+ p->iph.protocol == IPPROTO_IPV6 ? "ipv6" :
+ "unknown",
+ p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr) : "any",
+ p->iph.saddr ? format_host(AF_INET, 4, &p->iph.saddr) : "any"
+ );
if (p->link) {
char *n = do_ioctl_get_ifname(p->link);
if (n) {
if (!(p->iph.frag_off & htons(IP_DF)))
printf(" nopmtudisc");
+ inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
+ inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));
if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
printf(" key %s", s3);
- else if ((p->i_flags | p->o_flags) & GRE_KEY) {
+ else {
if (p->i_flags & GRE_KEY)
printf(" ikey %s ", s3);
if (p->o_flags & GRE_KEY)
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;
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
extern uint32_t get_u32(char *arg, const char *errmsg);
extern uint16_t get_u16(char *arg, const char *errmsg);
-extern const char *rt_addr_n2a(int af, void *addr, char *buf, int buflen);
+extern const char *rt_addr_n2a(int af, void *addr);
#ifdef RESOLVE_HOSTNAMES
-extern const char *format_host(int af, int len, void *addr, char *buf, int buflen);
+extern const char *format_host(int af, int len, void *addr);
#else
-#define format_host(af, len, addr, buf, buflen) \
- rt_addr_n2a(af, addr, buf, buflen)
+#define format_host(af, len, addr) \
+ rt_addr_n2a(af, addr)
#endif
void invarg_1_to_2(const char *, const char *) NORETURN;