141c99275SPeter Avalos /*
241c99275SPeter Avalos * Copyright (c) 1993, 1994 Jeffrey C. Mogul, Digital Equipment Corporation,
341c99275SPeter Avalos * Western Research Laboratory. All rights reserved.
441c99275SPeter Avalos * Copyright (c) 2001 Compaq Computer Corporation. All rights reserved.
541c99275SPeter Avalos *
641c99275SPeter Avalos * Permission to use, copy, and modify this software and its
741c99275SPeter Avalos * documentation is hereby granted only under the following terms and
841c99275SPeter Avalos * conditions. Both the above copyright notice and this permission
941c99275SPeter Avalos * notice must appear in all copies of the software, derivative works
1041c99275SPeter Avalos * or modified versions, and any portions thereof, and both notices
1141c99275SPeter Avalos * must appear in supporting documentation.
1241c99275SPeter Avalos *
1341c99275SPeter Avalos * Redistribution and use in source and binary forms, with or without
1441c99275SPeter Avalos * modification, are permitted provided that the following conditions
1541c99275SPeter Avalos * are met:
1641c99275SPeter Avalos * 1. Redistributions of source code must retain the above copyright
1741c99275SPeter Avalos * notice, this list of conditions and the following disclaimer.
1841c99275SPeter Avalos * 2. Redistributions in binary form must reproduce the above copyright
1941c99275SPeter Avalos * notice, this list of conditions and the following disclaimer in
2041c99275SPeter Avalos * the documentation and/or other materials provided with the
2141c99275SPeter Avalos * distribution.
2241c99275SPeter Avalos *
2341c99275SPeter Avalos * THE SOFTWARE IS PROVIDED "AS IS" AND COMPAQ COMPUTER CORPORATION
2441c99275SPeter Avalos * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
2541c99275SPeter Avalos * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
2641c99275SPeter Avalos * EVENT SHALL COMPAQ COMPUTER CORPORATION BE LIABLE FOR ANY
2741c99275SPeter Avalos * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2841c99275SPeter Avalos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
2941c99275SPeter Avalos * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
3041c99275SPeter Avalos * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
3141c99275SPeter Avalos * SOFTWARE.
3241c99275SPeter Avalos */
3341c99275SPeter Avalos
3441c99275SPeter Avalos /*
3541c99275SPeter Avalos * parsenfsfh.c - portable parser for NFS file handles
3641c99275SPeter Avalos * uses all sorts of heuristics
3741c99275SPeter Avalos *
3841c99275SPeter Avalos * Jeffrey C. Mogul
3941c99275SPeter Avalos * Digital Equipment Corporation
4041c99275SPeter Avalos * Western Research Laboratory
4141c99275SPeter Avalos */
4241c99275SPeter Avalos
4341c99275SPeter Avalos #ifdef HAVE_CONFIG_H
44*ed775ee7SAntonio Huete Jimenez #include <config.h>
4541c99275SPeter Avalos #endif
4641c99275SPeter Avalos
47*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
4841c99275SPeter Avalos
4941c99275SPeter Avalos #include <stdio.h>
5041c99275SPeter Avalos #include <string.h>
5141c99275SPeter Avalos
52*ed775ee7SAntonio Huete Jimenez #include "netdissect-ctype.h"
53*ed775ee7SAntonio Huete Jimenez
54411677aeSAaron LI #include "netdissect.h"
55*ed775ee7SAntonio Huete Jimenez #include "extract.h"
5641c99275SPeter Avalos #include "nfsfh.h"
5741c99275SPeter Avalos
5841c99275SPeter Avalos /*
5941c99275SPeter Avalos * This routine attempts to parse a file handle (in network byte order),
6041c99275SPeter Avalos * using heuristics to guess what kind of format it is in. See the
6141c99275SPeter Avalos * file "fhandle_layouts" for a detailed description of the various
6241c99275SPeter Avalos * patterns we know about.
6341c99275SPeter Avalos *
6441c99275SPeter Avalos * The file handle is parsed into our internal representation of a
6541c99275SPeter Avalos * file-system id, and an internal representation of an inode-number.
6641c99275SPeter Avalos */
6741c99275SPeter Avalos
6841c99275SPeter Avalos #define FHT_UNKNOWN 0
6941c99275SPeter Avalos #define FHT_AUSPEX 1
7041c99275SPeter Avalos #define FHT_DECOSF 2
7141c99275SPeter Avalos #define FHT_IRIX4 3
7241c99275SPeter Avalos #define FHT_IRIX5 4
7341c99275SPeter Avalos #define FHT_SUNOS3 5
7441c99275SPeter Avalos #define FHT_SUNOS4 6
7541c99275SPeter Avalos #define FHT_ULTRIX 7
7641c99275SPeter Avalos #define FHT_VMSUCX 8
7741c99275SPeter Avalos #define FHT_SUNOS5 9
7841c99275SPeter Avalos #define FHT_AIX32 10
7941c99275SPeter Avalos #define FHT_HPUX9 11
8041c99275SPeter Avalos #define FHT_BSD44 12
8141c99275SPeter Avalos
82*ed775ee7SAntonio Huete Jimenez static int is_UCX(netdissect_options *, const unsigned char *, u_int);
8341c99275SPeter Avalos
8441c99275SPeter Avalos void
Parse_fh(netdissect_options * ndo,const unsigned char * fh,u_int len,my_fsid * fsidp,uint32_t * inop,const char ** osnamep,const char ** fsnamep,int ourself)85*ed775ee7SAntonio Huete Jimenez Parse_fh(netdissect_options *ndo, const unsigned char *fh, u_int len,
86*ed775ee7SAntonio Huete Jimenez my_fsid *fsidp, uint32_t *inop,
87411677aeSAaron LI const char **osnamep, /* if non-NULL, return OS name here */
88411677aeSAaron LI const char **fsnamep, /* if non-NULL, return server fs name here (for VMS) */
89411677aeSAaron LI int ourself) /* true if file handle was generated on this host */
9041c99275SPeter Avalos {
91*ed775ee7SAntonio Huete Jimenez const unsigned char *fhp = fh;
92411677aeSAaron LI uint32_t temp;
9341c99275SPeter Avalos int fhtype = FHT_UNKNOWN;
94411677aeSAaron LI u_int i;
9541c99275SPeter Avalos
96411677aeSAaron LI /*
97411677aeSAaron LI * Require at least 16 bytes of file handle; it's variable-length
98411677aeSAaron LI * in NFSv3. "len" is in units of 32-bit words, not bytes.
99411677aeSAaron LI */
100411677aeSAaron LI if (len < 16/4)
101411677aeSAaron LI fhtype = FHT_UNKNOWN;
102411677aeSAaron LI else {
10341c99275SPeter Avalos if (ourself) {
10441c99275SPeter Avalos /* File handle generated on this host, no need for guessing */
10541c99275SPeter Avalos #if defined(IRIX40)
10641c99275SPeter Avalos fhtype = FHT_IRIX4;
10741c99275SPeter Avalos #endif
10841c99275SPeter Avalos #if defined(IRIX50)
10941c99275SPeter Avalos fhtype = FHT_IRIX5;
11041c99275SPeter Avalos #endif
11141c99275SPeter Avalos #if defined(IRIX51)
11241c99275SPeter Avalos fhtype = FHT_IRIX5;
11341c99275SPeter Avalos #endif
11441c99275SPeter Avalos #if defined(SUNOS4)
11541c99275SPeter Avalos fhtype = FHT_SUNOS4;
11641c99275SPeter Avalos #endif
11741c99275SPeter Avalos #if defined(SUNOS5)
11841c99275SPeter Avalos fhtype = FHT_SUNOS5;
11941c99275SPeter Avalos #endif
12041c99275SPeter Avalos #if defined(ultrix)
12141c99275SPeter Avalos fhtype = FHT_ULTRIX;
12241c99275SPeter Avalos #endif
12341c99275SPeter Avalos #if defined(__osf__)
12441c99275SPeter Avalos fhtype = FHT_DECOSF;
12541c99275SPeter Avalos #endif
12641c99275SPeter Avalos #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) \
12741c99275SPeter Avalos || defined(__OpenBSD__)
12841c99275SPeter Avalos fhtype = FHT_BSD44;
12941c99275SPeter Avalos #endif
13041c99275SPeter Avalos }
13141c99275SPeter Avalos /*
13241c99275SPeter Avalos * This is basically a big decision tree
13341c99275SPeter Avalos */
134*ed775ee7SAntonio Huete Jimenez else if ((GET_U_1(fhp) == 0) && (GET_U_1(fhp + 1) == 0)) {
13541c99275SPeter Avalos /* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */
13641c99275SPeter Avalos /* probably rules out HP-UX, AIX unless they allow major=0 */
137*ed775ee7SAntonio Huete Jimenez if ((GET_U_1(fhp + 2) == 0) && (GET_U_1(fhp + 3) == 0)) {
13841c99275SPeter Avalos /* bytes[2,3] == (0,0); must be Auspex */
13941c99275SPeter Avalos /* XXX or could be Ultrix+MASSBUS "hp" disk? */
14041c99275SPeter Avalos fhtype = FHT_AUSPEX;
14141c99275SPeter Avalos }
14241c99275SPeter Avalos else {
14341c99275SPeter Avalos /*
14441c99275SPeter Avalos * bytes[2,3] != (0,0); rules out Auspex, could be
14541c99275SPeter Avalos * DECOSF, SUNOS4, or IRIX4
14641c99275SPeter Avalos */
147*ed775ee7SAntonio Huete Jimenez if ((GET_U_1(fhp + 4) != 0) && (GET_U_1(fhp + 5) == 0) &&
148*ed775ee7SAntonio Huete Jimenez (GET_U_1(fhp + 8) == 12) && (GET_U_1(fhp + 9) == 0)) {
14941c99275SPeter Avalos /* seems to be DECOSF, with minor == 0 */
15041c99275SPeter Avalos fhtype = FHT_DECOSF;
15141c99275SPeter Avalos }
15241c99275SPeter Avalos else {
15341c99275SPeter Avalos /* could be SUNOS4 or IRIX4 */
15441c99275SPeter Avalos /* XXX the test of fhp[5] == 8 could be wrong */
155*ed775ee7SAntonio Huete Jimenez if ((GET_U_1(fhp + 4) == 0) && (GET_U_1(fhp + 5) == 8) && (GET_U_1(fhp + 6) == 0) &&
156*ed775ee7SAntonio Huete Jimenez (GET_U_1(fhp + 7) == 0)) {
15741c99275SPeter Avalos /* looks like a length, not a file system typecode */
15841c99275SPeter Avalos fhtype = FHT_IRIX4;
15941c99275SPeter Avalos }
16041c99275SPeter Avalos else {
16141c99275SPeter Avalos /* by elimination */
16241c99275SPeter Avalos fhtype = FHT_SUNOS4;
16341c99275SPeter Avalos }
16441c99275SPeter Avalos }
16541c99275SPeter Avalos }
16641c99275SPeter Avalos }
16741c99275SPeter Avalos else {
16841c99275SPeter Avalos /*
16941c99275SPeter Avalos * bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4
17041c99275SPeter Avalos * could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5
17141c99275SPeter Avalos * could be AIX, HP-UX
17241c99275SPeter Avalos */
173*ed775ee7SAntonio Huete Jimenez if ((GET_U_1(fhp + 2) == 0) && (GET_U_1(fhp + 3) == 0)) {
17441c99275SPeter Avalos /*
17541c99275SPeter Avalos * bytes[2,3] == (0,0); rules out OSF, probably not UCX
17641c99275SPeter Avalos * (unless the exported device name is just one letter!),
17741c99275SPeter Avalos * could be Ultrix, IRIX5, AIX, or SUNOS5
17841c99275SPeter Avalos * might be HP-UX (depends on their values for minor devs)
17941c99275SPeter Avalos */
180*ed775ee7SAntonio Huete Jimenez if ((GET_U_1(fhp + 6) == 0) && (GET_U_1(fhp + 7) == 0)) {
18141c99275SPeter Avalos fhtype = FHT_BSD44;
18241c99275SPeter Avalos }
18341c99275SPeter Avalos /*XXX we probably only need to test of these two bytes */
184*ed775ee7SAntonio Huete Jimenez else if ((len >= 24/4) && (GET_U_1(fhp + 21) == 0) && (GET_U_1(fhp + 23) == 0)) {
18541c99275SPeter Avalos fhtype = FHT_ULTRIX;
18641c99275SPeter Avalos }
18741c99275SPeter Avalos else {
18841c99275SPeter Avalos /* Could be SUNOS5/IRIX5, maybe AIX */
18941c99275SPeter Avalos /* XXX no obvious difference between SUNOS5 and IRIX5 */
190*ed775ee7SAntonio Huete Jimenez if (GET_U_1(fhp + 9) == 10)
19141c99275SPeter Avalos fhtype = FHT_SUNOS5;
19241c99275SPeter Avalos /* XXX what about AIX? */
19341c99275SPeter Avalos }
19441c99275SPeter Avalos }
19541c99275SPeter Avalos else {
19641c99275SPeter Avalos /*
19741c99275SPeter Avalos * bytes[2,3] != (0,0); rules out Ultrix, could be
19841c99275SPeter Avalos * DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX
19941c99275SPeter Avalos */
200*ed775ee7SAntonio Huete Jimenez if ((GET_U_1(fhp + 8) == 12) && (GET_U_1(fhp + 9) == 0)) {
20141c99275SPeter Avalos fhtype = FHT_DECOSF;
20241c99275SPeter Avalos }
203*ed775ee7SAntonio Huete Jimenez else if ((GET_U_1(fhp + 8) == 0) && (GET_U_1(fhp + 9) == 10)) {
20441c99275SPeter Avalos /* could be SUNOS5/IRIX5, AIX, HP-UX */
205*ed775ee7SAntonio Huete Jimenez if ((GET_U_1(fhp + 7) == 0) && (GET_U_1(fhp + 6) == 0) &&
206*ed775ee7SAntonio Huete Jimenez (GET_U_1(fhp + 5) == 0) && (GET_U_1(fhp + 4) == 0)) {
20741c99275SPeter Avalos /* XXX is this always true of HP-UX? */
20841c99275SPeter Avalos fhtype = FHT_HPUX9;
20941c99275SPeter Avalos }
210*ed775ee7SAntonio Huete Jimenez else if (GET_U_1(fhp + 7) == 2) {
21141c99275SPeter Avalos /* This would be MNT_NFS on AIX, which is impossible */
21241c99275SPeter Avalos fhtype = FHT_SUNOS5; /* or maybe IRIX5 */
21341c99275SPeter Avalos }
21441c99275SPeter Avalos else {
21541c99275SPeter Avalos /*
21641c99275SPeter Avalos * XXX Could be SUNOS5/IRIX5 or AIX. I don't
21741c99275SPeter Avalos * XXX see any way to disambiguate these, so
21841c99275SPeter Avalos * XXX I'm going with the more likely guess.
21941c99275SPeter Avalos * XXX Sorry, Big Blue.
22041c99275SPeter Avalos */
22141c99275SPeter Avalos fhtype = FHT_SUNOS5; /* or maybe IRIX5 */
22241c99275SPeter Avalos }
22341c99275SPeter Avalos }
22441c99275SPeter Avalos else {
225*ed775ee7SAntonio Huete Jimenez if (is_UCX(ndo, fhp, len)) {
22641c99275SPeter Avalos fhtype = FHT_VMSUCX;
22741c99275SPeter Avalos }
22841c99275SPeter Avalos else {
22941c99275SPeter Avalos fhtype = FHT_UNKNOWN;
23041c99275SPeter Avalos }
23141c99275SPeter Avalos }
23241c99275SPeter Avalos }
23341c99275SPeter Avalos }
234411677aeSAaron LI }
23541c99275SPeter Avalos
23641c99275SPeter Avalos /* XXX still needs to handle SUNOS3 */
23741c99275SPeter Avalos
23841c99275SPeter Avalos switch (fhtype) {
23941c99275SPeter Avalos case FHT_AUSPEX:
240*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Minor = GET_U_1(fhp + 7);
241*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Major = GET_U_1(fhp + 6);
24241c99275SPeter Avalos fsidp->fsid_code = 0;
24341c99275SPeter Avalos
244*ed775ee7SAntonio Huete Jimenez *inop = GET_BE_U_4(fhp + 12);
24541c99275SPeter Avalos
24641c99275SPeter Avalos if (osnamep)
24741c99275SPeter Avalos *osnamep = "Auspex";
24841c99275SPeter Avalos break;
24941c99275SPeter Avalos
25041c99275SPeter Avalos case FHT_BSD44:
251*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Minor = GET_U_1(fhp);
252*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Major = GET_U_1(fhp + 1);
25341c99275SPeter Avalos fsidp->fsid_code = 0;
25441c99275SPeter Avalos
255*ed775ee7SAntonio Huete Jimenez *inop = GET_LE_U_4(fhp + 12);
25641c99275SPeter Avalos
25741c99275SPeter Avalos if (osnamep)
25841c99275SPeter Avalos *osnamep = "BSD 4.4";
25941c99275SPeter Avalos break;
26041c99275SPeter Avalos
26141c99275SPeter Avalos case FHT_DECOSF:
262*ed775ee7SAntonio Huete Jimenez fsidp->fsid_code = GET_LE_U_4(fhp + 4);
26341c99275SPeter Avalos /* XXX could ignore 3 high-order bytes */
26441c99275SPeter Avalos
265*ed775ee7SAntonio Huete Jimenez temp = GET_LE_U_4(fhp);
26641c99275SPeter Avalos fsidp->Fsid_dev.Minor = temp & 0xFFFFF;
26741c99275SPeter Avalos fsidp->Fsid_dev.Major = (temp>>20) & 0xFFF;
26841c99275SPeter Avalos
269*ed775ee7SAntonio Huete Jimenez *inop = GET_LE_U_4(fhp + 12);
27041c99275SPeter Avalos if (osnamep)
27141c99275SPeter Avalos *osnamep = "OSF";
27241c99275SPeter Avalos break;
27341c99275SPeter Avalos
27441c99275SPeter Avalos case FHT_IRIX4:
275*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Minor = GET_U_1(fhp + 3);
276*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Major = GET_U_1(fhp + 2);
27741c99275SPeter Avalos fsidp->fsid_code = 0;
27841c99275SPeter Avalos
279*ed775ee7SAntonio Huete Jimenez *inop = GET_BE_U_4(fhp + 8);
28041c99275SPeter Avalos
28141c99275SPeter Avalos if (osnamep)
28241c99275SPeter Avalos *osnamep = "IRIX4";
28341c99275SPeter Avalos break;
28441c99275SPeter Avalos
28541c99275SPeter Avalos case FHT_IRIX5:
286*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Minor = GET_BE_U_2(fhp + 2);
287*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Major = GET_BE_U_2(fhp);
288*ed775ee7SAntonio Huete Jimenez fsidp->fsid_code = GET_BE_U_4(fhp + 4);
28941c99275SPeter Avalos
290*ed775ee7SAntonio Huete Jimenez *inop = GET_BE_U_4(fhp + 12);
29141c99275SPeter Avalos
29241c99275SPeter Avalos if (osnamep)
29341c99275SPeter Avalos *osnamep = "IRIX5";
29441c99275SPeter Avalos break;
29541c99275SPeter Avalos
29641c99275SPeter Avalos #ifdef notdef
29741c99275SPeter Avalos case FHT_SUNOS3:
29841c99275SPeter Avalos /*
29941c99275SPeter Avalos * XXX - none of the heuristics above return this.
30041c99275SPeter Avalos * Are there any SunOS 3.x systems around to care about?
30141c99275SPeter Avalos */
30241c99275SPeter Avalos if (osnamep)
30341c99275SPeter Avalos *osnamep = "SUNOS3";
30441c99275SPeter Avalos break;
30541c99275SPeter Avalos #endif
30641c99275SPeter Avalos
30741c99275SPeter Avalos case FHT_SUNOS4:
308*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Minor = GET_U_1(fhp + 3);
309*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Major = GET_U_1(fhp + 2);
310*ed775ee7SAntonio Huete Jimenez fsidp->fsid_code = GET_BE_U_4(fhp + 4);
31141c99275SPeter Avalos
312*ed775ee7SAntonio Huete Jimenez *inop = GET_BE_U_4(fhp + 12);
31341c99275SPeter Avalos
31441c99275SPeter Avalos if (osnamep)
31541c99275SPeter Avalos *osnamep = "SUNOS4";
31641c99275SPeter Avalos break;
31741c99275SPeter Avalos
31841c99275SPeter Avalos case FHT_SUNOS5:
319*ed775ee7SAntonio Huete Jimenez temp = GET_BE_U_2(fhp);
32041c99275SPeter Avalos fsidp->Fsid_dev.Major = (temp>>2) & 0x3FFF;
321*ed775ee7SAntonio Huete Jimenez temp = GET_BE_U_3(fhp + 1);
32241c99275SPeter Avalos fsidp->Fsid_dev.Minor = temp & 0x3FFFF;
323*ed775ee7SAntonio Huete Jimenez fsidp->fsid_code = GET_BE_U_4(fhp + 4);
32441c99275SPeter Avalos
325*ed775ee7SAntonio Huete Jimenez *inop = GET_BE_U_4(fhp + 12);
32641c99275SPeter Avalos
32741c99275SPeter Avalos if (osnamep)
32841c99275SPeter Avalos *osnamep = "SUNOS5";
32941c99275SPeter Avalos break;
33041c99275SPeter Avalos
33141c99275SPeter Avalos case FHT_ULTRIX:
33241c99275SPeter Avalos fsidp->fsid_code = 0;
333*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Minor = GET_U_1(fhp);
334*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Major = GET_U_1(fhp + 1);
33541c99275SPeter Avalos
336*ed775ee7SAntonio Huete Jimenez temp = GET_LE_U_4(fhp + 4);
33741c99275SPeter Avalos *inop = temp;
33841c99275SPeter Avalos if (osnamep)
33941c99275SPeter Avalos *osnamep = "Ultrix";
34041c99275SPeter Avalos break;
34141c99275SPeter Avalos
34241c99275SPeter Avalos case FHT_VMSUCX:
34341c99275SPeter Avalos /* No numeric file system ID, so hash on the device-name */
34441c99275SPeter Avalos if (sizeof(*fsidp) >= 14) {
34541c99275SPeter Avalos if (sizeof(*fsidp) > 14)
34641c99275SPeter Avalos memset((char *)fsidp, 0, sizeof(*fsidp));
34741c99275SPeter Avalos /* just use the whole thing */
348411677aeSAaron LI memcpy((char *)fsidp, (const char *)fh, 14);
34941c99275SPeter Avalos }
35041c99275SPeter Avalos else {
351411677aeSAaron LI uint32_t tempa[4]; /* at least 16 bytes, maybe more */
35241c99275SPeter Avalos
35341c99275SPeter Avalos memset((char *)tempa, 0, sizeof(tempa));
354411677aeSAaron LI memcpy((char *)tempa, (const char *)fh, 14); /* ensure alignment */
35541c99275SPeter Avalos fsidp->Fsid_dev.Minor = tempa[0] + (tempa[1]<<1);
35641c99275SPeter Avalos fsidp->Fsid_dev.Major = tempa[2] + (tempa[3]<<1);
35741c99275SPeter Avalos fsidp->fsid_code = 0;
35841c99275SPeter Avalos }
35941c99275SPeter Avalos
36041c99275SPeter Avalos /* VMS file ID is: (RVN, FidHi, FidLo) */
361*ed775ee7SAntonio Huete Jimenez *inop = (((uint32_t) GET_U_1(fhp + 26)) << 24) |
362*ed775ee7SAntonio Huete Jimenez (((uint32_t) GET_U_1(fhp + 27)) << 16) |
363*ed775ee7SAntonio Huete Jimenez (GET_LE_U_2(fhp + 22) << 0);
36441c99275SPeter Avalos
36541c99275SPeter Avalos /* Caller must save (and null-terminate?) this value */
36641c99275SPeter Avalos if (fsnamep)
367*ed775ee7SAntonio Huete Jimenez *fsnamep = (const char *)(fhp + 1);
36841c99275SPeter Avalos
36941c99275SPeter Avalos if (osnamep)
37041c99275SPeter Avalos *osnamep = "VMS";
37141c99275SPeter Avalos break;
37241c99275SPeter Avalos
37341c99275SPeter Avalos case FHT_AIX32:
374*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Minor = GET_BE_U_2(fhp + 2);
375*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Major = GET_BE_U_2(fhp);
376*ed775ee7SAntonio Huete Jimenez fsidp->fsid_code = GET_BE_U_4(fhp + 4);
37741c99275SPeter Avalos
378*ed775ee7SAntonio Huete Jimenez *inop = GET_BE_U_4(fhp + 12);
37941c99275SPeter Avalos
38041c99275SPeter Avalos if (osnamep)
38141c99275SPeter Avalos *osnamep = "AIX32";
38241c99275SPeter Avalos break;
38341c99275SPeter Avalos
38441c99275SPeter Avalos case FHT_HPUX9:
385*ed775ee7SAntonio Huete Jimenez fsidp->Fsid_dev.Major = GET_U_1(fhp);
386*ed775ee7SAntonio Huete Jimenez temp = GET_BE_U_3(fhp + 1);
38741c99275SPeter Avalos fsidp->Fsid_dev.Minor = temp;
388*ed775ee7SAntonio Huete Jimenez fsidp->fsid_code = GET_BE_U_4(fhp + 4);
38941c99275SPeter Avalos
390*ed775ee7SAntonio Huete Jimenez *inop = GET_BE_U_4(fhp + 12);
39141c99275SPeter Avalos
39241c99275SPeter Avalos if (osnamep)
39341c99275SPeter Avalos *osnamep = "HPUX9";
39441c99275SPeter Avalos break;
39541c99275SPeter Avalos
39641c99275SPeter Avalos case FHT_UNKNOWN:
39741c99275SPeter Avalos #ifdef DEBUG
39841c99275SPeter Avalos /* XXX debugging */
399411677aeSAaron LI for (i = 0; i < len*4; i++)
400*ed775ee7SAntonio Huete Jimenez (void)fprintf(stderr, "%x.", GET_U_1(fhp + i));
40141c99275SPeter Avalos (void)fprintf(stderr, "\n");
40241c99275SPeter Avalos #endif
40341c99275SPeter Avalos /* Save the actual handle, so it can be display with -u */
404411677aeSAaron LI for (i = 0; i < len*4 && i*2 < sizeof(fsidp->Opaque_Handle) - 1; i++)
405*ed775ee7SAntonio Huete Jimenez (void)snprintf(&(fsidp->Opaque_Handle[i*2]), 3, "%.2X",
406*ed775ee7SAntonio Huete Jimenez GET_U_1(fhp + i));
407411677aeSAaron LI fsidp->Opaque_Handle[i*2] = '\0';
40841c99275SPeter Avalos
40941c99275SPeter Avalos /* XXX for now, give "bogus" values to aid debugging */
41041c99275SPeter Avalos fsidp->fsid_code = 0;
41141c99275SPeter Avalos fsidp->Fsid_dev.Minor = 257;
41241c99275SPeter Avalos fsidp->Fsid_dev.Major = 257;
41341c99275SPeter Avalos *inop = 1;
41441c99275SPeter Avalos
41541c99275SPeter Avalos /* display will show this string instead of (257,257) */
41641c99275SPeter Avalos if (fsnamep)
41741c99275SPeter Avalos *fsnamep = "Unknown";
41841c99275SPeter Avalos
41941c99275SPeter Avalos if (osnamep)
42041c99275SPeter Avalos *osnamep = "Unknown";
42141c99275SPeter Avalos break;
42241c99275SPeter Avalos
42341c99275SPeter Avalos }
42441c99275SPeter Avalos }
42541c99275SPeter Avalos
42641c99275SPeter Avalos /*
42741c99275SPeter Avalos * Is this a VMS UCX file handle?
42841c99275SPeter Avalos * Check for:
42941c99275SPeter Avalos * (1) leading code byte [XXX not yet]
43041c99275SPeter Avalos * (2) followed by string of printing chars & spaces
43141c99275SPeter Avalos * (3) followed by string of nulls
43241c99275SPeter Avalos */
43341c99275SPeter Avalos static int
is_UCX(netdissect_options * ndo,const unsigned char * fhp,u_int len)434*ed775ee7SAntonio Huete Jimenez is_UCX(netdissect_options *ndo, const unsigned char *fhp, u_int len)
43541c99275SPeter Avalos {
436*ed775ee7SAntonio Huete Jimenez u_int i;
43741c99275SPeter Avalos int seen_null = 0;
43841c99275SPeter Avalos
439411677aeSAaron LI /*
440411677aeSAaron LI * Require at least 28 bytes of file handle; it's variable-length
441411677aeSAaron LI * in NFSv3. "len" is in units of 32-bit words, not bytes.
442411677aeSAaron LI */
443411677aeSAaron LI if (len < 28/4)
444411677aeSAaron LI return(0);
445411677aeSAaron LI
44641c99275SPeter Avalos for (i = 1; i < 14; i++) {
447*ed775ee7SAntonio Huete Jimenez if (ND_ASCII_ISPRINT(GET_U_1(fhp + i))) {
44841c99275SPeter Avalos if (seen_null)
44941c99275SPeter Avalos return(0);
45041c99275SPeter Avalos else
45141c99275SPeter Avalos continue;
45241c99275SPeter Avalos }
453*ed775ee7SAntonio Huete Jimenez else if (GET_U_1(fhp + i) == 0) {
45441c99275SPeter Avalos seen_null = 1;
45541c99275SPeter Avalos continue;
45641c99275SPeter Avalos }
45741c99275SPeter Avalos else
45841c99275SPeter Avalos return(0);
45941c99275SPeter Avalos }
46041c99275SPeter Avalos
46141c99275SPeter Avalos return(1);
46241c99275SPeter Avalos }
463