OLD | NEW |
1 #define _GNU_SOURCE | 1 #define _GNU_SOURCE |
2 | 2 |
3 #include <netdb.h> | 3 #include <netdb.h> |
4 #include <errno.h> | 4 #include <errno.h> |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 struct hostent *gethostbyaddr(const void *a, socklen_t l, int af) | 7 struct hostent* gethostbyaddr(const void* a, socklen_t l, int af) { |
8 { | 8 static struct hostent* h; |
9 » static struct hostent *h; | 9 size_t size = 63; |
10 » size_t size = 63; | 10 struct hostent* res; |
11 » struct hostent *res; | 11 int err; |
12 » int err; | 12 do { |
13 » do { | 13 free(h); |
14 » » free(h); | 14 h = malloc(size += size + 1); |
15 » » h = malloc(size+=size+1); | 15 if (!h) { |
16 » » if (!h) { | 16 h_errno = NO_RECOVERY; |
17 » » » h_errno = NO_RECOVERY; | 17 return 0; |
18 » » » return 0; | 18 } |
19 » » } | 19 err = gethostbyaddr_r(a, l, af, h, (void*)(h + 1), size - sizeof *h, &res, |
20 » » err = gethostbyaddr_r(a, l, af, h, | 20 &h_errno); |
21 » » » (void *)(h+1), size-sizeof *h, &res, &h_errno); | 21 } while (err == ERANGE); |
22 » } while (err == ERANGE); | 22 return err ? 0 : h; |
23 » return err ? 0 : h; | |
24 } | 23 } |
OLD | NEW |