]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-nfs.c
Add an "fn_printzp()" routine for printing null-padded strings (strings
[tcpdump] / print-nfs.c
index 0e7bdb5ab657936f5cd5109677c1f8bc80391d4c..7502823e51883f3260de43e9394cb9cd9e14a30b 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.101 2003-11-16 09:36:30 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.106.2.2 2005-05-06 07:57:18 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -30,8 +30,6 @@ static const char rcsid[] _U_ =
 
 #include <tcpdump-stdinc.h>
 
-#include <rpc/rpc.h>
-
 #include <pcap.h>
 #include <stdio.h>
 #include <string.h>
@@ -47,15 +45,16 @@ static const char rcsid[] _U_ =
 #ifdef INET6
 #include "ip6.h"
 #endif
+#include "rpc_auth.h"
+#include "rpc_msg.h"
 
 static void nfs_printfh(const u_int32_t *, const u_int);
-static void xid_map_enter(const struct rpc_msg *, const u_char *);
-static int32_t xid_map_find(const struct rpc_msg *, const u_char *,
+static void xid_map_enter(const struct sunrpc_msg *, const u_char *);
+static int32_t 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 *);
 
 /*
@@ -157,59 +156,6 @@ 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)
-{
-#ifdef INT64_FORMAT
-       u_int64_t res;
-
-       res = ((u_int64_t)EXTRACT_32BITS(&dp[0]) << 32) | (u_int64_t)EXTRACT_32BITS(&dp[1]);
-       switch (how) {
-       case SIGNED:
-               printf(INT64_FORMAT, res);
-               break;
-       case UNSIGNED:
-               printf(U_INT64_FORMAT, res);
-               break;
-       case HEX:
-               printf(HEX_INT64_FORMAT, res);
-               break;
-       default:
-               return (0);
-       }
-#else
-       u_int32_t high;
-
-       high = EXTRACT_32BITS(&dp[0]);
-
-       switch (how) {
-       case SIGNED:
-       case UNSIGNED:
-       case HEX:
-               if (high != 0)
-                       printf("0x%x%08x", high, EXTRACT_32BITS(&dp[1]));
-               else
-                       printf("0x%x", EXTRACT_32BITS(&dp[1]));
-               break;
-       default:
-               return (0);
-       }
-#endif
-       return 1;
-}
-
 static void
 print_nfsaddr(const u_char *bp, const char *s, const char *d)
 {
@@ -340,12 +286,12 @@ 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 sunrpc_msg *rp;
        u_int32_t proc, vers;
        char srcid[20], dstid[20];      /*fits 32bit*/
 
        nfserr = 0;             /* assume no error */
-       rp = (const struct rpc_msg *)bp;
+       rp = (const struct sunrpc_msg *)bp;
 
        if (!nflag) {
                strlcpy(srcid, "nfs", sizeof(srcid));
@@ -358,9 +304,9 @@ nfsreply_print(register const u_char *bp, u_int length,
        }
        print_nfsaddr(bp2, srcid, dstid);
        (void)printf("reply %s %d",
-                    EXTRACT_32BITS(&rp->rm_reply.rp_stat) == MSG_ACCEPTED?
-                            "ok":"ERR",
-                            length);
+            EXTRACT_32BITS(&rp->rm_reply.rp_stat) == SUNRPC_MSG_ACCEPTED?
+                    "ok":"ERR",
+            length);
 
        if (xid_map_find(rp, bp2, &proc, &vers) >= 0)
                interp_reply(rp, proc, vers, length);
@@ -371,7 +317,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;
@@ -442,9 +388,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);
@@ -471,7 +419,7 @@ 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 sunrpc_msg *rp;
        register const u_int32_t *dp;
        nfs_type type;
        int v3;
@@ -480,7 +428,7 @@ nfsreq_print(register const u_char *bp, u_int length,
        char srcid[20], dstid[20];      /*fits 32bit*/
 
        nfserr = 0;             /* assume no error */
-       rp = (const struct rpc_msg *)bp;
+       rp = (const struct sunrpc_msg *)bp;
        if (!nflag) {
                snprintf(srcid, sizeof(srcid), "%u",
                    EXTRACT_32BITS(&rp->rm_xid));
@@ -553,9 +501,9 @@ nfsreq_print(register const u_char *bp, u_int length,
                    (dp = parsefh(dp, v3)) != NULL) {
                        if (v3) {
                                TCHECK(dp[2]);
-                               printf(" %u bytes @ ",
-                                      EXTRACT_32BITS(&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",
@@ -571,10 +519,11 @@ 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 @ ",
-                                               EXTRACT_32BITS(&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]);
@@ -689,9 +638,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 @ ",
-                                   EXTRACT_32BITS(&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]);
@@ -718,11 +667,14 @@ nfsreq_print(register const u_char *bp, u_int length,
                         * We don't try to interpret the offset
                         * cookie here.
                         */
-                       printf(" %u bytes @ ", EXTRACT_32BITS(&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",
                                       EXTRACT_32BITS(&dp[5]), dp[2], dp[3]);
+                       }
                        return;
                }
                break;
@@ -752,8 +704,10 @@ nfsreq_print(register const u_char *bp, u_int length,
                printf(" commit");
                if ((dp = parsereq(rp, length)) != NULL &&
                    (dp = parsefh(dp, v3)) != NULL) {
-                       printf(" %u bytes @ ", EXTRACT_32BITS(&dp[2]));
-                       print_int64(dp, UNSIGNED);
+                       TCHECK(dp[2]);
+                       printf(" %u bytes @ %" PRIu64,
+                               EXTRACT_32BITS(&dp[2]),
+                               EXTRACT_64BITS(&dp[0]));
                        return;
                }
                break;
@@ -859,7 +813,7 @@ int xid_map_next = 0;
 int    xid_map_hint = 0;
 
 static void
-xid_map_enter(const struct rpc_msg *rp, const u_char *bp)
+xid_map_enter(const struct sunrpc_msg *rp, const u_char *bp)
 {
        struct ip *ip = NULL;
 #ifdef INET6
@@ -907,7 +861,7 @@ xid_map_enter(const struct rpc_msg *rp, const u_char *bp)
  * version in vers return, or returns -1 on failure
  */
 static int
-xid_map_find(const struct rpc_msg *rp, const u_char *bp, 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;
@@ -974,11 +928,11 @@ xid_map_find(const struct rpc_msg *rp, const u_char *bp, 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:
@@ -1009,33 +963,33 @@ parserep(register const struct rpc_msg *rp, register u_int length)
        /*
         * now we can check the ar_stat field
         */
-       astat = EXTRACT_32BITS(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);
@@ -1089,8 +1043,8 @@ parsefattr(const u_int32_t *dp, int verbose, int v3)
                    EXTRACT_32BITS(&fap->fa_gid));
                if (v3) {
                        TCHECK(fap->fa3_size);
-                       printf(" sz ");
-                       print_int64((u_int32_t *)&fap->fa3_size, UNSIGNED);
+                       printf(" sz %" PRIu64,
+                               EXTRACT_64BITS((u_int32_t *)&fap->fa3_size));
                } else {
                        TCHECK(fap->fa2_size);
                        printf(" sz %d", EXTRACT_32BITS(&fap->fa2_size));
@@ -1104,10 +1058,10 @@ parsefattr(const u_int32_t *dp, int verbose, int v3)
                               EXTRACT_32BITS(&fap->fa_nlink),
                               EXTRACT_32BITS(&fap->fa3_rdev.specdata1),
                               EXTRACT_32BITS(&fap->fa3_rdev.specdata2));
-                       printf(" fsid ");
-                       print_int64((u_int32_t *)&fap->fa3_fsid, HEX);
-                       printf(" fileid ");
-                       print_int64((u_int32_t *)&fap->fa3_fileid, HEX);
+                       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));
@@ -1215,20 +1169,15 @@ parsestatfs(const u_int32_t *dp, int v3)
        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",
+                       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 {
@@ -1272,8 +1221,7 @@ 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",
               EXTRACT_32BITS(&dp[2]), EXTRACT_32BITS(&dp[3]),
               EXTRACT_32BITS(&dp[4]), EXTRACT_32BITS(&dp[5]));
@@ -1419,10 +1367,10 @@ parsefsinfo(const u_int32_t *dp)
               EXTRACT_32BITS(&sfp->fs_wtpref),
               EXTRACT_32BITS(&sfp->fs_dtpref));
        if (vflag) {
-               printf(" rtmult %u wtmult %u maxfsz ",
+               printf(" rtmult %u wtmult %u maxfsz %" PRIu64,
                       EXTRACT_32BITS(&sfp->fs_rtmult),
-                      EXTRACT_32BITS(&sfp->fs_wtmult));
-               print_int64((u_int32_t *)&sfp->fs_maxfilesize, UNSIGNED);
+                      EXTRACT_32BITS(&sfp->fs_wtmult),
+                      EXTRACT_64BITS((u_int32_t *)&sfp->fs_maxfilesize));
                printf(" delta %u.%06u ",
                       EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_sec),
                       EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_nsec));
@@ -1463,7 +1411,7 @@ trunc:
 }
 
 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;