return ret;
}
-/*
- * Plant port number in @sap. @port is already in network byte order.
- */
-static void nfs_gp_set_port(struct sockaddr *sap, const in_port_t port)
-{
- struct sockaddr_in *sin = (struct sockaddr_in *)sap;
- struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
-
- switch (sap->sa_family) {
- case AF_INET:
- sin->sin_port = port;
- break;
- case AF_INET6:
- sin6->sin6_port = port;
- break;
- }
-}
-
/*
* Look up a network service in /etc/services and return the
* network-order port number of that service.
rpcprog_t rpcb_prog = nfs_getrpcbyname(RPCBPROG, rpcb_pgmtbl);
CLIENT *clnt;
- nfs_gp_set_port(sap, nfs_gp_get_rpcb_port(transport));
+ nfs_set_port(sap, ntohs(nfs_gp_get_rpcb_port(transport)));
clnt = nfs_get_rpcclient(sap, salen, transport, rpcb_prog,
version, timeout);
nfs_gp_map_tcp_errorcodes(transport);
struct sockaddr *saddr = (struct sockaddr *)&address;
memcpy(saddr, sap, (size_t)salen);
- nfs_gp_set_port(saddr, htons(port));
+ nfs_set_port(saddr, port);
nfs_clear_rpc_createerr();
}
if (result)
- nfs_gp_set_port(sap, htons(port));
+ nfs_set_port(sap, port);
return result;
}
return client;
}
+/**
+ * nfs_get_port - extract port value from a socket address
+ * @sap: pointer to socket address
+ *
+ * Returns port value in host byte order.
+ */
+uint16_t
+nfs_get_port(const struct sockaddr *sap)
+{
+ const struct sockaddr_in *sin = (const struct sockaddr_in *)sap;
+ const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sap;
+
+ switch (sap->sa_family) {
+ case AF_INET:
+ return ntohs(sin->sin_port);
+ case AF_INET6:
+ return ntohs(sin6->sin6_port);
+ }
+ return 0;
+}
+
+/**
+ * nfs_set_port - set port value in a socket address
+ * @sap: pointer to socket address
+ * @port: port value to set
+ *
+ */
+void
+nfs_set_port(struct sockaddr *sap, const uint16_t port)
+{
+ struct sockaddr_in *sin = (struct sockaddr_in *)sap;
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
+
+ switch (sap->sa_family) {
+ case AF_INET:
+ sin->sin_port = htons(port);
+ break;
+ case AF_INET6:
+ sin6->sin6_port = htons(port);
+ break;
+ }
+}
+
/**
* nfs_get_rpcclient - acquire an RPC client
* @sap: pointer to socket address of RPC server
const rpcvers_t version,
struct timeval *timeout)
{
- struct sockaddr_in *sin = (struct sockaddr_in *)sap;
- struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
-
nfs_clear_rpc_createerr();
switch (sap->sa_family) {
return nfs_get_localclient(sap, salen, program,
version, timeout);
case AF_INET:
- if (sin->sin_port == 0) {
- rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
- return NULL;
- }
- break;
case AF_INET6:
- if (sin6->sin6_port == 0) {
+ if (nfs_get_port(sap) == 0) {
rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
return NULL;
}
const rpcvers_t version,
struct timeval *timeout)
{
- struct sockaddr_in *sin = (struct sockaddr_in *)sap;
- struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
-
nfs_clear_rpc_createerr();
switch (sap->sa_family) {
return nfs_get_localclient(sap, salen, program,
version, timeout);
case AF_INET:
- if (sin->sin_port == 0) {
- rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
- return NULL;
- }
- break;
case AF_INET6:
- if (sin6->sin6_port == 0) {
+ if (nfs_get_port(sap) == 0) {
rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
return NULL;
}
0,
};
-static void nfs_set_port(struct sockaddr *sap, const unsigned short port)
-{
- switch (sap->sa_family) {
- case AF_INET:
- ((struct sockaddr_in *)sap)->sin_port = htons(port);
- break;
- case AF_INET6:
- ((struct sockaddr_in6 *)sap)->sin6_port = htons(port);
- break;
- default:
- nfs_error(_("%s: unrecognized address family in %s"),
- progname, __func__);
- }
-}
-
static int nfs_lookup(const char *hostname, const sa_family_t family,
struct sockaddr *sap, socklen_t *salen)
{