1 /* $NetBSD: inet_neta.c,v 1.15 2002/11/11 18:02:37 thorpej Exp $ */
4 * Copyright (c) 1996 by Internet Software Consortium.
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
11 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
12 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
13 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
16 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
20 #include <sys/cdefs.h>
21 #if defined(LIBC_SCCS) && !defined(lint)
23 static const char rcsid
[] = "Id: inet_neta.c,v 8.2 1996/08/08 06:54:44 vixie Exp ";
25 __RCSID("$NetBSD: inet_neta.c,v 1.15 2002/11/11 18:02:37 thorpej Exp $");
29 #include "namespace.h"
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
41 __weak_alias(inet_neta
,_inet_neta
)
46 * inet_neta(src, dst, size)
47 * format a u_long network number into presentation format.
49 * pointer to dst, or NULL if an error occurred (check errno).
51 * format of ``src'' is as for inet_network().
53 * Paul Vixie (ISC), July 1996
56 inet_neta(src
, dst
, size
)
65 _DIAGASSERT(dst
!= NULL
);
67 if (src
== 0x00000000) {
68 if (size
< sizeof "0.0.0.0")
70 strlcpy(dst
, "0.0.0.0", size
);
76 while (src
& 0xffffffff) {
77 u_char b
= (u_char
)((src
& 0xff000000) >> 24);
81 advance
= snprintf(dst
, (size_t)(ep
- dst
), "%u", b
);
82 if (advance
<= 0 || advance
>= ep
- dst
)