Blog
Linux "gethostbyname_r"
Date: 12/10/2007
Ever since v1.87-test21 the linux build of Scribe has used gethostbyname_r to resolve hosts before making a socket connection. This on the most part has worked, but on some machines it fails consistently. And like most weird errors it's very difficult to find a solution when the person experiencing the issue stops responding to your emails. Nevertheless eventually it happens to me and I get a crack at fixing the issue up close and personal. That was today.

I was valgrinding some code in Ubuntu and gethostbyname_r was returning non-zero, with an error code of -1. Which is basically what people have been reporting on and off for years. So I started hunting around on Google and I found this. The example shows how to increase the buffer size until the function returns success. I was passing in a fixed buffer of 256 bytes, and they start with a variable length buffer of 1024 bytes and double it if it fails... so I try tweaking it up to 1024 and magically it starts working. It is curious that the function needs an extra block of application allocated memory to function. You'd think that internally it could just use malloc/free for all it's own memory needs. Or even maybe return a valid error code via the "int *h_errnop" parameter instead of -1, like say ERANGE!

Glibc... what can I say?
 
Reply
From:
Email (optional): (Will be HTML encoded to evade harvesting)
Message:
 
Remember username and/or email in a cookie.
Notify me of new posts in this thread via email.
BBcode:
[q]text[/q]
[url=link]description[/url]
[img]url_to_image[/img]
[pre]some_code[/pre]
[b]bold_text[/b]