inet_ntoa.c revision 2
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A * Portions of this source code were derived from Berkeley 2N/A * 4.3 BSD under license from the Regents of the University of 2N/A * Copyright (c) 1983, 1990, 1993 2N/A * The Regents of the University of California. All rights reserved. 2N/A * Redistribution and use in source and binary forms, with or without 2N/A * modification, are permitted provided that the following conditions 2N/A * 1. Redistributions of source code must retain the above copyright 2N/A * notice, this list of conditions and the following disclaimer. 2N/A * 2. Redistributions in binary form must reproduce the above copyright 2N/A * notice, this list of conditions and the following disclaimer in the 2N/A * documentation and/or other materials provided with the distribution. 2N/A * 3. All advertising materials mentioning features or use of this software 2N/A * must display the following acknowledgement: 2N/A * This product includes software developed by the University of 2N/A * California, Berkeley and its contributors. 2N/A * 4. Neither the name of the University nor the names of its contributors 2N/A * may be used to endorse or promote products derived from this software 2N/A * without specific prior written permission. 2N/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2N/A * Portions Copyright (c) 1993 by Digital Equipment Corporation. 2N/A * Permission to use, copy, modify, and distribute this software for any 2N/A * purpose with or without fee is hereby granted, provided that the above 2N/A * copyright notice and this permission notice appear in all copies, and that 2N/A * the name of Digital Equipment Corporation not be used in advertising or 2N/A * publicity pertaining to distribution of the document or software without 2N/A * specific, written prior permission. 2N/A * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 2N/A * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 2N/A * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 2N/A * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 2N/A * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 2N/A * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 2N/A * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 2N/A * Portions Copyright (c) 1996-1999 by Internet Software Consortium. 2N/A * Permission to use, copy, modify, and distribute this software for any 2N/A * purpose with or without fee is hereby granted, provided that the above 2N/A * copyright notice and this permission notice appear in all copies. 2N/A * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS 2N/A * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 2N/A * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE 2N/A * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 2N/A * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 2N/A * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 2N/A * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * Convert network-format internet address 2N/A * to base 256 d.d.d.d representation. 2N/A * Reentrant interface 2N/A char b[];
/* Assumed >= 18 bytes */ 2N/A#
define UC(b) (((
int)b)&
0xff)
2N/A * Check whether "cp" is a valid ascii representation 2N/A * of an Internet address and convert to a binary address. 2N/A * Returns 1 if the address is valid, 0 if not. 2N/A * This replaces inet_addr, the return value from which 2N/A * cannot distinguish between failure and a local broadcast address. 2N/A * Collect number up to ``.''. 2N/A * Values are specified as for C: 2N/A * 0x=hex, 0=octal, isdigit=decimal. 2N/A if (c ==
'x' || c ==
'X')
2N/A * a.b (with b treated as 24 bits) 2N/A * Check for trailing characters. 2N/A * Concoct the address according to 2N/A * the number of parts specified. 2N/A return (0);
/* initial nondigit */ 2N/A case 1:
/* a -- 32 bits */ 2N/A case 2:
/* a.b -- 8.24 bits */ 2N/A * Internet address interpretation routine. 2N/A * All the network library routines call this 2N/A * routine to interpret entries in the data bases 2N/A * which are expected to be an address. 2N/A * The value returned is in network order. 2N/A * Return the network number from an internet 2N/A * address; handles class a/b/c network #'s.