summaryrefslogtreecommitdiffstats
path: root/lib/sockunion.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2015-05-23 10:08:38 +0200
committerDaniel Walton <dwalton@cumulusnetworks.com>2016-05-26 17:33:30 +0200
commit67e2b6f013abb23b42f9e2f85e5a3a44916b617c (patch)
tree10a34154fbbc52315b13d4087032b211a38f6127 /lib/sockunion.c
parentroute table: constify some APIs (diff)
downloadfrr-67e2b6f013abb23b42f9e2f85e5a3a44916b617c.tar.xz
frr-67e2b6f013abb23b42f9e2f85e5a3a44916b617c.zip
lib: make sockunion2str safer to use
It's mostly used for logging, and the return value is never checked, so try to make it valid. Signed-off-by: Timo Teräs <timo.teras@iki.fi> Signed-off-by: David Lamparter <equinox@opensourcerouting.org> (cherry picked from commit 53009d387a633997b16d32224b50451b5c81b61a)
Diffstat (limited to 'lib/sockunion.c')
-rw-r--r--lib/sockunion.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/sockunion.c b/lib/sockunion.c
index fdff61f54..4fd5f1444 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -166,13 +166,20 @@ str2sockunion (const char *str, union sockunion *su)
const char *
sockunion2str (union sockunion *su, char *buf, size_t len)
{
- if (su->sa.sa_family == AF_INET)
- return inet_ntop (AF_INET, &su->sin.sin_addr, buf, len);
+ switch (sockunion_family(su))
+ {
+ case AF_UNSPEC:
+ snprintf (buf, len, "(unspec)");
+ return buf;
+ case AF_INET:
+ return inet_ntop (AF_INET, &su->sin.sin_addr, buf, len);
#ifdef HAVE_IPV6
- else if (su->sa.sa_family == AF_INET6)
- return inet_ntop (AF_INET6, &su->sin6.sin6_addr, buf, len);
+ case AF_INET6:
+ return inet_ntop (AF_INET6, &su->sin6.sin6_addr, buf, len);
#endif /* HAVE_IPV6 */
- return NULL;
+ }
+ snprintf (buf, len, "(af %d)", sockunion_family(su));
+ return buf;
}
union sockunion *