aboutsummaryrefslogtreecommitdiff
path: root/contrib/bind/lib/inet/inet_addr.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bind/lib/inet/inet_addr.c')
-rw-r--r--contrib/bind/lib/inet/inet_addr.c78
1 files changed, 49 insertions, 29 deletions
diff --git a/contrib/bind/lib/inet/inet_addr.c b/contrib/bind/lib/inet/inet_addr.c
index 1d3943be84b3..3b54aa84797e 100644
--- a/contrib/bind/lib/inet/inet_addr.c
+++ b/contrib/bind/lib/inet/inet_addr.c
@@ -1,6 +1,4 @@
/*
- * ++Copyright++ 1983, 1990, 1993
- * -
* Copyright (c) 1983, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -31,7 +29,9 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- * -
+ */
+
+/*
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
*
* Permission to use, copy, modify, and distribute this software for any
@@ -49,33 +49,48 @@
* 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.
- * -
- * --Copyright--
+ */
+
+/*
+ * Portions Copyright (c) 1996-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 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
-static char rcsid[] = "$Id: inet_addr.c,v 8.7 1996/11/18 09:09:07 vixie Exp $";
+static const char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
+static const char rcsid[] = "$Id: inet_addr.c,v 8.11 1999/10/13 16:39:25 vixie Exp $";
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
+
#include <sys/types.h>
#include <sys/param.h>
+
#include <netinet/in.h>
#include <arpa/inet.h>
+
#include <ctype.h>
-#include "port_after.h"
-/* these are compatibility routines, not needed on recent BSD releases */
+#include "port_after.h"
/*
* Ascii internet address interpretation routine.
* The value returned is in network order.
*/
u_long
-inet_addr(cp)
- register const char *cp;
-{
+inet_addr(const char *cp) {
struct in_addr val;
if (inet_aton(cp, &val))
@@ -91,15 +106,13 @@ inet_addr(cp)
* cannot distinguish between failure and a local broadcast address.
*/
int
-inet_aton(cp, addr)
- register const char *cp;
- struct in_addr *addr;
-{
- register u_long val;
- register int base, n;
- register char c;
- u_int parts[4];
- register u_int *pp = parts;
+inet_aton(const char *cp, struct in_addr *addr) {
+ u_long val;
+ int base, n;
+ char c;
+ u_int8_t parts[4];
+ u_int8_t *pp = parts;
+ int digit;
c = *cp;
for (;;) {
@@ -110,22 +123,28 @@ inet_aton(cp, addr)
*/
if (!isdigit(c))
return (0);
- val = 0; base = 10;
+ val = 0; base = 10; digit = 0;
if (c == '0') {
c = *++cp;
if (c == 'x' || c == 'X')
base = 16, c = *++cp;
- else
+ else {
base = 8;
+ digit = 1 ;
+ }
}
for (;;) {
if (isascii(c) && isdigit(c)) {
+ if (base == 8 && (c == '8' || c == '9'))
+ return (0);
val = (val * base) + (c - '0');
c = *++cp;
+ digit = 1;
} else if (base == 16 && isascii(c) && isxdigit(c)) {
val = (val << 4) |
(c + 10 - (islower(c) ? 'a' : 'A'));
c = *++cp;
+ digit = 1;
} else
break;
}
@@ -136,7 +155,7 @@ inet_aton(cp, addr)
* a.b.c (with c treated as 16 bits)
* a.b (with b treated as 24 bits)
*/
- if (pp >= parts + 3)
+ if (pp >= parts + 3 || val > 0xff)
return (0);
*pp++ = val;
c = *++cp;
@@ -149,15 +168,16 @@ inet_aton(cp, addr)
if (c != '\0' && (!isascii(c) || !isspace(c)))
return (0);
/*
+ * Did we get a valid digit?
+ */
+ if (!digit)
+ return (0);
+ /*
* Concoct the address according to
* the number of parts specified.
*/
n = pp - parts + 1;
switch (n) {
-
- case 0:
- return (0); /* initial nondigit */
-
case 1: /* a -- 32 bits */
break;
@@ -179,7 +199,7 @@ inet_aton(cp, addr)
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
break;
}
- if (addr)
+ if (addr != NULL)
addr->s_addr = htonl(val);
return (1);
}