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