summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-01 09:41:41 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-01 09:41:41 +0000
commit3b1b9d4638f0b92c161453f2896355183296803f (patch)
tree0f535b97adc6188d643959e2fbea7c9d7b39b12d
parent62de00801c704ef1f2711a385c2260ffaed6add6 (diff)
gethostbyname can use gethostbyname2, saving one nearly 0.5k static buffer
text data bss dec hex filename - 45 0 480 525 20d libc/inet/gethostbyname.o + 18 0 0 18 12 libc/inet/gethostbyname.o
-rw-r--r--include/netdb.h1
-rw-r--r--libc/inet/resolv.c35
2 files changed, 21 insertions, 15 deletions
diff --git a/include/netdb.h b/include/netdb.h
index 99ba243f5..7d76b9c26 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -159,6 +159,7 @@ libc_hidden_proto(gethostbyname)
or due to the implementation it is a cancellation point and
therefore not marked with __THROW. */
extern struct hostent *gethostbyname2 (__const char *__name, int __af);
+libc_hidden_proto(gethostbyname2)
/* Reentrant versions of the functions above. The additional
arguments specify a buffer of BUFLEN starting at BUF. The last
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index d421aae4b..08246e85f 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -2052,10 +2052,10 @@ int gethostbyname2_r(const char *name,
if (family == AF_INET)
return gethostbyname_r(name, result_buf, buf, buflen, result, h_errnop);
+ *result = NULL;
if (family != AF_INET6)
return EINVAL;
- *result = NULL;
if (!name)
return EINVAL;
@@ -2064,7 +2064,7 @@ int gethostbyname2_r(const char *name,
int old_errno = errno; /* Save the old errno and reset errno */
__set_errno(0); /* to check for missing /etc/hosts. */
- i = __get_hosts_byname_r(name, family, result_buf,
+ i = __get_hosts_byname_r(name, AF_INET6 /*family*/, result_buf,
buf, buflen, result, h_errnop);
if (i == NETDB_SUCCESS) {
__set_errno(old_errno);
@@ -2431,40 +2431,45 @@ struct hostent *gethostent(void)
#endif
-#ifdef L_gethostbyname
+#ifdef L_gethostbyname2
-struct hostent *gethostbyname(const char *name)
+struct hostent *gethostbyname2(const char *name, int family)
{
+#ifndef __UCLIBC_HAS_IPV6__
+ return family == AF_INET ? gethostbyname(name) : (struct hostent*)NULL;
+#else
static struct hostent h;
- static char buf[sizeof(struct in_addr) +
- sizeof(struct in_addr *) * 2 +
+ static char buf[sizeof(struct in6_addr) +
+ sizeof(struct in6_addr *) * 2 +
sizeof(char *)*ALIAS_DIM + 384/*namebuffer*/ + 32/* margin */];
struct hostent *hp;
- gethostbyname_r(name, &h, buf, sizeof(buf), &hp, &h_errno);
+ gethostbyname2_r(name, family, &h, buf, sizeof(buf), &hp, &h_errno);
return hp;
+#endif
}
-libc_hidden_def(gethostbyname)
+libc_hidden_def(gethostbyname2)
#endif
-#ifdef L_gethostbyname2
+#ifdef L_gethostbyname
-struct hostent *gethostbyname2(const char *name, int family)
+struct hostent *gethostbyname(const char *name)
{
#ifndef __UCLIBC_HAS_IPV6__
- return family == AF_INET ? gethostbyname(name) : (struct hostent*)NULL;
-#else
static struct hostent h;
- static char buf[sizeof(struct in6_addr) +
- sizeof(struct in6_addr *) * 2 +
+ static char buf[sizeof(struct in_addr) +
+ sizeof(struct in_addr *) * 2 +
sizeof(char *)*ALIAS_DIM + 384/*namebuffer*/ + 32/* margin */];
struct hostent *hp;
- gethostbyname2_r(name, family, &h, buf, sizeof(buf), &hp, &h_errno);
+ gethostbyname_r(name, &h, buf, sizeof(buf), &hp, &h_errno);
return hp;
+#else
+ return gethostbyname2(name, AF_INET);
#endif
}
+libc_hidden_def(gethostbyname)
#endif