]>
Commit | Line | Data |
---|---|---|
d7ce7006 | 1 | /*\r |
2 | * Copyright (c) 1996 by Internet Software Consortium.\r | |
3 | *\r | |
4 | * Permission to use, copy, modify, and distribute this software for any\r | |
5 | * purpose with or without fee is hereby granted, provided that the above\r | |
6 | * copyright notice and this permission notice appear in all copies.\r | |
7 | *\r | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS\r | |
9 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES\r | |
10 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\r | |
11 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r | |
12 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r | |
13 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r | |
14 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r | |
15 | * SOFTWARE.\r | |
16 | */\r | |
17 | \r | |
18 | /*\r | |
19 | * Portions copyright (c) 1999, 2000\r | |
20 | * Intel Corporation.\r | |
21 | * All rights reserved.\r | |
22 | * \r | |
23 | * Redistribution and use in source and binary forms, with or without\r | |
24 | * modification, are permitted provided that the following conditions\r | |
25 | * are met:\r | |
26 | * \r | |
27 | * 1. Redistributions of source code must retain the above copyright\r | |
28 | * notice, this list of conditions and the following disclaimer.\r | |
29 | * \r | |
30 | * 2. Redistributions in binary form must reproduce the above copyright\r | |
31 | * notice, this list of conditions and the following disclaimer in the\r | |
32 | * documentation and/or other materials provided with the distribution.\r | |
33 | * \r | |
34 | * 3. All advertising materials mentioning features or use of this software\r | |
35 | * must display the following acknowledgement:\r | |
36 | * \r | |
37 | * This product includes software developed by Intel Corporation and\r | |
38 | * its contributors.\r | |
39 | * \r | |
40 | * 4. Neither the name of Intel Corporation or its contributors may be\r | |
41 | * used to endorse or promote products derived from this software\r | |
42 | * without specific prior written permission.\r | |
43 | * \r | |
44 | * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''\r | |
45 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r | |
46 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r | |
47 | * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE\r | |
48 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r | |
49 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r | |
50 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r | |
51 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r | |
52 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r | |
53 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\r | |
54 | * THE POSSIBILITY OF SUCH DAMAGE.\r | |
55 | * \r | |
56 | */\r | |
57 | \r | |
58 | #if defined(LIBC_SCCS) && !defined(lint)\r | |
59 | static const char orig_rcsid[] = "From Id: inet_neta.c,v 8.2 1996/08/08 06:54:44 vixie Exp";\r | |
60 | static const char rcsid[] = "$Id: inet_neta.c,v 1.1.1.1 2003/11/19 01:51:29 kyu3 Exp $";\r | |
61 | #endif\r | |
62 | \r | |
63 | #include <sys/types.h>\r | |
64 | #include <sys/socket.h>\r | |
65 | #include <netinet/in.h>\r | |
66 | #include <arpa/inet.h>\r | |
67 | \r | |
68 | #include <errno.h>\r | |
69 | #include <stdio.h>\r | |
70 | #include <string.h>\r | |
71 | \r | |
72 | #ifdef SPRINTF_CHAR\r | |
73 | # define SPRINTF(x) strlen(sprintf/**/x)\r | |
74 | #else\r | |
75 | # define SPRINTF(x) ((size_t)sprintf x)\r | |
76 | #endif\r | |
77 | \r | |
78 | /*\r | |
79 | * char *\r | |
80 | * inet_neta(src, dst, size)\r | |
81 | * format a u_long network number into presentation format.\r | |
82 | * return:\r | |
83 | * pointer to dst, or NULL if an error occurred (check errno).\r | |
84 | * note:\r | |
85 | * format of ``src'' is as for inet_network().\r | |
86 | * author:\r | |
87 | * Paul Vixie (ISC), July 1996\r | |
88 | */\r | |
89 | char *\r | |
90 | inet_neta(\r | |
91 | u_long src,\r | |
92 | char *dst,\r | |
93 | size_t size\r | |
94 | )\r | |
95 | {\r | |
96 | char *odst = dst;\r | |
97 | char *tp;\r | |
98 | \r | |
99 | while (src & 0xffffffff) {\r | |
100 | u_char b = (u_char)((src & 0xff000000) >> 24);\r | |
101 | \r | |
102 | src <<= 8;\r | |
103 | if (b) {\r | |
104 | if (size < sizeof "255.")\r | |
105 | goto emsgsize;\r | |
106 | tp = dst;\r | |
107 | dst += SPRINTF((dst, "%u", b));\r | |
108 | if (src != 0L) {\r | |
109 | *dst++ = '.';\r | |
110 | *dst = '\0';\r | |
111 | }\r | |
112 | size -= (size_t)(dst - tp);\r | |
113 | }\r | |
114 | }\r | |
115 | if (dst == odst) {\r | |
116 | if (size < sizeof "0.0.0.0")\r | |
117 | goto emsgsize;\r | |
118 | strcpy(dst, "0.0.0.0");\r | |
119 | }\r | |
120 | return (odst);\r | |
121 | \r | |
122 | emsgsize:\r | |
123 | errno = EMSGSIZE;\r | |
124 | return (NULL);\r | |
125 | }\r |