summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoritojun <>2001-11-14 02:31:57 +0000
committeritojun <>2001-11-14 02:31:57 +0000
commite67e7aab2d9624df4bd4c559984450972fd68d03 (patch)
tree2d0f5eef51af2746cd7160c6fd280dc9b31ca742
parent5f2b327040542968eef8d66df6399c69ca2ccd06 (diff)
downloadopenbsd-e67e7aab2d9624df4bd4c559984450972fd68d03.tar.gz
openbsd-e67e7aab2d9624df4bd4c559984450972fd68d03.tar.bz2
openbsd-e67e7aab2d9624df4bd4c559984450972fd68d03.zip
sync with kame better. open some renaming #defines (ENI_xx).
-rw-r--r--src/lib/libc/net/getnameinfo.c69
1 files changed, 27 insertions, 42 deletions
diff --git a/src/lib/libc/net/getnameinfo.c b/src/lib/libc/net/getnameinfo.c
index 0dee5a6c4c..9f2da6720c 100644
--- a/src/lib/libc/net/getnameinfo.c
+++ b/src/lib/libc/net/getnameinfo.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getnameinfo.c,v 1.19 2001/08/20 02:23:33 itojun Exp $ */ 1/* $OpenBSD: getnameinfo.c,v 1.20 2001/11/14 02:31:57 itojun Exp $ */
2/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ 2/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */
3 3
4/* 4/*
@@ -57,12 +57,7 @@
57#include <string.h> 57#include <string.h>
58#include <stddef.h> 58#include <stddef.h>
59 59
60#define SUCCESS 0 60static const struct afd {
61#define ANY 0
62#define YES 1
63#define NO 0
64
65static struct afd {
66 int a_af; 61 int a_af;
67 int a_addrlen; 62 int a_addrlen;
68 int a_socklen; 63 int a_socklen;
@@ -89,15 +84,6 @@ static int ip6_parsenumeric __P((const struct sockaddr *, const char *, char *,
89static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t, int)); 84static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t, int));
90#endif 85#endif
91 86
92/* 2553bis: use EAI_xx for getnameinfo */
93#define ENI_NOSOCKET EAI_FAIL /*XXX*/
94#define ENI_NOSERVNAME EAI_NONAME
95#define ENI_NOHOSTNAME EAI_NONAME
96#define ENI_MEMORY EAI_MEMORY
97#define ENI_SYSTEM EAI_SYSTEM
98#define ENI_FAMILY EAI_FAMILY
99#define ENI_SALEN EAI_FAMILY
100
101int 87int
102getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) 88getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
103 const struct sockaddr *sa; 89 const struct sockaddr *sa;
@@ -108,7 +94,7 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
108 size_t servlen; 94 size_t servlen;
109 int flags; 95 int flags;
110{ 96{
111 struct afd *afd; 97 const struct afd *afd;
112 struct servent *sp; 98 struct servent *sp;
113 struct hostent *hp; 99 struct hostent *hp;
114 u_short port; 100 u_short port;
@@ -120,10 +106,10 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
120 char numaddr[512]; 106 char numaddr[512];
121 107
122 if (sa == NULL) 108 if (sa == NULL)
123 return ENI_NOSOCKET; 109 return EAI_FAIL;
124 110
125 if (sa->sa_len != salen) 111 if (sa->sa_len != salen)
126 return ENI_SALEN; 112 return EAI_FAIL;
127 113
128 family = sa->sa_family; 114 family = sa->sa_family;
129 for (i = 0; afdl[i].a_af; i++) 115 for (i = 0; afdl[i].a_af; i++)
@@ -131,12 +117,12 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
131 afd = &afdl[i]; 117 afd = &afdl[i];
132 goto found; 118 goto found;
133 } 119 }
134 return ENI_FAMILY; 120 return EAI_FAMILY;
135 121
136 found: 122 found:
137 if (salen != afd->a_socklen) 123 if (salen != afd->a_socklen)
138 return ENI_SALEN; 124 return EAI_FAIL;
139 125
140 /* network byte order */ 126 /* network byte order */
141 port = ((const struct sockinet *)sa)->si_port; 127 port = ((const struct sockinet *)sa)->si_port;
142 addr = (const char *)sa + afd->a_off; 128 addr = (const char *)sa + afd->a_off;
@@ -145,8 +131,8 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
145 /* 131 /*
146 * do nothing in this case. 132 * do nothing in this case.
147 * in case you are wondering if "&&" is more correct than 133 * in case you are wondering if "&&" is more correct than
148 * "||" here: RFC2553 says that serv == NULL OR servlen == 0 134 * "||" here: rfc2553bis-03 says that serv == NULL OR
149 * means that the caller does not want the result. 135 * servlen == 0 means that the caller does not want the result.
150 */ 136 */
151 } else { 137 } else {
152 if (flags & NI_NUMERICSERV) 138 if (flags & NI_NUMERICSERV)
@@ -157,12 +143,12 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
157 } 143 }
158 if (sp) { 144 if (sp) {
159 if (strlen(sp->s_name) + 1 > servlen) 145 if (strlen(sp->s_name) + 1 > servlen)
160 return ENI_MEMORY; 146 return EAI_MEMORY;
161 strcpy(serv, sp->s_name); 147 strcpy(serv, sp->s_name);
162 } else { 148 } else {
163 snprintf(numserv, sizeof(numserv), "%d", ntohs(port)); 149 snprintf(numserv, sizeof(numserv), "%d", ntohs(port));
164 if (strlen(numserv) + 1 > servlen) 150 if (strlen(numserv) + 1 > servlen)
165 return ENI_MEMORY; 151 return EAI_MEMORY;
166 strcpy(serv, numserv); 152 strcpy(serv, numserv);
167 } 153 }
168 } 154 }
@@ -207,15 +193,15 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
207 /* 193 /*
208 * do nothing in this case. 194 * do nothing in this case.
209 * in case you are wondering if "&&" is more correct than 195 * in case you are wondering if "&&" is more correct than
210 * "||" here: RFC2553 says that host == NULL OR hostlen == 0 196 * "||" here: rfc2553bis-03 says that host == NULL or
211 * means that the caller does not want the result. 197 * hostlen == 0 means that the caller does not want the result.
212 */ 198 */
213 } else if (flags & NI_NUMERICHOST) { 199 } else if (flags & NI_NUMERICHOST) {
214 int numaddrlen; 200 int numaddrlen;
215 201
216 /* NUMERICHOST and NAMEREQD conflicts with each other */ 202 /* NUMERICHOST and NAMEREQD conflicts with each other */
217 if (flags & NI_NAMEREQD) 203 if (flags & NI_NAMEREQD)
218 return ENI_NOHOSTNAME; 204 return EAI_NONAME;
219 205
220 switch(afd->a_af) { 206 switch(afd->a_af) {
221#ifdef INET6 207#ifdef INET6
@@ -232,10 +218,10 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
232 default: 218 default:
233 if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) 219 if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr))
234 == NULL) 220 == NULL)
235 return ENI_SYSTEM; 221 return EAI_SYSTEM;
236 numaddrlen = strlen(numaddr); 222 numaddrlen = strlen(numaddr);
237 if (numaddrlen + 1 > hostlen) /* don't forget terminator */ 223 if (numaddrlen + 1 > hostlen) /* don't forget terminator */
238 return ENI_MEMORY; 224 return EAI_MEMORY;
239 strcpy(host, numaddr); 225 strcpy(host, numaddr);
240 break; 226 break;
241 } 227 }
@@ -257,12 +243,12 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
257 } 243 }
258#endif 244#endif
259 if (strlen(hp->h_name) + 1 > hostlen) { 245 if (strlen(hp->h_name) + 1 > hostlen) {
260 return ENI_MEMORY; 246 return EAI_MEMORY;
261 } 247 }
262 strcpy(host, hp->h_name); 248 strcpy(host, hp->h_name);
263 } else { 249 } else {
264 if (flags & NI_NAMEREQD) 250 if (flags & NI_NAMEREQD)
265 return ENI_NOHOSTNAME; 251 return EAI_NONAME;
266 switch(afd->a_af) { 252 switch(afd->a_af) {
267#ifdef INET6 253#ifdef INET6
268 case AF_INET6: 254 case AF_INET6:
@@ -279,12 +265,12 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
279 default: 265 default:
280 if (inet_ntop(afd->a_af, addr, host, 266 if (inet_ntop(afd->a_af, addr, host,
281 hostlen) == NULL) 267 hostlen) == NULL)
282 return ENI_SYSTEM; 268 return EAI_SYSTEM;
283 break; 269 break;
284 } 270 }
285 } 271 }
286 } 272 }
287 return SUCCESS; 273 return(0);
288} 274}
289 275
290#ifdef INET6 276#ifdef INET6
@@ -299,13 +285,12 @@ ip6_parsenumeric(sa, addr, host, hostlen, flags)
299 int numaddrlen; 285 int numaddrlen;
300 char numaddr[512]; 286 char numaddr[512];
301 287
302 if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) 288 if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL)
303 == NULL) 289 return EAI_SYSTEM;
304 return ENI_SYSTEM;
305 290
306 numaddrlen = strlen(numaddr); 291 numaddrlen = strlen(numaddr);
307 if (numaddrlen + 1 > hostlen) /* don't forget terminator */ 292 if (numaddrlen + 1 > hostlen) /* don't forget terminator */
308 return ENI_MEMORY; 293 return EAI_MEMORY;
309 strcpy(host, numaddr); 294 strcpy(host, numaddr);
310 295
311#ifdef NI_WITHSCOPEID 296#ifdef NI_WITHSCOPEID
@@ -319,9 +304,9 @@ ip6_parsenumeric(sa, addr, host, hostlen, flags)
319 (const struct sockaddr_in6 *)(const void *)sa, 304 (const struct sockaddr_in6 *)(const void *)sa,
320 scopebuf, sizeof(scopebuf), 0); 305 scopebuf, sizeof(scopebuf), 0);
321 if (scopelen < 0) 306 if (scopelen < 0)
322 return ENI_MEMORY; 307 return EAI_MEMORY;
323 if (scopelen + 1 + numaddrlen + 1 > hostlen) 308 if (scopelen + 1 + numaddrlen + 1 > hostlen)
324 return ENI_MEMORY; 309 return EAI_MEMORY;
325 /* 310 /*
326 * construct <numeric-addr><delim><scopeid> 311 * construct <numeric-addr><delim><scopeid>
327 */ 312 */