inet_ntoa.c revision 98937
198937Sdes/* 298937Sdes * Copyright (c) 1983, 1993 398937Sdes * The Regents of the University of California. All rights reserved. 498937Sdes * 598937Sdes * Redistribution and use in source and binary forms, with or without 698937Sdes * modification, are permitted provided that the following conditions 798937Sdes * are met: 898937Sdes * 1. Redistributions of source code must retain the above copyright 998937Sdes * notice, this list of conditions and the following disclaimer. 1098937Sdes * 2. Redistributions in binary form must reproduce the above copyright 1198937Sdes * notice, this list of conditions and the following disclaimer in the 1298937Sdes * documentation and/or other materials provided with the distribution. 1398937Sdes * 3. All advertising materials mentioning features or use of this software 1498937Sdes * must display the following acknowledgement: 1598937Sdes * This product includes software developed by the University of 1698937Sdes * California, Berkeley and its contributors. 1798937Sdes * 4. Neither the name of the University nor the names of its contributors 1898937Sdes * may be used to endorse or promote products derived from this software 1998937Sdes * without specific prior written permission. 2098937Sdes * 2198937Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2298937Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2398937Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2498937Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2598937Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2698937Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2798937Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2898937Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2998937Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3098937Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3198937Sdes * SUCH DAMAGE. 3298937Sdes */ 3398937Sdes 3498937Sdes#include "config.h" 3598937Sdes 3698937Sdes#if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) 3798937Sdes 3898937Sdes#if defined(LIBC_SCCS) && !defined(lint) 3998937Sdesstatic char rcsid[] = "$OpenBSD: inet_ntoa.c,v 1.2 1996/08/19 08:29:16 tholo Exp $"; 4098937Sdes#endif /* LIBC_SCCS and not lint */ 4198937Sdes 4298937Sdes/* 4398937Sdes * Convert network-format internet address 4498937Sdes * to base 256 d.d.d.d representation. 4598937Sdes */ 4698937Sdes#include <sys/types.h> 4798937Sdes#include <netinet/in.h> 4898937Sdes#include <arpa/inet.h> 4998937Sdes#include <stdio.h> 5098937Sdes#include "inet_ntoa.h" 5198937Sdes 5298937Sdeschar *inet_ntoa(struct in_addr in) 5398937Sdes{ 5498937Sdes static char b[18]; 5598937Sdes register char *p; 5698937Sdes 5798937Sdes p = (char *)∈ 5898937Sdes#define UC(b) (((int)b)&0xff) 5998937Sdes (void)snprintf(b, sizeof(b), 6098937Sdes "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); 6198937Sdes return (b); 6298937Sdes} 6398937Sdes 6498937Sdes#endif /* defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) */ 65