1156952Sume/* 2156952Sume * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 3156952Sume * Copyright (c) 1996,1999 by Internet Software Consortium. 4156952Sume * 5156952Sume * Permission to use, copy, modify, and distribute this software for any 6156952Sume * purpose with or without fee is hereby granted, provided that the above 7156952Sume * copyright notice and this permission notice appear in all copies. 8156952Sume * 9156952Sume * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 10156952Sume * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11156952Sume * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 12156952Sume * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13156952Sume * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14156952Sume * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 15156952Sume * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16156952Sume */ 17156952Sume 18156952Sume#if defined(LIBC_SCCS) && !defined(lint) 19269867Sumestatic const char rcsid[] = "$Id: inet_neta.c,v 1.3 2005/04/27 04:56:20 sra Exp $"; 20156952Sume#endif 21156956Sume#include <sys/cdefs.h> 22156956Sume__FBSDID("$FreeBSD: releng/11.0/lib/libc/inet/inet_neta.c 288038 2015-09-20 20:50:56Z rodrigc $"); 23156952Sume 24156952Sume#include "port_before.h" 25156952Sume 26156952Sume#include <sys/types.h> 27156952Sume#include <sys/socket.h> 28156952Sume#include <netinet/in.h> 29156952Sume#include <arpa/inet.h> 30156952Sume 31156952Sume#include <errno.h> 32156952Sume#include <stdio.h> 33156952Sume#include <string.h> 34156952Sume 35156952Sume#include "port_after.h" 36156952Sume 37156952Sume#ifdef SPRINTF_CHAR 38156952Sume# define SPRINTF(x) strlen(sprintf/**/x) 39156952Sume#else 40156952Sume# define SPRINTF(x) ((size_t)sprintf x) 41156952Sume#endif 42156952Sume 43170244Sume/*% 44156952Sume * char * 45156952Sume * inet_neta(src, dst, size) 46156956Sume * format an in_addr_t network number into presentation format. 47156952Sume * return: 48156952Sume * pointer to dst, or NULL if an error occurred (check errno). 49156952Sume * note: 50156952Sume * format of ``src'' is as for inet_network(). 51156952Sume * author: 52156952Sume * Paul Vixie (ISC), July 1996 53156952Sume */ 54156952Sumechar * 55288038Srodrigcinet_neta(in_addr_t src, char *dst, size_t size) 56156952Sume{ 57156952Sume char *odst = dst; 58156952Sume char *tp; 59156952Sume 60156952Sume while (src & 0xffffffff) { 61156952Sume u_char b = (src & 0xff000000) >> 24; 62156952Sume 63156952Sume src <<= 8; 64156952Sume if (b) { 65156952Sume if (size < sizeof "255.") 66156952Sume goto emsgsize; 67156952Sume tp = dst; 68156952Sume dst += SPRINTF((dst, "%u", b)); 69156952Sume if (src != 0L) { 70156952Sume *dst++ = '.'; 71156952Sume *dst = '\0'; 72156952Sume } 73156952Sume size -= (size_t)(dst - tp); 74156952Sume } 75156952Sume } 76156952Sume if (dst == odst) { 77156952Sume if (size < sizeof "0.0.0.0") 78156952Sume goto emsgsize; 79156952Sume strcpy(dst, "0.0.0.0"); 80156952Sume } 81156952Sume return (odst); 82156952Sume 83156952Sume emsgsize: 84156952Sume errno = EMSGSIZE; 85156952Sume return (NULL); 86156952Sume} 87156956Sume 88156956Sume/* 89156956Sume * Weak aliases for applications that use certain private entry points, 90156956Sume * and fail to include <arpa/inet.h>. 91156956Sume */ 92156956Sume#undef inet_neta 93156956Sume__weak_reference(__inet_neta, inet_neta); 94170244Sume 95170244Sume/*! \file */ 96