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