]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-nfs.c
More UNALIGNED_MEM{CPY,CMP} on IP addresses.
[tcpdump] / print-nfs.c
index 8993911ebe21abfcd4614d903f3892ce0cd50b70..4ec55e8c513c28fb0144eacfdb54691ff6a04bb4 100644 (file)
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#ifndef lint
-static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.71 2000-05-15 00:40:26 assar Exp $ (LBL)";
-#endif
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-
-#if __STDC__
-struct mbuf;
-struct rtentry;
-#endif
-#include <net/if.h>
-
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-
-#include <rpc/rpc.h>
+#include <tcpdump-stdinc.h>
 
-#include <ctype.h>
 #include <pcap.h>
 #include <stdio.h>
 #include <string.h>
 
 #include "interface.h"
 #include "addrtoname.h"
+#include "extract.h"
 
 #include "nfs.h"
 #include "nfsfh.h"
 
+#include "ip.h"
+#ifdef INET6
+#include "ip6.h"
+#endif
+#include "rpc_auth.h"
+#include "rpc_msg.h"
+
+static const char tstr[] = " [|nfs]";
+
 static void nfs_printfh(const u_int32_t *, const u_int);
-static void xid_map_enter(const struct rpc_msg *, const struct ip *);
-static int32_t xid_map_find(const struct rpc_msg *, const struct ip *,
+static int xid_map_enter(const struct sunrpc_msg *, const u_char *);
+static int xid_map_find(const struct sunrpc_msg *, const u_char *,
                            u_int32_t *, u_int32_t *);
-static void interp_reply(const struct rpc_msg *, u_int32_t, u_int32_t, int);
+static void interp_reply(const struct sunrpc_msg *, u_int32_t, u_int32_t, int);
 static const u_int32_t *parse_post_op_attr(const u_int32_t *, int);
 static void print_sattr3(const struct nfsv3_sattr *sa3, int verbose);
-static int print_int64(const u_int32_t *dp, int how);
+static void print_nfsaddr(const u_char *, const char *, const char *);
 
 /*
  * Mapping of old NFS Version 2 RPC numbers to generic numbers.
@@ -97,14 +86,63 @@ u_int32_t nfsv3_procid[NFS_NPROCS] = {
        NFSPROC_NOOP
 };
 
-static struct tok nfsv3_writemodes[] = {
+/*
+ * NFS V2 and V3 status values.
+ *
+ * Some of these come from the RFCs for NFS V2 and V3, with the message
+ * strings taken from the FreeBSD C library "errlst.c".
+ *
+ * Others are errors that are not in the RFC but that I suspect some
+ * NFS servers could return; the values are FreeBSD errno values, as
+ * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
+ * was primarily BSD-derived.
+ */
+static const struct tok status2str[] = {
+       { 1,     "Operation not permitted" },   /* EPERM */
+       { 2,     "No such file or directory" }, /* ENOENT */
+       { 5,     "Input/output error" },        /* EIO */
+       { 6,     "Device not configured" },     /* ENXIO */
+       { 11,    "Resource deadlock avoided" }, /* EDEADLK */
+       { 12,    "Cannot allocate memory" },    /* ENOMEM */
+       { 13,    "Permission denied" },         /* EACCES */
+       { 17,    "File exists" },               /* EEXIST */
+       { 18,    "Cross-device link" },         /* EXDEV */
+       { 19,    "Operation not supported by device" }, /* ENODEV */
+       { 20,    "Not a directory" },           /* ENOTDIR */
+       { 21,    "Is a directory" },            /* EISDIR */
+       { 22,    "Invalid argument" },          /* EINVAL */
+       { 26,    "Text file busy" },            /* ETXTBSY */
+       { 27,    "File too large" },            /* EFBIG */
+       { 28,    "No space left on device" },   /* ENOSPC */
+       { 30,    "Read-only file system" },     /* EROFS */
+       { 31,    "Too many links" },            /* EMLINK */
+       { 45,    "Operation not supported" },   /* EOPNOTSUPP */
+       { 62,    "Too many levels of symbolic links" }, /* ELOOP */
+       { 63,    "File name too long" },        /* ENAMETOOLONG */
+       { 66,    "Directory not empty" },       /* ENOTEMPTY */
+       { 69,    "Disc quota exceeded" },       /* EDQUOT */
+       { 70,    "Stale NFS file handle" },     /* ESTALE */
+       { 71,    "Too many levels of remote in path" }, /* EREMOTE */
+       { 99,    "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
+       { 10001, "Illegal NFS file handle" },   /* NFS3ERR_BADHANDLE */
+       { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
+       { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
+       { 10004, "Operation not supported" },   /* NFS3ERR_NOTSUPP */
+       { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
+       { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
+       { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
+       { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
+       { 0,     NULL }
+};
+
+static const struct tok nfsv3_writemodes[] = {
        { 0,            "unstable" },
        { 1,            "datasync" },
        { 2,            "filesync" },
        { 0,            NULL }
 };
 
-static struct tok type2str[] = {
+static const struct tok type2str[] = {
        { NFNON,        "NON" },
        { NFREG,        "REG" },
        { NFDIR,        "DIR" },
@@ -115,91 +153,104 @@ static struct tok type2str[] = {
        { 0,            NULL }
 };
 
-/*
- * Print out a 64-bit integer. This appears to be different on each system,
- * try to make the best of it. The integer stored as 2 consecutive XDR
- * encoded 32-bit integers, to which a pointer is passed.
- *
- * Assume that a system that has INT64_FORMAT defined, has a 64-bit
- * integer datatype and can print it.
- */ 
-
-#define UNSIGNED 0
-#define SIGNED   1
-#define HEX      2
-
-static int print_int64(const u_int32_t *dp, int how)
+static void
+print_nfsaddr(const u_char *bp, const char *s, const char *d)
 {
-#ifdef INT64_FORMAT
-       u_int64_t res;
+       struct ip *ip;
+#ifdef INET6
+       struct ip6_hdr *ip6;
+       char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];
+#else
+#ifndef INET_ADDRSTRLEN
+#define INET_ADDRSTRLEN        16
+#endif
+       char srcaddr[INET_ADDRSTRLEN], dstaddr[INET_ADDRSTRLEN];
+#endif
 
-       res = ((u_int64_t)ntohl(dp[0]) << 32) | (u_int64_t)ntohl(dp[1]);
-       switch (how) {
-       case SIGNED:
-               printf(INT64_FORMAT, res);
-               break;
-       case UNSIGNED:
-               printf(U_INT64_FORMAT, res);
+       srcaddr[0] = dstaddr[0] = '\0';
+       switch (IP_V((struct ip *)bp)) {
+       case 4:
+               ip = (struct ip *)bp;
+               strlcpy(srcaddr, ipaddr_string(&ip->ip_src), sizeof(srcaddr));
+               strlcpy(dstaddr, ipaddr_string(&ip->ip_dst), sizeof(dstaddr));
                break;
-       case HEX:
-               printf(HEX_INT64_FORMAT, res);
+#ifdef INET6
+       case 6:
+               ip6 = (struct ip6_hdr *)bp;
+               strlcpy(srcaddr, ip6addr_string(&ip6->ip6_src),
+                   sizeof(srcaddr));
+               strlcpy(dstaddr, ip6addr_string(&ip6->ip6_dst),
+                   sizeof(dstaddr));
                break;
+#endif
        default:
-               return (0);
-       }
-#else
-       switch (how) {
-       case SIGNED :
-       case UNSIGNED :
-       case HEX :
-           printf ("0x%x%08x", dp[0], dp[1]);
-           break;
-       default :
-           return (0);
+               strlcpy(srcaddr, "?", sizeof(srcaddr));
+               strlcpy(dstaddr, "?", sizeof(dstaddr));
+               break;
        }
-#endif
-       return 1;
+
+       (void)printf("%s.%s > %s.%s: ", srcaddr, s, dstaddr, d);
 }
 
 static const u_int32_t *
 parse_sattr3(const u_int32_t *dp, struct nfsv3_sattr *sa3)
 {
        TCHECK(dp[0]);
-       if ((sa3->sa_modeset = ntohl(*dp++))) {
+       sa3->sa_modeset = EXTRACT_32BITS(dp);
+       dp++;
+       if (sa3->sa_modeset) {
                TCHECK(dp[0]);
-               sa3->sa_mode = ntohl(*dp++);
+               sa3->sa_mode = EXTRACT_32BITS(dp);
+               dp++;
        }
 
        TCHECK(dp[0]);
-       if ((sa3->sa_uidset = ntohl(*dp++))) {
+       sa3->sa_uidset = EXTRACT_32BITS(dp);
+       dp++;
+       if (sa3->sa_uidset) {
                TCHECK(dp[0]);
-               sa3->sa_uid = ntohl(*dp++);
+               sa3->sa_uid = EXTRACT_32BITS(dp);
+               dp++;
        }
 
        TCHECK(dp[0]);
-       if ((sa3->sa_gidset = ntohl(*dp++))) {
+       sa3->sa_gidset = EXTRACT_32BITS(dp);
+       dp++;
+       if (sa3->sa_gidset) {
                TCHECK(dp[0]);
-               sa3->sa_gid = ntohl(*dp++);
+               sa3->sa_gid = EXTRACT_32BITS(dp);
+               dp++;
        }
 
        TCHECK(dp[0]);
-       if ((sa3->sa_sizeset = ntohl(*dp++))) {
+       sa3->sa_sizeset = EXTRACT_32BITS(dp);
+       dp++;
+       if (sa3->sa_sizeset) {
                TCHECK(dp[0]);
-               sa3->sa_size = ntohl(*dp++);
+               sa3->sa_size = EXTRACT_32BITS(dp);
+               dp++;
        }
 
        TCHECK(dp[0]);
-       if ((sa3->sa_atimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) {
+       sa3->sa_atimetype = EXTRACT_32BITS(dp);
+       dp++;
+       if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT) {
                TCHECK(dp[1]);
-               sa3->sa_atime.nfsv3_sec = ntohl(*dp++);
-               sa3->sa_atime.nfsv3_nsec = ntohl(*dp++);
+               sa3->sa_atime.nfsv3_sec = EXTRACT_32BITS(dp);
+               dp++;
+               sa3->sa_atime.nfsv3_nsec = EXTRACT_32BITS(dp);
+               dp++;
        }
 
        TCHECK(dp[0]);
-       if ((sa3->sa_mtimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) {
+       sa3->sa_mtimetype = EXTRACT_32BITS(dp);
+       dp++;
+       if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT) {
                TCHECK(dp[1]);
-               sa3->sa_mtime.nfsv3_sec = ntohl(*dp++);
-               sa3->sa_mtime.nfsv3_nsec = ntohl(*dp++);
+               sa3->sa_mtime.nfsv3_sec = EXTRACT_32BITS(dp);
+               dp++;
+               sa3->sa_mtime.nfsv3_nsec = EXTRACT_32BITS(dp);
+               dp++;
        }
 
        return dp;
@@ -232,34 +283,132 @@ void
 nfsreply_print(register const u_char *bp, u_int length,
               register const u_char *bp2)
 {
-       register const struct rpc_msg *rp;
-       register const struct ip *ip;
-       u_int32_t proc, vers;
+       register const struct sunrpc_msg *rp;
+       char srcid[20], dstid[20];      /*fits 32bit*/
 
        nfserr = 0;             /* assume no error */
-       rp = (const struct rpc_msg *)bp;
-       ip = (const struct ip *)bp2;
-
-       if (!nflag)
-               (void)printf("%s.nfs > %s.%u: reply %s %d",
-                            ipaddr_string(&ip->ip_src),
-                            ipaddr_string(&ip->ip_dst),
-                            (u_int32_t)ntohl(rp->rm_xid),
-                            ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED?
-                                    "ok":"ERR",
-                            length);
-       else
-               (void)printf("%s.%u > %s.%u: reply %s %d",
-                            ipaddr_string(&ip->ip_src),
-                            NFS_PORT,
-                            ipaddr_string(&ip->ip_dst),
-                            (u_int32_t)ntohl(rp->rm_xid),
-                            ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED?
-                               "ok":"ERR",
-                            length);
-
-       if (xid_map_find(rp, ip, &proc, &vers) >= 0)
-               interp_reply(rp, proc, vers, length);
+       rp = (const struct sunrpc_msg *)bp;
+
+       TCHECK(rp->rm_xid);
+       if (!nflag) {
+               strlcpy(srcid, "nfs", sizeof(srcid));
+               snprintf(dstid, sizeof(dstid), "%u",
+                   EXTRACT_32BITS(&rp->rm_xid));
+       } else {
+               snprintf(srcid, sizeof(srcid), "%u", NFS_PORT);
+               snprintf(dstid, sizeof(dstid), "%u",
+                   EXTRACT_32BITS(&rp->rm_xid));
+       }
+       print_nfsaddr(bp2, srcid, dstid);
+
+       nfsreply_print_noaddr(bp, length, bp2);
+       return;
+
+trunc:
+       if (!nfserr)
+               printf("%s", tstr);
+}
+
+void
+nfsreply_print_noaddr(register const u_char *bp, u_int length,
+              register const u_char *bp2)
+{
+       register const struct sunrpc_msg *rp;
+       u_int32_t proc, vers, reply_stat;
+       enum sunrpc_reject_stat rstat;
+       u_int32_t rlow;
+       u_int32_t rhigh;
+       enum sunrpc_auth_stat rwhy;
+
+       nfserr = 0;             /* assume no error */
+       rp = (const struct sunrpc_msg *)bp;
+
+       TCHECK(rp->rm_reply.rp_stat);
+       reply_stat = EXTRACT_32BITS(&rp->rm_reply.rp_stat);
+       switch (reply_stat) {
+
+       case SUNRPC_MSG_ACCEPTED:
+               (void)printf("reply ok %u", length);
+               if (xid_map_find(rp, bp2, &proc, &vers) >= 0)
+                       interp_reply(rp, proc, vers, length);
+               break;
+
+       case SUNRPC_MSG_DENIED:
+               (void)printf("reply ERR %u: ", length);
+               TCHECK(rp->rm_reply.rp_reject.rj_stat);
+               rstat = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_stat);
+               switch (rstat) {
+
+               case SUNRPC_RPC_MISMATCH:
+                       TCHECK(rp->rm_reply.rp_reject.rj_vers.high);
+                       rlow = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_vers.low);
+                       rhigh = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_vers.high);
+                       (void)printf("RPC Version mismatch (%u-%u)",
+                           rlow, rhigh);
+                       break;
+
+               case SUNRPC_AUTH_ERROR:
+                       TCHECK(rp->rm_reply.rp_reject.rj_why);
+                       rwhy = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_why);
+                       (void)printf("Auth ");
+                       switch (rwhy) {
+
+                       case SUNRPC_AUTH_OK:
+                               (void)printf("OK");
+                               break;
+
+                       case SUNRPC_AUTH_BADCRED:
+                               (void)printf("Bogus Credentials (seal broken)");
+                               break;
+
+                       case SUNRPC_AUTH_REJECTEDCRED:
+                               (void)printf("Rejected Credentials (client should begin new session)");
+                               break;
+
+                       case SUNRPC_AUTH_BADVERF:
+                               (void)printf("Bogus Verifier (seal broken)");
+                               break;
+
+                       case SUNRPC_AUTH_REJECTEDVERF:
+                               (void)printf("Verifier expired or was replayed");
+                               break;
+
+                       case SUNRPC_AUTH_TOOWEAK:
+                               (void)printf("Credentials are too weak");
+                               break;
+
+                       case SUNRPC_AUTH_INVALIDRESP:
+                               (void)printf("Bogus response verifier");
+                               break;
+
+                       case SUNRPC_AUTH_FAILED:
+                               (void)printf("Unknown failure");
+                               break;
+
+                       default:
+                               (void)printf("Invalid failure code %u",
+                                   (unsigned int)rwhy);
+                               break;
+                       }
+                       break;
+
+               default:
+                       (void)printf("Unknown reason for rejecting rpc message %u",
+                           (unsigned int)rstat);
+                       break;
+               }
+               break;
+
+       default:
+               (void)printf("reply Unknown rpc response code=%u %u",
+                   reply_stat, length);
+               break;
+       }
+       return;
+
+trunc:
+       if (!nfserr)
+               printf("%s", tstr);
 }
 
 /*
@@ -267,7 +416,7 @@ nfsreply_print(register const u_char *bp, u_int length,
  * If the packet was truncated, return 0.
  */
 static const u_int32_t *
-parsereq(register const struct rpc_msg *rp, register u_int length)
+parsereq(register const struct sunrpc_msg *rp, register u_int length)
 {
        register const u_int32_t *dp;
        register u_int len;
@@ -277,11 +426,11 @@ parsereq(register const struct rpc_msg *rp, register u_int length)
         */
        dp = (u_int32_t *)&rp->rm_call.cb_cred;
        TCHECK(dp[1]);
-       len = ntohl(dp[1]);
+       len = EXTRACT_32BITS(&dp[1]);
        if (len < length) {
                dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
                TCHECK(dp[1]);
-               len = ntohl(dp[1]);
+               len = EXTRACT_32BITS(&dp[1]);
                if (len < length) {
                        dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
                        TCHECK2(dp[0], 0);
@@ -299,11 +448,11 @@ trunc:
 static const u_int32_t *
 parsefh(register const u_int32_t *dp, int v3)
 {
-       int len;
+       u_int len;
 
        if (v3) {
                TCHECK(dp[0]);
-               len = (int)ntohl(*dp) / 4;
+               len = EXTRACT_32BITS(dp) / 4;
                dp++;
        } else
                len = NFSX_V2FH / 4;
@@ -338,9 +487,11 @@ parsefn(register const u_int32_t *dp)
        cp = (u_char *)dp;
        /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
        dp += ((len + 3) & ~3) / sizeof(*dp);
-       /* XXX seems like we should be checking the length */
        putchar('"');
-       (void) fn_printn(cp, len, NULL);
+       if (fn_printn(cp, len, snapend)) {
+               putchar('"');
+               goto trunc;
+       }
        putchar('"');
 
        return (dp);
@@ -367,35 +518,53 @@ void
 nfsreq_print(register const u_char *bp, u_int length,
     register const u_char *bp2)
 {
-       register const struct rpc_msg *rp;
-       register const struct ip *ip;
+       register const struct sunrpc_msg *rp;
+       char srcid[20], dstid[20];      /*fits 32bit*/
+
+       nfserr = 0;             /* assume no error */
+       rp = (const struct sunrpc_msg *)bp;
+
+       TCHECK(rp->rm_xid);
+       if (!nflag) {
+               snprintf(srcid, sizeof(srcid), "%u",
+                   EXTRACT_32BITS(&rp->rm_xid));
+               strlcpy(dstid, "nfs", sizeof(dstid));
+       } else {
+               snprintf(srcid, sizeof(srcid), "%u",
+                   EXTRACT_32BITS(&rp->rm_xid));
+               snprintf(dstid, sizeof(dstid), "%u", NFS_PORT);
+       }
+       print_nfsaddr(bp2, srcid, dstid);
+       (void)printf("%d", length);
+
+       nfsreq_print_noaddr(bp, length, bp2);
+       return;
+
+trunc:
+       if (!nfserr)
+               printf("%s", tstr);
+}
+
+void
+nfsreq_print_noaddr(register const u_char *bp, u_int length,
+    register const u_char *bp2)
+{
+       register const struct sunrpc_msg *rp;
        register const u_int32_t *dp;
-       nfstype type;
+       nfs_type type;
        int v3;
        u_int32_t proc;
+       u_int32_t access_flags;
        struct nfsv3_sattr sa3;
 
        nfserr = 0;             /* assume no error */
-       rp = (const struct rpc_msg *)bp;
-       ip = (const struct ip *)bp2;
-       if (!nflag)
-               (void)printf("%s.%u > %s.nfs: %d",
-                            ipaddr_string(&ip->ip_src),
-                            (u_int32_t)ntohl(rp->rm_xid),
-                            ipaddr_string(&ip->ip_dst),
-                            length);
-       else
-               (void)printf("%s.%u > %s.%u: %d",
-                            ipaddr_string(&ip->ip_src),
-                            (u_int32_t)ntohl(rp->rm_xid),
-                            ipaddr_string(&ip->ip_dst),
-                            NFS_PORT,
-                            length);
+       rp = (const struct sunrpc_msg *)bp;
 
-       xid_map_enter(rp, ip);  /* record proc number for later on */
+       if (!xid_map_enter(rp, bp2))    /* record proc number for later on */
+               goto trunc;
 
-       v3 = (ntohl(rp->rm_call.cb_vers) == NFS_VER3);
-       proc = ntohl(rp->rm_call.cb_proc);
+       v3 = (EXTRACT_32BITS(&rp->rm_call.cb_vers) == NFS_VER3);
+       proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
 
        if (!v3 && proc < NFS_NPROCS)
                proc =  nfsv3_procid[proc];
@@ -434,7 +603,37 @@ nfsreq_print(register const u_char *bp, u_int length,
                if ((dp = parsereq(rp, length)) != NULL &&
                    (dp = parsefh(dp, v3)) != NULL) {
                        TCHECK(dp[0]);
-                       printf(" %04x", (unsigned)ntohl(dp[0]));
+                       access_flags = EXTRACT_32BITS(&dp[0]);
+                       if (access_flags & ~NFSV3ACCESS_FULL) {
+                               /* NFSV3ACCESS definitions aren't up to date */
+                               printf(" %04x", access_flags);
+                       } else if ((access_flags & NFSV3ACCESS_FULL) == NFSV3ACCESS_FULL) {
+                               printf(" NFS_ACCESS_FULL");
+                       } else {
+                               char separator = ' ';
+                               if (access_flags & NFSV3ACCESS_READ) {
+                                       printf(" NFS_ACCESS_READ");
+                                       separator = '|';
+                               }
+                               if (access_flags & NFSV3ACCESS_LOOKUP) {
+                                       printf("%cNFS_ACCESS_LOOKUP", separator);
+                                       separator = '|';
+                               }
+                               if (access_flags & NFSV3ACCESS_MODIFY) {
+                                       printf("%cNFS_ACCESS_MODIFY", separator);
+                                       separator = '|';
+                               }
+                               if (access_flags & NFSV3ACCESS_EXTEND) {
+                                       printf("%cNFS_ACCESS_EXTEND", separator);
+                                       separator = '|';
+                               }
+                               if (access_flags & NFSV3ACCESS_DELETE) {
+                                       printf("%cNFS_ACCESS_DELETE", separator);
+                                       separator = '|';
+                               }
+                               if (access_flags & NFSV3ACCESS_EXECUTE)
+                                       printf("%cNFS_ACCESS_EXECUTE", separator);
+                       }
                        return;
                }
                break;
@@ -452,14 +651,14 @@ nfsreq_print(register const u_char *bp, u_int length,
                    (dp = parsefh(dp, v3)) != NULL) {
                        if (v3) {
                                TCHECK(dp[2]);
-                               printf(" %u bytes @ ",
-                                      (u_int32_t) ntohl(dp[2]));
-                               print_int64(dp, UNSIGNED);
+                               printf(" %u bytes @ %" PRIu64,
+                                      EXTRACT_32BITS(&dp[2]),
+                                      EXTRACT_64BITS(&dp[0]));
                        } else {
                                TCHECK(dp[1]);
                                printf(" %u bytes @ %u",
-                                   (u_int32_t)ntohl(dp[1]),
-                                   (u_int32_t)ntohl(dp[0]));
+                                   EXTRACT_32BITS(&dp[1]),
+                                   EXTRACT_32BITS(&dp[0]));
                        }
                        return;
                }
@@ -470,24 +669,25 @@ nfsreq_print(register const u_char *bp, u_int length,
                if ((dp = parsereq(rp, length)) != NULL &&
                    (dp = parsefh(dp, v3)) != NULL) {
                        if (v3) {
-                               TCHECK(dp[4]);
-                               printf(" %u bytes @ ",
-                                               (u_int32_t) ntohl(dp[4]));
-                               print_int64(dp, UNSIGNED);
+                               TCHECK(dp[2]);
+                               printf(" %u (%u) bytes @ %" PRIu64,
+                                               EXTRACT_32BITS(&dp[4]),
+                                               EXTRACT_32BITS(&dp[2]),
+                                               EXTRACT_64BITS(&dp[0]));
                                if (vflag) {
                                        dp += 3;
                                        TCHECK(dp[0]);
                                        printf(" <%s>",
                                                tok2str(nfsv3_writemodes,
-                                                       NULL, ntohl(*dp)));
+                                                       NULL, EXTRACT_32BITS(dp)));
                                }
                        } else {
                                TCHECK(dp[3]);
                                printf(" %u (%u) bytes @ %u (%u)",
-                                               (u_int32_t)ntohl(dp[3]),
-                                               (u_int32_t)ntohl(dp[2]),
-                                               (u_int32_t)ntohl(dp[1]),
-                                               (u_int32_t)ntohl(dp[0]));
+                                               EXTRACT_32BITS(&dp[3]),
+                                               EXTRACT_32BITS(&dp[2]),
+                                               EXTRACT_32BITS(&dp[1]),
+                                               EXTRACT_32BITS(&dp[0]));
                        }
                        return;
                }
@@ -526,15 +726,16 @@ nfsreq_print(register const u_char *bp, u_int length,
                if ((dp = parsereq(rp, length)) != 0 &&
                    (dp = parsefhn(dp, v3)) != 0) {
                        TCHECK(*dp);
-                       type = (nfstype)ntohl(*dp++);
+                       type = (nfs_type)EXTRACT_32BITS(dp);
+                       dp++;
                        if ((dp = parse_sattr3(dp, &sa3)) == 0)
                                break;
                        printf(" %s", tok2str(type2str, "unk-ft %d", type));
                        if (vflag && (type == NFCHR || type == NFBLK)) {
                                TCHECK(dp[1]);
                                printf(" %u/%u",
-                                      (unsigned)ntohl(dp[0]),
-                                      (unsigned)ntohl(dp[1]));
+                                      EXTRACT_32BITS(&dp[0]),
+                                      EXTRACT_32BITS(&dp[1]));
                                dp += 2;
                        }
                        if (vflag)
@@ -587,9 +788,9 @@ nfsreq_print(register const u_char *bp, u_int length,
                                 * We shouldn't really try to interpret the
                                 * offset cookie here.
                                 */
-                               printf(" %u bytes @ ",
-                                   (u_int32_t) ntohl(dp[4]));
-                               print_int64(dp, SIGNED);
+                               printf(" %u bytes @ %" PRId64,
+                                   EXTRACT_32BITS(&dp[4]),
+                                   EXTRACT_64BITS(&dp[0]));
                                if (vflag)
                                        printf(" verf %08x%08x", dp[2],
                                               dp[3]);
@@ -600,8 +801,8 @@ nfsreq_print(register const u_char *bp, u_int length,
                                 * common, but offsets > 2^31 aren't.
                                 */
                                printf(" %u bytes @ %d",
-                                   (u_int32_t)ntohl(dp[1]),
-                                   (u_int32_t)ntohl(dp[0]));
+                                   EXTRACT_32BITS(&dp[1]),
+                                   EXTRACT_32BITS(&dp[0]));
                        }
                        return;
                }
@@ -616,11 +817,14 @@ nfsreq_print(register const u_char *bp, u_int length,
                         * We don't try to interpret the offset
                         * cookie here.
                         */
-                       printf(" %u bytes @ ", (u_int32_t) ntohl(dp[4]));
-                       print_int64(dp, SIGNED);
-                       if (vflag)
+                       printf(" %u bytes @ %" PRId64,
+                               EXTRACT_32BITS(&dp[4]),
+                               EXTRACT_64BITS(&dp[0]));
+                       if (vflag) {
+                               TCHECK(dp[5]);
                                printf(" max %u verf %08x%08x",
-                                      (u_int32_t) ntohl(dp[5]), dp[2], dp[3]);
+                                      EXTRACT_32BITS(&dp[5]), dp[2], dp[3]);
+                       }
                        return;
                }
                break;
@@ -634,30 +838,38 @@ nfsreq_print(register const u_char *bp, u_int length,
 
        case NFSPROC_FSINFO:
                printf(" fsinfo");
+               if ((dp = parsereq(rp, length)) != NULL &&
+                   parsefh(dp, v3) != NULL)
+                       return;
                break;
 
        case NFSPROC_PATHCONF:
                printf(" pathconf");
+               if ((dp = parsereq(rp, length)) != NULL &&
+                   parsefh(dp, v3) != NULL)
+                       return;
                break;
 
        case NFSPROC_COMMIT:
                printf(" commit");
                if ((dp = parsereq(rp, length)) != NULL &&
                    (dp = parsefh(dp, v3)) != NULL) {
-                       printf(" %u bytes @ ", (u_int32_t) ntohl(dp[2]));
-                       print_int64(dp, UNSIGNED);
+                       TCHECK(dp[2]);
+                       printf(" %u bytes @ %" PRIu64,
+                               EXTRACT_32BITS(&dp[2]),
+                               EXTRACT_64BITS(&dp[0]));
                        return;
                }
                break;
 
        default:
-               printf(" proc-%u", (u_int32_t)ntohl(rp->rm_call.cb_proc));
+               printf(" proc-%u", EXTRACT_32BITS(&rp->rm_call.cb_proc));
                return;
        }
 
 trunc:
        if (!nfserr)
-               fputs(" [|nfs]", stdout);
+               printf("%s", tstr);
 }
 
 /*
@@ -673,10 +885,24 @@ static void
 nfs_printfh(register const u_int32_t *dp, const u_int len)
 {
        my_fsid fsid;
-       ino_t ino;
-       char *sfsname = NULL;
+       u_int32_t ino;
+       const char *sfsname = NULL;
+       char *spacep;
+
+       if (uflag) {
+               u_int i;
+               char const *sep = "";
+
+               printf(" fh[");
+               for (i=0; i<len; i++) {
+                       (void)printf("%s%x", sep, dp[i]);
+                       sep = ":";
+               }
+               printf("]");
+               return;
+       }
 
-       Parse_fh((caddr_t*)dp, len, &fsid, &ino, NULL, &sfsname, 0);
+       Parse_fh((const u_char *)dp, len, &fsid, &ino, NULL, &sfsname, 0);
 
        if (sfsname) {
                /* file system ID is ASCII, not numeric, for this server OS */
@@ -684,18 +910,23 @@ nfs_printfh(register const u_int32_t *dp, const u_int len)
 
                /* Make sure string is null-terminated */
                strncpy(temp, sfsname, NFSX_V3FHMAX);
+               temp[sizeof(temp) - 1] = '\0';
                /* Remove trailing spaces */
-               sfsname = strchr(temp, ' ');
-               if (sfsname)
-                       *sfsname = 0;
+               spacep = strchr(temp, ' ');
+               if (spacep)
+                       *spacep = '\0';
 
-               (void)printf(" fh %s/%ld", temp, (long) ino);
-       }
-       else {
-               (void)printf(" fh %d,%d/%ld",
-                       fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor,
-                       (long) ino);
+               (void)printf(" fh %s/", temp);
+       } else {
+               (void)printf(" fh %d,%d/",
+                            fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor);
        }
+
+       if(fsid.Fsid_dev.Minor == 257)
+               /* Print the undecoded handle */
+               (void)printf("%s", fsid.Opaque_Handle);
+       else
+               (void)printf("%ld", (long) ino);
 }
 
 /*
@@ -705,11 +936,17 @@ nfs_printfh(register const u_int32_t *dp, const u_int len)
  */
 
 struct xid_map_entry {
-       u_int32_t               xid;            /* transaction ID (net order) */
+       u_int32_t       xid;            /* transaction ID (net order) */
+       int ipver;                      /* IP version (4 or 6) */
+#ifdef INET6
+       struct in6_addr client;         /* client IP address (net order) */
+       struct in6_addr server;         /* server IP address (net order) */
+#else
        struct in_addr  client;         /* client IP address (net order) */
        struct in_addr  server;         /* server IP address (net order) */
-       u_int32_t               proc;           /* call proc number (host order) */
-       u_int32_t               vers;   /* program version (host order) */
+#endif
+       u_int32_t       proc;           /* call proc number (host order) */
+       u_int32_t       vers;           /* program version (host order) */
 };
 
 /*
@@ -725,21 +962,51 @@ struct xid_map_entry xid_map[XIDMAPSIZE];
 int    xid_map_next = 0;
 int    xid_map_hint = 0;
 
-static void
-xid_map_enter(const struct rpc_msg *rp, const struct ip *ip)
+static int
+xid_map_enter(const struct sunrpc_msg *rp, const u_char *bp)
 {
+       struct ip *ip = NULL;
+#ifdef INET6
+       struct ip6_hdr *ip6 = NULL;
+#endif
        struct xid_map_entry *xmep;
 
+       if (!TTEST(rp->rm_call.cb_vers))
+               return (0);
+       switch (IP_V((struct ip *)bp)) {
+       case 4:
+               ip = (struct ip *)bp;
+               break;
+#ifdef INET6
+       case 6:
+               ip6 = (struct ip6_hdr *)bp;
+               break;
+#endif
+       default:
+               return (1);
+       }
+
        xmep = &xid_map[xid_map_next];
 
        if (++xid_map_next >= XIDMAPSIZE)
                xid_map_next = 0;
 
        xmep->xid = rp->rm_xid;
-       xmep->client = ip->ip_src;
-       xmep->server = ip->ip_dst;
-       xmep->proc = ntohl(rp->rm_call.cb_proc);
-       xmep->vers = ntohl(rp->rm_call.cb_vers);
+       if (ip) {
+               xmep->ipver = 4;
+               UNALIGNED_MEMCPY(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
+               UNALIGNED_MEMCPY(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
+       }
+#ifdef INET6
+       else if (ip6) {
+               xmep->ipver = 6;
+               UNALIGNED_MEMCPY(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
+               UNALIGNED_MEMCPY(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
+       }
+#endif
+       xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
+       xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
+       return (1);
 }
 
 /*
@@ -747,27 +1014,56 @@ xid_map_enter(const struct rpc_msg *rp, const struct ip *ip)
  * version in vers return, or returns -1 on failure
  */
 static int
-xid_map_find(const struct rpc_msg *rp, const struct ip *ip, u_int32_t *proc,
+xid_map_find(const struct sunrpc_msg *rp, const u_char *bp, u_int32_t *proc,
             u_int32_t *vers)
 {
        int i;
        struct xid_map_entry *xmep;
        u_int32_t xid = rp->rm_xid;
-       u_int32_t clip = ip->ip_dst.s_addr;
-       u_int32_t sip = ip->ip_src.s_addr;
+       struct ip *ip = (struct ip *)bp;
+#ifdef INET6
+       struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
+#endif
+       int cmp;
 
        /* Start searching from where we last left off */
        i = xid_map_hint;
        do {
                xmep = &xid_map[i];
-               if (xmep->xid == xid && xmep->client.s_addr == clip &&
-                   xmep->server.s_addr == sip) {
+               cmp = 1;
+               if (xmep->ipver != IP_V(ip) || xmep->xid != xid)
+                       goto nextitem;
+               switch (xmep->ipver) {
+               case 4:
+                       if (memcmp(&ip->ip_src, &xmep->server,
+                                  sizeof(ip->ip_src)) != 0 ||
+                           memcmp(&ip->ip_dst, &xmep->client,
+                                  sizeof(ip->ip_dst)) != 0) {
+                               cmp = 0;
+                       }
+                       break;
+#ifdef INET6
+               case 6:
+                       if (memcmp(&ip6->ip6_src, &xmep->server,
+                                  sizeof(ip6->ip6_src)) != 0 ||
+                           memcmp(&ip6->ip6_dst, &xmep->client,
+                                  sizeof(ip6->ip6_dst)) != 0) {
+                               cmp = 0;
+                       }
+                       break;
+#endif
+               default:
+                       cmp = 0;
+                       break;
+               }
+               if (cmp) {
                        /* match */
                        xid_map_hint = i;
                        *proc = xmep->proc;
                        *vers = xmep->vers;
                        return 0;
                }
+       nextitem:
                if (++i >= XIDMAPSIZE)
                        i = 0;
        } while (i != xid_map_hint);
@@ -785,11 +1081,11 @@ xid_map_find(const struct rpc_msg *rp, const struct ip *ip, u_int32_t *proc,
  * If the packet was truncated, return 0.
  */
 static const u_int32_t *
-parserep(register const struct rpc_msg *rp, register u_int length)
+parserep(register const struct sunrpc_msg *rp, register u_int length)
 {
        register const u_int32_t *dp;
        u_int len;
-       enum accept_stat astat;
+       enum sunrpc_accept_stat astat;
 
        /*
         * Portability note:
@@ -808,7 +1104,7 @@ parserep(register const struct rpc_msg *rp, register u_int length)
         */
        dp = ((const u_int32_t *)&rp->rm_reply) + 1;
        TCHECK(dp[1]);
-       len = ntohl(dp[1]);
+       len = EXTRACT_32BITS(&dp[1]);
        if (len >= length)
                return (NULL);
        /*
@@ -820,33 +1116,33 @@ parserep(register const struct rpc_msg *rp, register u_int length)
        /*
         * now we can check the ar_stat field
         */
-       astat = ntohl(*(enum accept_stat *)dp);
+       astat = (enum sunrpc_accept_stat) EXTRACT_32BITS(dp);
        switch (astat) {
 
-       case SUCCESS:
+       case SUNRPC_SUCCESS:
                break;
 
-       case PROG_UNAVAIL:
+       case SUNRPC_PROG_UNAVAIL:
                printf(" PROG_UNAVAIL");
                nfserr = 1;             /* suppress trunc string */
                return (NULL);
 
-       case PROG_MISMATCH:
+       case SUNRPC_PROG_MISMATCH:
                printf(" PROG_MISMATCH");
                nfserr = 1;             /* suppress trunc string */
                return (NULL);
 
-       case PROC_UNAVAIL:
+       case SUNRPC_PROC_UNAVAIL:
                printf(" PROC_UNAVAIL");
                nfserr = 1;             /* suppress trunc string */
                return (NULL);
 
-       case GARBAGE_ARGS:
+       case SUNRPC_GARBAGE_ARGS:
                printf(" GARBAGE_ARGS");
                nfserr = 1;             /* suppress trunc string */
                return (NULL);
 
-       case SYSTEM_ERR:
+       case SUNRPC_SYSTEM_ERR:
                printf(" SYSTEM_ERR");
                nfserr = 1;             /* suppress trunc string */
                return (NULL);
@@ -870,14 +1166,14 @@ parsestatus(const u_int32_t *dp, int *er)
 
        TCHECK(dp[0]);
 
-       errnum = ntohl(dp[0]);
+       errnum = EXTRACT_32BITS(&dp[0]);
        if (er)
                *er = errnum;
        if (errnum != 0) {
                if (!qflag)
-                       printf(" ERROR: %s", pcap_strerror(errnum));
+                       printf(" ERROR: %s",
+                           tok2str(status2str, "unk %d", errnum));
                nfserr = 1;
-               return (NULL);
        }
        return (dp + 1);
 trunc:
@@ -894,57 +1190,56 @@ parsefattr(const u_int32_t *dp, int verbose, int v3)
        if (verbose) {
                printf(" %s %o ids %d/%d",
                    tok2str(type2str, "unk-ft %d ",
-                   (u_int32_t)ntohl(fap->fa_type)),
-                   (u_int32_t)ntohl(fap->fa_mode),
-                   (u_int32_t)ntohl(fap->fa_uid),
-                   (u_int32_t) ntohl(fap->fa_gid));
+                   EXTRACT_32BITS(&fap->fa_type)),
+                   EXTRACT_32BITS(&fap->fa_mode),
+                   EXTRACT_32BITS(&fap->fa_uid),
+                   EXTRACT_32BITS(&fap->fa_gid));
                if (v3) {
                        TCHECK(fap->fa3_size);
-                       printf(" sz ");
-                       print_int64((u_int32_t *)&fap->fa3_size, UNSIGNED);
-                       putchar(' ');
+                       printf(" sz %" PRIu64,
+                               EXTRACT_64BITS((u_int32_t *)&fap->fa3_size));
                } else {
                        TCHECK(fap->fa2_size);
-                       printf(" sz %d ", (u_int32_t) ntohl(fap->fa2_size));
+                       printf(" sz %d", EXTRACT_32BITS(&fap->fa2_size));
                }
        }
        /* print lots more stuff */
        if (verbose > 1) {
                if (v3) {
                        TCHECK(fap->fa3_ctime);
-                       printf("nlink %d rdev %d/%d ",
-                              (u_int32_t)ntohl(fap->fa_nlink),
-                              (u_int32_t) ntohl(fap->fa3_rdev.specdata1),
-                              (u_int32_t) ntohl(fap->fa3_rdev.specdata2));
-                       printf("fsid ");
-                       print_int64((u_int32_t *)&fap->fa2_fsid, HEX);
-                       printf(" nodeid ");
-                       print_int64((u_int32_t *)&fap->fa2_fileid, HEX);
-                       printf(" a/m/ctime %u.%06u ",
-                              (u_int32_t) ntohl(fap->fa3_atime.nfsv3_sec),
-                              (u_int32_t) ntohl(fap->fa3_atime.nfsv3_nsec));
-                       printf("%u.%06u ",
-                              (u_int32_t) ntohl(fap->fa3_mtime.nfsv3_sec),
-                              (u_int32_t) ntohl(fap->fa3_mtime.nfsv3_nsec));
-                       printf("%u.%06u ",
-                              (u_int32_t) ntohl(fap->fa3_ctime.nfsv3_sec),
-                              (u_int32_t) ntohl(fap->fa3_ctime.nfsv3_nsec));
+                       printf(" nlink %d rdev %d/%d",
+                              EXTRACT_32BITS(&fap->fa_nlink),
+                              EXTRACT_32BITS(&fap->fa3_rdev.specdata1),
+                              EXTRACT_32BITS(&fap->fa3_rdev.specdata2));
+                       printf(" fsid %" PRIx64,
+                               EXTRACT_64BITS((u_int32_t *)&fap->fa3_fsid));
+                       printf(" fileid %" PRIx64,
+                               EXTRACT_64BITS((u_int32_t *)&fap->fa3_fileid));
+                       printf(" a/m/ctime %u.%06u",
+                              EXTRACT_32BITS(&fap->fa3_atime.nfsv3_sec),
+                              EXTRACT_32BITS(&fap->fa3_atime.nfsv3_nsec));
+                       printf(" %u.%06u",
+                              EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_sec),
+                              EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_nsec));
+                       printf(" %u.%06u",
+                              EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_sec),
+                              EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_nsec));
                } else {
                        TCHECK(fap->fa2_ctime);
-                       printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
-                              (u_int32_t) ntohl(fap->fa_nlink),
-                              (u_int32_t) ntohl(fap->fa2_rdev),
-                              (u_int32_t) ntohl(fap->fa2_fsid),
-                              (u_int32_t) ntohl(fap->fa2_fileid));
-                       printf("%u.%06u ",
-                              (u_int32_t) ntohl(fap->fa2_atime.nfsv2_sec),
-                              (u_int32_t) ntohl(fap->fa2_atime.nfsv2_usec));
-                       printf("%u.%06u ",
-                              (u_int32_t) ntohl(fap->fa2_mtime.nfsv2_sec),
-                              (u_int32_t) ntohl(fap->fa2_mtime.nfsv2_usec));
-                       printf("%u.%06u ",
-                              (u_int32_t) ntohl(fap->fa2_ctime.nfsv2_sec),
-                              (u_int32_t) ntohl(fap->fa2_ctime.nfsv2_usec));
+                       printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
+                              EXTRACT_32BITS(&fap->fa_nlink),
+                              EXTRACT_32BITS(&fap->fa2_rdev),
+                              EXTRACT_32BITS(&fap->fa2_fsid),
+                              EXTRACT_32BITS(&fap->fa2_fileid));
+                       printf(" %u.%06u",
+                              EXTRACT_32BITS(&fap->fa2_atime.nfsv2_sec),
+                              EXTRACT_32BITS(&fap->fa2_atime.nfsv2_usec));
+                       printf(" %u.%06u",
+                              EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_sec),
+                              EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_usec));
+                       printf(" %u.%06u",
+                              EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_sec),
+                              EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_usec));
                }
        }
        return ((const u_int32_t *)((unsigned char *)dp +
@@ -959,8 +1254,10 @@ parseattrstat(const u_int32_t *dp, int verbose, int v3)
        int er;
 
        dp = parsestatus(dp, &er);
-       if (dp == NULL || er)
+       if (dp == NULL)
                return (0);
+       if (er)
+               return (1);
 
        return (parsefattr(dp, verbose, v3) != NULL);
 }
@@ -970,8 +1267,10 @@ parsediropres(const u_int32_t *dp)
 {
        int er;
 
-       if (!(dp = parsestatus(dp, &er)) || er)
+       if (!(dp = parsestatus(dp, &er)))
                return (0);
+       if (er)
+               return (1);
 
        dp = parsefh(dp, 0);
        if (dp == NULL)
@@ -986,8 +1285,10 @@ parselinkres(const u_int32_t *dp, int v3)
        int er;
 
        dp = parsestatus(dp, &er);
-       if (dp == NULL || er)
+       if (dp == NULL)
                return(0);
+       if (er)
+               return(1);
        if (v3 && !(dp = parse_post_op_attr(dp, vflag)))
                return (0);
        putchar(' ');
@@ -1001,8 +1302,10 @@ parsestatfs(const u_int32_t *dp, int v3)
        int er;
 
        dp = parsestatus(dp, &er);
-       if (dp == NULL || (!v3 && er))
+       if (dp == NULL)
                return (0);
+       if (!v3 && er)
+               return (1);
 
        if (qflag)
                return(1);
@@ -1014,34 +1317,29 @@ parsestatfs(const u_int32_t *dp, int v3)
                        return (0);
        }
 
-       TCHECK2(dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
+       TCHECK2(*dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
 
        sfsp = (const struct nfs_statfs *)dp;
 
        if (v3) {
-               printf(" tbytes ");
-               print_int64((u_int32_t *)&sfsp->sf_tbytes, UNSIGNED);
-               printf(" fbytes ");
-               print_int64((u_int32_t *)&sfsp->sf_fbytes, UNSIGNED);
-               printf(" abytes ");
-               print_int64((u_int32_t *)&sfsp->sf_abytes, UNSIGNED);
+               printf(" tbytes %" PRIu64 " fbytes %" PRIu64 " abytes %" PRIu64,
+                       EXTRACT_64BITS((u_int32_t *)&sfsp->sf_tbytes),
+                       EXTRACT_64BITS((u_int32_t *)&sfsp->sf_fbytes),
+                       EXTRACT_64BITS((u_int32_t *)&sfsp->sf_abytes));
                if (vflag) {
-                       printf(" tfiles ");
-                       print_int64((u_int32_t *)&sfsp->sf_tfiles, UNSIGNED);
-                       printf(" ffiles ");
-                       print_int64((u_int32_t *)&sfsp->sf_ffiles, UNSIGNED);
-                       printf(" afiles ");
-                       print_int64((u_int32_t *)&sfsp->sf_afiles, UNSIGNED);
-                       printf(" invar %u",
-                              (u_int32_t) ntohl(sfsp->sf_invarsec));
+                       printf(" tfiles %" PRIu64 " ffiles %" PRIu64 " afiles %" PRIu64 " invar %u",
+                              EXTRACT_64BITS((u_int32_t *)&sfsp->sf_tfiles),
+                              EXTRACT_64BITS((u_int32_t *)&sfsp->sf_ffiles),
+                              EXTRACT_64BITS((u_int32_t *)&sfsp->sf_afiles),
+                              EXTRACT_32BITS(&sfsp->sf_invarsec));
                }
        } else {
                printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
-                       (u_int32_t)ntohl(sfsp->sf_tsize),
-                       (u_int32_t)ntohl(sfsp->sf_bsize),
-                       (u_int32_t)ntohl(sfsp->sf_blocks),
-                       (u_int32_t)ntohl(sfsp->sf_bfree),
-                       (u_int32_t)ntohl(sfsp->sf_bavail));
+                       EXTRACT_32BITS(&sfsp->sf_tsize),
+                       EXTRACT_32BITS(&sfsp->sf_bsize),
+                       EXTRACT_32BITS(&sfsp->sf_blocks),
+                       EXTRACT_32BITS(&sfsp->sf_bfree),
+                       EXTRACT_32BITS(&sfsp->sf_bavail));
        }
 
        return (1);
@@ -1055,14 +1353,16 @@ parserddires(const u_int32_t *dp)
        int er;
 
        dp = parsestatus(dp, &er);
-       if (dp == 0 || er)
+       if (dp == NULL)
                return (0);
+       if (er)
+               return (1);
        if (qflag)
                return (1);
 
        TCHECK(dp[2]);
        printf(" offset %x size %d ",
-              (unsigned)ntohl(dp[0]), (unsigned)ntohl(dp[1]));
+              EXTRACT_32BITS(&dp[0]), EXTRACT_32BITS(&dp[1]));
        if (dp[2] != 0)
                printf(" eof");
 
@@ -1074,11 +1374,10 @@ trunc:
 static const u_int32_t *
 parse_wcc_attr(const u_int32_t *dp)
 {
-       printf(" sz ");
-       print_int64(dp, UNSIGNED);
+       printf(" sz %" PRIu64, EXTRACT_64BITS(&dp[0]));
        printf(" mtime %u.%06u ctime %u.%06u",
-              (unsigned)ntohl(dp[2]), (unsigned)ntohl(dp[3]),
-              (unsigned)ntohl(dp[4]), (unsigned)ntohl(dp[5]));
+              EXTRACT_32BITS(&dp[2]), EXTRACT_32BITS(&dp[3]),
+              EXTRACT_32BITS(&dp[4]), EXTRACT_32BITS(&dp[5]));
        return (dp + 6);
 }
 
@@ -1089,10 +1388,10 @@ static const u_int32_t *
 parse_pre_op_attr(const u_int32_t *dp, int verbose)
 {
        TCHECK(dp[0]);
-       if (!ntohl(dp[0]))
+       if (!EXTRACT_32BITS(&dp[0]))
                return (dp + 1);
        dp++;
-       TCHECK2(dp, 24);
+       TCHECK2(*dp, 24);
        if (verbose > 1) {
                return parse_wcc_attr(dp);
        } else {
@@ -1110,7 +1409,7 @@ static const u_int32_t *
 parse_post_op_attr(const u_int32_t *dp, int verbose)
 {
        TCHECK(dp[0]);
-       if (!ntohl(dp[0]))
+       if (!EXTRACT_32BITS(&dp[0]))
                return (dp + 1);
        dp++;
        if (verbose) {
@@ -1145,7 +1444,7 @@ parsecreateopres(const u_int32_t *dp, int verbose)
                dp = parse_wcc_data(dp, verbose);
        else {
                TCHECK(dp[0]);
-               if (!ntohl(dp[0]))
+               if (!EXTRACT_32BITS(&dp[0]))
                        return (dp + 1);
                dp++;
                if (!(dp = parsefh(dp, 1)))
@@ -1154,7 +1453,7 @@ parsecreateopres(const u_int32_t *dp, int verbose)
                        if (!(dp = parse_post_op_attr(dp, verbose)))
                                return (0);
                        if (vflag > 1) {
-                               printf("dir attr:");
+                               printf(" dir attr:");
                                dp = parse_wcc_data(dp, verbose);
                        }
                }
@@ -1215,23 +1514,23 @@ parsefsinfo(const u_int32_t *dp)
        sfp = (struct nfsv3_fsinfo *)dp;
        TCHECK(*sfp);
        printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
-              (u_int32_t) ntohl(sfp->fs_rtmax),
-              (u_int32_t) ntohl(sfp->fs_rtpref),
-              (u_int32_t) ntohl(sfp->fs_wtmax),
-              (u_int32_t) ntohl(sfp->fs_wtpref),
-              (u_int32_t) ntohl(sfp->fs_dtpref));
+              EXTRACT_32BITS(&sfp->fs_rtmax),
+              EXTRACT_32BITS(&sfp->fs_rtpref),
+              EXTRACT_32BITS(&sfp->fs_wtmax),
+              EXTRACT_32BITS(&sfp->fs_wtpref),
+              EXTRACT_32BITS(&sfp->fs_dtpref));
        if (vflag) {
-               printf(" rtmult %u wtmult %u maxfsz ",
-                      (u_int32_t) ntohl(sfp->fs_rtmult),
-                      (u_int32_t) ntohl(sfp->fs_wtmult));
-               print_int64((u_int32_t *)&sfp->fs_maxfilesize, UNSIGNED);
+               printf(" rtmult %u wtmult %u maxfsz %" PRIu64,
+                      EXTRACT_32BITS(&sfp->fs_rtmult),
+                      EXTRACT_32BITS(&sfp->fs_wtmult),
+                      EXTRACT_64BITS((u_int32_t *)&sfp->fs_maxfilesize));
                printf(" delta %u.%06u ",
-                      (u_int32_t) ntohl(sfp->fs_timedelta.nfsv3_sec),
-                      (u_int32_t) ntohl(sfp->fs_timedelta.nfsv3_nsec));
+                      EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_sec),
+                      EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_nsec));
        }
-       return (0);
-trunc:
        return (1);
+trunc:
+       return (0);
 }
 
 static int
@@ -1253,19 +1552,19 @@ parsepathconf(const u_int32_t *dp)
        TCHECK(*spp);
 
        printf(" linkmax %u namemax %u %s %s %s %s",
-              (u_int32_t) ntohl(spp->pc_linkmax),
-              (u_int32_t) ntohl(spp->pc_namemax),
-              ntohl(spp->pc_notrunc) ? "notrunc" : "",
-              ntohl(spp->pc_chownrestricted) ? "chownres" : "",
-              ntohl(spp->pc_caseinsensitive) ? "igncase" : "",
-              ntohl(spp->pc_casepreserving) ? "keepcase" : "");
-       return (0);
-trunc:
+              EXTRACT_32BITS(&spp->pc_linkmax),
+              EXTRACT_32BITS(&spp->pc_namemax),
+              EXTRACT_32BITS(&spp->pc_notrunc) ? "notrunc" : "",
+              EXTRACT_32BITS(&spp->pc_chownrestricted) ? "chownres" : "",
+              EXTRACT_32BITS(&spp->pc_caseinsensitive) ? "igncase" : "",
+              EXTRACT_32BITS(&spp->pc_casepreserving) ? "keepcase" : "");
        return (1);
+trunc:
+       return (0);
 }
 
 static void
-interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int length)
+interp_reply(const struct sunrpc_msg *rp, u_int32_t proc, u_int32_t vers, int length)
 {
        register const u_int32_t *dp;
        register int v3;
@@ -1337,7 +1636,8 @@ interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int lengt
 
        case NFSPROC_ACCESS:
                printf(" access");
-               dp = parserep(rp, length);
+               if (!(dp = parserep(rp, length)))
+                       break;
                if (!(dp = parsestatus(dp, &er)))
                        break;
                if (vflag)
@@ -1345,7 +1645,7 @@ interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int lengt
                if (!(dp = parse_post_op_attr(dp, vflag)))
                        break;
                if (!er)
-                       printf(" c %04x", (unsigned)ntohl(dp[0]));
+                       printf(" c %04x", EXTRACT_32BITS(&dp[0]));
                return;
 
        case NFSPROC_READLINK:
@@ -1368,8 +1668,8 @@ interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int lengt
                                return;
                        if (vflag) {
                                TCHECK(dp[1]);
-                               printf("%u bytes", (u_int32_t) ntohl(dp[0]));
-                               if (ntohl(dp[1]))
+                               printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
+                               if (EXTRACT_32BITS(&dp[1]))
                                        printf(" EOF");
                        }
                        return;
@@ -1392,12 +1692,12 @@ interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int lengt
                                return;
                        if (vflag) {
                                TCHECK(dp[0]);
-                               printf("%u bytes", (u_int32_t) ntohl(dp[0]));
+                               printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
                                if (vflag > 1) {
                                        TCHECK(dp[1]);
                                        printf(" <%s>",
                                                tok2str(nfsv3_writemodes,
-                                                       NULL, ntohl(dp[1])));
+                                                       NULL, EXTRACT_32BITS(&dp[1])));
                                }
                                return;
                        }
@@ -1579,5 +1879,5 @@ interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int lengt
        }
 trunc:
        if (!nfserr)
-               fputs(" [|nfs]", stdout);
+               printf("%s", tstr);
 }