Merge pull request #1131 from SummerGGift/fix_bug_in_nfs_ipv6

[nfs] : fix bug in nfs when enable ipv6
This commit is contained in:
Bernard Xiong 2017-12-25 19:35:39 +08:00 committed by GitHub
commit 2289f6ac1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 38 deletions

View File

@ -41,38 +41,36 @@ static char sccsid[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";
* returns client handle. Default options are set, which the user can * returns client handle. Default options are set, which the user can
* change using the rpc equivalent of ioctl()'s. * change using the rpc equivalent of ioctl()'s.
*/ */
CLIENT *clnt_create (const char *hostname, const unsigned long prog, CLIENT *clnt_create(const char *hostname, const unsigned long prog,
const unsigned long vers, const char *proto) const unsigned long vers, const char *proto)
{ {
int sock; int sock;
struct hostent *h; struct sockaddr_in server;
struct sockaddr_in sin; struct addrinfo hint, *res = NULL;
struct timeval tv; struct timeval tv;
CLIENT *client; CLIENT *client;
int ret;
h = (struct hostent *)gethostbyname(hostname); memset(&hint, 0, sizeof(hint));
if (h == NULL) { ret = getaddrinfo(hostname, NULL, &hint, &res);
rt_kprintf("unknown host\n"); if (ret != 0)
return (NULL); {
rt_kprintf("getaddrinfo err: %d '%s'\n", ret, hostname);
return NULL;
} }
if (h->h_addrtype != AF_INET) {
rt_kprintf("unknow inet\n"); memcpy(&server, res->ai_addr, sizeof(struct sockaddr_in));
return (NULL); freeaddrinfo(res);
}
memset((char*)&sin,0,sizeof(sin));
sin.sin_family = h->h_addrtype;
sin.sin_port = 0;
memmove((char *) &sin.sin_addr, h->h_addr, h->h_length);
sock = -1; sock = -1;
if (strcmp(proto, "udp") == 0) if (strcmp(proto, "udp") == 0)
{ {
tv.tv_sec = 5; tv.tv_sec = 5;
tv.tv_usec = 0; tv.tv_usec = 0;
client = clntudp_create(&sin, prog, vers, tv, &sock); client = clntudp_create(&server, prog, vers, tv, &sock);
if (client == NULL) return NULL; if (client == NULL) return NULL;
tv.tv_sec = 1; tv.tv_sec = 1;
clnt_control(client, CLSET_TIMEOUT, (char*)&tv); clnt_control(client, CLSET_TIMEOUT, (char *)&tv);
} }
else else
{ {