gethostnamadr.c (158477) | gethostnamadr.c (158791) |
---|---|
1/*- 2 * Copyright (c) 1994, Garrett Wollman 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 10 unchanged lines hidden (view full) --- 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1994, Garrett Wollman 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 10 unchanged lines hidden (view full) --- 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26#include <sys/cdefs.h> |
27__FBSDID("$FreeBSD: head/lib/libc/net/gethostnamadr.c 158477 2006-05-12 15:37:23Z ume $"); | 27__FBSDID("$FreeBSD: head/lib/libc/net/gethostnamadr.c 158791 2006-05-21 11:27:28Z ume $"); |
28 29#include "namespace.h" 30#include "reentrant.h" 31#include <sys/param.h> 32#include <sys/socket.h> 33#include <netinet/in.h> 34#include <arpa/inet.h> 35#include <netdb.h> --- 128 unchanged lines hidden (view full) --- 164static int 165host_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata) 166{ 167 res_state statp; 168 u_long res_options; 169 170 const int op_id = 1; 171 char *str; | 28 29#include "namespace.h" 30#include "reentrant.h" 31#include <sys/param.h> 32#include <sys/socket.h> 33#include <netinet/in.h> 34#include <arpa/inet.h> 35#include <netdb.h> --- 128 unchanged lines hidden (view full) --- 164static int 165host_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata) 166{ 167 res_state statp; 168 u_long res_options; 169 170 const int op_id = 1; 171 char *str; |
172 int len, type; | 172 void *addr; 173 socklen_t len; 174 int type; |
173 174 size_t desired_size, size; 175 enum nss_lookup_type lookup_type; 176 char *p; 177 int res = NS_UNAVAIL; 178 179 statp = __res_state(); 180 res_options = statp->options & (RES_RECURSE | RES_DEFNAMES | --- 28 unchanged lines hidden (view full) --- 209 memcpy(p, &type, sizeof(int)); 210 p += sizeof(int); 211 212 memcpy(p, str, size + 1); 213 214 res = NS_SUCCESS; 215 break; 216 case nss_lt_id: | 175 176 size_t desired_size, size; 177 enum nss_lookup_type lookup_type; 178 char *p; 179 int res = NS_UNAVAIL; 180 181 statp = __res_state(); 182 res_options = statp->options & (RES_RECURSE | RES_DEFNAMES | --- 28 unchanged lines hidden (view full) --- 211 memcpy(p, &type, sizeof(int)); 212 p += sizeof(int); 213 214 memcpy(p, str, size + 1); 215 216 res = NS_SUCCESS; 217 break; 218 case nss_lt_id: |
217 str = va_arg(ap, char *); 218 len = va_arg(ap, int); | 219 addr = va_arg(ap, void *); 220 len = va_arg(ap, socklen_t); |
219 type = va_arg(ap, int); 220 221 desired_size = sizeof(res_options) + sizeof(int) + | 221 type = va_arg(ap, int); 222 223 desired_size = sizeof(res_options) + sizeof(int) + |
222 sizeof(enum nss_lookup_type) + sizeof(int) * 2 + len; | 224 sizeof(enum nss_lookup_type) + sizeof(int) + 225 sizeof(socklen_t) + len; |
223 224 if (desired_size > *buffer_size) { 225 res = NS_RETURN; 226 goto fin; 227 } 228 229 p = buffer; 230 memcpy(p, &res_options, sizeof(res_options)); 231 p += sizeof(res_options); 232 233 memcpy(p, &op_id, sizeof(int)); 234 p += sizeof(int); 235 236 memcpy(p, &lookup_type, sizeof(enum nss_lookup_type)); 237 p += sizeof(int); 238 239 memcpy(p, &type, sizeof(int)); 240 p += sizeof(int); 241 | 226 227 if (desired_size > *buffer_size) { 228 res = NS_RETURN; 229 goto fin; 230 } 231 232 p = buffer; 233 memcpy(p, &res_options, sizeof(res_options)); 234 p += sizeof(res_options); 235 236 memcpy(p, &op_id, sizeof(int)); 237 p += sizeof(int); 238 239 memcpy(p, &lookup_type, sizeof(enum nss_lookup_type)); 240 p += sizeof(int); 241 242 memcpy(p, &type, sizeof(int)); 243 p += sizeof(int); 244 |
242 memcpy(p, &len, sizeof(int)); 243 p += sizeof(int); | 245 memcpy(p, &len, sizeof(socklen_t)); 246 p += sizeof(socklen_t); |
244 | 247 |
245 memcpy(p, str, len); | 248 memcpy(p, addr, len); |
246 247 res = NS_SUCCESS; 248 break; 249 default: 250 /* should be unreachable */ 251 return (NS_UNAVAIL); 252 } 253 254fin: 255 *buffer_size = desired_size; 256 return (res); 257} 258 259static int 260host_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap, 261 void *cache_mdata) 262{ 263 char *str; | 249 250 res = NS_SUCCESS; 251 break; 252 default: 253 /* should be unreachable */ 254 return (NS_UNAVAIL); 255 } 256 257fin: 258 *buffer_size = desired_size; 259 return (res); 260} 261 262static int 263host_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap, 264 void *cache_mdata) 265{ 266 char *str; |
264 int len, type; | 267 void *addr; 268 socklen_t len; 269 int type; |
265 struct hostent *ht; 266 267 struct hostent new_ht; 268 size_t desired_size, aliases_size, addr_size, size; 269 char *p, **iter; 270 271 switch ((enum nss_lookup_type)cache_mdata) { 272 case nss_lt_name: 273 str = va_arg(ap, char *); 274 type = va_arg(ap, int); 275 break; 276 case nss_lt_id: | 270 struct hostent *ht; 271 272 struct hostent new_ht; 273 size_t desired_size, aliases_size, addr_size, size; 274 char *p, **iter; 275 276 switch ((enum nss_lookup_type)cache_mdata) { 277 case nss_lt_name: 278 str = va_arg(ap, char *); 279 type = va_arg(ap, int); 280 break; 281 case nss_lt_id: |
277 str = va_arg(ap, char *); 278 len = va_arg(ap, int); | 282 addr = va_arg(ap, void *); 283 len = va_arg(ap, socklen_t); |
279 type = va_arg(ap, int); 280 break; 281 default: 282 /* should be unreachable */ 283 return (NS_UNAVAIL); 284 } 285 ht = va_arg(ap, struct hostent *); 286 --- 73 unchanged lines hidden (view full) --- 360 return (NS_SUCCESS); 361} 362 363static int 364host_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap, 365 void *cache_mdata) 366{ 367 char *str; | 284 type = va_arg(ap, int); 285 break; 286 default: 287 /* should be unreachable */ 288 return (NS_UNAVAIL); 289 } 290 ht = va_arg(ap, struct hostent *); 291 --- 73 unchanged lines hidden (view full) --- 365 return (NS_SUCCESS); 366} 367 368static int 369host_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap, 370 void *cache_mdata) 371{ 372 char *str; |
368 int len, type; | 373 void *addr; 374 socklen_t len; 375 int type; |
369 struct hostent *ht; 370 371 char *p; 372 char **iter; 373 char *orig_buf; 374 size_t orig_buf_size; 375 376 switch ((enum nss_lookup_type)cache_mdata) { 377 case nss_lt_name: 378 str = va_arg(ap, char *); 379 type = va_arg(ap, int); 380 break; 381 case nss_lt_id: | 376 struct hostent *ht; 377 378 char *p; 379 char **iter; 380 char *orig_buf; 381 size_t orig_buf_size; 382 383 switch ((enum nss_lookup_type)cache_mdata) { 384 case nss_lt_name: 385 str = va_arg(ap, char *); 386 type = va_arg(ap, int); 387 break; 388 case nss_lt_id: |
382 str = va_arg(ap, char *); 383 len = va_arg(ap, int); | 389 addr = va_arg(ap, void *); 390 len = va_arg(ap, socklen_t); |
384 type = va_arg(ap, int); 385 break; 386 default: 387 /* should be unreachable */ 388 return (NS_UNAVAIL); 389 } 390 391 ht = va_arg(ap, struct hostent *); --- 176 unchanged lines hidden (view full) --- 568 rval = _nsdispatch((void *)result, dtab, NSDB_HOSTS, 569 "gethostbyname2_r", default_src, name, af, hp, buf, buflen, 570 &ret_errno, h_errnop); 571 572 return ((rval == NS_SUCCESS) ? 0 : -1); 573} 574 575int | 391 type = va_arg(ap, int); 392 break; 393 default: 394 /* should be unreachable */ 395 return (NS_UNAVAIL); 396 } 397 398 ht = va_arg(ap, struct hostent *); --- 176 unchanged lines hidden (view full) --- 575 rval = _nsdispatch((void *)result, dtab, NSDB_HOSTS, 576 "gethostbyname2_r", default_src, name, af, hp, buf, buflen, 577 &ret_errno, h_errnop); 578 579 return ((rval == NS_SUCCESS) ? 0 : -1); 580} 581 582int |
576gethostbyaddr_r(const void *addr, 577#if __LONG_BIT == 64 578 int len, 579#else 580 socklen_t len, 581#endif 582 int af, struct hostent *hp, char *buf, size_t buflen, 583 struct hostent **result, int *h_errnop) | 583gethostbyaddr_r(const void *addr, socklen_t len, int af, struct hostent *hp, 584 char *buf, size_t buflen, struct hostent **result, int *h_errnop) |
584{ 585 const u_char *uaddr = (const u_char *)addr; 586 const struct in6_addr *addr6; 587 socklen_t size; 588 int rval, ret_errno; 589 res_state statp; 590 591#ifdef NS_CACHING --- 87 unchanged lines hidden (view full) --- 679 return (NULL); 680 if (gethostbyname2_r(name, af, &hd->host, hd->data, sizeof(hd->data), 681 &rval, &ret_h_errno) != 0) 682 return (NULL); 683 return (rval); 684} 685 686struct hostent * | 585{ 586 const u_char *uaddr = (const u_char *)addr; 587 const struct in6_addr *addr6; 588 socklen_t size; 589 int rval, ret_errno; 590 res_state statp; 591 592#ifdef NS_CACHING --- 87 unchanged lines hidden (view full) --- 680 return (NULL); 681 if (gethostbyname2_r(name, af, &hd->host, hd->data, sizeof(hd->data), 682 &rval, &ret_h_errno) != 0) 683 return (NULL); 684 return (rval); 685} 686 687struct hostent * |
687#if __LONG_BIT == 64 688gethostbyaddr(const void *addr, int len, int af) 689#else | |
690gethostbyaddr(const void *addr, socklen_t len, int af) | 688gethostbyaddr(const void *addr, socklen_t len, int af) |
691#endif | |
692{ 693 struct hostdata *hd; 694 struct hostent *rval; 695 int ret_h_errno; 696 697 if ((hd = __hostdata_init()) == NULL) 698 return (NULL); 699 if (gethostbyaddr_r(addr, len, af, &hd->host, hd->data, --- 26 unchanged lines hidden --- | 689{ 690 struct hostdata *hd; 691 struct hostent *rval; 692 int ret_h_errno; 693 694 if ((hd = __hostdata_init()) == NULL) 695 return (NULL); 696 if (gethostbyaddr_r(addr, len, af, &hd->host, hd->data, --- 26 unchanged lines hidden --- |