lib: make prefix2str simpler to use, and use it in zclient
Returning the buffer allows using it in the logging functions
in easier way. This also makes the API consistent with sockunion.
Add also PREFIX_STRLEN to be the generic buffer length required
for any prefix string representation.
Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/lib/prefix.c b/lib/prefix.c
index 57cf12a..63742f3 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -760,14 +760,15 @@
return 0;
}
-int
-prefix2str (const struct prefix *p, char *str, int size)
+const char *
+prefix2str (union prefix46constptr pu, char *str, int size)
{
+ const struct prefix *p = pu.p;
char buf[BUFSIZ];
inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ);
snprintf (str, size, "%s/%d", buf, p->prefixlen);
- return 0;
+ return str;
}
struct prefix *