Blame SOURCES/autofs-5.0.7-use-numeric-protocol-ids-instead-of-protoent-structs.patch

ab3a3d
autofs-5.0.7 - use numeric protocol ids instead of protoent structs
ab3a3d
ab3a3d
From: Leonardo Chiquitto <leonardo.lists@gmail.com>
ab3a3d
ab3a3d
The function getprotobyname() is not reentrant, so we can't call
ab3a3d
it simultaneously from multiple threads. Instead of switching to
ab3a3d
the reentrant version which adds more complexity to the code,
ab3a3d
lets use numeric protocol IDs instead of protoent structures.
ab3a3d
---
ab3a3d
ab3a3d
 CHANGELOG            |    1 +
ab3a3d
 include/rpc_subs.h   |    4 +--
ab3a3d
 lib/rpc_subs.c       |   80 ++++++++++++++++++--------------------------------
ab3a3d
 modules/replicated.c |   42 +++++++++++---------------
ab3a3d
 4 files changed, 50 insertions(+), 77 deletions(-)
ab3a3d
ab3a3d
ab3a3d
diff --git a/CHANGELOG b/CHANGELOG
ab3a3d
index 4cf5621..ba1d65b 100644
ab3a3d
--- a/CHANGELOG
ab3a3d
+++ b/CHANGELOG
ab3a3d
@@ -23,6 +23,7 @@
ab3a3d
 - fix use get_proximity() without libtirpc.
ab3a3d
 - don't use dirent d_type to filter out files in scandir()
ab3a3d
 - don't schedule new alarms after readmap.
ab3a3d
+- use numeric protocol ids instead of protoent structs.
ab3a3d
 
ab3a3d
 25/07/2012 autofs-5.0.7
ab3a3d
 =======================
ab3a3d
diff --git a/include/rpc_subs.h b/include/rpc_subs.h
ab3a3d
index ca474d9..b6d59f9 100644
ab3a3d
--- a/include/rpc_subs.h
ab3a3d
+++ b/include/rpc_subs.h
ab3a3d
@@ -54,7 +54,7 @@ struct conn_info {
ab3a3d
 	unsigned short port;
ab3a3d
 	unsigned long program;
ab3a3d
 	unsigned long version;
ab3a3d
-	struct protoent *proto;
ab3a3d
+	int proto;
ab3a3d
 	unsigned int send_sz;
ab3a3d
 	unsigned int recv_sz;
ab3a3d
 	struct timeval timeout;
ab3a3d
@@ -66,7 +66,7 @@ int rpc_udp_getclient(struct conn_info *, unsigned int, unsigned int);
ab3a3d
 void rpc_destroy_udp_client(struct conn_info *);
ab3a3d
 int rpc_tcp_getclient(struct conn_info *, unsigned int, unsigned int);
ab3a3d
 void rpc_destroy_tcp_client(struct conn_info *);
ab3a3d
-int rpc_portmap_getclient(struct conn_info *, const char *, struct sockaddr *, size_t, const char *, unsigned int);
ab3a3d
+int rpc_portmap_getclient(struct conn_info *, const char *, struct sockaddr *, size_t, int, unsigned int);
ab3a3d
 int rpc_portmap_getport(struct conn_info *, struct pmap *, unsigned short *);
ab3a3d
 int rpc_ping_proto(struct conn_info *);
ab3a3d
 int rpc_ping(const char *, long, long, unsigned int);
ab3a3d
diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c
ab3a3d
index d33a3c4..ad1d557 100644
ab3a3d
--- a/lib/rpc_subs.c
ab3a3d
+++ b/lib/rpc_subs.c
ab3a3d
@@ -170,7 +170,7 @@ static int rpc_do_create_client(struct sockaddr *addr, struct conn_info *info, i
ab3a3d
 
ab3a3d
 	*client = NULL;
ab3a3d
 
ab3a3d
-	proto = info->proto->p_proto;
ab3a3d
+	proto = info->proto;
ab3a3d
 	if (proto == IPPROTO_UDP)
ab3a3d
 		type = SOCK_DGRAM;
ab3a3d
 	else
ab3a3d
@@ -201,7 +201,7 @@ static int rpc_do_create_client(struct sockaddr *addr, struct conn_info *info, i
ab3a3d
 	in4_raddr = (struct sockaddr_in *) addr;
ab3a3d
 	in4_raddr->sin_port = htons(info->port);
ab3a3d
 
ab3a3d
-	switch (info->proto->p_proto) {
ab3a3d
+	switch (info->proto) {
ab3a3d
 	case IPPROTO_UDP:
ab3a3d
 		clnt = clntudp_bufcreate(in4_raddr,
ab3a3d
 					 info->program, info->version,
ab3a3d
@@ -241,7 +241,7 @@ static int rpc_do_create_client(struct sockaddr *addr, struct conn_info *info, i
ab3a3d
 
ab3a3d
 	*client = NULL;
ab3a3d
 
ab3a3d
-	proto = info->proto->p_proto;
ab3a3d
+	proto = info->proto;
ab3a3d
 	if (proto == IPPROTO_UDP)
ab3a3d
 		type = SOCK_DGRAM;
ab3a3d
 	else
ab3a3d
@@ -292,11 +292,11 @@ static int rpc_do_create_client(struct sockaddr *addr, struct conn_info *info, i
ab3a3d
 	nb_addr.maxlen = nb_addr.len = slen;
ab3a3d
 	nb_addr.buf = addr;
ab3a3d
 
ab3a3d
-	if (info->proto->p_proto == IPPROTO_UDP)
ab3a3d
+	if (info->proto == IPPROTO_UDP)
ab3a3d
 		clnt = clnt_dg_create(*fd, &nb_addr,
ab3a3d
 				      info->program, info->version,
ab3a3d
 				      info->send_sz, info->recv_sz);
ab3a3d
-	else if (info->proto->p_proto == IPPROTO_TCP) {
ab3a3d
+	else if (info->proto == IPPROTO_TCP) {
ab3a3d
 		ret = connect_nb(*fd, addr, slen, &info->timeout);
ab3a3d
 		if (ret < 0)
ab3a3d
 			return ret;
ab3a3d
@@ -355,7 +355,7 @@ static int create_client(struct conn_info *info, CLIENT **client)
ab3a3d
 	memset(&hints, 0, sizeof(hints));
ab3a3d
 	hints.ai_flags = AI_ADDRCONFIG;
ab3a3d
 	hints.ai_family = AF_UNSPEC;
ab3a3d
-	if (info->proto->p_proto == IPPROTO_UDP)
ab3a3d
+	if (info->proto == IPPROTO_UDP)
ab3a3d
 		hints.ai_socktype = SOCK_DGRAM;
ab3a3d
 	else
ab3a3d
 		hints.ai_socktype = SOCK_STREAM;
ab3a3d
@@ -370,7 +370,7 @@ static int create_client(struct conn_info *info, CLIENT **client)
ab3a3d
 
ab3a3d
 	haddr = ai;
ab3a3d
 	while (haddr) {
ab3a3d
-		if (haddr->ai_protocol != info->proto->p_proto) {
ab3a3d
+		if (haddr->ai_protocol != info->proto) {
ab3a3d
 			haddr = haddr->ai_next;
ab3a3d
 			continue;
ab3a3d
 		}
ab3a3d
@@ -417,16 +417,11 @@ out_close:
ab3a3d
 int rpc_udp_getclient(struct conn_info *info,
ab3a3d
 		      unsigned int program, unsigned int version)
ab3a3d
 {
ab3a3d
-	struct protoent *pe_proto;
ab3a3d
 	CLIENT *client;
ab3a3d
 	int ret;
ab3a3d
 
ab3a3d
 	if (!info->client) {
ab3a3d
-		pe_proto = getprotobyname("udp");
ab3a3d
-		if (!pe_proto)
ab3a3d
-			return -ENOENT;
ab3a3d
-
ab3a3d
-		info->proto = pe_proto;
ab3a3d
+		info->proto = IPPROTO_UDP;
ab3a3d
 		info->timeout.tv_sec = RPC_TOUT_UDP;
ab3a3d
 		info->timeout.tv_usec = 0;
ab3a3d
 		info->send_sz = UDPMSGSIZE;
ab3a3d
@@ -458,16 +453,11 @@ void rpc_destroy_udp_client(struct conn_info *info)
ab3a3d
 int rpc_tcp_getclient(struct conn_info *info,
ab3a3d
 		      unsigned int program, unsigned int version)
ab3a3d
 {
ab3a3d
-	struct protoent *pe_proto;
ab3a3d
 	CLIENT *client;
ab3a3d
 	int ret;
ab3a3d
 
ab3a3d
 	if (!info->client) {
ab3a3d
-		pe_proto = getprotobyname("tcp");
ab3a3d
-		if (!pe_proto)
ab3a3d
-			return -ENOENT;
ab3a3d
-
ab3a3d
-		info->proto = pe_proto;
ab3a3d
+		info->proto = IPPROTO_TCP;
ab3a3d
 		info->timeout.tv_sec = RPC_TOUT_TCP;
ab3a3d
 		info->timeout.tv_usec = 0;
ab3a3d
 		info->send_sz = 0;
ab3a3d
@@ -513,23 +503,18 @@ void rpc_destroy_tcp_client(struct conn_info *info)
ab3a3d
 
ab3a3d
 int rpc_portmap_getclient(struct conn_info *info,
ab3a3d
 			  const char *host, struct sockaddr *addr, size_t addr_len,
ab3a3d
-			  const char *proto, unsigned int option)
ab3a3d
+			  int proto, unsigned int option)
ab3a3d
 {
ab3a3d
-	struct protoent *pe_proto;
ab3a3d
 	CLIENT *client;
ab3a3d
 	int ret;
ab3a3d
 
ab3a3d
-	pe_proto = getprotobyname(proto);
ab3a3d
-	if (!pe_proto)
ab3a3d
-		return -ENOENT;
ab3a3d
-
ab3a3d
 	info->host = host;
ab3a3d
 	info->addr = addr;
ab3a3d
 	info->addr_len = addr_len;
ab3a3d
 	info->program = PMAPPROG;
ab3a3d
 	info->port = PMAPPORT;
ab3a3d
 	info->version = PMAPVERS;
ab3a3d
-	info->proto = pe_proto;
ab3a3d
+	info->proto = proto;
ab3a3d
 	info->send_sz = RPCSMALLMSGSIZE;
ab3a3d
 	info->recv_sz = RPCSMALLMSGSIZE;
ab3a3d
 	info->timeout.tv_sec = PMAP_TOUT_UDP;
ab3a3d
@@ -537,7 +522,7 @@ int rpc_portmap_getclient(struct conn_info *info,
ab3a3d
 	info->close_option = option;
ab3a3d
 	info->client = NULL;
ab3a3d
 
ab3a3d
-	if (pe_proto->p_proto == IPPROTO_TCP)
ab3a3d
+	if (info->proto == IPPROTO_TCP)
ab3a3d
 		info->timeout.tv_sec = PMAP_TOUT_TCP;
ab3a3d
 
ab3a3d
 	ret = create_client(info, &client);
ab3a3d
@@ -555,7 +540,7 @@ int rpc_portmap_getport(struct conn_info *info,
ab3a3d
 	struct conn_info pmap_info;
ab3a3d
 	CLIENT *client;
ab3a3d
 	enum clnt_stat status;
ab3a3d
-	int proto = info->proto->p_proto;
ab3a3d
+	int proto = info->proto;
ab3a3d
 	int ret;
ab3a3d
 
ab3a3d
 	memset(&pmap_info, 0, sizeof(struct conn_info));
ab3a3d
@@ -633,13 +618,13 @@ int rpc_ping_proto(struct conn_info *info)
ab3a3d
 {
ab3a3d
 	CLIENT *client;
ab3a3d
 	enum clnt_stat status;
ab3a3d
-	int proto = info->proto->p_proto;
ab3a3d
+	int proto = info->proto;
ab3a3d
 	int ret;
ab3a3d
 
ab3a3d
 	if (info->client)
ab3a3d
 		client = info->client;
ab3a3d
 	else {
ab3a3d
-		if (info->proto->p_proto == IPPROTO_UDP) {
ab3a3d
+		if (info->proto == IPPROTO_UDP) {
ab3a3d
 			info->send_sz = UDPMSGSIZE;
ab3a3d
 			info->recv_sz = UDPMSGSIZE;
ab3a3d
 		}
ab3a3d
@@ -688,7 +673,7 @@ int rpc_ping_proto(struct conn_info *info)
ab3a3d
 
ab3a3d
 static unsigned int __rpc_ping(const char *host,
ab3a3d
 				unsigned long version,
ab3a3d
-				char *proto,
ab3a3d
+				int proto,
ab3a3d
 				long seconds, long micros,
ab3a3d
 				unsigned int option)
ab3a3d
 {
ab3a3d
@@ -696,6 +681,7 @@ static unsigned int __rpc_ping(const char *host,
ab3a3d
 	struct conn_info info;
ab3a3d
 	struct pmap parms;
ab3a3d
 
ab3a3d
+	info.proto = proto;
ab3a3d
 	info.host = host;
ab3a3d
 	info.addr = NULL;
ab3a3d
 	info.addr_len = 0;
ab3a3d
@@ -710,13 +696,9 @@ static unsigned int __rpc_ping(const char *host,
ab3a3d
 
ab3a3d
 	status = RPC_PING_FAIL;
ab3a3d
 
ab3a3d
-	info.proto = getprotobyname(proto);
ab3a3d
-	if (!info.proto)
ab3a3d
-		return status;
ab3a3d
-
ab3a3d
 	parms.pm_prog = NFS_PROGRAM;
ab3a3d
 	parms.pm_vers = version;
ab3a3d
-	parms.pm_prot = info.proto->p_proto;
ab3a3d
+	parms.pm_prot = info.proto;
ab3a3d
 	parms.pm_port = 0;
ab3a3d
 
ab3a3d
 	status = rpc_portmap_getport(&info, &parms, &info.port);
ab3a3d
@@ -734,19 +716,19 @@ int rpc_ping(const char *host, long seconds, long micros, unsigned int option)
ab3a3d
 	unsigned long vers2 = NFS2_VERSION;
ab3a3d
 	unsigned int status;
ab3a3d
 
ab3a3d
-	status = __rpc_ping(host, vers2, "udp", seconds, micros, option);
ab3a3d
+	status = __rpc_ping(host, vers2, IPPROTO_UDP, seconds, micros, option);
ab3a3d
 	if (status > 0)
ab3a3d
 		return RPC_PING_V2 | RPC_PING_UDP;
ab3a3d
 
ab3a3d
-	status = __rpc_ping(host, vers3, "udp", seconds, micros, option);
ab3a3d
+	status = __rpc_ping(host, vers3, IPPROTO_UDP, seconds, micros, option);
ab3a3d
 	if (status > 0)
ab3a3d
 		return RPC_PING_V3 | RPC_PING_UDP;
ab3a3d
 
ab3a3d
-	status = __rpc_ping(host, vers2, "tcp", seconds, micros, option);
ab3a3d
+	status = __rpc_ping(host, vers2, IPPROTO_TCP, seconds, micros, option);
ab3a3d
 	if (status > 0)
ab3a3d
 		return RPC_PING_V2 | RPC_PING_TCP;
ab3a3d
 
ab3a3d
-	status = __rpc_ping(host, vers3, "tcp", seconds, micros, option);
ab3a3d
+	status = __rpc_ping(host, vers3, IPPROTO_TCP, seconds, micros, option);
ab3a3d
 	if (status > 0)
ab3a3d
 		return RPC_PING_V3 | RPC_PING_TCP;
ab3a3d
 
ab3a3d
@@ -769,7 +751,7 @@ int rpc_time(const char *host,
ab3a3d
 	double taken;
ab3a3d
 	struct timeval start, end;
ab3a3d
 	struct timezone tz;
ab3a3d
-	char *proto = (ping_proto & RPC_PING_UDP) ? "udp" : "tcp";
ab3a3d
+	int proto = (ping_proto & RPC_PING_UDP) ? IPPROTO_UDP : IPPROTO_TCP;
ab3a3d
 	unsigned long vers = ping_vers;
ab3a3d
 
ab3a3d
 	gettimeofday(&start, &tz;;
ab3a3d
@@ -791,12 +773,12 @@ static int rpc_get_exports_proto(struct conn_info *info, exports *exp)
ab3a3d
 {
ab3a3d
 	CLIENT *client;
ab3a3d
 	enum clnt_stat status;
ab3a3d
-	int proto = info->proto->p_proto;
ab3a3d
+	int proto = info->proto;
ab3a3d
 	unsigned int option = info->close_option;
ab3a3d
 	int vers_entry;
ab3a3d
 	int ret;
ab3a3d
 
ab3a3d
-	if (info->proto->p_proto == IPPROTO_UDP) {
ab3a3d
+	if (info->proto == IPPROTO_UDP) {
ab3a3d
 		info->send_sz = UDPMSGSIZE;
ab3a3d
 		info->recv_sz = UDPMSGSIZE;
ab3a3d
 	}
ab3a3d
@@ -903,11 +885,9 @@ exports rpc_get_exports(const char *host, long seconds, long micros, unsigned in
ab3a3d
 	parms.pm_port = 0;
ab3a3d
 
ab3a3d
 	/* Try UDP first */
ab3a3d
-	info.proto = getprotobyname("udp");
ab3a3d
-	if (!info.proto)
ab3a3d
-		goto try_tcp;
ab3a3d
+	info.proto = IPPROTO_UDP;
ab3a3d
 
ab3a3d
-	parms.pm_prot = info.proto->p_proto;
ab3a3d
+	parms.pm_prot = info.proto;
ab3a3d
 
ab3a3d
 	status = rpc_portmap_getport(&info, &parms, &info.port);
ab3a3d
 	if (status < 0)
ab3a3d
@@ -920,11 +900,9 @@ exports rpc_get_exports(const char *host, long seconds, long micros, unsigned in
ab3a3d
 		return exportlist;
ab3a3d
 
ab3a3d
 try_tcp:
ab3a3d
-	info.proto = getprotobyname("tcp");
ab3a3d
-	if (!info.proto)
ab3a3d
-		return NULL;
ab3a3d
+	info.proto = IPPROTO_TCP;
ab3a3d
 
ab3a3d
-	parms.pm_prot = info.proto->p_proto;
ab3a3d
+	parms.pm_prot = info.proto;
ab3a3d
 
ab3a3d
 	status = rpc_portmap_getport(&info, &parms, &info.port);
ab3a3d
 	if (status < 0)
ab3a3d
diff --git a/modules/replicated.c b/modules/replicated.c
ab3a3d
index 6b96320..dbd5513 100644
ab3a3d
--- a/modules/replicated.c
ab3a3d
+++ b/modules/replicated.c
ab3a3d
@@ -419,7 +419,7 @@ void free_host_list(struct host **list)
ab3a3d
 
ab3a3d
 static unsigned int get_nfs_info(unsigned logopt, struct host *host,
ab3a3d
 			 struct conn_info *pm_info, struct conn_info *rpc_info,
ab3a3d
-			 const char *proto, unsigned int version, int port)
ab3a3d
+			 int proto, unsigned int version, int port)
ab3a3d
 {
ab3a3d
 	unsigned int random_selection = host->options & MOUNT_FLAG_RANDOM_SELECT;
ab3a3d
 	unsigned int use_weight_only = host->options & MOUNT_FLAG_USE_WEIGHT_ONLY;
ab3a3d
@@ -433,22 +433,18 @@ static unsigned int get_nfs_info(unsigned logopt, struct host *host,
ab3a3d
 	int status, count = 0;
ab3a3d
 
ab3a3d
 	if (host->addr)
ab3a3d
-		debug(logopt, "called with host %s(%s) proto %s version 0x%x",
ab3a3d
+		debug(logopt, "called with host %s(%s) proto %d version 0x%x",
ab3a3d
 		      host->name, get_addr_string(host->addr, buf, len),
ab3a3d
 		      proto, version);
ab3a3d
 	else
ab3a3d
 		debug(logopt,
ab3a3d
-		      "called for host %s proto %s version 0x%x",
ab3a3d
+		      "called for host %s proto %d version 0x%x",
ab3a3d
 		      host->name, proto, version);
ab3a3d
 
ab3a3d
-	rpc_info->proto = getprotobyname(proto);
ab3a3d
-	if (!rpc_info->proto)
ab3a3d
-		return 0;
ab3a3d
-
ab3a3d
+	rpc_info->proto = proto;
ab3a3d
 	memset(&parms, 0, sizeof(struct pmap));
ab3a3d
-
ab3a3d
 	parms.pm_prog = NFS_PROGRAM;
ab3a3d
-	parms.pm_prot = rpc_info->proto->p_proto;
ab3a3d
+	parms.pm_prot = proto;
ab3a3d
 
ab3a3d
 	if (!(version & NFS4_REQUESTED))
ab3a3d
 		goto v3_ver;
ab3a3d
@@ -479,7 +475,7 @@ static unsigned int get_nfs_info(unsigned logopt, struct host *host,
ab3a3d
 		}
ab3a3d
 	}
ab3a3d
 
ab3a3d
-	if (rpc_info->proto->p_proto == IPPROTO_UDP)
ab3a3d
+	if (rpc_info->proto == IPPROTO_UDP)
ab3a3d
 		status = rpc_udp_getclient(rpc_info, NFS_PROGRAM, NFS4_VERSION);
ab3a3d
 	else
ab3a3d
 		status = rpc_tcp_getclient(rpc_info, NFS_PROGRAM, NFS4_VERSION);
ab3a3d
@@ -540,7 +536,7 @@ v3_ver:
ab3a3d
 			goto v2_ver;
ab3a3d
 	}
ab3a3d
 
ab3a3d
-	if (rpc_info->proto->p_proto == IPPROTO_UDP)
ab3a3d
+	if (rpc_info->proto == IPPROTO_UDP)
ab3a3d
 		status = rpc_udp_getclient(rpc_info, NFS_PROGRAM, NFS3_VERSION);
ab3a3d
 	else
ab3a3d
 		status = rpc_tcp_getclient(rpc_info, NFS_PROGRAM, NFS3_VERSION);
ab3a3d
@@ -587,7 +583,7 @@ v2_ver:
ab3a3d
 			goto done_ver;
ab3a3d
 	}
ab3a3d
 
ab3a3d
-	if (rpc_info->proto->p_proto == IPPROTO_UDP)
ab3a3d
+	if (rpc_info->proto == IPPROTO_UDP)
ab3a3d
 		status = rpc_udp_getclient(rpc_info, NFS_PROGRAM, NFS2_VERSION);
ab3a3d
 	else
ab3a3d
 		status = rpc_tcp_getclient(rpc_info, NFS_PROGRAM, NFS2_VERSION);
ab3a3d
@@ -618,7 +614,7 @@ v2_ver:
ab3a3d
 	}
ab3a3d
 
ab3a3d
 done_ver:
ab3a3d
-	if (rpc_info->proto->p_proto == IPPROTO_UDP) {
ab3a3d
+	if (rpc_info->proto == IPPROTO_UDP) {
ab3a3d
 		rpc_destroy_udp_client(rpc_info);
ab3a3d
 		rpc_destroy_udp_client(pm_info);
ab3a3d
 	} else {
ab3a3d
@@ -675,7 +671,7 @@ static int get_vers_and_cost(unsigned logopt, struct host *host,
ab3a3d
 
ab3a3d
 	if (version & TCP_REQUESTED) {
ab3a3d
 		supported = get_nfs_info(logopt, host,
ab3a3d
-				   &pm_info, &rpc_info, "tcp", vers, port);
ab3a3d
+				   &pm_info, &rpc_info, IPPROTO_TCP, vers, port);
ab3a3d
 		if (IS_ERR(supported)) {
ab3a3d
 			if (ERR(supported) == EHOSTUNREACH ||
ab3a3d
 			    ERR(supported) == ETIMEDOUT)
ab3a3d
@@ -688,7 +684,7 @@ static int get_vers_and_cost(unsigned logopt, struct host *host,
ab3a3d
 
ab3a3d
 	if (version & UDP_REQUESTED) {
ab3a3d
 		supported = get_nfs_info(logopt, host,
ab3a3d
-				   &pm_info, &rpc_info, "udp", vers, port);
ab3a3d
+				   &pm_info, &rpc_info, IPPROTO_UDP, vers, port);
ab3a3d
 		if (IS_ERR(supported)) {
ab3a3d
 			if (!ret && ERR(supported) == ETIMEDOUT)
ab3a3d
 				return ret;
ab3a3d
@@ -709,7 +705,7 @@ static int get_supported_ver_and_cost(unsigned logopt, struct host *host,
ab3a3d
 	socklen_t len = INET6_ADDRSTRLEN;
ab3a3d
 	char buf[len + 1];
ab3a3d
 	struct conn_info pm_info, rpc_info;
ab3a3d
-	const char *proto;
ab3a3d
+	int proto;
ab3a3d
 	unsigned int vers;
ab3a3d
 	struct timeval start, end;
ab3a3d
 	struct timezone tz;
ab3a3d
@@ -748,10 +744,10 @@ static int get_supported_ver_and_cost(unsigned logopt, struct host *host,
ab3a3d
 	 *  So, we do the conversion here.
ab3a3d
 	 */
ab3a3d
 	if (version & UDP_SELECTED_MASK) {
ab3a3d
-		proto = "udp";
ab3a3d
+		proto = IPPROTO_UDP;
ab3a3d
 		version >>= 8;
ab3a3d
 	} else
ab3a3d
-		proto = "tcp";
ab3a3d
+		proto = IPPROTO_TCP;
ab3a3d
 
ab3a3d
 	switch (version) {
ab3a3d
 	case NFS2_SUPPORTED:
ab3a3d
@@ -768,9 +764,7 @@ static int get_supported_ver_and_cost(unsigned logopt, struct host *host,
ab3a3d
 		return 0;
ab3a3d
 	}
ab3a3d
 
ab3a3d
-	rpc_info.proto = getprotobyname(proto);
ab3a3d
-	if (!rpc_info.proto)
ab3a3d
-		return 0;
ab3a3d
+	rpc_info.proto = proto;
ab3a3d
 
ab3a3d
 	if (port > 0)
ab3a3d
 		rpc_info.port = port;
ab3a3d
@@ -786,14 +780,14 @@ static int get_supported_ver_and_cost(unsigned logopt, struct host *host,
ab3a3d
 
ab3a3d
 		memset(&parms, 0, sizeof(struct pmap));
ab3a3d
 		parms.pm_prog = NFS_PROGRAM;
ab3a3d
-		parms.pm_prot = rpc_info.proto->p_proto;
ab3a3d
+		parms.pm_prot = rpc_info.proto;
ab3a3d
 		parms.pm_vers = vers;
ab3a3d
 		ret = rpc_portmap_getport(&pm_info, &parms, &rpc_info.port);
ab3a3d
 		if (ret < 0)
ab3a3d
 			goto done;
ab3a3d
 	}
ab3a3d
 
ab3a3d
-	if (rpc_info.proto->p_proto == IPPROTO_UDP)
ab3a3d
+	if (rpc_info.proto == IPPROTO_UDP)
ab3a3d
 		status = rpc_udp_getclient(&rpc_info, NFS_PROGRAM, vers);
ab3a3d
 	else
ab3a3d
 		status = rpc_tcp_getclient(&rpc_info, NFS_PROGRAM, vers);
ab3a3d
@@ -815,7 +809,7 @@ static int get_supported_ver_and_cost(unsigned logopt, struct host *host,
ab3a3d
 		}
ab3a3d
 	}
ab3a3d
 done:
ab3a3d
-	if (rpc_info.proto->p_proto == IPPROTO_UDP) {
ab3a3d
+	if (rpc_info.proto == IPPROTO_UDP) {
ab3a3d
 		rpc_destroy_udp_client(&rpc_info);
ab3a3d
 		rpc_destroy_udp_client(&pm_info);
ab3a3d
 	} else {