void nfsreply_print(netdissect_options *ndo, const u_char *bp, u_int length, const u_char *bp2) { const struct sunrpc_msg *rp; char srcid[20], dstid[20]; /*fits 32bit*/ ndo->ndo_protocol = "nfs"; nfserr = 0; /* assume no error */ rp = (const struct sunrpc_msg *)bp; ND_TCHECK_4(rp->rm_xid); if (!ndo->ndo_nflag) { strlcpy(srcid, "nfs", sizeof(srcid)); nd_snprintf(dstid, sizeof(dstid), "%u", EXTRACT_BE_U_4(rp->rm_xid)); } else { nd_snprintf(srcid, sizeof(srcid), "%u", NFS_PORT); nd_snprintf(dstid, sizeof(dstid), "%u", EXTRACT_BE_U_4(rp->rm_xid)); } print_nfsaddr(ndo, bp2, srcid, dstid); nfsreply_noaddr_print(ndo, bp, length, bp2); return; trunc: if (!nfserr) nd_print_trunc(ndo); }
/* * Return path to "%SystemRoot%/drivers/etc/<file>" (Win-NT+) * or to "%Windir%/etc/<file>" (Win-9x/ME) */ const char *etc_path (const char *file) { BOOL win9x = is_win9x(); const char *env = win9x ? getenv("WinDir") : getenv("SystemRoot"); static char path[MAX_PATH]; if (!env) return (file); if (win9x) nd_snprintf (path, sizeof(path), "%s\\etc\\%s", env, file); else nd_snprintf (path, sizeof(path), "%s\\system32\\drivers\\etc\\%s", env, file); return (path); }
static char * stp_print_bridge_id(const u_char *p) { static char bridge_id_str[sizeof("pppp.aa:bb:cc:dd:ee:ff")]; nd_snprintf(bridge_id_str, sizeof(bridge_id_str), "%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", EXTRACT_U_1(p), EXTRACT_U_1(p + 1), EXTRACT_U_1(p + 2), EXTRACT_U_1(p + 3), EXTRACT_U_1(p + 4), EXTRACT_U_1(p + 5), EXTRACT_U_1(p + 6), EXTRACT_U_1(p + 7)); return bridge_id_str; }
static char * progstr(uint32_t prog) { #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) 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) nd_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); }
void sunrpc_print(netdissect_options *ndo, const u_char *bp, u_int length, const u_char *bp2) { 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 = (const struct sunrpc_msg *)bp; if (!ndo->ndo_nflag) { nd_snprintf(srcid, sizeof(srcid), "0x%x", EXTRACT_BE_U_4(rp->rm_xid)); strlcpy(dstid, "sunrpc", sizeof(dstid)); } else { nd_snprintf(srcid, sizeof(srcid), "0x%x", EXTRACT_BE_U_4(rp->rm_xid)); nd_snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT); } switch (IP_V((const struct ip *)bp2)) { case 4: ip = (const struct ip *)bp2; ND_PRINT("%s.%s > %s.%s: %u", 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("%s.%s > %s.%s: %u", ip6addr_string(ndo, ip6->ip6_src), srcid, ip6addr_string(ndo, ip6->ip6_dst), dstid, length); break; default: ND_PRINT("%s.%s > %s.%s: %u", "?", srcid, "?", dstid, length); break; } ND_PRINT(" %s", tok2str(proc2str, " proc #%u", EXTRACT_BE_U_4(rp->rm_call.cb_proc))); x = EXTRACT_BE_U_4(rp->rm_call.cb_rpcvers); if (x != 2) ND_PRINT(" [rpcver %u]", x); switch (EXTRACT_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_BE_U_4(rp->rm_call.cb_prog); if (!ndo->ndo_nflag) ND_PRINT(" %s", progstr(x)); else ND_PRINT(" %u", x); ND_PRINT(".%u", EXTRACT_BE_U_4(rp->rm_call.cb_vers)); break; } }
void Parse_fh(netdissect_options *ndo, const unsigned char *fh, u_int len, my_fsid *fsidp, uint32_t *inop, const char **osnamep, /* if non-NULL, return OS name here */ const char **fsnamep, /* if non-NULL, return server fs name here (for VMS) */ int ourself) /* true if file handle was generated on this host */ { const unsigned char *fhp = fh; uint32_t temp; int fhtype = FHT_UNKNOWN; u_int i; /* * Require at least 16 bytes of file handle; it's variable-length * in NFSv3. "len" is in units of 32-bit words, not bytes. */ if (len < 16/4) fhtype = FHT_UNKNOWN; else { if (ourself) { /* File handle generated on this host, no need for guessing */ #if defined(IRIX40) fhtype = FHT_IRIX4; #endif #if defined(IRIX50) fhtype = FHT_IRIX5; #endif #if defined(IRIX51) fhtype = FHT_IRIX5; #endif #if defined(SUNOS4) fhtype = FHT_SUNOS4; #endif #if defined(SUNOS5) fhtype = FHT_SUNOS5; #endif #if defined(ultrix) fhtype = FHT_ULTRIX; #endif #if defined(__osf__) fhtype = FHT_DECOSF; #endif #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) \ || defined(__OpenBSD__) fhtype = FHT_BSD44; #endif } /* * This is basically a big decision tree */ else if ((GET_U_1(fhp) == 0) && (GET_U_1(fhp + 1) == 0)) { /* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */ /* probably rules out HP-UX, AIX unless they allow major=0 */ if ((GET_U_1(fhp + 2) == 0) && (GET_U_1(fhp + 3) == 0)) { /* bytes[2,3] == (0,0); must be Auspex */ /* XXX or could be Ultrix+MASSBUS "hp" disk? */ fhtype = FHT_AUSPEX; } else { /* * bytes[2,3] != (0,0); rules out Auspex, could be * DECOSF, SUNOS4, or IRIX4 */ if ((GET_U_1(fhp + 4) != 0) && (GET_U_1(fhp + 5) == 0) && (GET_U_1(fhp + 8) == 12) && (GET_U_1(fhp + 9) == 0)) { /* seems to be DECOSF, with minor == 0 */ fhtype = FHT_DECOSF; } else { /* could be SUNOS4 or IRIX4 */ /* XXX the test of fhp[5] == 8 could be wrong */ if ((GET_U_1(fhp + 4) == 0) && (GET_U_1(fhp + 5) == 8) && (GET_U_1(fhp + 6) == 0) && (GET_U_1(fhp + 7) == 0)) { /* looks like a length, not a file system typecode */ fhtype = FHT_IRIX4; } else { /* by elimination */ fhtype = FHT_SUNOS4; } } } } else { /* * bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4 * could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5 * could be AIX, HP-UX */ if ((GET_U_1(fhp + 2) == 0) && (GET_U_1(fhp + 3) == 0)) { /* * bytes[2,3] == (0,0); rules out OSF, probably not UCX * (unless the exported device name is just one letter!), * could be Ultrix, IRIX5, AIX, or SUNOS5 * might be HP-UX (depends on their values for minor devs) */ if ((GET_U_1(fhp + 6) == 0) && (GET_U_1(fhp + 7) == 0)) { fhtype = FHT_BSD44; } /*XXX we probably only need to test of these two bytes */ else if ((len >= 24/4) && (GET_U_1(fhp + 21) == 0) && (GET_U_1(fhp + 23) == 0)) { fhtype = FHT_ULTRIX; } else { /* Could be SUNOS5/IRIX5, maybe AIX */ /* XXX no obvious difference between SUNOS5 and IRIX5 */ if (GET_U_1(fhp + 9) == 10) fhtype = FHT_SUNOS5; /* XXX what about AIX? */ } } else { /* * bytes[2,3] != (0,0); rules out Ultrix, could be * DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX */ if ((GET_U_1(fhp + 8) == 12) && (GET_U_1(fhp + 9) == 0)) { fhtype = FHT_DECOSF; } else if ((GET_U_1(fhp + 8) == 0) && (GET_U_1(fhp + 9) == 10)) { /* could be SUNOS5/IRIX5, AIX, HP-UX */ if ((GET_U_1(fhp + 7) == 0) && (GET_U_1(fhp + 6) == 0) && (GET_U_1(fhp + 5) == 0) && (GET_U_1(fhp + 4) == 0)) { /* XXX is this always true of HP-UX? */ fhtype = FHT_HPUX9; } else if (GET_U_1(fhp + 7) == 2) { /* This would be MNT_NFS on AIX, which is impossible */ fhtype = FHT_SUNOS5; /* or maybe IRIX5 */ } else { /* * XXX Could be SUNOS5/IRIX5 or AIX. I don't * XXX see any way to disambiguate these, so * XXX I'm going with the more likely guess. * XXX Sorry, Big Blue. */ fhtype = FHT_SUNOS5; /* or maybe IRIX5 */ } } else { if (is_UCX(ndo, fhp, len)) { fhtype = FHT_VMSUCX; } else { fhtype = FHT_UNKNOWN; } } } } } /* XXX still needs to handle SUNOS3 */ switch (fhtype) { case FHT_AUSPEX: fsidp->Fsid_dev.Minor = GET_U_1(fhp + 7); fsidp->Fsid_dev.Major = GET_U_1(fhp + 6); fsidp->fsid_code = 0; *inop = GET_BE_U_4(fhp + 12); if (osnamep) *osnamep = "Auspex"; break; case FHT_BSD44: fsidp->Fsid_dev.Minor = GET_U_1(fhp); fsidp->Fsid_dev.Major = GET_U_1(fhp + 1); fsidp->fsid_code = 0; *inop = GET_LE_U_4(fhp + 12); if (osnamep) *osnamep = "BSD 4.4"; break; case FHT_DECOSF: fsidp->fsid_code = GET_LE_U_4(fhp + 4); /* XXX could ignore 3 high-order bytes */ temp = GET_LE_U_4(fhp); fsidp->Fsid_dev.Minor = temp & 0xFFFFF; fsidp->Fsid_dev.Major = (temp>>20) & 0xFFF; *inop = GET_LE_U_4(fhp + 12); if (osnamep) *osnamep = "OSF"; break; case FHT_IRIX4: fsidp->Fsid_dev.Minor = GET_U_1(fhp + 3); fsidp->Fsid_dev.Major = GET_U_1(fhp + 2); fsidp->fsid_code = 0; *inop = GET_BE_U_4(fhp + 8); if (osnamep) *osnamep = "IRIX4"; break; case FHT_IRIX5: fsidp->Fsid_dev.Minor = GET_BE_U_2(fhp + 2); fsidp->Fsid_dev.Major = GET_BE_U_2(fhp); fsidp->fsid_code = GET_BE_U_4(fhp + 4); *inop = GET_BE_U_4(fhp + 12); if (osnamep) *osnamep = "IRIX5"; break; #ifdef notdef case FHT_SUNOS3: /* * XXX - none of the heuristics above return this. * Are there any SunOS 3.x systems around to care about? */ if (osnamep) *osnamep = "SUNOS3"; break; #endif case FHT_SUNOS4: fsidp->Fsid_dev.Minor = GET_U_1(fhp + 3); fsidp->Fsid_dev.Major = GET_U_1(fhp + 2); fsidp->fsid_code = GET_BE_U_4(fhp + 4); *inop = GET_BE_U_4(fhp + 12); if (osnamep) *osnamep = "SUNOS4"; break; case FHT_SUNOS5: temp = GET_BE_U_2(fhp); fsidp->Fsid_dev.Major = (temp>>2) & 0x3FFF; temp = GET_BE_U_3(fhp + 1); fsidp->Fsid_dev.Minor = temp & 0x3FFFF; fsidp->fsid_code = GET_BE_U_4(fhp + 4); *inop = GET_BE_U_4(fhp + 12); if (osnamep) *osnamep = "SUNOS5"; break; case FHT_ULTRIX: fsidp->fsid_code = 0; fsidp->Fsid_dev.Minor = GET_U_1(fhp); fsidp->Fsid_dev.Major = GET_U_1(fhp + 1); temp = GET_LE_U_4(fhp + 4); *inop = temp; if (osnamep) *osnamep = "Ultrix"; break; case FHT_VMSUCX: /* No numeric file system ID, so hash on the device-name */ if (sizeof(*fsidp) >= 14) { if (sizeof(*fsidp) > 14) memset((char *)fsidp, 0, sizeof(*fsidp)); /* just use the whole thing */ memcpy((char *)fsidp, (const char *)fh, 14); } else { uint32_t tempa[4]; /* at least 16 bytes, maybe more */ memset((char *)tempa, 0, sizeof(tempa)); memcpy((char *)tempa, (const char *)fh, 14); /* ensure alignment */ fsidp->Fsid_dev.Minor = tempa[0] + (tempa[1]<<1); fsidp->Fsid_dev.Major = tempa[2] + (tempa[3]<<1); fsidp->fsid_code = 0; } /* VMS file ID is: (RVN, FidHi, FidLo) */ *inop = (((uint32_t) GET_U_1(fhp + 26)) << 24) | (((uint32_t) GET_U_1(fhp + 27)) << 16) | (GET_LE_U_2(fhp + 22) << 0); /* Caller must save (and null-terminate?) this value */ if (fsnamep) *fsnamep = (const char *)(fhp + 1); if (osnamep) *osnamep = "VMS"; break; case FHT_AIX32: fsidp->Fsid_dev.Minor = GET_BE_U_2(fhp + 2); fsidp->Fsid_dev.Major = GET_BE_U_2(fhp); fsidp->fsid_code = GET_BE_U_4(fhp + 4); *inop = GET_BE_U_4(fhp + 12); if (osnamep) *osnamep = "AIX32"; break; case FHT_HPUX9: fsidp->Fsid_dev.Major = GET_U_1(fhp); temp = GET_BE_U_3(fhp + 1); fsidp->Fsid_dev.Minor = temp; fsidp->fsid_code = GET_BE_U_4(fhp + 4); *inop = GET_BE_U_4(fhp + 12); if (osnamep) *osnamep = "HPUX9"; break; case FHT_UNKNOWN: #ifdef DEBUG /* XXX debugging */ for (i = 0; i < len*4; i++) (void)fprintf(stderr, "%x.", GET_U_1(fhp + i)); (void)fprintf(stderr, "\n"); #endif /* Save the actual handle, so it can be display with -u */ for (i = 0; i < len*4 && i*2 < sizeof(fsidp->Opaque_Handle) - 1; i++) (void)nd_snprintf(&(fsidp->Opaque_Handle[i*2]), 3, "%.2X", GET_U_1(fhp + i)); fsidp->Opaque_Handle[i*2] = '\0'; /* XXX for now, give "bogus" values to aid debugging */ fsidp->fsid_code = 0; fsidp->Fsid_dev.Minor = 257; fsidp->Fsid_dev.Major = 257; *inop = 1; /* display will show this string instead of (257,257) */ if (fsnamep) *fsnamep = "Unknown"; if (osnamep) *osnamep = "Unknown"; break; } }