xref: /netbsd-src/lib/libc/inet/inet_ntoa.c (revision c5e820cae412164fcbee52f470436200af5358ea)
1*c5e820caSchristos /*	$NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $	*/
23fa54233Schristos 
33fa54233Schristos /*
43fa54233Schristos  * Copyright (c) 1983, 1993
53fa54233Schristos  *	The Regents of the University of California.  All rights reserved.
63fa54233Schristos  *
73fa54233Schristos  * Redistribution and use in source and binary forms, with or without
83fa54233Schristos  * modification, are permitted provided that the following conditions
93fa54233Schristos  * are met:
103fa54233Schristos  * 1. Redistributions of source code must retain the above copyright
113fa54233Schristos  *    notice, this list of conditions and the following disclaimer.
123fa54233Schristos  * 2. Redistributions in binary form must reproduce the above copyright
133fa54233Schristos  *    notice, this list of conditions and the following disclaimer in the
143fa54233Schristos  *    documentation and/or other materials provided with the distribution.
153fa54233Schristos  * 3. Neither the name of the University nor the names of its contributors
163fa54233Schristos  *    may be used to endorse or promote products derived from this software
173fa54233Schristos  *    without specific prior written permission.
183fa54233Schristos  *
193fa54233Schristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
203fa54233Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
213fa54233Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
223fa54233Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
233fa54233Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
243fa54233Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
253fa54233Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
263fa54233Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
273fa54233Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
283fa54233Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
293fa54233Schristos  * SUCH DAMAGE.
303fa54233Schristos  */
313fa54233Schristos 
323fa54233Schristos #include <sys/cdefs.h>
333fa54233Schristos #if defined(LIBC_SCCS) && !defined(lint)
343fa54233Schristos #if 0
353fa54233Schristos static char sccsid[] = "@(#)inet_ntoa.c	8.1 (Berkeley) 6/4/93";
363fa54233Schristos #else
37*c5e820caSchristos __RCSID("$NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $");
383fa54233Schristos #endif
393fa54233Schristos #endif /* LIBC_SCCS and not lint */
403fa54233Schristos 
413fa54233Schristos #include "namespace.h"
423fa54233Schristos #include <sys/types.h>
433fa54233Schristos #include <sys/socket.h>
443fa54233Schristos #include <netinet/in.h>
453fa54233Schristos #include <arpa/inet.h>
463fa54233Schristos #include <stdio.h>
473fa54233Schristos #include <string.h>
483fa54233Schristos 
493fa54233Schristos #ifdef __weak_alias
__weak_alias(inet_ntoa,_inet_ntoa)503fa54233Schristos __weak_alias(inet_ntoa,_inet_ntoa)
513fa54233Schristos #endif
523fa54233Schristos 
533fa54233Schristos /*
543fa54233Schristos  * Convert network-format internet address
553fa54233Schristos  * to base 256 d.d.d.d representation.
563fa54233Schristos  */
573fa54233Schristos /*const*/ char *
583fa54233Schristos inet_ntoa(struct in_addr in) {
593fa54233Schristos 	static char ret[18];
603fa54233Schristos 
613fa54233Schristos 	strlcpy(ret, "[inet_ntoa error]", sizeof(ret));
62*c5e820caSchristos 	(void) inet_ntop(AF_INET, &in, ret, (socklen_t)sizeof ret);
63*c5e820caSchristos 	return ret;
643fa54233Schristos }
65