/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1998,1999 by 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 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.
*/
#endif
#include "port_before.h"
#include <isc/assertions.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "port_after.h"
#ifdef SPRINTF_CHAR
#else
#endif
int *bits));
/*%
* int
* inet_cidr_pton(af, src, dst, *bits)
* convert network address from presentation to network format.
* accepts inet_pton()'s input for this "af" plus trailing "/CIDR".
* "dst" is assumed large enough for its "af". "bits" is set to the
* /CIDR prefix length, which can have defaults (like /32 for IPv4).
* return:
* -1 if an error occurred (inspect errno; ENOENT means bad format).
* 0 if successful conversion occurred.
* note:
* 192.5.5.1/28 has a nonzero host part, which means it isn't a network
* as called for by inet_net_pton() but it can be a host address with
* an included netmask.
* author:
* Paul Vixie (ISC), October 1998
*/
int
switch (af) {
case AF_INET:
case AF_INET6:
default:
return (-1);
}
}
static int
/* Get the mantissa. */
tmp = 0;
do {
INSIST(n >= 0 && n <= 9);
tmp *= 10;
tmp += n;
if (tmp > 255)
goto enoent;
if (size-- == 0U)
goto emsgsize;
break;
if (ch != '.')
goto enoent;
}
/* Get the prefix length if any. */
bits = -1;
if (bits == -2)
goto enoent;
} else if (ch != '\0')
goto enoent;
/* Prefix length can default to /32 only if all four octets spec'd. */
if (bits == -1) {
else
goto enoent;
}
/* If nothing was written to the destination, we found no address. */
goto enoent;
/* If prefix length overspecifies mantissa, life is bad. */
goto enoent;
/* Extend address to four octets. */
while (size-- > 0U)
*dst++ = 0;
return (0);
return (-1);
return (-1);
}
static int
int bits;
/* Leading :: requires some special handling. */
if (*src == ':')
if (*++src != ':')
return (0);
saw_xdigit = 0;
val = 0;
bits = -1;
const char *pch;
val <<= 4;
if (val > 0xffff)
return (0);
saw_xdigit = 1;
continue;
}
if (ch == ':') {
if (!saw_xdigit) {
if (colonp)
return (0);
continue;
} else if (*src == '\0') {
return (0);
}
return (0);
saw_xdigit = 0;
val = 0;
continue;
}
tp += NS_INADDRSZ;
saw_xdigit = 0;
break; /*%< '\\0' was seen by inet_pton4(). */
}
if (ch == '/') {
if (bits == -2)
goto enoent;
break;
}
goto enoent;
}
if (saw_xdigit) {
goto emsgsize;
}
/*
* Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand.
*/
int i;
goto enoent;
for (i = 1; i <= n; i++) {
colonp[n - i] = 0;
}
}
return (0);
return (-1);
return (-1);
}
static int
int bits = 0;
return (-2);
do {
return (-2);
bits *= 10;
return (-2);
return (-2);
} while (*src != '\0');
return (bits);
}
/*! \file */