X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fnetwork%2Fgethostbyaddr.c;h=598e2241a9f808e8ecafb72e24d7d6959cb49a28;hb=96315d27b0e5000d53e09fb915c5066b3d47d3d2;hp=51e1c5699856be573a3e45e288af2689772e07be;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/network/gethostbyaddr.c b/src/network/gethostbyaddr.c index 51e1c569..598e2241 100644 --- a/src/network/gethostbyaddr.c +++ b/src/network/gethostbyaddr.c @@ -1,15 +1,24 @@ #define _GNU_SOURCE #include -#include -#include +#include +#include struct hostent *gethostbyaddr(const void *a, socklen_t l, int af) { - static struct hostent h; - static long buf[512/sizeof(long)]; + static struct hostent *h; + size_t size = 63; struct hostent *res; - if (gethostbyaddr_r(a, l, af, &h, - (void *)buf, sizeof buf, &res, &h_errno)) return 0; - return &h; + int err; + do { + free(h); + h = malloc(size+=size+1); + if (!h) { + h_errno = NO_RECOVERY; + return 0; + } + err = gethostbyaddr_r(a, l, af, h, + (void *)(h+1), size-sizeof *h, &res, &h_errno); + } while (err == ERANGE); + return err ? 0 : h; }