lwinetaton.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
6ae232055d4d8a97267517c5e50074c2c819941and * Portions Copyright (C) 1996-2001, 2003-2005, 2007, 2012-2014, 2016 Internet Systems Consortium, Inc. ("ISC")
6ae232055d4d8a97267517c5e50074c2c819941and * This Source Code Form is subject to the terms of the Mozilla Public
6ae232055d4d8a97267517c5e50074c2c819941and * License, v. 2.0. If a copy of the MPL was not distributed with this
6ae232055d4d8a97267517c5e50074c2c819941and * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6ae232055d4d8a97267517c5e50074c2c819941and * Copyright (c) 1983, 1990, 1993
6ae232055d4d8a97267517c5e50074c2c819941and * The Regents of the University of California. All rights reserved.
6ae232055d4d8a97267517c5e50074c2c819941and * Redistribution and use in source and binary forms, with or without
6ae232055d4d8a97267517c5e50074c2c819941and * modification, are permitted provided that the following conditions
6ae232055d4d8a97267517c5e50074c2c819941and * are met:
6ae232055d4d8a97267517c5e50074c2c819941and * 1. Redistributions of source code must retain the above copyright
6ae232055d4d8a97267517c5e50074c2c819941and * notice, this list of conditions and the following disclaimer.
6ae232055d4d8a97267517c5e50074c2c819941and * 2. Redistributions in binary form must reproduce the above copyright
6ae232055d4d8a97267517c5e50074c2c819941and * notice, this list of conditions and the following disclaimer in the
6ae232055d4d8a97267517c5e50074c2c819941and * documentation and/or other materials provided with the distribution.
6ae232055d4d8a97267517c5e50074c2c819941and * 3. Neither the name of the University nor the names of its contributors
4b3a8afbfcea8b265d179a122bf40dfedd1ce280takashi * may be used to endorse or promote products derived from this software
6ae232055d4d8a97267517c5e50074c2c819941and * without specific prior written permission.
6ae232055d4d8a97267517c5e50074c2c819941and * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
6ae232055d4d8a97267517c5e50074c2c819941and * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6ae232055d4d8a97267517c5e50074c2c819941and * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
6ae232055d4d8a97267517c5e50074c2c819941and * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
6ae232055d4d8a97267517c5e50074c2c819941and * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
6ae232055d4d8a97267517c5e50074c2c819941and * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
6ae232055d4d8a97267517c5e50074c2c819941and * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
6ae232055d4d8a97267517c5e50074c2c819941and * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6ae232055d4d8a97267517c5e50074c2c819941and * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6ae232055d4d8a97267517c5e50074c2c819941and * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6ae232055d4d8a97267517c5e50074c2c819941and * SUCH DAMAGE.
6ae232055d4d8a97267517c5e50074c2c819941and * Portions Copyright (c) 1993 by Digital Equipment Corporation.
6ae232055d4d8a97267517c5e50074c2c819941and * Permission to use, copy, modify, and distribute this software for any
6ae232055d4d8a97267517c5e50074c2c819941and * purpose with or without fee is hereby granted, provided that the above
6ae232055d4d8a97267517c5e50074c2c819941and * copyright notice and this permission notice appear in all copies, and that
6ae232055d4d8a97267517c5e50074c2c819941and * the name of Digital Equipment Corporation not be used in advertising or
6ae232055d4d8a97267517c5e50074c2c819941and * publicity pertaining to distribution of the document or software without
6ae232055d4d8a97267517c5e50074c2c819941and * specific, written prior permission.
6ae232055d4d8a97267517c5e50074c2c819941and * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
6ae232055d4d8a97267517c5e50074c2c819941and * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
6ae232055d4d8a97267517c5e50074c2c819941and * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
6ae232055d4d8a97267517c5e50074c2c819941and * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
6ae232055d4d8a97267517c5e50074c2c819941and * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
6ae232055d4d8a97267517c5e50074c2c819941and * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
6ae232055d4d8a97267517c5e50074c2c819941and * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
6ae232055d4d8a97267517c5e50074c2c819941and * SOFTWARE.
6ae232055d4d8a97267517c5e50074c2c819941andstatic char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
6ae232055d4d8a97267517c5e50074c2c819941andstatic char rcsid[] = "$Id: lwinetaton.c,v 1.16 2007/06/19 23:47:22 tbox Exp $";
6ae232055d4d8a97267517c5e50074c2c819941and#endif /* LIBC_SCCS and not lint */
6ae232055d4d8a97267517c5e50074c2c819941and * Check whether "cp" is a valid ascii representation
6ae232055d4d8a97267517c5e50074c2c819941and * of an Internet address and convert to a binary address.
6ae232055d4d8a97267517c5e50074c2c819941and * Returns 1 if the address is valid, 0 if not.
6ae232055d4d8a97267517c5e50074c2c819941and * This replaces inet_addr, the return value from which
6ae232055d4d8a97267517c5e50074c2c819941and * cannot distinguish between failure and a local broadcast address.
6ae232055d4d8a97267517c5e50074c2c819941and unsigned char c;
6ae232055d4d8a97267517c5e50074c2c819941and for (;;) {
6ae232055d4d8a97267517c5e50074c2c819941and * Collect number up to ``.''.
6ae232055d4d8a97267517c5e50074c2c819941and * Values are specified as for C:
6ae232055d4d8a97267517c5e50074c2c819941and * 0x=hex, 0=octal, isdigit=decimal.
6ae232055d4d8a97267517c5e50074c2c819941and return (0);
6ae232055d4d8a97267517c5e50074c2c819941and if (c == '0') {
6ae232055d4d8a97267517c5e50074c2c819941and for (;;) {
6ae232055d4d8a97267517c5e50074c2c819941and * isascii() is valid for all integer values, and
6ae232055d4d8a97267517c5e50074c2c819941and * when it is true, c is known to be in scope
6ae232055d4d8a97267517c5e50074c2c819941and * for isdigit(). No cast necessary. Similar
6ae232055d4d8a97267517c5e50074c2c819941and * comment applies for later ctype uses.
6ae232055d4d8a97267517c5e50074c2c819941and return (0);
6ae232055d4d8a97267517c5e50074c2c819941and if (c == '.') {
6ae232055d4d8a97267517c5e50074c2c819941and * Internet format:
6ae232055d4d8a97267517c5e50074c2c819941and * a.b.c (with c treated as 16 bits)
6ae232055d4d8a97267517c5e50074c2c819941and * a.b (with b treated as 24 bits)
6ae232055d4d8a97267517c5e50074c2c819941and return (0);
6ae232055d4d8a97267517c5e50074c2c819941and * Check for trailing characters.
6ae232055d4d8a97267517c5e50074c2c819941and return (0);
6ae232055d4d8a97267517c5e50074c2c819941and * Did we get a valid digit?
6ae232055d4d8a97267517c5e50074c2c819941and return (0);
6ae232055d4d8a97267517c5e50074c2c819941and * Concoct the address according to
6ae232055d4d8a97267517c5e50074c2c819941and * the number of parts specified.
4b3a8afbfcea8b265d179a122bf40dfedd1ce280takashi switch (n) {
6ae232055d4d8a97267517c5e50074c2c819941and return (0);