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