netaddr.c revision 40f53fa8d9c6a4fc38c0014495e7a42b08f52481
/*
* Copyright (C) 1999, 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* 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 INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM 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.12 2000/08/01 01:29:37 tale Exp $ */
#include <config.h>
#include <stdio.h>
#include <isc/sockaddr.h>
return (ISC_FALSE);
switch (a->family) {
case AF_INET:
return (ISC_FALSE);
break;
case AF_INET6:
!= 0)
return (ISC_FALSE);
break;
default:
return (ISC_FALSE);
}
return (ISC_TRUE);
}
unsigned int prefixlen)
{
unsigned int ipabytes; /* 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);
switch (a->family) {
case AF_INET:
ipabytes = 4;
break;
case AF_INET6:
ipabytes = 16;
break;
default:
ipabytes = 0; /* Ditto. */
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"];
unsigned int alen;
const char *r;
if (r == NULL)
return (ISC_R_FAILURE);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
void
/*
* Null terminate.
*/
if (result == ISC_R_SUCCESS) {
isc_buffer_putuint8(&buf, 0);
else
}
if (result != ISC_R_SUCCESS) {
"<unknown address, family %u>",
}
}
const unsigned char *p;
switch (s->family) {
case AF_INET:
ipbytes = 4;
break;
case AF_INET6:
ipbytes = 16;
break;
default:
ipbytes = 0;
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
}
void
switch (family) {
case AF_INET:
break;
case AF_INET6:
break;
default:
INSIST(0);
}
}
case AF_INET:
case AF_INET6:
default:
return (ISC_FALSE); /* XXXMLG ? */
}
}