/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")4* Copyright (c) 1996,1999 by Internet Software Consortium.5*6* Permission to use, copy, modify, and distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT16* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*/1819#include "port_before.h"2021#include <sys/types.h>22#include <sys/socket.h>23#include <netinet/in.h>24#include <arpa/inet.h>2526#include <errno.h>27#include <stdio.h>28#include <string.h>2930#include "port_after.h"3132#ifdef SPRINTF_CHAR33# define SPRINTF(x) strlen(sprintf/**/x)34#else35# define SPRINTF(x) ((size_t)sprintf x)36#endif3738/*%39* char *40* inet_neta(src, dst, size)41* format an in_addr_t network number into presentation format.42* return:43* pointer to dst, or NULL if an error occurred (check errno).44* note:45* format of ``src'' is as for inet_network().46* author:47* Paul Vixie (ISC), July 199648*/49char *50inet_neta(in_addr_t src, char *dst, size_t size)51{52char *odst = dst;53char *tp;5455while (src & 0xffffffff) {56u_char b = (src & 0xff000000) >> 24;5758src <<= 8;59if (b) {60if (size < sizeof "255.")61goto emsgsize;62tp = dst;63dst += SPRINTF((dst, "%u", b));64if (src != 0L) {65*dst++ = '.';66*dst = '\0';67}68size -= (size_t)(dst - tp);69}70}71if (dst == odst) {72if (size < sizeof "0.0.0.0")73goto emsgsize;74strcpy(dst, "0.0.0.0");75}76return (odst);7778emsgsize:79errno = EMSGSIZE;80return (NULL);81}8283/*84* Weak aliases for applications that use certain private entry points,85* and fail to include <arpa/inet.h>.86*/87#undef inet_neta88__weak_reference(__inet_neta, inet_neta);8990/*! \file */919293