From 2ac7be0d51a112108dc6c2b1c6f46da022f72f40 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 26 Feb 2002 22:47:51 +0000 Subject: [PATCH] Tweaking IPv6 support. --- src/net.h | 8 ++++---- src/netutl.c | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/net.h b/src/net.h index ea1657be..df431979 100644 --- a/src/net.h +++ b/src/net.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.h,v 1.9.4.41 2002/02/20 22:37:38 guus Exp $ + $Id: net.h,v 1.9.4.42 2002/02/26 22:47:51 guus Exp $ */ #ifndef __TINC_NET_H__ @@ -65,10 +65,10 @@ typedef union { struct sockaddr_in6 in6; } sockaddr_t; -#ifdef HAVE_LINUX - #define SALEN(s) sizeof(sockaddr_t) +#ifdef SA_LEN +#define SALEN(s) SA_LEN(&s) #else - #define SALEN(s) (s.sa_len) +#define SALEN(s) (s.sa_family==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6)) #endif typedef struct vpn_packet_t { diff --git a/src/netutl.c b/src/netutl.c index ca3ea2d8..a5886fc1 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: netutl.c,v 1.12.4.27 2002/02/20 22:37:38 guus Exp $ + $Id: netutl.c,v 1.12.4.28 2002/02/26 22:47:51 guus Exp $ */ #include "config.h" @@ -101,6 +101,7 @@ void sockaddr2str(sockaddr_t *sa, char **addrstr, char **portstr) { char address[NI_MAXHOST]; char port[NI_MAXSERV]; + char *scopeid; int err; cp if((err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST|NI_NUMERICSERV))) @@ -111,6 +112,11 @@ cp exit(0); } +#ifdef HAVE_LINUX + if((scopeid = strchr(address, '%'))) + *scopeid = '\0'; /* Descope. */ +#endif + *addrstr = xstrdup(address); *portstr = xstrdup(port); cp @@ -147,9 +153,15 @@ cp case AF_UNSPEC: return 0; case AF_INET: - return memcmp(&a->in, &b->in, sizeof(a->in)); + result = memcmp(&a->in.sin_addr, &b->in.sin_addr, sizeof(a->in.sin_addr)); + if(result) + return result; + return memcmp(&a->in.sin_port, &b->in.sin_port, sizeof(a->in.sin_port)); case AF_INET6: - return memcmp(&a->in6, &b->in6, sizeof(a->in6)); + result = memcmp(&a->in6.sin6_addr, &b->in6.sin6_addr, sizeof(a->in6.sin6_addr)); + if(result) + return result; + return memcmp(&a->in6.sin6_port, &b->in6.sin6_port, sizeof(a->in6.sin6_port)); default: syslog(LOG_ERR, _("sockaddrcmp() was called with unknown address family %d, exitting!"), a->sa.sa_family); cp_trace(); -- 2.39.5