diff options
Diffstat (limited to 'src/lib/libc/net')
-rw-r--r-- | src/lib/libc/net/Makefile.inc | 6 | ||||
-rw-r--r-- | src/lib/libc/net/gethostnamadr.c | 84 | ||||
-rw-r--r-- | src/lib/libc/net/getservbyname.c | 26 |
3 files changed, 103 insertions, 13 deletions
diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc index 935a1904c1..35a9632a94 100644 --- a/src/lib/libc/net/Makefile.inc +++ b/src/lib/libc/net/Makefile.inc | |||
@@ -1,7 +1,7 @@ | |||
1 | # $OpenBSD: Makefile.inc,v 1.16 1998/08/29 21:11:40 deraadt Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.17 1998/11/20 11:18:43 d Exp $ |
2 | 2 | ||
3 | # net sources | 3 | # net sources |
4 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/net ${.CURDIR}/net | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net ${LIBCSRCDIR}/net |
5 | 5 | ||
6 | CFLAGS+=-DRESOLVSORT | 6 | CFLAGS+=-DRESOLVSORT |
7 | 7 | ||
@@ -19,7 +19,7 @@ SRCS+= base64.c gethostnamadr.c getnetbyaddr.c getnetbyname.c getnetent.c \ | |||
19 | # m-d Makefile.inc must include sources for: | 19 | # m-d Makefile.inc must include sources for: |
20 | # htonl() htons() ntohl() ntohs() | 20 | # htonl() htons() ntohl() ntohs() |
21 | 21 | ||
22 | .include "${.CURDIR}/arch/${MACHINE_ARCH}/net/Makefile.inc" | 22 | .include "${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net/Makefile.inc" |
23 | 23 | ||
24 | MAN+= byteorder.3 ethers.3 gethostbyname.3 getnetent.3 getprotoent.3 \ | 24 | MAN+= byteorder.3 ethers.3 gethostbyname.3 getnetent.3 getprotoent.3 \ |
25 | getservent.3 inet.3 inet_net.3 iso_addr.3 link_addr.3 ns.3 ipx.3 \ | 25 | getservent.3 inet.3 inet_net.3 iso_addr.3 link_addr.3 ns.3 ipx.3 \ |
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 | } |
diff --git a/src/lib/libc/net/getservbyname.c b/src/lib/libc/net/getservbyname.c index 25f0e27d06..7375c89404 100644 --- a/src/lib/libc/net/getservbyname.c +++ b/src/lib/libc/net/getservbyname.c | |||
@@ -32,21 +32,28 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | static char rcsid[] = "$OpenBSD: getservbyname.c,v 1.3 1997/07/09 01:08:34 millert Exp $"; | 35 | static char rcsid[] = "$OpenBSD: getservbyname.c,v 1.4 1998/11/20 11:18:44 d Exp $"; |
36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
37 | 37 | ||
38 | #include <netdb.h> | 38 | #include <netdb.h> |
39 | #include <string.h> | 39 | #include <string.h> |
40 | #include "thread_private.h" | ||
40 | 41 | ||
41 | extern int _serv_stayopen; | 42 | extern int _serv_stayopen; |
42 | 43 | ||
44 | _THREAD_PRIVATE_MUTEX(getservbyname_r) | ||
45 | |||
43 | struct servent * | 46 | struct servent * |
44 | getservbyname(name, proto) | 47 | getservbyname_r(name, proto, se, buf, buflen) |
45 | const char *name, *proto; | 48 | const char *name, *proto; |
49 | struct servent *se; | ||
50 | char *buf; | ||
51 | int buflen; | ||
46 | { | 52 | { |
47 | register struct servent *p; | 53 | register struct servent *p; |
48 | register char **cp; | 54 | register char **cp; |
49 | 55 | ||
56 | _THREAD_PRIVATE_MUTEX_LOCK(getservbyname_r); | ||
50 | setservent(_serv_stayopen); | 57 | setservent(_serv_stayopen); |
51 | while ((p = getservent())) { | 58 | while ((p = getservent())) { |
52 | if (strcmp(name, p->s_name) == 0) | 59 | if (strcmp(name, p->s_name) == 0) |
@@ -61,5 +68,20 @@ gotname: | |||
61 | } | 68 | } |
62 | if (!_serv_stayopen) | 69 | if (!_serv_stayopen) |
63 | endservent(); | 70 | endservent(); |
71 | _THREAD_PRIVATE_MUTEX_UNLOCK(getservbyname_r); | ||
64 | return (p); | 72 | return (p); |
65 | } | 73 | } |
74 | |||
75 | struct servent *getservbyname(name, proto) | ||
76 | const char *name, *proto; | ||
77 | { | ||
78 | _THREAD_PRIVATE_KEY(getservbyname) | ||
79 | static char buf[4096]; | ||
80 | char *bufp = (char*)_THREAD_PRIVATE(getservbyname, buf, NULL); | ||
81 | |||
82 | if (bufp == NULL) | ||
83 | return (NULL); | ||
84 | return getservbyname_r(name, proto, (struct servent*) bufp, | ||
85 | bufp + sizeof(struct servent), | ||
86 | sizeof buf - sizeof(struct servent) ); | ||
87 | } | ||