d8307d
commit 5e30b8ef0758763effa115634e0ed7d8938e4bc0
d8307d
Author: Florian Weimer <fweimer@redhat.com>
d8307d
Date:   Mon Jan 21 08:59:42 2019 +0100
d8307d
d8307d
    resolv: Reformat inet_addr, inet_aton to GNU style
d8307d
d8307d
diff --git a/resolv/inet_addr.c b/resolv/inet_addr.c
d8307d
index 022f7ea0841b6bae..32f58b0e13598b32 100644
d8307d
--- a/resolv/inet_addr.c
d8307d
+++ b/resolv/inet_addr.c
d8307d
@@ -1,3 +1,21 @@
d8307d
+/* Legacy IPv4 text-to-address functions.
d8307d
+   Copyright (C) 2019 Free Software Foundation, Inc.
d8307d
+   This file is part of the GNU C Library.
d8307d
+
d8307d
+   The GNU C Library is free software; you can redistribute it and/or
d8307d
+   modify it under the terms of the GNU Lesser General Public
d8307d
+   License as published by the Free Software Foundation; either
d8307d
+   version 2.1 of the License, or (at your option) any later version.
d8307d
+
d8307d
+   The GNU C Library is distributed in the hope that it will be useful,
d8307d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
d8307d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d8307d
+   Lesser General Public License for more details.
d8307d
+
d8307d
+   You should have received a copy of the GNU Lesser General Public
d8307d
+   License along with the GNU C Library; if not, see
d8307d
+   <http://www.gnu.org/licenses/>.  */
d8307d
+
d8307d
 /*
d8307d
  * Copyright (c) 1983, 1990, 1993
d8307d
  *    The Regents of the University of California.  All rights reserved.
d8307d
@@ -78,105 +96,97 @@
d8307d
 #include <limits.h>
d8307d
 #include <errno.h>
d8307d
 
d8307d
-/*
d8307d
- * Ascii internet address interpretation routine.
d8307d
- * The value returned is in network order.
d8307d
- */
d8307d
+/* ASCII IPv4 Internet address interpretation routine.  The value
d8307d
+   returned is in network order.  */
d8307d
 in_addr_t
d8307d
-__inet_addr(const char *cp) {
d8307d
-	struct in_addr val;
d8307d
+__inet_addr (const char *cp)
d8307d
+{
d8307d
+  struct in_addr val;
d8307d
 
d8307d
-	if (__inet_aton(cp, &val))
d8307d
-		return (val.s_addr);
d8307d
-	return (INADDR_NONE);
d8307d
+  if (__inet_aton (cp, &val))
d8307d
+    return val.s_addr;
d8307d
+  return INADDR_NONE;
d8307d
 }
d8307d
 weak_alias (__inet_addr, inet_addr)
d8307d
 
d8307d
-/*
d8307d
- * Check whether "cp" is a valid ascii representation
d8307d
- * of an Internet address and convert to a binary address.
d8307d
- * Returns 1 if the address is valid, 0 if not.
d8307d
- * This replaces inet_addr, the return value from which
d8307d
- * cannot distinguish between failure and a local broadcast address.
d8307d
- */
d8307d
+/* Check whether "cp" is a valid ASCII representation of an IPv4
d8307d
+   Internet address and convert it to a binary address.  Returns 1 if
d8307d
+   the address is valid, 0 if not.  This replaces inet_addr, the
d8307d
+   return value from which cannot distinguish between failure and a
d8307d
+   local broadcast address.  */
d8307d
 int
d8307d
-__inet_aton(const char *cp, struct in_addr *addr)
d8307d
+__inet_aton (const char *cp, struct in_addr *addr)
d8307d
 {
d8307d
-	static const in_addr_t max[4] = { 0xffffffff, 0xffffff, 0xffff, 0xff };
d8307d
-	in_addr_t val;
d8307d
-	char c;
d8307d
-	union iaddr {
d8307d
-	  uint8_t bytes[4];
d8307d
-	  uint32_t word;
d8307d
-	} res;
d8307d
-	uint8_t *pp = res.bytes;
d8307d
-	int digit;
d8307d
-
d8307d
-	int saved_errno = errno;
d8307d
-	__set_errno (0);
d8307d
-
d8307d
-	res.word = 0;
d8307d
-
d8307d
-	c = *cp;
d8307d
-	for (;;) {
d8307d
-		/*
d8307d
-		 * Collect number up to ``.''.
d8307d
-		 * Values are specified as for C:
d8307d
-		 * 0x=hex, 0=octal, isdigit=decimal.
d8307d
-		 */
d8307d
-		if (!isdigit(c))
d8307d
-			goto ret_0;
d8307d
-		{
d8307d
-			char *endp;
d8307d
-			unsigned long ul = strtoul (cp, (char **) &endp, 0);
d8307d
-			if (ul == ULONG_MAX && errno == ERANGE)
d8307d
-				goto ret_0;
d8307d
-			if (ul > 0xfffffffful)
d8307d
-				goto ret_0;
d8307d
-			val = ul;
d8307d
-			digit = cp != endp;
d8307d
-			cp = endp;
d8307d
-		}
d8307d
-		c = *cp;
d8307d
-		if (c == '.') {
d8307d
-			/*
d8307d
-			 * Internet format:
d8307d
-			 *	a.b.c.d
d8307d
-			 *	a.b.c	(with c treated as 16 bits)
d8307d
-			 *	a.b	(with b treated as 24 bits)
d8307d
-			 */
d8307d
-			if (pp > res.bytes + 2 || val > 0xff)
d8307d
-				goto ret_0;
d8307d
-			*pp++ = val;
d8307d
-			c = *++cp;
d8307d
-		} else
d8307d
-			break;
d8307d
-	}
d8307d
-	/*
d8307d
-	 * Check for trailing characters.
d8307d
-	 */
d8307d
-	if (c != '\0' && (!isascii(c) || !isspace(c)))
d8307d
-		goto ret_0;
d8307d
-	/*
d8307d
-	 * Did we get a valid digit?
d8307d
-	 */
d8307d
-	if (!digit)
d8307d
-		goto ret_0;
d8307d
-
d8307d
-	/* Check whether the last part is in its limits depending on
d8307d
-	   the number of parts in total.  */
d8307d
-	if (val > max[pp - res.bytes])
d8307d
+  static const in_addr_t max[4] = { 0xffffffff, 0xffffff, 0xffff, 0xff };
d8307d
+  in_addr_t val;
d8307d
+  char c;
d8307d
+  union iaddr
d8307d
+  {
d8307d
+    uint8_t bytes[4];
d8307d
+    uint32_t word;
d8307d
+  } res;
d8307d
+  uint8_t *pp = res.bytes;
d8307d
+  int digit;
d8307d
+
d8307d
+  int saved_errno = errno;
d8307d
+  __set_errno (0);
d8307d
+
d8307d
+  res.word = 0;
d8307d
+
d8307d
+  c = *cp;
d8307d
+  for (;;)
d8307d
+    {
d8307d
+      /* Collect number up to ``.''.  Values are specified as for C:
d8307d
+	 0x=hex, 0=octal, isdigit=decimal.  */
d8307d
+      if (!isdigit (c))
d8307d
+	goto ret_0;
d8307d
+      {
d8307d
+	char *endp;
d8307d
+	unsigned long ul = strtoul (cp, &endp, 0);
d8307d
+	if (ul == ULONG_MAX && errno == ERANGE)
d8307d
 	  goto ret_0;
d8307d
-
d8307d
-	if (addr != NULL)
d8307d
-		addr->s_addr = res.word | htonl (val);
d8307d
-
d8307d
-	__set_errno (saved_errno);
d8307d
-	return (1);
d8307d
-
d8307d
-ret_0:
d8307d
-	__set_errno (saved_errno);
d8307d
-	return (0);
d8307d
+	if (ul > 0xfffffffful)
d8307d
+	  goto ret_0;
d8307d
+	val = ul;
d8307d
+	digit = cp != endp;
d8307d
+	cp = endp;
d8307d
+      }
d8307d
+      c = *cp;
d8307d
+      if (c == '.')
d8307d
+	{
d8307d
+	  /* Internet format:
d8307d
+	     a.b.c.d
d8307d
+	     a.b.c	(with c treated as 16 bits)
d8307d
+	     a.b	(with b treated as 24 bits).  */
d8307d
+	  if (pp > res.bytes + 2 || val > 0xff)
d8307d
+	    goto ret_0;
d8307d
+	  *pp++ = val;
d8307d
+	  c = *++cp;
d8307d
+	}
d8307d
+      else
d8307d
+	break;
d8307d
+    }
d8307d
+  /* Check for trailing characters.  */
d8307d
+  if (c != '\0' && (!isascii (c) || !isspace (c)))
d8307d
+    goto ret_0;
d8307d
+  /*  Did we get a valid digit?  */
d8307d
+  if (!digit)
d8307d
+    goto ret_0;
d8307d
+
d8307d
+  /* Check whether the last part is in its limits depending on the
d8307d
+     number of parts in total.  */
d8307d
+  if (val > max[pp - res.bytes])
d8307d
+    goto ret_0;
d8307d
+
d8307d
+  if (addr != NULL)
d8307d
+    addr->s_addr = res.word | htonl (val);
d8307d
+
d8307d
+  __set_errno (saved_errno);
d8307d
+  return 1;
d8307d
+
d8307d
+ ret_0:
d8307d
+  __set_errno (saved_errno);
d8307d
+  return 0;
d8307d
 }
d8307d
 weak_alias (__inet_aton, inet_aton)
d8307d
 libc_hidden_def (__inet_aton)