netaddr.c revision 0874abad14e3e9ecfc3dc1a1a2b9969f2f027724
/*
* Copyright (C) 2004, 2005, 2007, 2010, 2011 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2002 Internet Software Consortium.
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: netaddr.c,v 1.44 2011/03/11 06:11:26 marka Exp $ */
/*! \file */
#include <config.h>
#include <stdio.h>
#include <isc/sockaddr.h>
return (ISC_FALSE);
return (ISC_FALSE);
switch (a->family) {
case AF_INET:
return (ISC_FALSE);
break;
case AF_INET6:
return (ISC_FALSE);
break;
#ifdef ISC_PLATFORM_HAVESYSUNH
case AF_UNIX:
return (ISC_FALSE);
break;
#endif
default:
return (ISC_FALSE);
}
return (ISC_TRUE);
}
unsigned int prefixlen)
{
unsigned int ipabytes = 0; /* Length of whole IP address in bytes */
unsigned int nbytes; /* Number of significant whole bytes */
unsigned int nbits; /* Number of significant leftover bits */
return (ISC_FALSE);
return (ISC_FALSE);
switch (a->family) {
case AF_INET:
ipabytes = 4;
break;
case AF_INET6:
ipabytes = 16;
break;
default:
return (ISC_FALSE);
}
/*
* Don't crash if we get a pattern like 10.0.0.1/9999999.
*/
if (nbytes > 0) {
return (ISC_FALSE);
}
if (nbits > 0) {
return (ISC_FALSE);
}
return (ISC_TRUE);
}
char abuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")];
char zbuf[sizeof("%4294967295")];
unsigned int alen;
int zlen;
const char *r;
const void *type;
case AF_INET:
break;
case AF_INET6:
break;
#ifdef ISC_PLATFORM_HAVESYSUNH
case AF_UNIX:
return (ISC_R_NOSPACE);
alen);
return (ISC_R_SUCCESS);
#endif
default:
return (ISC_R_FAILURE);
}
if (r == NULL)
return (ISC_R_FAILURE);
zlen = 0;
if (zlen < 0)
return (ISC_R_FAILURE);
}
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
void
if (size == 0)
return;
/*
* Null terminate.
*/
if (result == ISC_R_SUCCESS) {
isc_buffer_putuint8(&buf, 0);
else
}
if (result != ISC_R_SUCCESS) {
"<unknown address, family %u>"),
}
}
static const unsigned char zeros[16];
const unsigned char *p;
case AF_INET:
ipbytes = 4;
if (prefixlen > 32)
return (ISC_R_RANGE);
break;
case AF_INET6:
ipbytes = 16;
if (prefixlen > 128)
return (ISC_R_RANGE);
break;
default:
return (ISC_R_NOTIMPLEMENTED);
}
if (nbits != 0) {
return (ISC_R_FAILURE);
nbytes++;
}
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
}
const unsigned char *p;
switch (s->family) {
case AF_INET:
ipbytes = 4;
break;
case AF_INET6:
ipbytes = 16;
break;
default:
return (ISC_R_NOTIMPLEMENTED);
}
for (i = 0; i < ipbytes; i++) {
if (p[i] != 0xFF)
break;
}
nbytes = i;
if (i < ipbytes) {
unsigned int c = p[nbytes];
c <<= 1; nbits++;
}
if ((c & 0xFF) != 0)
return (ISC_R_MASKNONCONTIG);
i++;
}
for (; i < ipbytes; i++) {
if (p[i] != 0)
return (ISC_R_MASKNONCONTIG);
i++;
}
return (ISC_R_SUCCESS);
}
void
}
void
}
#ifdef ISC_PLATFORM_HAVESYSUNH
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
#else
return (ISC_R_NOTIMPLEMENTED);
#endif
}
void
/* we currently only support AF_INET6. */
}
}
void
switch (family) {
case AF_INET:
t->zone = 0;
break;
case AF_INET6:
#ifdef ISC_PLATFORM_HAVESCOPEID
#else
t->zone = 0;
#endif
break;
#ifdef ISC_PLATFORM_HAVESYSUNH
case AF_UNIX:
t->zone = 0;
break;
#endif
default:
INSIST(0);
}
}
void
}
void
}
case AF_INET:
case AF_INET6:
default:
return (ISC_FALSE); /* XXXMLG ? */
}
}
case AF_INET:
default:
return (ISC_FALSE); /* XXXMLG ? */
}
}
case AF_INET:
return (ISC_FALSE);
case AF_INET6:
default:
return (ISC_FALSE);
}
}
case AF_INET:
return (ISC_FALSE);
case AF_INET6:
default:
return (ISC_FALSE);
}
}
void
memset(t, 0, sizeof(*t));
return;
}