]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - support/nfs/conn.c
Use socklen_t some more to avoid warnings.
[nfs-utils.git] / support / nfs / conn.c
index bf2afad678c71ad3b6e39b740f8745e09d387af8..89f767676b2aeb5f85d0b485c6865b6f5837c2bb 100644 (file)
@@ -6,6 +6,7 @@
  *
  */
 
+#include "config.h"
 #include <errno.h>
 #include <unistd.h>
 #include <rpc/rpc.h>
 
 #include "conn.h"
 
+#if SIZEOF_SOCKLEN_T - 0 == 0
+#define socklen_t int
+#endif
+
 extern int verbose;
 
 /* Map an NFS version into the corresponding Mountd version */
@@ -93,7 +98,7 @@ int get_socket(struct sockaddr_in *saddr, u_int p_prot, int resvp)
                        return RPC_ANYSOCK;
                }
        }
-       if (type == SOCK_STREAM) {
+       if (type == SOCK_STREAM || type == SOCK_DGRAM) {
                cc = connect(so, (struct sockaddr *)saddr, namelen);
                if (cc < 0) {
                        rpc_createerr.cf_stat = RPC_SYSTEMERROR;
@@ -119,7 +124,7 @@ int get_socket(struct sockaddr_in *saddr, u_int p_prot, int resvp)
  */
 int
 clnt_ping(struct sockaddr_in *saddr, const u_long prog, const u_long vers,
-         const u_int prot)
+         const u_int prot, struct sockaddr_in *caddr)
 {
        CLIENT *clnt=NULL;
        int sock, stat;
@@ -161,8 +166,15 @@ clnt_ping(struct sockaddr_in *saddr, const u_long prog, const u_long vers,
                rpc_createerr.cf_stat = stat;
        }
        clnt_destroy(clnt);
-       if (sock != -1)
+       if (sock != -1) {
+               if (caddr) {
+                       /* Get the address of our end of this connection */
+                       socklen_t len = sizeof(*caddr);
+                       if (getsockname(sock, caddr, &len) != 0)
+                               caddr->sin_family = 0;
+               }
                close(sock);
+       }
 
        if (stat == RPC_SUCCESS)
                return 1;