diff options
author | Timo Teräs <timo.teras@iki.fi> | 2015-05-23 11:08:39 +0300 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2015-06-01 16:31:14 +0200 |
commit | 41eb9a4305fbcb206c900a18af7df7115d857d60 (patch) | |
tree | d132fa1a4e113aa5d0bcf84d60933b36383b182d | |
parent | 53009d387a633997b16d32224b50451b5c81b61a (diff) | |
download | quagga-41eb9a4305fbcb206c900a18af7df7115d857d60.tar.bz2 quagga-41eb9a4305fbcb206c900a18af7df7115d857d60.tar.xz |
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>
-rw-r--r-- | lib/prefix.c | 7 | ||||
-rw-r--r-- | lib/prefix.h | 5 | ||||
-rw-r--r-- | lib/zclient.c | 6 |
3 files changed, 11 insertions, 7 deletions
diff --git a/lib/prefix.c b/lib/prefix.c index 57cf12af..63742f39 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -760,14 +760,15 @@ str2prefix (const char *str, struct prefix *p) 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 * diff --git a/lib/prefix.h b/lib/prefix.h index 404a63ac..bc8aebc5 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -129,6 +129,9 @@ union prefix46constptr #define INET6_BUFSIZ 51 #endif /* INET6_BUFSIZ */ +/* Maximum prefix string length (IPv6) */ +#define PREFIX_STRLEN 51 + /* Max bit/byte length of IPv4 address. */ #define IPV4_MAX_BYTELEN 4 #define IPV4_MAX_BITLEN 32 @@ -179,7 +182,7 @@ extern void prefix_free (struct prefix *); extern const char *prefix_family_str (const struct prefix *); extern int prefix_blen (const struct prefix *); extern int str2prefix (const char *, struct prefix *); -extern int prefix2str (const struct prefix *, char *, int); +extern const char *prefix2str (union prefix46constptr, char *, int); extern int prefix_match (const struct prefix *, const struct prefix *); extern int prefix_same (const struct prefix *, const struct prefix *); extern int prefix_cmp (const struct prefix *, const struct prefix *); diff --git a/lib/zclient.c b/lib/zclient.c index 1e05d6dd..71da87c6 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -808,11 +808,11 @@ zebra_interface_address_read (int type, struct stream *s) else if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER)) { /* carp interfaces on OpenBSD with 0.0.0.0/0 as "peer" */ - char buf[BUFSIZ]; - prefix2str (ifc->address, buf, sizeof(buf)); + char buf[PREFIX_STRLEN]; zlog_warn("warning: interface %s address %s " "with peer flag set, but no peer address!", - ifp->name, buf); + ifp->name, + prefix2str (ifc->address, buf, sizeof buf)); UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER); } } |