1 | #include <machine/rtems-bsd-user-space.h> |
---|
2 | |
---|
3 | /*- |
---|
4 | * SPDX-License-Identifier: ISC |
---|
5 | * |
---|
6 | * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") |
---|
7 | * Copyright (c) 1996,1999 by Internet Software Consortium. |
---|
8 | * |
---|
9 | * Permission to use, copy, modify, and distribute this software for any |
---|
10 | * purpose with or without fee is hereby granted, provided that the above |
---|
11 | * copyright notice and this permission notice appear in all copies. |
---|
12 | * |
---|
13 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES |
---|
14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
---|
15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR |
---|
16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
---|
17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
---|
18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
---|
19 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
---|
20 | */ |
---|
21 | |
---|
22 | #if defined(LIBC_SCCS) && !defined(lint) |
---|
23 | static const char rcsid[] = "$Id: inet_neta.c,v 1.3 2005/04/27 04:56:20 sra Exp $"; |
---|
24 | #endif |
---|
25 | #include <sys/cdefs.h> |
---|
26 | __FBSDID("$FreeBSD$"); |
---|
27 | |
---|
28 | #include "port_before.h" |
---|
29 | |
---|
30 | #include <sys/types.h> |
---|
31 | #include <sys/socket.h> |
---|
32 | #include <netinet/in.h> |
---|
33 | #include <arpa/inet.h> |
---|
34 | |
---|
35 | #include <errno.h> |
---|
36 | #include <stdio.h> |
---|
37 | #include <string.h> |
---|
38 | |
---|
39 | #include "port_after.h" |
---|
40 | |
---|
41 | #ifdef SPRINTF_CHAR |
---|
42 | # define SPRINTF(x) strlen(sprintf/**/x) |
---|
43 | #else |
---|
44 | # define SPRINTF(x) ((size_t)sprintf x) |
---|
45 | #endif |
---|
46 | |
---|
47 | /*% |
---|
48 | * char * |
---|
49 | * inet_neta(src, dst, size) |
---|
50 | * format an in_addr_t network number into presentation format. |
---|
51 | * return: |
---|
52 | * pointer to dst, or NULL if an error occurred (check errno). |
---|
53 | * note: |
---|
54 | * format of ``src'' is as for inet_network(). |
---|
55 | * author: |
---|
56 | * Paul Vixie (ISC), July 1996 |
---|
57 | */ |
---|
58 | char * |
---|
59 | inet_neta(in_addr_t src, char *dst, size_t size) |
---|
60 | { |
---|
61 | char *odst = dst; |
---|
62 | char *tp; |
---|
63 | |
---|
64 | while (src & 0xffffffff) { |
---|
65 | u_char b = (src & 0xff000000) >> 24; |
---|
66 | |
---|
67 | src <<= 8; |
---|
68 | if (b) { |
---|
69 | if (size < sizeof "255.") |
---|
70 | goto emsgsize; |
---|
71 | tp = dst; |
---|
72 | dst += SPRINTF((dst, "%u", b)); |
---|
73 | if (src != 0L) { |
---|
74 | *dst++ = '.'; |
---|
75 | *dst = '\0'; |
---|
76 | } |
---|
77 | size -= (size_t)(dst - tp); |
---|
78 | } |
---|
79 | } |
---|
80 | if (dst == odst) { |
---|
81 | if (size < sizeof "0.0.0.0") |
---|
82 | goto emsgsize; |
---|
83 | strcpy(dst, "0.0.0.0"); |
---|
84 | } |
---|
85 | return (odst); |
---|
86 | |
---|
87 | emsgsize: |
---|
88 | errno = EMSGSIZE; |
---|
89 | return (NULL); |
---|
90 | } |
---|
91 | |
---|
92 | #ifndef __rtems__ |
---|
93 | /* |
---|
94 | * Weak aliases for applications that use certain private entry points, |
---|
95 | * and fail to include <arpa/inet.h>. |
---|
96 | */ |
---|
97 | #undef inet_neta |
---|
98 | __weak_reference(__inet_neta, inet_neta); |
---|
99 | #endif /* __rtems__ */ |
---|
100 | |
---|
101 | /*! \file */ |
---|