diff options
| author | marc <> | 2003-01-28 04:58:00 +0000 |
|---|---|---|
| committer | marc <> | 2003-01-28 04:58:00 +0000 |
| commit | 547ebab319b228b064cf5dcb3ff0ae1bf23d24a2 (patch) | |
| tree | f57454716593fb3b68672505c6dccab6438498f1 /src/lib/libc/net/getnetnamadr.c | |
| parent | 98a78d57b176408b5aca87705f9681c5b155b47c (diff) | |
| download | openbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.tar.gz openbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.tar.bz2 openbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.zip | |
thread safer libc (note: safer, not safe)
Access to the global _res structure replaced by pointers to a
per thread instance. If unthreaded the pointer is to the
global structure.
Also replaced a 64k stack array with malloc-ed memory so
threaded aps (with a default 64k stack) have a chance at working.
ok deraadt@
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/net/getnetnamadr.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/lib/libc/net/getnetnamadr.c b/src/lib/libc/net/getnetnamadr.c index f183fbe3fe..75a75243ef 100644 --- a/src/lib/libc/net/getnetnamadr.c +++ b/src/lib/libc/net/getnetnamadr.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: getnetnamadr.c,v 1.19 2002/11/14 02:48:00 millert Exp $ */ | 1 | /* $OpenBSD: getnetnamadr.c,v 1.20 2003/01/28 04:58:00 marc Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1997, Jason Downs. All rights reserved. | 4 | * Copyright (c) 1997, Jason Downs. All rights reserved. |
| @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; | |||
| 77 | static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; | 77 | static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; |
| 78 | static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; | 78 | static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; |
| 79 | #else | 79 | #else |
| 80 | static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.19 2002/11/14 02:48:00 millert Exp $"; | 80 | static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.20 2003/01/28 04:58:00 marc Exp $"; |
| 81 | #endif | 81 | #endif |
| 82 | #endif /* LIBC_SCCS and not lint */ | 82 | #endif /* LIBC_SCCS and not lint */ |
| 83 | 83 | ||
| @@ -96,6 +96,8 @@ static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.19 2002/11/14 02:48:00 mille | |||
| 96 | #include <string.h> | 96 | #include <string.h> |
| 97 | #include <stdlib.h> | 97 | #include <stdlib.h> |
| 98 | 98 | ||
| 99 | #include "thread_private.h" | ||
| 100 | |||
| 99 | extern int h_errno; | 101 | extern int h_errno; |
| 100 | 102 | ||
| 101 | struct netent *_getnetbyaddr(in_addr_t net, int type); | 103 | struct netent *_getnetbyaddr(in_addr_t net, int type); |
| @@ -262,6 +264,7 @@ getnetbyaddr(net, net_type) | |||
| 262 | register in_addr_t net; | 264 | register in_addr_t net; |
| 263 | register int net_type; | 265 | register int net_type; |
| 264 | { | 266 | { |
| 267 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 265 | unsigned int netbr[4]; | 268 | unsigned int netbr[4]; |
| 266 | int nn, anslen; | 269 | int nn, anslen; |
| 267 | querybuf *buf; | 270 | querybuf *buf; |
| @@ -271,10 +274,10 @@ getnetbyaddr(net, net_type) | |||
| 271 | char lookups[MAXDNSLUS]; | 274 | char lookups[MAXDNSLUS]; |
| 272 | int i; | 275 | int i; |
| 273 | 276 | ||
| 274 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 277 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) |
| 275 | return(_getnetbyaddr(net, net_type)); | 278 | return(_getnetbyaddr(net, net_type)); |
| 276 | 279 | ||
| 277 | bcopy(_res.lookups, lookups, sizeof lookups); | 280 | bcopy(_resp->lookups, lookups, sizeof lookups); |
| 278 | if (lookups[0] == '\0') | 281 | if (lookups[0] == '\0') |
| 279 | strlcpy(lookups, "bf", sizeof lookups); | 282 | strlcpy(lookups, "bf", sizeof lookups); |
| 280 | 283 | ||
| @@ -320,7 +323,7 @@ getnetbyaddr(net, net_type) | |||
| 320 | if (anslen < 0) { | 323 | if (anslen < 0) { |
| 321 | free(buf); | 324 | free(buf); |
| 322 | #ifdef DEBUG | 325 | #ifdef DEBUG |
| 323 | if (_res.options & RES_DEBUG) | 326 | if (_resp->options & RES_DEBUG) |
| 324 | printf("res_query failed\n"); | 327 | printf("res_query failed\n"); |
| 325 | #endif | 328 | #endif |
| 326 | break; | 329 | break; |
| @@ -352,6 +355,7 @@ struct netent * | |||
| 352 | getnetbyname(net) | 355 | getnetbyname(net) |
| 353 | register const char *net; | 356 | register const char *net; |
| 354 | { | 357 | { |
| 358 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | ||
| 355 | int anslen; | 359 | int anslen; |
| 356 | querybuf *buf; | 360 | querybuf *buf; |
| 357 | char qbuf[MAXDNAME]; | 361 | char qbuf[MAXDNAME]; |
| @@ -359,10 +363,10 @@ getnetbyname(net) | |||
| 359 | char lookups[MAXDNSLUS]; | 363 | char lookups[MAXDNSLUS]; |
| 360 | int i; | 364 | int i; |
| 361 | 365 | ||
| 362 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) | 366 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) |
| 363 | return (_getnetbyname(net)); | 367 | return (_getnetbyname(net)); |
| 364 | 368 | ||
| 365 | bcopy(_res.lookups, lookups, sizeof lookups); | 369 | bcopy(_resp->lookups, lookups, sizeof lookups); |
| 366 | if (lookups[0] == '\0') | 370 | if (lookups[0] == '\0') |
| 367 | strlcpy(lookups, "bf", sizeof lookups); | 371 | strlcpy(lookups, "bf", sizeof lookups); |
| 368 | 372 | ||
| @@ -383,7 +387,7 @@ getnetbyname(net) | |||
| 383 | if (anslen < 0) { | 387 | if (anslen < 0) { |
| 384 | free(buf); | 388 | free(buf); |
| 385 | #ifdef DEBUG | 389 | #ifdef DEBUG |
| 386 | if (_res.options & RES_DEBUG) | 390 | if (_resp->options & RES_DEBUG) |
| 387 | printf("res_query failed\n"); | 391 | printf("res_query failed\n"); |
| 388 | #endif | 392 | #endif |
| 389 | break; | 393 | break; |
