summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2009-01-30 22:19:50 +0100
committerStefan Metzmacher <metze@samba.org>2009-01-30 22:26:08 +0100
commit4519eae158e7821dcd2f818eea830cfcdd4a0105 (patch)
tree42d7859183a3c716be923b6e0fc19f854e022827
parent03bd9b2683ab7abf967118b5970f6a59c101782a (diff)
downloadsamba-4519eae158e7821dcd2f818eea830cfcdd4a0105.tar.gz
samba-4519eae158e7821dcd2f818eea830cfcdd4a0105.tar.bz2
samba-4519eae158e7821dcd2f818eea830cfcdd4a0105.zip
s4:lib/socket: don't use gethostbyname2()
metze
-rw-r--r--source4/lib/socket/config.m41
-rw-r--r--source4/lib/socket/socket_ip.c33
2 files changed, 25 insertions, 9 deletions
diff --git a/source4/lib/socket/config.m4 b/source4/lib/socket/config.m4
index 9c0072dd8b..fa987a1f46 100644
--- a/source4/lib/socket/config.m4
+++ b/source4/lib/socket/config.m4
@@ -1,6 +1,5 @@
AC_CHECK_FUNCS(writev)
AC_CHECK_FUNCS(readv)
-AC_CHECK_FUNCS(gethostbyname2)
############################################
# check for unix domain sockets
diff --git a/source4/lib/socket/socket_ip.c b/source4/lib/socket/socket_ip.c
index bca0aab924..cdb75fe021 100644
--- a/source4/lib/socket/socket_ip.c
+++ b/source4/lib/socket/socket_ip.c
@@ -549,19 +549,36 @@ _PUBLIC_ const struct socket_ops *socket_ipv4_ops(enum socket_type type)
static struct in6_addr interpret_addr6(const char *name)
{
- struct hostent *he;
-
- if (name == NULL) return in6addr_any;
+ char addr[INET6_ADDRSTRLEN];
+ struct in6_addr dest6;
+ const char *sp = name;
+ char *p = strchr_m(sp, '%');
+ int ret;
+
+ if (sp == NULL) return in6addr_any;
- if (strcasecmp(name, "localhost") == 0) {
- name = "::1";
+ if (strcasecmp(sp, "localhost") == 0) {
+ sp = "::1";
}
- he = gethostbyname2(name, PF_INET6);
+ /*
+ * Cope with link-local.
+ * This is IP:v6:addr%ifname.
+ */
+
+ if (p && (p > sp) && (if_nametoindex(p+1) != 0)) {
+ strlcpy(addr, sp,
+ MIN(PTR_DIFF(p,sp)+1,
+ sizeof(addr)));
+ sp = addr;
+ }
- if (he == NULL) return in6addr_any;
+ ret = inet_pton(AF_INET6, sp, &dest6);
+ if (ret > 0) {
+ return dest6;
+ }
- return *((struct in6_addr *)he->h_addr);
+ return in6addr_any;
}
static NTSTATUS ipv6_init(struct socket_context *sock)