93 * copyright notice and this permission notice appear in all copies.
94 *
95 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
96 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
97 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
98 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
99 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
100 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
101 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
102 * SOFTWARE.
103 */
104
105 /*
106 * Convert network-format internet address
107 * to base 256 d.d.d.d representation.
108 *
109 * Reentrant interface
110 */
111
112 #include "lint.h"
113 #include "thr_uberdata.h"
114
115 #include <sys/types.h>
116
117 #include <netinet/in.h>
118
119 #include <ctype.h>
120 #include <errno.h>
121 #include <stdio.h>
122 #include <stdlib.h>
123
124 char *
125 inet_ntoa_r(struct in_addr in, char b[])
126 {
127 char *p;
128
129 p = (char *)∈
130 #define UC(b) (((int)b)&0xff)
131 (void) sprintf(b, "%d.%d.%d.%d",
132 UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
133 return (b);
134 }
135
136 char *
137 inet_ntoa(struct in_addr in)
138 {
139 return (inet_ntoa_r(in, curthread->ul_ntoabuf));
140 }
141
142 /*
143 * Check whether "cp" is a valid ascii representation
144 * of an Internet address and convert to a binary address.
145 * Returns 1 if the address is valid, 0 if not.
146 * This replaces inet_addr, the return value from which
147 * cannot distinguish between failure and a local broadcast address.
148 */
149 int
150 inet_aton(const char *cp, struct in_addr *addr)
151 {
152 uint32_t val;
153 int base, n;
154 char c;
155 unsigned int parts[4];
156 unsigned int *pp = parts;
157
158 c = *cp;
159 for (;;) {
|
93 * copyright notice and this permission notice appear in all copies.
94 *
95 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
96 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
97 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
98 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
99 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
100 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
101 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
102 * SOFTWARE.
103 */
104
105 /*
106 * Convert network-format internet address
107 * to base 256 d.d.d.d representation.
108 *
109 * Reentrant interface
110 */
111
112 #include "lint.h"
113
114 #include <sys/types.h>
115
116 #include <netinet/in.h>
117
118 #include <ctype.h>
119 #include <errno.h>
120 #include <stdio.h>
121 #include <stdlib.h>
122 #include <threads.h>
123
124 static thread_local char ntoa_buf[18];
125
126 char *
127 inet_ntoa_r(struct in_addr in, char b[])
128 {
129 char *p;
130
131 p = (char *)∈
132 #define UC(b) (((int)b)&0xff)
133 (void) sprintf(b, "%d.%d.%d.%d",
134 UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
135 return (b);
136 }
137
138 char *
139 inet_ntoa(struct in_addr in)
140 {
141 return (inet_ntoa_r(in, ntoa_buf));
142 }
143
144 /*
145 * Check whether "cp" is a valid ascii representation
146 * of an Internet address and convert to a binary address.
147 * Returns 1 if the address is valid, 0 if not.
148 * This replaces inet_addr, the return value from which
149 * cannot distinguish between failure and a local broadcast address.
150 */
151 int
152 inet_aton(const char *cp, struct in_addr *addr)
153 {
154 uint32_t val;
155 int base, n;
156 char c;
157 unsigned int parts[4];
158 unsigned int *pp = parts;
159
160 c = *cp;
161 for (;;) {
|