X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fnetwork%2Fgethostbyaddr.c;fp=src%2Fnetwork%2Fgethostbyaddr.c;h=c9b6388a415b5c5aa78c449003cf8ce3519b84b6;hp=51e1c5699856be573a3e45e288af2689772e07be;hb=a47ad3ebce8e20a5d72535996a0d0d5458241213;hpb=c0193550a022cb75d1cddb0254e98029b3b56420 diff --git a/src/network/gethostbyaddr.c b/src/network/gethostbyaddr.c index 51e1c569..c9b6388a 100644 --- a/src/network/gethostbyaddr.c +++ b/src/network/gethostbyaddr.c @@ -3,13 +3,24 @@ #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; }