diff --git a/source/client/mount.cifs.c b/source/client/mount.cifs.c index fdee87a..a44f455 100644 --- a/source/client/mount.cifs.c +++ b/source/client/mount.cifs.c @@ -479,7 +479,7 @@ static int parse_options(char ** optionsp, int * filesys_flags) } else if (strncmp(data, "ip", 2) == 0) { if (!value || !*value) { printf("target ip address argument missing"); - } else if (strnlen(value, 35) < 35) { + } else if (strnlen(value, INET6_ADDRSTRLEN) < INET6_ADDRSTRLEN) { if(verboseflag) printf("ip address %s override specified\n",value); got_ip = 1; @@ -861,6 +861,13 @@ static char * parse_server(char ** punc_name) char * ipaddress_string = NULL; struct hostent * host_entry = NULL; struct in_addr server_ipaddr; + int status; + struct addrinfo *ainfo, hints; + char host[1024]; + + hints.ai_family = AF_INET6; + hints.ai_socktype = 0; + hints.ai_flags = AI_V4MAPPED; if(length > (MAX_UNC_LEN - 1)) { printf("mount error: UNC name too long"); @@ -910,7 +917,7 @@ continue_unc_parsing: *share = 0; /* temporarily terminate the string */ share += 1; if(got_ip == 0) { - host_entry = gethostbyname(unc_name); + status = getaddrinfo(unc_name, NULL, &hints, &ainfo); } *(share - 1) = '/'; /* put delimiter back */ @@ -925,19 +932,31 @@ continue_unc_parsing: printf("ip address specified explicitly\n"); return NULL; } - if(host_entry == NULL) { + if(status) { printf("mount error: could not find target server. TCP name %s not found\n", unc_name); + printf("Error getaddrinfo: %s\n", gai_strerror(status)); + + freeaddrinfo(ainfo); + return NULL; } else { /* BB should we pass an alternate version of the share name as Unicode */ /* BB what about ipv6? BB */ /* BB add retries with alternate servers in list */ - memcpy(&server_ipaddr.s_addr, host_entry->h_addr, 4); + status = getnameinfo((struct sockaddr *)ainfo->ai_addr, + ainfo->ai_addrlen, + host, sizeof(host), + NULL, 0, + NI_NUMERICHOST); + + freeaddrinfo(ainfo); + + ipaddress_string = strdup(&host[0]); - ipaddress_string = inet_ntoa(server_ipaddr); - if(ipaddress_string == NULL) { + if(status) { printf("mount error: could not get valid ip address for target server\n"); + printf("Error getnameinfo: %s\n", gai_strerror(status)); return NULL; } return ipaddress_string; @@ -1316,6 +1335,7 @@ mount_retry: if(ipaddr) { strlcat(options,",ip=",options_size); strlcat(options,ipaddr,options_size); + free(ipaddr); } if(user_name) {