1157016Sdes/*	$OpenBSD: inet_ntoa.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */
298937Sdes/*
398937Sdes * Copyright (c) 1983, 1993
498937Sdes *	The Regents of the University of California.  All rights reserved.
598937Sdes *
698937Sdes * Redistribution and use in source and binary forms, with or without
798937Sdes * modification, are permitted provided that the following conditions
898937Sdes * are met:
998937Sdes * 1. Redistributions of source code must retain the above copyright
1098937Sdes *    notice, this list of conditions and the following disclaimer.
1198937Sdes * 2. Redistributions in binary form must reproduce the above copyright
1298937Sdes *    notice, this list of conditions and the following disclaimer in the
1398937Sdes *    documentation and/or other materials provided with the distribution.
14124208Sdes * 3. Neither the name of the University nor the names of its contributors
1598937Sdes *    may be used to endorse or promote products derived from this software
1698937Sdes *    without specific prior written permission.
1798937Sdes *
1898937Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1998937Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2098937Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2198937Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2298937Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2398937Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2498937Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2598937Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2698937Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2798937Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2898937Sdes * SUCH DAMAGE.
2998937Sdes */
3098937Sdes
31157016Sdes/* OPENBSD ORIGINAL: lib/libc/net/inet_ntoa.c */
32157016Sdes
33106121Sdes#include "includes.h"
3498937Sdes
3598937Sdes#if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA)
3698937Sdes
3798937Sdes/*
3898937Sdes * Convert network-format internet address
3998937Sdes * to base 256 d.d.d.d representation.
4098937Sdes */
4198937Sdes#include <sys/types.h>
4298937Sdes#include <netinet/in.h>
4398937Sdes#include <arpa/inet.h>
4498937Sdes#include <stdio.h>
4598937Sdes
46157016Sdeschar *
47157016Sdesinet_ntoa(struct in_addr in)
4898937Sdes{
4998937Sdes	static char b[18];
50157016Sdes	char *p;
5198937Sdes
5298937Sdes	p = (char *)&in;
5398937Sdes#define	UC(b)	(((int)b)&0xff)
5498937Sdes	(void)snprintf(b, sizeof(b),
55106121Sdes	    "%u.%u.%u.%u", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
5698937Sdes	return (b);
5798937Sdes}
5898937Sdes
5998937Sdes#endif /* defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) */
60