miniupnpd: Use SA_LEN consistently

This commit is contained in:
Thomas Bernard 2014-04-01 11:44:39 +02:00
parent 3491535854
commit c4d99670e7
3 changed files with 31 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $Id: getroute.c,v 1.3 2013/02/06 13:11:45 nanard Exp $ */
/* $Id: getroute.c,v 1.4 2014/03/31 12:27:14 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2013 Thomas Bernard
@ -83,7 +83,7 @@ get_src_for_route_to(const struct sockaddr * dst,
sa = (struct sockaddr *)p;
sockaddr_to_string(sa, tmp, sizeof(tmp));
syslog(LOG_DEBUG, "type=%d sa_len=%d sa_family=%d %s",
i, sa->sa_len, sa->sa_family, tmp);
i, SA_LEN(sa), sa->sa_family, tmp);
if((i == RTA_DST || i == RTA_GATEWAY) &&
(src_len && src)) {
size_t len = 0;
@ -113,7 +113,7 @@ get_src_for_route_to(const struct sockaddr * dst,
*index = sdl->sdl_index;
}
#endif
p += sa->sa_len;
p += SA_LEN(sa);
}
}
}

View File

@ -1,4 +1,4 @@
/* $Id: ifacewatcher.c,v 1.5 2012/05/21 08:55:10 nanard Exp $ */
/* $Id: ifacewatcher.c,v 1.6 2014/03/31 12:27:14 nanard Exp $ */
/* Project MiniUPnP
* web : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2011 Thomas BERNARD
@ -15,12 +15,8 @@
#include <syslog.h>
#include <signal.h>
#if !defined(SA_LEN)
#define SA_LEN(sa) (sa)->sa_len
#endif
#define SALIGN (sizeof(long) - 1)
#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : (SALIGN + 1))
#define SA_RLEN(sa) (SA_LEN(sa) ? ((SA_LEN(sa) + SALIGN) & ~SALIGN) : (SALIGN + 1))
#include "../upnputils.h"
#include "../upnpglobalvars.h"

View File

@ -1,4 +1,4 @@
/* $Id: upnputils.h,v 1.4 2013/02/06 10:50:04 nanard Exp $ */
/* $Id: upnputils.h,v 1.6 2014/03/31 12:32:57 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2011-2013 Thomas Bernard
@ -29,5 +29,30 @@ set_non_blocking(int fd);
struct lan_addr_s *
get_lan_for_peer(const struct sockaddr * peer);
/**
* define portability macros
*/
#if defined(__sun)
static size_t _sa_len(const struct sockaddr *addr)
{
if (addr->sa_family == AF_INET)
return (sizeof(struct sockaddr_in));
else if (addr->sa_family == AF_INET6)
return (sizeof(struct sockaddr_in6));
else
return (sizeof(struct sockaddr));
}
# define SA_LEN(sa) (_sa_len(sa))
#else
#if !defined(SA_LEN)
# define SA_LEN(sa) ((sa)->sa_len)
#endif
#endif
#ifndef MAX
# define MAX(a,b) (((a)>(b))?(a):(b))
#endif
#endif