"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "network_io/unix/sockaddr.c" between
apr-1.6.5.tar.bz2 and apr-1.7.0.tar.bz2

About: APR (Apache Portable Runtime) project offers software libraries that provide a predictable and consistent interface to underlying platform-specific implementations (APR core library).

sockaddr.c  (apr-1.6.5.tar.bz2):sockaddr.c  (apr-1.7.0.tar.bz2)
skipping to change at line 28 skipping to change at line 28
#include "apr_strings.h" #include "apr_strings.h"
#include "apr.h" #include "apr.h"
#include "apr_lib.h" #include "apr_lib.h"
#include "apr_strings.h" #include "apr_strings.h"
#include "apr_private.h" #include "apr_private.h"
#if APR_HAVE_STDLIB_H #if APR_HAVE_STDLIB_H
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
#if defined(HAVE_IF_INDEXTONAME) && defined(_MSC_VER)
#include "arch/win32/apr_arch_misc.h"
#endif
#define APR_WANT_STRFUNC #define APR_WANT_STRFUNC
#include "apr_want.h" #include "apr_want.h"
struct apr_ipsubnet_t { struct apr_ipsubnet_t {
int family; int family;
#if APR_HAVE_IPV6 #if APR_HAVE_IPV6
apr_uint32_t sub[4]; /* big enough for IPv4 and IPv6 addresses */ apr_uint32_t sub[4]; /* big enough for IPv4 and IPv6 addresses */
apr_uint32_t mask[4]; apr_uint32_t mask[4];
#else #else
apr_uint32_t sub[1]; apr_uint32_t sub[1];
skipping to change at line 128 skipping to change at line 136
if (sockaddr->family == AF_INET6 if (sockaddr->family == AF_INET6
&& IN6_IS_ADDR_V4MAPPED((struct in6_addr *)sockaddr->ipaddr_ptr) && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)sockaddr->ipaddr_ptr)
&& buflen > strlen("::ffff:")) { && buflen > strlen("::ffff:")) {
/* This is an IPv4-mapped IPv6 address; drop the leading /* This is an IPv4-mapped IPv6 address; drop the leading
* part of the address string so we're left with the familiar * part of the address string so we're left with the familiar
* IPv4 format. * IPv4 format.
*/ */
memmove(buf, buf + strlen("::ffff:"), memmove(buf, buf + strlen("::ffff:"),
strlen(buf + strlen("::ffff:"))+1); strlen(buf + strlen("::ffff:"))+1);
} }
#endif
/* ensure NUL termination if the buffer is too short */ /* ensure NUL termination if the buffer is too short */
buf[buflen-1] = '\0'; buf[buflen-1] = '\0';
#ifdef HAVE_IF_INDEXTONAME
/* Append scope name for link-local addresses. */
if (sockaddr->family == AF_INET6
&& IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)sockaddr->ipaddr_ptr)) {
char scbuf[IF_NAMESIZE], *p = buf + strlen(buf);
if (if_indextoname(sockaddr->sa.sin6.sin6_scope_id, scbuf) == scbuf) {
/* Space check, need room for buf + '%' + scope + '\0'.
* Assert: buflen >= strlen(buf) + strlen(scbuf) + 2
* Equiv: buflen >= (p-buf) + strlen(buf) + 2
* Thus, fail in inverse condition: */
if (buflen < strlen(scbuf) + (p - buf) + 2) {
return APR_ENOSPC;
}
*p++ = '%';
memcpy(p, scbuf, strlen(scbuf) + 1);
}
}
#endif /* HAVE_IF_INDEXTONAME */
#endif /* APR_HAVE_IPV6 */
return APR_SUCCESS; return APR_SUCCESS;
} }
APR_DECLARE(apr_status_t) apr_sockaddr_ip_get(char **addr, APR_DECLARE(apr_status_t) apr_sockaddr_ip_get(char **addr,
apr_sockaddr_t *sockaddr) apr_sockaddr_t *sockaddr)
{ {
*addr = apr_palloc(sockaddr->pool, sockaddr->addr_str_len); *addr = apr_palloc(sockaddr->pool, sockaddr->addr_str_len);
return apr_sockaddr_ip_getbuf(*addr, sockaddr->addr_str_len, sockaddr); return apr_sockaddr_ip_getbuf(*addr, sockaddr->addr_str_len, sockaddr);
} }
skipping to change at line 903 skipping to change at line 933
} }
#define V4MAPPED_EQUAL(a,b) \ #define V4MAPPED_EQUAL(a,b) \
((a)->sa.sin.sin_family == AF_INET && \ ((a)->sa.sin.sin_family == AF_INET && \
(b)->sa.sin.sin_family == AF_INET6 && \ (b)->sa.sin.sin_family == AF_INET6 && \
IN6_IS_ADDR_V4MAPPED((struct in6_addr *)(b)->ipaddr_ptr) && \ IN6_IS_ADDR_V4MAPPED((struct in6_addr *)(b)->ipaddr_ptr) && \
!memcmp((a)->ipaddr_ptr, \ !memcmp((a)->ipaddr_ptr, \
&((struct in6_addr *)(b)->ipaddr_ptr)->s6_addr[12], \ &((struct in6_addr *)(b)->ipaddr_ptr)->s6_addr[12], \
(a)->ipaddr_len)) (a)->ipaddr_len))
#if APR_HAVE_IPV6
#define SCOPE_OR_ZERO(sa_) ((sa_)->family != AF_INET6 ? 0 : \
((sa_)->sa.sin6.sin6_scope_id))
#else
#define SCOPE_OR_ZERO(sa_) (0)
#endif
APR_DECLARE(int) apr_sockaddr_equal(const apr_sockaddr_t *addr1, APR_DECLARE(int) apr_sockaddr_equal(const apr_sockaddr_t *addr1,
const apr_sockaddr_t *addr2) const apr_sockaddr_t *addr2)
{ {
if (addr1->ipaddr_len == addr2->ipaddr_len && if (addr1->ipaddr_len == addr2->ipaddr_len
!memcmp(addr1->ipaddr_ptr, addr2->ipaddr_ptr, addr1->ipaddr_len)) { && !memcmp(addr1->ipaddr_ptr, addr2->ipaddr_ptr, addr1->ipaddr_len)
&& SCOPE_OR_ZERO(addr1) == SCOPE_OR_ZERO(addr2)) {
return 1; return 1;
} }
#if APR_HAVE_IPV6 #if APR_HAVE_IPV6
if (V4MAPPED_EQUAL(addr1, addr2)) { if (V4MAPPED_EQUAL(addr1, addr2)) {
return 1; return 1;
} }
if (V4MAPPED_EQUAL(addr2, addr1)) { if (V4MAPPED_EQUAL(addr2, addr1)) {
return 1; return 1;
} }
#endif #endif
skipping to change at line 1186 skipping to change at line 1224
return 1; return 1;
} }
} }
#else #else
if ((sa->sa.sin.sin_addr.s_addr & ipsub->mask[0]) == ipsub->sub[0]) { if ((sa->sa.sin.sin_addr.s_addr & ipsub->mask[0]) == ipsub->sub[0]) {
return 1; return 1;
} }
#endif /* APR_HAVE_IPV6 */ #endif /* APR_HAVE_IPV6 */
return 0; /* no match */ return 0; /* no match */
} }
APR_DECLARE(apr_status_t) apr_sockaddr_zone_set(apr_sockaddr_t *sa,
const char *zone_id)
{
#if !APR_HAVE_IPV6 || !defined(HAVE_IF_NAMETOINDEX)
return APR_ENOTIMPL;
#else
unsigned int idx;
if (sa->family != APR_INET6
|| !IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)sa->ipaddr_ptr)) {
return APR_EBADIP;
}
idx = if_nametoindex(zone_id);
if (idx) {
sa->sa.sin6.sin6_scope_id = idx;
return APR_SUCCESS;
}
if (errno != ENODEV) {
return errno;
}
else {
char *endptr;
apr_int64_t i = apr_strtoi64(zone_id, &endptr, 10);
if (*endptr != '\0' || errno || i < 1 || i > APR_INT16_MAX) {
return APR_EGENERAL;
}
sa->sa.sin6.sin6_scope_id = (unsigned int) i;
return APR_SUCCESS;
}
#endif
}
APR_DECLARE(apr_status_t) apr_sockaddr_zone_get(const apr_sockaddr_t *sa,
const char **name,
apr_uint32_t *id,
apr_pool_t *p)
{
#if !APR_HAVE_IPV6 || !defined(HAVE_IF_INDEXTONAME)
return APR_ENOTIMPL;
#else
if (sa->family != APR_INET6 || !sa->sa.sin6.sin6_scope_id) {
return APR_EBADIP;
}
if (name) {
char *buf = apr_palloc(p, IF_NAMESIZE);
if (if_indextoname(sa->sa.sin6.sin6_scope_id, buf) == NULL)
return errno;
*name = buf;
}
if (id) *id = sa->sa.sin6.sin6_scope_id;
return APR_SUCCESS;
#endif
}
 End of changes. 6 change blocks. 
3 lines changed or deleted 41 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)