From f88b7a076be74a29a3bf876b4e2705f4a1ecf42b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Oct 2007 14:16:54 -0700 Subject: This is a large patch (sorry). Migrate from struct in_addr to struct sockaddr_storage in most places that matter (ie. not the nmbd and NetBIOS lookups). This passes make test on an IPv4 box, but I'll have to do more work/testing on IPv6 enabled boxes. This should now give us a framework for testing and finishing the IPv6 migration. It's at the state where someone with a working IPv6 setup should (theorecically) be able to type : smbclient //ipv6-address/share and have it work. Jeremy. (This used to be commit 98e154c3125d5732c37a72d74b0eb5cd7b6155fd) --- source3/lib/util_str.c | 83 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 23 deletions(-) (limited to 'source3/lib/util_str.c') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 2fd22280a4..226bf826fb 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -2270,27 +2270,54 @@ bool str_list_substitute(char **list, const char *pattern, const char *insert) * reallocated to new length **/ -char *ipstr_list_add(char **ipstr_list, const struct ip_service *service) +static char *ipstr_list_add(char **ipstr_list, const struct ip_service *service) { char *new_ipstr = NULL; + char addr_buf[INET6_ADDRSTRLEN]; /* arguments checking */ - if (!ipstr_list || !service) return NULL; + if (!ipstr_list || !service) { + return NULL; + } /* attempt to convert ip to a string and append colon separator to it */ if (*ipstr_list) { - asprintf(&new_ipstr, "%s%s%s:%d", *ipstr_list, IPSTR_LIST_SEP, - inet_ntoa(service->ip), service->port); + print_sockaddr(addr_buf, + sizeof(addr_buf), + &service->ss); + if (service->ss.ss_family == AF_INET) { + /* IPv4 */ + asprintf(&new_ipstr, "%s%s%s:%d", + *ipstr_list, + IPSTR_LIST_SEP, + addr_buf, + service->port); + } else { + /* IPv6 */ + asprintf(&new_ipstr, "%s%s[%s]:%d", + *ipstr_list, + IPSTR_LIST_SEP, + addr_buf, + service->port); + } SAFE_FREE(*ipstr_list); } else { - asprintf(&new_ipstr, "%s:%d", - inet_ntoa(service->ip), service->port); + if (service->ss.ss_family == AF_INET) { + /* IPv4 */ + asprintf(&new_ipstr, "%s:%d", + addr_buf, + service->port); + } else { + /* IPv6 */ + asprintf(&new_ipstr, "[%s]:%d", + addr_buf, + service->port); + } } *ipstr_list = new_ipstr; return *ipstr_list; } - /** * Allocate and initialise an ipstr list using ip adresses * passed as arguments. @@ -2302,18 +2329,22 @@ char *ipstr_list_add(char **ipstr_list, const struct ip_service *service) **/ char *ipstr_list_make(char **ipstr_list, - const struct ip_service * ip_list, int ip_count) + const struct ip_service *ip_list, + int ip_count) { int i; /* arguments checking */ - if (!ip_list || !ipstr_list) return 0; + if (!ip_list || !ipstr_list) { + return 0; + } *ipstr_list = NULL; /* process ip addresses given as arguments */ - for (i = 0; i < ip_count; i++) + for (i = 0; i < ip_count; i++) { *ipstr_list = ipstr_list_add(ipstr_list, &ip_list[i]); + } return (*ipstr_list); } @@ -2322,7 +2353,7 @@ char *ipstr_list_make(char **ipstr_list, /** * Parse given ip string list into array of ip addresses * (as ip_service structures) - * e.g. 192.168.1.100:389,192.168.1.78, ... + * e.g. [IPv6]:port,192.168.1.100:389,192.168.1.78, ... * * @param ipstr ip string list to be parsed * @param ip_list pointer to array of ip addresses which is @@ -2330,7 +2361,7 @@ char *ipstr_list_make(char **ipstr_list, * @return number of succesfully parsed addresses **/ -int ipstr_list_parse(const char* ipstr_list, struct ip_service **ip_list) +int ipstr_list_parse(const char *ipstr_list, struct ip_service **ip_list) { fstring token_str; size_t count; @@ -2348,27 +2379,34 @@ int ipstr_list_parse(const char* ipstr_list, struct ip_service **ip_list) for ( i=0; next_token(&ipstr_list, token_str, IPSTR_LIST_SEP, FSTRING_LEN) && i