diff options
author | Stefan Metzmacher <metze@samba.org> | 2009-01-30 22:19:50 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2009-01-30 22:26:08 +0100 |
commit | 4519eae158e7821dcd2f818eea830cfcdd4a0105 (patch) | |
tree | 42d7859183a3c716be923b6e0fc19f854e022827 /source4/lib/socket/socket_ip.c | |
parent | 03bd9b2683ab7abf967118b5970f6a59c101782a (diff) | |
download | samba-4519eae158e7821dcd2f818eea830cfcdd4a0105.tar.gz samba-4519eae158e7821dcd2f818eea830cfcdd4a0105.tar.xz samba-4519eae158e7821dcd2f818eea830cfcdd4a0105.zip |
s4:lib/socket: don't use gethostbyname2()
metze
Diffstat (limited to 'source4/lib/socket/socket_ip.c')
-rw-r--r-- | source4/lib/socket/socket_ip.c | 33 |
1 files changed, 25 insertions, 8 deletions
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) |