summaryrefslogtreecommitdiffstats
path: root/lib/libc/net
diff options
context:
space:
mode:
authord <d@openbsd.org>1998-11-20 11:18:22 +0000
committerd <d@openbsd.org>1998-11-20 11:18:22 +0000
commit92efb7350713770eeac379dc990eaecbee107aa1 (patch)
tree9e7a54e9f5f807b6269323fc5be9480298ad6de5 /lib/libc/net
parentMove atomic_lock code from asm to C with inline asm; (diff)
downloadwireguard-openbsd-92efb7350713770eeac379dc990eaecbee107aa1.tar.xz
wireguard-openbsd-92efb7350713770eeac379dc990eaecbee107aa1.zip
Add thread-safety to libc, so that libc_r will build (on i386 at least).
All POSIX libc api now there (to P1003.1c/D10) (more md stuff is needed for other libc/arch/*) (setlogin is no longer a special syscall) Add -pthread option to gcc (that makes it use -lc_r and -D_POSIX_THREADS). Doc some re-entrant routines Add libc_r to intro(3) dig() uses some libc srcs and an extra -I was needed there. Add more md stuff to libc_r. Update includes for the pthreads api Update libc_r TODO
Diffstat (limited to 'lib/libc/net')
-rw-r--r--lib/libc/net/Makefile.inc6
-rw-r--r--lib/libc/net/gethostnamadr.c84
-rw-r--r--lib/libc/net/getservbyname.c26
3 files changed, 103 insertions, 13 deletions
diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc
index 935a1904c12..35a9632a94e 100644
--- a/lib/libc/net/Makefile.inc
+++ b/lib/libc/net/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.16 1998/08/29 21:11:40 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.17 1998/11/20 11:18:43 d Exp $
# net sources
-.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/net ${.CURDIR}/net
+.PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net ${LIBCSRCDIR}/net
CFLAGS+=-DRESOLVSORT
@@ -19,7 +19,7 @@ SRCS+= base64.c gethostnamadr.c getnetbyaddr.c getnetbyname.c getnetent.c \
# m-d Makefile.inc must include sources for:
# htonl() htons() ntohl() ntohs()
-.include "${.CURDIR}/arch/${MACHINE_ARCH}/net/Makefile.inc"
+.include "${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net/Makefile.inc"
MAN+= byteorder.3 ethers.3 gethostbyname.3 getnetent.3 getprotoent.3 \
getservent.3 inet.3 inet_net.3 iso_addr.3 link_addr.3 ns.3 ipx.3 \
diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c
index 7321225863a..6ff456fb0c1 100644
--- a/lib/libc/net/gethostnamadr.c
+++ b/lib/libc/net/gethostnamadr.c
@@ -52,7 +52,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.30 1998/03/16 05:06:55 millert Exp $";
+static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.31 1998/11/20 11:18:44 d Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -67,12 +67,14 @@ static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.30 1998/03/16 05:06:55 mill
#include <errno.h>
#include <string.h>
#include <syslog.h>
+#include <stdlib.h>
#ifdef YP
#include <rpc/rpc.h>
#include <rpcsvc/yp.h>
#include <rpcsvc/ypclnt.h>
#include "ypinternal.h"
#endif
+#include "thread_private.h"
#define MULTI_PTRS_ARE_ALIASES 1 /* XXX - experimental */
@@ -423,6 +425,60 @@ getanswer(answer, anslen, qname, qtype)
return (NULL);
}
+#ifndef notyet
+/*
+ * XXX This is an extremely bogus implementations.
+ *
+ * FreeBSD has this interface:
+ * int gethostbyaddr_r(const char *addr, int len, int type,
+ * struct hostent *result, struct hostent_data *buffer)
+ */
+
+struct hostent *
+gethostbyname_r(name, hp, buf, buflen, errorp)
+ const char * name;
+ struct hostent * hp;
+ char * buf;
+ int buflen;
+ int * errorp;
+{
+ struct hostent *res;
+
+ res = gethostbyname(name);
+ *errorp = h_errno;
+ if (res == NULL)
+ return NULL;
+ memcpy(hp, res, sizeof *hp); /* XXX not sufficient */
+ return hp;
+}
+
+/*
+ * XXX This is an extremely bogus implementations.
+ */
+struct hostent *
+gethostbyaddr_r(addr, len, af, he, buf, buflen, errorp)
+ const char *addr; /* XXX should have been def'd as u_char! */
+ int len, af;
+ struct hostent * he;
+ char * buf;
+ int buflen;
+ int * errorp;
+{
+ struct hostent * res;
+
+ res = gethostbyaddr(addr, len, af);
+ *errorp = h_errno;
+ if (res == NULL)
+ return NULL;
+ memcpy(he, res, sizeof *he); /* XXX not sufficient */
+ return he;
+}
+
+/* XXX RFC2133 expects a gethostbyname2_r() -- unimplemented */
+#endif
+
+_THREAD_PRIVATE_MUTEX(gethostnamadr)
+
struct hostent *
gethostbyname(name)
const char *name;
@@ -430,15 +486,19 @@ gethostbyname(name)
struct hostent *hp;
extern struct hostent *_gethtbyname2();
+ _THREAD_PRIVATE_MUTEX_LOCK(gethostnamadr);
if ((_res.options & RES_INIT) == 0 && res_init() == -1)
- return (_gethtbyname2(name, AF_INET));
+ hp = _gethtbyname2(name, AF_INET);
- if (_res.options & RES_USE_INET6) {
+ else if (_res.options & RES_USE_INET6) {
hp = gethostbyname2(name, AF_INET6);
- if (hp)
- return (hp);
+ if (hp == NULL)
+ hp = gethostbyname2(name, AF_INET);
}
- return (gethostbyname2(name, AF_INET));
+ else
+ hp = gethostbyname2(name, AF_INET);
+ _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr);
+ return hp;
}
struct hostent *
@@ -599,9 +659,14 @@ gethostbyaddr(addr, len, af)
char qbuf[MAXDNAME+1], *qp;
extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr();
char lookups[MAXDNSLUS];
+ struct hostent *res;
- if ((_res.options & RES_INIT) == 0 && res_init() == -1)
- return (_gethtbyaddr(addr, len, af));
+ _THREAD_PRIVATE_MUTEX_LOCK(gethostnamadr);
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ res = _gethtbyaddr(addr, len, af);
+ _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr);
+ return (res);
+ }
if (af == AF_INET6 && len == IN6ADDRSZ &&
(!bcmp(uaddr, mapped, sizeof mapped) ||
@@ -622,11 +687,13 @@ gethostbyaddr(addr, len, af)
default:
errno = EAFNOSUPPORT;
h_errno = NETDB_INTERNAL;
+ _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr);
return (NULL);
}
if (size != len) {
errno = EINVAL;
h_errno = NETDB_INTERNAL;
+ _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr);
return (NULL);
}
switch (af) {
@@ -692,6 +759,7 @@ gethostbyaddr(addr, len, af)
break;
}
}
+ _THREAD_PRIVATE_MUTEX_UNLOCK(gethostnamadr);
/* XXX h_errno not correct in all cases... */
return (hp);
}
diff --git a/lib/libc/net/getservbyname.c b/lib/libc/net/getservbyname.c
index 25f0e27d06a..7375c894042 100644
--- a/lib/libc/net/getservbyname.c
+++ b/lib/libc/net/getservbyname.c
@@ -32,21 +32,28 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getservbyname.c,v 1.3 1997/07/09 01:08:34 millert Exp $";
+static char rcsid[] = "$OpenBSD: getservbyname.c,v 1.4 1998/11/20 11:18:44 d Exp $";
#endif /* LIBC_SCCS and not lint */
#include <netdb.h>
#include <string.h>
+#include "thread_private.h"
extern int _serv_stayopen;
+_THREAD_PRIVATE_MUTEX(getservbyname_r)
+
struct servent *
-getservbyname(name, proto)
+getservbyname_r(name, proto, se, buf, buflen)
const char *name, *proto;
+ struct servent *se;
+ char *buf;
+ int buflen;
{
register struct servent *p;
register char **cp;
+ _THREAD_PRIVATE_MUTEX_LOCK(getservbyname_r);
setservent(_serv_stayopen);
while ((p = getservent())) {
if (strcmp(name, p->s_name) == 0)
@@ -61,5 +68,20 @@ gotname:
}
if (!_serv_stayopen)
endservent();
+ _THREAD_PRIVATE_MUTEX_UNLOCK(getservbyname_r);
return (p);
}
+
+struct servent *getservbyname(name, proto)
+ const char *name, *proto;
+{
+ _THREAD_PRIVATE_KEY(getservbyname)
+ static char buf[4096];
+ char *bufp = (char*)_THREAD_PRIVATE(getservbyname, buf, NULL);
+
+ if (bufp == NULL)
+ return (NULL);
+ return getservbyname_r(name, proto, (struct servent*) bufp,
+ bufp + sizeof(struct servent),
+ sizeof buf - sizeof(struct servent) );
+}