diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/net/gethostnamadr.c | 84 |
1 files changed, 76 insertions, 8 deletions
diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c index 7321225863..6ff456fb0c 100644 --- a/src/lib/libc/net/gethostnamadr.c +++ b/src/lib/libc/net/gethostnamadr.c | |||
| @@ -52,7 +52,7 @@ | |||
| 52 | */ | 52 | */ |
| 53 | 53 | ||
| 54 | #if defined(LIBC_SCCS) && !defined(lint) | 54 | #if defined(LIBC_SCCS) && !defined(lint) |
| 55 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.30 1998/03/16 05:06:55 millert Exp $"; | 55 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.31 1998/11/20 11:18:44 d Exp $"; |
| 56 | #endif /* LIBC_SCCS and not lint */ | 56 | #endif /* LIBC_SCCS and not lint */ |
| 57 | 57 | ||
| 58 | #include <sys/param.h> | 58 | #include <sys/param.h> |
| @@ -67,12 +67,14 @@ static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.30 1998/03/16 05:06:55 mill | |||
| 67 | #include <errno.h> | 67 | #include <errno.h> |
| 68 | #include <string.h> | 68 | #include <string.h> |
| 69 | #include <syslog.h> | 69 | #include <syslog.h> |
| 70 | #include <stdlib.h> | ||
| 70 | #ifdef YP | 71 | #ifdef YP |
| 71 | #include <rpc/rpc.h> | 72 | #include <rpc/rpc.h> |
| 72 | #include <rpcsvc/yp.h> | 73 | #include <rpcsvc/yp.h> |
| 73 | #include <rpcsvc/ypclnt.h> | 74 | #include <rpcsvc/ypclnt.h> |
| 74 | #include "ypinternal.h" | 75 | #include "ypinternal.h" |
| 75 | #endif | 76 | #endif |
| 77 | #include "thread_private.h" | ||
| 76 | 78 | ||
| 77 | #define MULTI_PTRS_ARE_ALIASES 1 /* XXX - experimental */ | 79 | #define MULTI_PTRS_ARE_ALIASES 1 /* XXX - experimental */ |
| 78 | 80 | ||
| @@ -423,6 +425,60 @@ getanswer(answer, anslen, qname, qtype) | |||
| 423 | return (NULL); | 425 | return (NULL); |
| 424 | } | 426 | } |
| 425 | 427 | ||
| 428 | #ifndef notyet | ||
| 429 | /* | ||
| 430 | * XXX This is an extremely bogus implementations. | ||
| 431 | * | ||
| 432 | * FreeBSD has this interface: | ||
| 433 | * int gethostbyaddr_r(const char *addr, int len, int type, | ||
| 434 | * struct hostent *result, struct hostent_data *buffer) | ||
| 435 | */ | ||
| 436 | |||
| 437 | struct hostent * | ||
| 438 | gethostbyname_r(name, hp, buf, buflen, errorp) | ||
| 439 | const char * name; | ||
| 440 | struct hostent * hp; | ||
| 441 | char * buf; | ||
| 442 | int buflen; | ||
| 443 | int * errorp; | ||
| 444 | { | ||
| 445 | struct hostent *res; | ||
| 446 | |||
| 447 | res = gethostbyname(name); | ||
| 448 | *errorp = h_errno; | ||
| 449 | if (res == NULL) | ||
| 450 | return NULL; | ||
| 451 | memcpy(hp, res, sizeof *hp); /* XXX not sufficient */ | ||
| 452 | return hp; | ||
| 453 | } | ||
| 454 | |||
| 455 | /* | ||
| 456 | * XXX This is an extremely bogus implementations. | ||
| 457 | */ | ||
| 458 | struct hostent * | ||
| 459 | gethostbyaddr_r(addr, len, af, he, buf, buflen, errorp) | ||
| 460 | const char *addr; /* XXX should have been def'd as u_char! */ | ||
| 461 | int len, af; | ||
| 462 | struct hostent * he; | ||
| 463 | char * buf; | ||
| 464 | int buflen; | ||
| 465 | int * errorp; | ||
| 466 | { | ||
| 467 | struct hostent * res; | ||
| 468 | |||
| 469 | res = gethostbyaddr(addr, len, af); | ||
| 470 | *errorp = h_errno; | ||
| 471 | if (res == NULL) | ||
| 472 | return NULL; | ||
| 473 | memcpy(he, res, sizeof *he); /* XXX not sufficient */ | ||
| 474 | return he; | ||
| 475 | } | ||
| 476 | |||
| 477 | /* XXX RFC2133 expects a gethostbyname2_r() -- unimplemented */ | ||
| 478 | #endif | ||
| 479 | |||
| 480 | _THREAD_PRIVATE_MUTEX(gethostnamadr) | ||
| 481 | |||
| 426 | struct hostent * | 482 | struct hostent * |
| 427 | gethostbyname(name) | 483 | gethostbyname(name) |
| 428 | const char *name; | 484 | const char *name; |
| @@ -430,15 +486,19 @@ gethostbyname(name) | |||
| 430 | struct hostent *hp; | 486 | struct hostent *hp; |
| 431 | extern struct hostent *_gethtbyname2(); | 487 | extern struct hostent *_gethtbyname2(); |
| 432 | 488 | ||
| 489 | _THREAD_PRIVATE_MUTEX_LOCK(gethostnamadr); | ||
| 433 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 490 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) |
| 434 | return (_gethtbyname2(name, AF_INET)); | 491 | hp = _gethtbyname2(name, AF_INET); |
| 435 | 492 | ||
| 436 | if (_res.options & RES_USE_INET6) { | 493 | else if (_res.options & RES_USE_INET6) { |
| 437 | hp = gethostbyname2(name, AF_INET6); | 494 | hp = gethostbyname2(name, AF_INET6); |
| 438 | if (hp) | 495 | if (hp == NULL) |
| 439 | return (hp); | 496 | hp = gethostbyname2(name, AF_INET); |
| 440 | } | 497 | } |
| 441 | return (gethostbyname2(name, AF_INET)); | 498 | else |
| 499 | hp = gethostbyname2(name, AF_INET); | ||
| 500 | _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr); | ||
| 501 | return hp; | ||
| 442 | } | 502 | } |
| 443 | 503 | ||
| 444 | struct hostent * | 504 | struct hostent * |
| @@ -599,9 +659,14 @@ gethostbyaddr(addr, len, af) | |||
| 599 | char qbuf[MAXDNAME+1], *qp; | 659 | char qbuf[MAXDNAME+1], *qp; |
| 600 | extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr(); | 660 | extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr(); |
| 601 | char lookups[MAXDNSLUS]; | 661 | char lookups[MAXDNSLUS]; |
| 662 | struct hostent *res; | ||
| 602 | 663 | ||
| 603 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 664 | _THREAD_PRIVATE_MUTEX_LOCK(gethostnamadr); |
| 604 | return (_gethtbyaddr(addr, len, af)); | 665 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { |
| 666 | res = _gethtbyaddr(addr, len, af); | ||
| 667 | _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr); | ||
| 668 | return (res); | ||
| 669 | } | ||
| 605 | 670 | ||
| 606 | if (af == AF_INET6 && len == IN6ADDRSZ && | 671 | if (af == AF_INET6 && len == IN6ADDRSZ && |
| 607 | (!bcmp(uaddr, mapped, sizeof mapped) || | 672 | (!bcmp(uaddr, mapped, sizeof mapped) || |
| @@ -622,11 +687,13 @@ gethostbyaddr(addr, len, af) | |||
| 622 | default: | 687 | default: |
| 623 | errno = EAFNOSUPPORT; | 688 | errno = EAFNOSUPPORT; |
| 624 | h_errno = NETDB_INTERNAL; | 689 | h_errno = NETDB_INTERNAL; |
| 690 | _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr); | ||
| 625 | return (NULL); | 691 | return (NULL); |
| 626 | } | 692 | } |
| 627 | if (size != len) { | 693 | if (size != len) { |
| 628 | errno = EINVAL; | 694 | errno = EINVAL; |
| 629 | h_errno = NETDB_INTERNAL; | 695 | h_errno = NETDB_INTERNAL; |
| 696 | _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr); | ||
| 630 | return (NULL); | 697 | return (NULL); |
| 631 | } | 698 | } |
| 632 | switch (af) { | 699 | switch (af) { |
| @@ -692,6 +759,7 @@ gethostbyaddr(addr, len, af) | |||
| 692 | break; | 759 | break; |
| 693 | } | 760 | } |
| 694 | } | 761 | } |
| 762 | _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr); | ||
| 695 | /* XXX h_errno not correct in all cases... */ | 763 | /* XXX h_errno not correct in all cases... */ |
| 696 | return (hp); | 764 | return (hp); |
| 697 | } | 765 | } |
