move SA_LEN() to upnputils.h

This commit is contained in:
Thomas Bernard 2016-11-11 08:51:28 -05:00
parent bc3aab0ca9
commit 590209e3e6
4 changed files with 23 additions and 20 deletions

View File

@ -1,7 +1,7 @@
/* $Id: asyncsendto.c,v 1.7 2015/09/03 18:19:20 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2014 Thomas Bernard
* (c) 2006-2016 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */

View File

@ -30,23 +30,6 @@
#include "getroute.h"
#include "upnputils.h"
#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
int
get_src_for_route_to(const struct sockaddr * dst,
void * src, size_t * src_len,

View File

@ -39,7 +39,7 @@ extern struct lan_addr_list lan_addrs;
#else
#define SALIGN (sizeof(int32_t) - 1)
#endif
#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))
#endif
int

View File

@ -1,7 +1,7 @@
/* $Id: upnputils.h,v 1.2 2014/11/28 16:20:07 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2011-2014 Thomas Bernard
* (c) 2011-2016 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -29,5 +29,25 @@ set_non_blocking(int fd);
struct lan_addr_s *
get_lan_for_peer(const struct sockaddr * peer);
/**
* define portability macros
*/
#if defined(__sun)
static __inline 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
#endif