Tweaking IPv6 support.

This commit is contained in:
Guus Sliepen 2002-02-26 22:47:51 +00:00
parent 23fda5688e
commit 2ac7be0d51
2 changed files with 19 additions and 7 deletions

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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__ #ifndef __TINC_NET_H__
@ -65,10 +65,10 @@ typedef union {
struct sockaddr_in6 in6; struct sockaddr_in6 in6;
} sockaddr_t; } sockaddr_t;
#ifdef HAVE_LINUX #ifdef SA_LEN
#define SALEN(s) sizeof(sockaddr_t) #define SALEN(s) SA_LEN(&s)
#else #else
#define SALEN(s) (s.sa_len) #define SALEN(s) (s.sa_family==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6))
#endif #endif
typedef struct vpn_packet_t { typedef struct vpn_packet_t {

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "config.h"
@ -101,6 +101,7 @@ void sockaddr2str(sockaddr_t *sa, char **addrstr, char **portstr)
{ {
char address[NI_MAXHOST]; char address[NI_MAXHOST];
char port[NI_MAXSERV]; char port[NI_MAXSERV];
char *scopeid;
int err; int err;
cp cp
if((err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST|NI_NUMERICSERV))) 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); exit(0);
} }
#ifdef HAVE_LINUX
if((scopeid = strchr(address, '%')))
*scopeid = '\0'; /* Descope. */
#endif
*addrstr = xstrdup(address); *addrstr = xstrdup(address);
*portstr = xstrdup(port); *portstr = xstrdup(port);
cp cp
@ -147,9 +153,15 @@ cp
case AF_UNSPEC: case AF_UNSPEC:
return 0; return 0;
case AF_INET: 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: 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: default:
syslog(LOG_ERR, _("sockaddrcmp() was called with unknown address family %d, exitting!"), a->sa.sa_family); syslog(LOG_ERR, _("sockaddrcmp() was called with unknown address family %d, exitting!"), a->sa.sa_family);
cp_trace(); cp_trace();