X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/b9ac23ce92ca22483d56ee3192c54aa8f782f9ac..4c2790a43252b9cac1fe7f6b50b51c3c55d2370a:/parsenfsfh.c diff --git a/parsenfsfh.c b/parsenfsfh.c index 1759b3a0..d5f877d8 100644 --- a/parsenfsfh.c +++ b/parsenfsfh.c @@ -1,3 +1,36 @@ +/* + * Copyright (c) 1993, 1994 Jeffrey C. Mogul, Digital Equipment Corporation, + * Western Research Laboratory. All rights reserved. + * Copyright (c) 2001 Compaq Computer Corporation. All rights reserved. + * + * Permission to use, copy, and modify this software and its + * documentation is hereby granted only under the following terms and + * conditions. Both the above copyright notice and this permission + * notice must appear in all copies of the software, derivative works + * or modified versions, and any portions thereof, and both notices + * must appear in supporting documentation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND COMPAQ COMPUTER CORPORATION + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO + * EVENT SHALL COMPAQ COMPUTER CORPORATION BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + /* * parsenfsfh.c - portable parser for NFS file handles * uses all sorts of heuristics @@ -8,21 +41,16 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/parsenfsfh.c,v 1.16 1999-11-21 09:36:47 fenner Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/parsenfsfh.c,v 1.29 2006-06-13 22:21:38 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include -#include +#include -#include -#ifdef HAVE_MEMORY_H -#include -#endif #include #include @@ -51,6 +79,7 @@ static const char rcsid[] = #define FHT_SUNOS5 9 #define FHT_AIX32 10 #define FHT_HPUX9 11 +#define FHT_BSD44 12 #ifdef ultrix /* Nasty hack to keep the Ultrix C compiler from emitting bogus warnings */ @@ -78,21 +107,22 @@ static const char rcsid[] = ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24)) #endif -static int is_UCX(unsigned char *); +static int is_UCX(const unsigned char *); void Parse_fh(fh, len, fsidp, inop, osnamep, fsnamep, ourself) -register caddr_t *fh; -int len; +register const unsigned char *fh; +int len _U_; my_fsid *fsidp; ino_t *inop; -char **osnamep; /* if non-NULL, return OS name here */ -char **fsnamep; /* if non-NULL, return server fs name here (for VMS) */ +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 */ { - register unsigned char *fhp = (unsigned char *)fh; + register const unsigned char *fhp = fh; u_int32_t temp; int fhtype = FHT_UNKNOWN; + int i; if (ourself) { /* File handle generated on this host, no need for guessing */ @@ -116,6 +146,10 @@ int ourself; /* true if file handle was generated on this host */ #endif #if defined(__osf__) fhtype = FHT_DECOSF; +#endif +#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) \ + || defined(__OpenBSD__) + fhtype = FHT_BSD44; #endif } /* @@ -167,8 +201,11 @@ int ourself; /* true if file handle was generated on this host */ * could be Ultrix, IRIX5, AIX, or SUNOS5 * might be HP-UX (depends on their values for minor devs) */ + if ((fhp[6] == 0) && (fhp[7] == 0)) { + fhtype = FHT_BSD44; + } /*XXX we probably only need to test of these two bytes */ - if ((fhp[21] == 0) && (fhp[23] == 0)) { + else if ((fhp[21] == 0) && (fhp[23] == 0)) { fhtype = FHT_ULTRIX; } else { @@ -234,6 +271,18 @@ int ourself; /* true if file handle was generated on this host */ *osnamep = "Auspex"; break; + case FHT_BSD44: + fsidp->Fsid_dev.Minor = fhp[0]; + fsidp->Fsid_dev.Major = fhp[1]; + fsidp->fsid_code = 0; + + temp = make_uint32(fhp[15], fhp[14], fhp[13], fhp[12]); + *inop = temp; + + if (osnamep) + *osnamep = "BSD 4.4"; + break; + case FHT_DECOSF: fsidp->fsid_code = make_uint32(fhp[7], fhp[6], fhp[5], fhp[4]); /* XXX could ignore 3 high-order bytes */ @@ -272,10 +321,16 @@ int ourself; /* true if file handle was generated on this host */ *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 = fhp[3]; @@ -370,14 +425,15 @@ int ourself; /* true if file handle was generated on this host */ case FHT_UNKNOWN: #ifdef DEBUG - { - /* XXX debugging */ - int i; - for (i = 0; i < 32; i++) - (void)fprintf(stderr, "%x.", fhp[i]); - (void)fprintf(stderr, "\n"); - } + /* XXX debugging */ + for (i = 0; i < 32; i++) + (void)fprintf(stderr, "%x.", fhp[i]); + (void)fprintf(stderr, "\n"); #endif + /* Save the actual handle, so it can be display with -u */ + for (i = 0; i < 32; i++) + (void)snprintf(&(fsidp->Opaque_Handle[i*2]), 3, "%.2X", fhp[i]); + /* XXX for now, give "bogus" values to aid debugging */ fsidp->fsid_code = 0; fsidp->Fsid_dev.Minor = 257; @@ -404,7 +460,7 @@ int ourself; /* true if file handle was generated on this host */ */ static int is_UCX(fhp) -unsigned char *fhp; +const unsigned char *fhp; { register int i; int seen_null = 0;