]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-sunrpc.c
Makefile.in: don't remove configure and config.h.in in make distclean.
[tcpdump] / print-sunrpc.c
index bc7138de5d53c3acfbdeeac275b5dc8ff4af7f8b..82bfd8a9d92a4583767cade34485af8f54995820 100644 (file)
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#define NETDISSECT_REWORKED
+/* \summary: Sun Remote Procedure Call printer */
+
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
 /*
@@ -39,7 +40,7 @@
  */
 #undef _XOPEN_SOURCE_EXTENDED
 
-#include <tcpdump-stdinc.h>
+#include "netdissect-stdinc.h"
 
 #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
 #include <rpc/rpc.h>
 #include <stdio.h>
 #include <string.h>
 
-#include "interface.h"
+#define ND_LONGJMP_FROM_TCHECK
+#include "netdissect.h"
 #include "addrtoname.h"
 #include "extract.h"
 
 #include "ip.h"
-#ifdef INET6
 #include "ip6.h"
-#endif
 
 #include "rpc_auth.h"
 #include "rpc_msg.h"
  */
 
 #define SUNRPC_PMAPPORT                ((uint16_t)111)
-#define SUNRPC_PMAPPROG                ((uint32_t)100000)
-#define SUNRPC_PMAPVERS                ((uint32_t)2)
-#define SUNRPC_PMAPVERS_PROTO  ((uint32_t)2)
-#define SUNRPC_PMAPVERS_ORIG   ((uint32_t)1)
 #define SUNRPC_PMAPPROC_NULL   ((uint32_t)0)
 #define SUNRPC_PMAPPROC_SET    ((uint32_t)1)
 #define SUNRPC_PMAPPROC_UNSET  ((uint32_t)2)
 #define SUNRPC_PMAPPROC_DUMP   ((uint32_t)4)
 #define SUNRPC_PMAPPROC_CALLIT ((uint32_t)5)
 
-struct sunrpc_pmap {
-       uint32_t pm_prog;
-       uint32_t pm_vers;
-       uint32_t pm_prot;
-       uint32_t pm_port;
-};
-
 static const struct tok proc2str[] = {
        { SUNRPC_PMAPPROC_NULL,         "null" },
        { SUNRPC_PMAPPROC_SET,          "set" },
@@ -166,67 +155,65 @@ static const struct tok proc2str[] = {
 static char *progstr(uint32_t);
 
 void
-sunrpcrequest_print(netdissect_options *ndo, register const u_char *bp,
-                    register u_int length, register const u_char *bp2)
+sunrpc_print(netdissect_options *ndo, const u_char *bp,
+                    u_int length, const u_char *bp2)
 {
-       register const struct sunrpc_msg *rp;
-       register const struct ip *ip;
-#ifdef INET6
-       register const struct ip6_hdr *ip6;
-#endif
+       const struct sunrpc_msg *rp;
+       const struct ip *ip;
+       const struct ip6_hdr *ip6;
        uint32_t x;
        char srcid[20], dstid[20];      /*fits 32bit*/
 
-       rp = (struct sunrpc_msg *)bp;
+       ndo->ndo_protocol = "sunrpc";
+       rp = (const struct sunrpc_msg *)bp;
+       ND_TCHECK_SIZE(rp);
 
        if (!ndo->ndo_nflag) {
                snprintf(srcid, sizeof(srcid), "0x%x",
-                   EXTRACT_32BITS(&rp->rm_xid));
+                   GET_BE_U_4(rp->rm_xid));
                strlcpy(dstid, "sunrpc", sizeof(dstid));
        } else {
                snprintf(srcid, sizeof(srcid), "0x%x",
-                   EXTRACT_32BITS(&rp->rm_xid));
+                   GET_BE_U_4(rp->rm_xid));
                snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT);
        }
 
-       switch (IP_V((struct ip *)bp2)) {
+       switch (IP_V((const struct ip *)bp2)) {
        case 4:
-               ip = (struct ip *)bp2;
-               ND_PRINT((ndo, "%s.%s > %s.%s: %d",
-                   ipaddr_string(ndo, &ip->ip_src), srcid,
-                   ipaddr_string(ndo, &ip->ip_dst), dstid, length));
+               ip = (const struct ip *)bp2;
+               ND_PRINT("%s.%s > %s.%s: %u",
+                   GET_IPADDR_STRING(ip->ip_src), srcid,
+                   GET_IPADDR_STRING(ip->ip_dst), dstid, length);
                break;
-#ifdef INET6
        case 6:
-               ip6 = (struct ip6_hdr *)bp2;
-               ND_PRINT((ndo, "%s.%s > %s.%s: %d",
-                   ip6addr_string(ndo, &ip6->ip6_src), srcid,
-                   ip6addr_string(ndo, &ip6->ip6_dst), dstid, length));
+               ip6 = (const struct ip6_hdr *)bp2;
+               ND_PRINT("%s.%s > %s.%s: %u",
+                   GET_IP6ADDR_STRING(ip6->ip6_src), srcid,
+                   GET_IP6ADDR_STRING(ip6->ip6_dst), dstid, length);
                break;
-#endif
        default:
-               ND_PRINT((ndo, "%s.%s > %s.%s: %d", "?", srcid, "?", dstid, length));
+               ND_PRINT("%s.%s > %s.%s: %u", "?", srcid, "?", dstid, length);
                break;
        }
 
-       ND_PRINT((ndo, " %s", tok2str(proc2str, " proc #%u",
-           EXTRACT_32BITS(&rp->rm_call.cb_proc))));
-       x = EXTRACT_32BITS(&rp->rm_call.cb_rpcvers);
-       if (x != 2)
-               ND_PRINT((ndo, " [rpcver %u]", x));
+       ND_PRINT(" %s", tok2str(proc2str, " proc #%u",
+           GET_BE_U_4(rp->rm_call.cb_proc)));
+       x = GET_BE_U_4(rp->rm_call.cb_rpcvers);
+       if (x != SUNRPC_MSG_VERSION)
+               ND_PRINT(" [rpcver %u]", x);
 
-       switch (EXTRACT_32BITS(&rp->rm_call.cb_proc)) {
+       switch (GET_BE_U_4(rp->rm_call.cb_proc)) {
 
        case SUNRPC_PMAPPROC_SET:
        case SUNRPC_PMAPPROC_UNSET:
        case SUNRPC_PMAPPROC_GETPORT:
        case SUNRPC_PMAPPROC_CALLIT:
-               x = EXTRACT_32BITS(&rp->rm_call.cb_prog);
+               x = GET_BE_U_4(rp->rm_call.cb_prog);
                if (!ndo->ndo_nflag)
-                       ND_PRINT((ndo, " %s", progstr(x)));
+                       ND_PRINT(" %s", progstr(x));
                else
-                       ND_PRINT((ndo, " %u", x));
-               ND_PRINT((ndo, ".%u", EXTRACT_32BITS(&rp->rm_call.cb_vers)));
+                       ND_PRINT(" %u", x);
+               ND_PRINT(".%u", GET_BE_U_4(rp->rm_call.cb_vers));
                break;
        }
 }
@@ -235,7 +222,7 @@ static char *
 progstr(uint32_t prog)
 {
 #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
-       register struct rpcent *rp;
+       struct rpcent *rp;
 #endif
        static char buf[32];
        static uint32_t lastprog = 0;
@@ -244,12 +231,11 @@ progstr(uint32_t prog)
                return (buf);
 #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
        rp = getrpcbynumber(prog);
-       if (rp == NULL)
-#endif
-               (void) snprintf(buf, sizeof(buf), "#%u", prog);
-#if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
-       else
+       if (rp != NULL)
                strlcpy(buf, rp->r_name, sizeof(buf));
+       else
 #endif
+               (void) snprintf(buf, sizeof(buf), "#%u", prog);
+       lastprog = prog;
        return (buf);
 }