summaryrefslogtreecommitdiffstats
path: root/lib/sockunion.c
diff options
context:
space:
mode:
authorAvneesh Sachdev <avneesh@opensourcerouting.org>2012-04-09 00:25:15 -0700
committerAvneesh Sachdev <avneesh@opensourcerouting.org>2012-04-09 00:25:15 -0700
commit3cf6c2b4e43f44a977d218c96c26250654ae333e (patch)
treee017cde2015fbf3ef6c250327428d7c6152aa8f7 /lib/sockunion.c
parent01d7ff0a2166a422c56bd26f04fc22832a9e690b (diff)
parente96b312150d8e376c1ef463793d1929eca3618d5 (diff)
downloadquagga-3cf6c2b4e43f44a977d218c96c26250654ae333e.tar.bz2
quagga-3cf6c2b4e43f44a977d218c96c26250654ae333e.tar.xz
Merge branch 'quagga' into google-bgp-multipath
Conflicts: bgpd/bgp_route.c
Diffstat (limited to 'lib/sockunion.c')
-rw-r--r--lib/sockunion.c47
1 files changed, 35 insertions, 12 deletions
diff --git a/lib/sockunion.c b/lib/sockunion.c
index a5382a72..59770529 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -297,27 +297,24 @@ sockunion_sizeof (union sockunion *su)
}
/* return sockunion structure : this function should be revised. */
-static char *
-sockunion_log (union sockunion *su)
+static const char *
+sockunion_log (union sockunion *su, char *buf, size_t len)
{
- static char buf[SU_ADDRSTRLEN];
-
switch (su->sa.sa_family)
{
case AF_INET:
- snprintf (buf, SU_ADDRSTRLEN, "%s", inet_ntoa (su->sin.sin_addr));
- break;
+ return inet_ntop(AF_INET, &su->sin.sin_addr, buf, len);
+
#ifdef HAVE_IPV6
case AF_INET6:
- snprintf (buf, SU_ADDRSTRLEN, "%s",
- inet_ntop (AF_INET6, &(su->sin6.sin6_addr), buf, SU_ADDRSTRLEN));
+ return inet_ntop(AF_INET6, &(su->sin6.sin6_addr), buf, len);
break;
#endif /* HAVE_IPV6 */
+
default:
- snprintf (buf, SU_ADDRSTRLEN, "af_unknown %d ", su->sa.sa_family);
- break;
+ snprintf (buf, len, "af_unknown %d ", su->sa.sa_family);
+ return buf;
}
- return (XSTRDUP (MTYPE_TMP, buf));
}
/* sockunion_connect returns
@@ -379,8 +376,10 @@ sockunion_connect (int fd, union sockunion *peersu, unsigned short port,
{
if (errno != EINPROGRESS)
{
+ char str[SU_ADDRSTRLEN];
zlog_info ("can't connect to %s fd %d : %s",
- sockunion_log (&su), fd, safe_strerror (errno));
+ sockunion_log (&su, str, sizeof str),
+ fd, safe_strerror (errno));
return connect_error;
}
}
@@ -567,6 +566,30 @@ sockopt_minttl (int family, int sock, int minttl)
return -1;
}
+int
+sockopt_v6only (int family, int sock)
+{
+ int ret, on = 1;
+
+#ifdef HAVE_IPV6
+#ifdef IPV6_V6ONLY
+ if (family == AF_INET6)
+ {
+ ret = setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY,
+ (void *) &on, sizeof (int));
+ if (ret < 0)
+ {
+ zlog (NULL, LOG_WARNING, "can't set sockopt IPV6_V6ONLY "
+ "to socket %d", sock);
+ return -1;
+ }
+ return 0;
+ }
+#endif /* IPV6_V6ONLY */
+#endif /* HAVE_IPV6 */
+ return 0;
+}
+
/* If same family and same prefix return 1. */
int
sockunion_same (union sockunion *su1, union sockunion *su2)