From af3b34f6903d395d30795ab2b6feee6530d2f783 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Sun, 18 Oct 2020 14:21:26 +0300 Subject: [PATCH] lib: Convert inet_ntoa to %pI4 Signed-off-by: Donatas Abraitis --- lib/filter.c | 33 ++++++++++++++------------------- lib/if.c | 7 +++---- lib/nexthop.c | 8 ++++---- lib/nexthop_group.c | 20 ++++++++++---------- lib/sockunion.c | 12 ++++-------- 5 files changed, 35 insertions(+), 45 deletions(-) diff --git a/lib/filter.c b/lib/filter.c index e6add0462b..f5ae9ee2b7 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -576,14 +576,12 @@ static int filter_show(struct vty *vty, const char *name, afi_t afi) if (filter->addr_mask.s_addr == 0xffffffff) vty_out(vty, " any\n"); else { - vty_out(vty, " %s", - inet_ntoa(filter->addr)); + vty_out(vty, " %pI4", &filter->addr); if (filter->addr_mask.s_addr != INADDR_ANY) vty_out(vty, - ", wildcard bits %s", - inet_ntoa( - filter->addr_mask)); + ", wildcard bits %pI4", + &filter->addr_mask); vty_out(vty, "\n"); } } @@ -625,14 +623,12 @@ static int filter_show(struct vty *vty, const char *name, afi_t afi) if (filter->addr_mask.s_addr == 0xffffffff) vty_out(vty, " any\n"); else { - vty_out(vty, " %s", - inet_ntoa(filter->addr)); + vty_out(vty, " %pI4", &filter->addr); if (filter->addr_mask.s_addr != INADDR_ANY) vty_out(vty, - ", wildcard bits %s", - inet_ntoa( - filter->addr_mask)); + ", wildcard bits %pI4", + &filter->addr_mask); vty_out(vty, "\n"); } } @@ -722,29 +718,28 @@ static void config_write_access_cisco(struct vty *vty, struct filter *mfilter) if (filter->addr_mask.s_addr == 0xffffffff) vty_out(vty, " any"); else if (filter->addr_mask.s_addr == INADDR_ANY) - vty_out(vty, " host %s", inet_ntoa(filter->addr)); + vty_out(vty, " host %pI4", &filter->addr); else { - vty_out(vty, " %s", inet_ntoa(filter->addr)); - vty_out(vty, " %s", inet_ntoa(filter->addr_mask)); + vty_out(vty, " %pI4", &filter->addr); + vty_out(vty, " %pI4", &filter->addr_mask); } if (filter->mask_mask.s_addr == 0xffffffff) vty_out(vty, " any"); else if (filter->mask_mask.s_addr == INADDR_ANY) - vty_out(vty, " host %s", inet_ntoa(filter->mask)); + vty_out(vty, " host %pI4", &filter->mask); else { - vty_out(vty, " %s", inet_ntoa(filter->mask)); - vty_out(vty, " %s", inet_ntoa(filter->mask_mask)); + vty_out(vty, " %pI4", &filter->mask); + vty_out(vty, " %pI4", &filter->mask_mask); } vty_out(vty, "\n"); } else { if (filter->addr_mask.s_addr == 0xffffffff) vty_out(vty, " any\n"); else { - vty_out(vty, " %s", inet_ntoa(filter->addr)); + vty_out(vty, " %pI4", &filter->addr); if (filter->addr_mask.s_addr != INADDR_ANY) - vty_out(vty, " %s", - inet_ntoa(filter->addr_mask)); + vty_out(vty, " %pI4", &filter->addr_mask); vty_out(vty, "\n"); } } diff --git a/lib/if.c b/lib/if.c index 35aa46ca2d..c707c4c6d9 100644 --- a/lib/if.c +++ b/lib/if.c @@ -1106,8 +1106,8 @@ ifaddr_ipv4_add (struct in_addr *ifaddr, struct interface *ifp) if (rn) { route_unlock_node (rn); - zlog_info ("ifaddr_ipv4_add(): address %s is already added", - inet_ntoa (*ifaddr)); + zlog_info("ifaddr_ipv4_add(): address %pI4 is already added", + ifaddr); return; } rn->info = ifp; @@ -1126,8 +1126,7 @@ ifaddr_ipv4_delete (struct in_addr *ifaddr, struct interface *ifp) rn = route_node_lookup (ifaddr_ipv4_table, (struct prefix *) &p); if (! rn) { - zlog_info ("ifaddr_ipv4_delete(): can't find address %s", - inet_ntoa (*ifaddr)); + zlog_info("%s: can't find address %pI4", __func__, ifaddr); return; } rn->info = NULL; diff --git a/lib/nexthop.c b/lib/nexthop.c index f1575649b1..b2fa945690 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -431,13 +431,13 @@ const char *nexthop2str(const struct nexthop *nexthop, char *str, int size) break; case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4_IFINDEX: - snprintf(str, size, "%s if %u", inet_ntoa(nexthop->gate.ipv4), - nexthop->ifindex); + snprintfrr(str, size, "%pI4 if %u", &nexthop->gate.ipv4, + nexthop->ifindex); break; case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6_IFINDEX: - snprintf(str, size, "%s if %u", inet6_ntoa(nexthop->gate.ipv6), - nexthop->ifindex); + snprintfrr(str, size, "%pI6 if %u", &nexthop->gate.ipv6, + nexthop->ifindex); break; case NEXTHOP_TYPE_BLACKHOLE: snprintf(str, size, "blackhole"); diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index 4afb1d642a..dee98ad8d7 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -975,7 +975,6 @@ void nexthop_group_write_nexthop_simple(struct vty *vty, const struct nexthop *nh, char *altifname) { - char buf[100]; char *ifname; vty_out(vty, "nexthop "); @@ -990,19 +989,16 @@ void nexthop_group_write_nexthop_simple(struct vty *vty, vty_out(vty, "%s", ifname); break; case NEXTHOP_TYPE_IPV4: - vty_out(vty, "%s", inet_ntoa(nh->gate.ipv4)); + vty_out(vty, "%pI4", &nh->gate.ipv4); break; case NEXTHOP_TYPE_IPV4_IFINDEX: - vty_out(vty, "%s %s", inet_ntoa(nh->gate.ipv4), ifname); + vty_out(vty, "%pI4 %s", &nh->gate.ipv4, ifname); break; case NEXTHOP_TYPE_IPV6: - vty_out(vty, "%s", - inet_ntop(AF_INET6, &nh->gate.ipv6, buf, sizeof(buf))); + vty_out(vty, "%pI6", &nh->gate.ipv6); break; case NEXTHOP_TYPE_IPV6_IFINDEX: - vty_out(vty, "%s %s", - inet_ntop(AF_INET6, &nh->gate.ipv6, buf, sizeof(buf)), - ifname); + vty_out(vty, "%pI6 %s", &nh->gate.ipv6, ifname); break; case NEXTHOP_TYPE_BLACKHOLE: break; @@ -1056,10 +1052,14 @@ void nexthop_group_json_nexthop(json_object *j, const struct nexthop *nh) ifindex2ifname(nh->ifindex, nh->vrf_id)); break; case NEXTHOP_TYPE_IPV4: - json_object_string_add(j, "nexthop", inet_ntoa(nh->gate.ipv4)); + json_object_string_add( + j, "nexthop", + inet_ntop(AF_INET, &nh->gate.ipv4, buf, sizeof(buf))); break; case NEXTHOP_TYPE_IPV4_IFINDEX: - json_object_string_add(j, "nexthop", inet_ntoa(nh->gate.ipv4)); + json_object_string_add( + j, "nexthop", + inet_ntop(AF_INET, &nh->gate.ipv4, buf, sizeof(buf))); json_object_string_add(j, "vrfId", ifindex2ifname(nh->ifindex, nh->vrf_id)); break; diff --git a/lib/sockunion.c b/lib/sockunion.c index d77229797c..c999845659 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -587,15 +587,11 @@ static void __attribute__((unused)) sockunion_print(const union sockunion *su) switch (su->sa.sa_family) { case AF_INET: - printf("%s\n", inet_ntoa(su->sin.sin_addr)); + printf("%pI4\n", &su->sin.sin_addr); + break; + case AF_INET6: + printf("%pI6\n", &su->sin6.sin6_addr); break; - case AF_INET6: { - char buf[SU_ADDRSTRLEN]; - - printf("%s\n", inet_ntop(AF_INET6, &(su->sin6.sin6_addr), buf, - sizeof(buf))); - } break; - #ifdef AF_LINK case AF_LINK: { struct sockaddr_dl *sdl; -- 2.39.5