X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=support%2Fnfs%2Frpc_socket.c;h=2b11e350669ab53729bc41d92f7378eadb26b268;hb=c56152202a3000c69b87f9cb90f40166f1f21275;hp=82ba818b03cac210cd73bf8c70778bab06084f5f;hpb=162cbdd19830abaf6a3fd64a22839023ce99185d;p=nfs-utils.git diff --git a/support/nfs/rpc_socket.c b/support/nfs/rpc_socket.c index 82ba818..2b11e35 100644 --- a/support/nfs/rpc_socket.c +++ b/support/nfs/rpc_socket.c @@ -40,51 +40,10 @@ #include "nfsrpc.h" -#ifdef HAVE_TIRPC_NETCONFIG_H - -/* - * Most of the headers under /usr/include/tirpc are currently - * unusable for various reasons. We statically define the bits - * we need here until the official headers are fixed. - * - * The commonly used RPC calls such as CLNT_CALL and CLNT_DESTROY - * are actually virtual functions in both the legacy and TI-RPC - * implementations. The proper _CALL or _DESTROY will be invoked - * no matter if we used a legacy clnt_create() or clnt_tli_create() - * from libtirpc. - */ - -#include -#include - -/* definitions from tirpc/rpc/types.h */ - -/* - * The netbuf structure is used for transport-independent address storage. - */ -struct netbuf { - unsigned int maxlen; - unsigned int len; - void *buf; -}; - -/* definitions from tirpc/rpc/clnt.h */ - -/* - * Low level clnt create routine for connectionless transports, e.g. udp. - */ -extern CLIENT *clnt_dg_create(const int, const struct netbuf *, - const rpcprog_t, const rpcvers_t, - const u_int, const u_int); - -/* - * Low level clnt create routine for connectionful transports, e.g. tcp. - */ -extern CLIENT *clnt_vc_create(const int, const struct netbuf *, - const rpcprog_t, const rpcvers_t, - u_int, u_int); - -#endif /* HAVE_TIRPC_NETCONFIG_H */ +#ifdef HAVE_LIBTIRPC +#include +#include +#endif /* HAVE_LIBTIRPC */ /* * If "-1" is specified in the tv_sec field, use these defaults instead. @@ -107,14 +66,14 @@ static CLIENT *nfs_get_localclient(const struct sockaddr *sap, const rpcvers_t version, struct timeval *timeout) { -#ifdef HAVE_CLNT_VC_CREATE +#ifdef HAVE_LIBTIRPC struct sockaddr_storage address; const struct netbuf nbuf = { .maxlen = sizeof(struct sockaddr_un), .len = (size_t)salen, .buf = &address, }; -#endif /* HAVE_CLNT_VC_CREATE */ +#endif /* HAVE_LIBTIRPC */ CLIENT *client; int sock; @@ -128,13 +87,13 @@ static CLIENT *nfs_get_localclient(const struct sockaddr *sap, if (timeout->tv_sec == -1) timeout->tv_sec = NFSRPC_TIMEOUT_TCP; -#ifdef HAVE_CLNT_VC_CREATE +#ifdef HAVE_LIBTIRPC memcpy(nbuf.buf, sap, (size_t)salen); client = clnt_vc_create(sock, &nbuf, program, version, 0, 0); -#else /* HAVE_CLNT_VC_CREATE */ +#else /* !HAVE_LIBTIRPC */ client = clntunix_create((struct sockaddr_un *)sap, program, version, &sock, 0, 0); -#endif /* HAVE_CLNT_VC_CREATE */ +#endif /* !HAVE_LIBTIRPC */ if (client != NULL) CLNT_CONTROL(client, CLSET_FD_CLOSE, NULL); else @@ -261,23 +220,23 @@ static CLIENT *nfs_get_udpclient(const struct sockaddr *sap, const rpcvers_t version, struct timeval *timeout) { -#ifdef HAVE_CLNT_DG_CREATE + CLIENT *client; + int ret, sock; +#ifdef HAVE_LIBTIRPC struct sockaddr_storage address; const struct netbuf nbuf = { .maxlen = salen, .len = salen, .buf = &address, }; -#endif /* HAVE_CLNT_DG_CREATE */ - CLIENT *client; - int ret, sock; -#ifndef HAVE_CLNT_DG_CREATE +#else /* !HAVE_LIBTIRPC */ + if (sap->sa_family != AF_INET) { rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; return NULL; } -#endif /* !HAVE_CLNT_DG_CREATE */ +#endif /* !HAVE_LIBTIRPC */ sock = socket((int)sap->sa_family, SOCK_DGRAM, IPPROTO_UDP); if (sock == -1) { @@ -305,13 +264,13 @@ static CLIENT *nfs_get_udpclient(const struct sockaddr *sap, return NULL; } -#ifdef HAVE_CLNT_DG_CREATE +#ifdef HAVE_LIBTIRPC memcpy(nbuf.buf, sap, (size_t)salen); client = clnt_dg_create(sock, &nbuf, program, version, 0, 0); -#else /* HAVE_CLNT_DG_CREATE */ +#else /* !HAVE_LIBTIRPC */ client = clntudp_create((struct sockaddr_in *)sap, program, version, *timeout, &sock); -#endif /* HAVE_CLNT_DG_CREATE */ +#endif /* !HAVE_LIBTIRPC */ if (client != NULL) { CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *)timeout); CLNT_CONTROL(client, CLSET_FD_CLOSE, NULL); @@ -337,23 +296,23 @@ static CLIENT *nfs_get_tcpclient(const struct sockaddr *sap, const rpcvers_t version, struct timeval *timeout) { -#ifdef HAVE_CLNT_VC_CREATE + CLIENT *client; + int ret, sock; +#ifdef HAVE_LIBTIRPC struct sockaddr_storage address; const struct netbuf nbuf = { .maxlen = salen, .len = salen, .buf = &address, }; -#endif /* HAVE_CLNT_VC_CREATE */ - CLIENT *client; - int ret, sock; -#ifndef HAVE_CLNT_VC_CREATE +#else /* !HAVE_LIBTIRPC */ + if (sap->sa_family != AF_INET) { rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; return NULL; } -#endif /* !HAVE_CLNT_VC_CREATE */ +#endif /* !HAVE_LIBTIRPC */ sock = socket((int)sap->sa_family, SOCK_STREAM, IPPROTO_TCP); if (sock == -1) { @@ -381,13 +340,13 @@ static CLIENT *nfs_get_tcpclient(const struct sockaddr *sap, return NULL; } -#ifdef HAVE_CLNT_VC_CREATE +#ifdef HAVE_LIBTIRPC memcpy(nbuf.buf, sap, (size_t)salen); client = clnt_vc_create(sock, &nbuf, program, version, 0, 0); -#else /* HAVE_CLNT_VC_CREATE */ +#else /* !HAVE_LIBTIRPC */ client = clnttcp_create((struct sockaddr_in *)sap, program, version, &sock, 0, 0); -#endif /* HAVE_CLNT_VC_CREATE */ +#endif /* !HAVE_LIBTIRPC */ if (client != NULL) CLNT_CONTROL(client, CLSET_FD_CLOSE, NULL); else @@ -480,49 +439,3 @@ rpcprog_t nfs_getrpcbyname(const rpcprog_t program, const char *table[]) return program; } - -static unsigned short nfs_tryportbyname(const char *name, - const char *protocol) -{ - struct servent *servp = NULL; - - servp = getservbyname(name, protocol); - if (servp != NULL) - return (unsigned short)ntohl((uint32_t)servp->s_port); - return 0; -} - -/** - * nfs_getportbynumber - convert an RPC program number to a port - * @program: RPC program number to look up - * @transport: IPPROTO_ value of transport protocol to use - * - * Returns a non-zero port number, in host byte order, on success; - * otherwise zero if some problem occurred. - */ -unsigned short nfs_getportbynumber(const rpcprog_t program, - const unsigned short transport) -{ - char *protocol = (transport == IPPROTO_TCP) ? "tcp" : "udp"; - struct rpcent *rpcp; - unsigned short port = 0; - - rpcp = getrpcbynumber((int)program); - if (rpcp == NULL) - return port; - - port = nfs_tryportbyname(rpcp->r_name, protocol); - if (port != 0) - return port; - - if (rpcp->r_aliases) { - int i; - for (i = 0; rpcp->r_aliases[i] != NULL; i++) { - port = nfs_tryportbyname(rpcp->r_aliases[i], protocol); - if (port != 0) - break; - } - } - - return port; -}