netaddr.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 1999-2002, 2004, 2005, 2007, 2010-2012, 2014-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id$ */
/*! \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);
}
}
#ifndef IN_ZERONET
#endif
case AF_INET:
case AF_INET6:
return (ISC_FALSE);
default:
return (ISC_FALSE);
}
}
void
memset(t, 0, sizeof(*t));
return;
}