123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #undef _XOPEN_SOURCE_EXTENDED
- #include <netdissect-stdinc.h>
- #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
- #include <rpc/rpc.h>
- #ifdef HAVE_RPC_RPCENT_H
- #include <rpc/rpcent.h>
- #endif
- #endif
- #include <stdio.h>
- #include <string.h>
- #include "netdissect.h"
- #include "addrtoname.h"
- #include "extract.h"
- #include "ip.h"
- #include "ip6.h"
- #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_GETPORT ((uint32_t)3)
- #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" },
- { SUNRPC_PMAPPROC_UNSET, "unset" },
- { SUNRPC_PMAPPROC_GETPORT, "getport" },
- { SUNRPC_PMAPPROC_DUMP, "dump" },
- { SUNRPC_PMAPPROC_CALLIT, "call" },
- { 0, NULL }
- };
- 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)
- {
- register const struct sunrpc_msg *rp;
- register const struct ip *ip;
- register const struct ip6_hdr *ip6;
- uint32_t x;
- char srcid[20], dstid[20];
- rp = (const struct sunrpc_msg *)bp;
- if (!ndo->ndo_nflag) {
- snprintf(srcid, sizeof(srcid), "0x%x",
- EXTRACT_32BITS(&rp->rm_xid));
- strlcpy(dstid, "sunrpc", sizeof(dstid));
- } else {
- snprintf(srcid, sizeof(srcid), "0x%x",
- EXTRACT_32BITS(&rp->rm_xid));
- snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT);
- }
- switch (IP_V((const struct ip *)bp2)) {
- case 4:
- ip = (const 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));
- break;
- case 6:
- ip6 = (const 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));
- break;
- default:
- ND_PRINT((ndo, "%s.%s > %s.%s: %d", "?", 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));
- switch (EXTRACT_32BITS(&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);
- if (!ndo->ndo_nflag)
- ND_PRINT((ndo, " %s", progstr(x)));
- else
- ND_PRINT((ndo, " %u", x));
- ND_PRINT((ndo, ".%u", EXTRACT_32BITS(&rp->rm_call.cb_vers)));
- break;
- }
- }
- static char *
- progstr(uint32_t prog)
- {
- #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
- register struct rpcent *rp;
- #endif
- static char buf[32];
- static uint32_t lastprog = 0;
- if (lastprog != 0 && prog == lastprog)
- 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
- strlcpy(buf, rp->r_name, sizeof(buf));
- #endif
- return (buf);
- }
|