From patchwork Fri Jan 18 20:08:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1027716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-99416-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="dc5H3aSQ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43hBpv2cQ4z9sD9 for ; Sat, 19 Jan 2019 07:08:55 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=E3x+XFoYpp+3wT0WQSmCRoghUrrDL /ZyItJZV/vVKUyscvBp20Tg5L7N5J9krZqTX61VYEFGsv4YVwPIs+T9/Utyau44Y M/OS2m223k7T7xs1CLZaEL2DFQfRfXngaX2GoXywo7CGnwPh7YbaYWs19EMJmzA+ mUsR07s6s7wiiU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=ZZ41V2fxKlEmJYW0psbchlA0Bes=; b=dc5 H3aSQ+uifBccWiQHyNLN/J9uNosZFwDy/y9lkCIwlWBwysxr3h7EkHcOP1KEc9WC oMfZKUYgAgpQZpCkm8Pq4bYTxUYdWM5Q1UFN0Iz533Ebwbs4TXl7ceu+6TGj1QS0 EL3rFcO2wiZa7JRXtaEE5Ic85pl7BWZVxtkfhIOU= Received: (qmail 83098 invoked by alias); 18 Jan 2019 20:08:49 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 83074 invoked by uid 89); 18 Jan 2019 20:08:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1990, Values, Legacy X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] resolv: Reformat inet_addr, inet_aton to GNU style Date: Fri, 18 Jan 2019 21:08:42 +0100 Message-ID: <878szhlodx.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 This is a precursor for fixing bug 20018. Maybe we want to put this into the release still? There's a new GLIBC_PRIVATE symbol. Thanks, Florian ---- 2019-01-18 Florian Weimer * resolv/inet_addr.c: Reformat to GNU style. (__inet_addr, __inet_aton): Update comment. diff --git a/resolv/inet_addr.c b/resolv/inet_addr.c index 022f7ea084..32f58b0e13 100644 --- a/resolv/inet_addr.c +++ b/resolv/inet_addr.c @@ -1,3 +1,21 @@ +/* Legacy IPv4 text-to-address functions. + Copyright (C) 2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + /* * Copyright (c) 1983, 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -78,105 +96,97 @@ #include #include -/* - * Ascii internet address interpretation routine. - * The value returned is in network order. - */ +/* ASCII IPv4 Internet address interpretation routine. The value + returned is in network order. */ in_addr_t -__inet_addr(const char *cp) { - struct in_addr val; +__inet_addr (const char *cp) +{ + struct in_addr val; - if (__inet_aton(cp, &val)) - return (val.s_addr); - return (INADDR_NONE); + if (__inet_aton (cp, &val)) + return val.s_addr; + return INADDR_NONE; } weak_alias (__inet_addr, inet_addr) -/* - * Check whether "cp" is a valid ascii representation - * of an Internet address and convert to a binary address. - * Returns 1 if the address is valid, 0 if not. - * This replaces inet_addr, the return value from which - * cannot distinguish between failure and a local broadcast address. - */ +/* Check whether "cp" is a valid ASCII representation of an IPv4 + Internet address and convert it to a binary address. Returns 1 if + the address is valid, 0 if not. This replaces inet_addr, the + return value from which cannot distinguish between failure and a + local broadcast address. */ int -__inet_aton(const char *cp, struct in_addr *addr) +__inet_aton (const char *cp, struct in_addr *addr) { - static const in_addr_t max[4] = { 0xffffffff, 0xffffff, 0xffff, 0xff }; - in_addr_t val; - char c; - union iaddr { - uint8_t bytes[4]; - uint32_t word; - } res; - uint8_t *pp = res.bytes; - int digit; + static const in_addr_t max[4] = { 0xffffffff, 0xffffff, 0xffff, 0xff }; + in_addr_t val; + char c; + union iaddr + { + uint8_t bytes[4]; + uint32_t word; + } res; + uint8_t *pp = res.bytes; + int digit; - int saved_errno = errno; - __set_errno (0); + int saved_errno = errno; + __set_errno (0); - res.word = 0; + res.word = 0; - c = *cp; - for (;;) { - /* - * Collect number up to ``.''. - * Values are specified as for C: - * 0x=hex, 0=octal, isdigit=decimal. - */ - if (!isdigit(c)) - goto ret_0; - { - char *endp; - unsigned long ul = strtoul (cp, (char **) &endp, 0); - if (ul == ULONG_MAX && errno == ERANGE) - goto ret_0; - if (ul > 0xfffffffful) - goto ret_0; - val = ul; - digit = cp != endp; - cp = endp; - } - c = *cp; - if (c == '.') { - /* - * Internet format: - * a.b.c.d - * a.b.c (with c treated as 16 bits) - * a.b (with b treated as 24 bits) - */ - if (pp > res.bytes + 2 || val > 0xff) - goto ret_0; - *pp++ = val; - c = *++cp; - } else - break; + c = *cp; + for (;;) + { + /* Collect number up to ``.''. Values are specified as for C: + 0x=hex, 0=octal, isdigit=decimal. */ + if (!isdigit (c)) + goto ret_0; + { + char *endp; + unsigned long ul = strtoul (cp, &endp, 0); + if (ul == ULONG_MAX && errno == ERANGE) + goto ret_0; + if (ul > 0xfffffffful) + goto ret_0; + val = ul; + digit = cp != endp; + cp = endp; + } + c = *cp; + if (c == '.') + { + /* Internet format: + a.b.c.d + a.b.c (with c treated as 16 bits) + a.b (with b treated as 24 bits). */ + if (pp > res.bytes + 2 || val > 0xff) + goto ret_0; + *pp++ = val; + c = *++cp; } - /* - * Check for trailing characters. - */ - if (c != '\0' && (!isascii(c) || !isspace(c))) - goto ret_0; - /* - * Did we get a valid digit? - */ - if (!digit) - goto ret_0; + else + break; + } + /* Check for trailing characters. */ + if (c != '\0' && (!isascii (c) || !isspace (c))) + goto ret_0; + /* Did we get a valid digit? */ + if (!digit) + goto ret_0; - /* Check whether the last part is in its limits depending on - the number of parts in total. */ - if (val > max[pp - res.bytes]) - goto ret_0; + /* Check whether the last part is in its limits depending on the + number of parts in total. */ + if (val > max[pp - res.bytes]) + goto ret_0; - if (addr != NULL) - addr->s_addr = res.word | htonl (val); + if (addr != NULL) + addr->s_addr = res.word | htonl (val); - __set_errno (saved_errno); - return (1); + __set_errno (saved_errno); + return 1; -ret_0: - __set_errno (saved_errno); - return (0); + ret_0: + __set_errno (saved_errno); + return 0; } weak_alias (__inet_aton, inet_aton) libc_hidden_def (__inet_aton)