From 6932f2282ba0578d6ca2f21eead920d6b78bc93c Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Sat, 2 Jan 2016 16:55:40 +0100 Subject: libc/inet: Unbreak gethostent() Although gethostent() is obsoleted, there is no reason to keep it broken. Fix two problems: * commit f65e66078b "resolver: switch to config parser" leave an extra break statement in case of GETHOSTENT in __read_etc_hosts_r. In result, output buffer wasn't initialized at all. * gethostent static buffer has insufficient size to store aliases, so __read_etc_hosts_r always returns ERANGE. Restore ALIAS_DIM define. Add test-case. Signed-off-by: Leonid Lisovskiy --- test/inet/gethost.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/inet/gethost.c (limited to 'test') diff --git a/test/inet/gethost.c b/test/inet/gethost.c new file mode 100644 index 000000000..77467e9e3 --- /dev/null +++ b/test/inet/gethost.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(void) +{ + in_addr_t addr = inet_addr("127.0.0.1"); + struct hostent *hent; + + hent = gethostent(); + if (hent == NULL) { + printf("gethostent(%d):%s\n", errno, hstrerror(h_errno)); + exit(1); + } + + hent = gethostbyname("localhost"); + if (hent == NULL) { + printf("gethostbyname(%d):%s\n", errno, hstrerror(h_errno)); + exit(1); + } + + hent = gethostbyname2("localhost", AF_INET); + if (hent == NULL) { + printf("gethostbyname2(%d):%s\n", errno, hstrerror(h_errno)); + exit(1); + } + + hent = gethostbyaddr(&addr, sizeof(addr), AF_INET); + if (hent == NULL) { + printf("gethostbyaddr(%d):%s\n", errno, hstrerror(h_errno)); + exit(1); + } + + return 0; +} + -- cgit v1.2.3