print-rx.c
来自「TCPDUMP的C语言源代码,是在数据链路层的应用」· C语言 代码 · 共 2,799 行 · 第 1/4 页
C
2,799 行
i = EXTRACT_32BITS(bp); \ bp += sizeof(int32_t); \ printf(" %lu", i); \ }#define UINT64OUT() { u_int64_t i; \ TCHECK2(bp[0], sizeof(u_int64_t)); \ i = EXTRACT_64BITS(bp); \ bp += sizeof(u_int64_t); \ printf(" %" PRIu64, i); \ }#define DATEOUT() { time_t t; struct tm *tm; char str[256]; \ TCHECK2(bp[0], sizeof(int32_t)); \ t = (time_t) EXTRACT_32BITS(bp); \ bp += sizeof(int32_t); \ tm = localtime(&t); \ strftime(str, 256, "%Y/%m/%d %T", tm); \ printf(" %s", str); \ }#define STOREATTROUT() { unsigned long mask, i; \ TCHECK2(bp[0], (sizeof(int32_t)*6)); \ mask = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \ if (mask) printf (" StoreStatus"); \ if (mask & 1) { printf(" date"); DATEOUT(); } \ else bp += sizeof(int32_t); \ i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \ if (mask & 2) printf(" owner %lu", i); \ i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \ if (mask & 4) printf(" group %lu", i); \ i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \ if (mask & 8) printf(" mode %lo", i & 07777); \ i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \ if (mask & 16) printf(" segsize %lu", i); \ /* undocumented in 3.3 docu */ \ if (mask & 1024) printf(" fsync"); \ }#define UBIK_VERSIONOUT() {int32_t epoch; int32_t counter; \ TCHECK2(bp[0], sizeof(int32_t) * 2); \ epoch = EXTRACT_32BITS(bp); \ bp += sizeof(int32_t); \ counter = EXTRACT_32BITS(bp); \ bp += sizeof(int32_t); \ printf(" %d.%d", epoch, counter); \ }#define AFSUUIDOUT() {u_int32_t temp; int i; \ TCHECK2(bp[0], 11*sizeof(u_int32_t)); \ temp = EXTRACT_32BITS(bp); \ bp += sizeof(u_int32_t); \ printf(" %08x", temp); \ temp = EXTRACT_32BITS(bp); \ bp += sizeof(u_int32_t); \ printf("%04x", temp); \ temp = EXTRACT_32BITS(bp); \ bp += sizeof(u_int32_t); \ printf("%04x", temp); \ for (i = 0; i < 8; i++) { \ temp = EXTRACT_32BITS(bp); \ bp += sizeof(u_int32_t); \ printf("%02x", (unsigned char) temp); \ } \ }/* * This is the sickest one of all */#define VECOUT(MAX) { u_char *sp; \ u_char s[AFSNAMEMAX]; \ int k; \ if ((MAX) + 1 > sizeof(s)) \ goto trunc; \ TCHECK2(bp[0], (MAX) * sizeof(int32_t)); \ sp = s; \ for (k = 0; k < (MAX); k++) { \ *sp++ = (u_char) EXTRACT_32BITS(bp); \ bp += sizeof(int32_t); \ } \ s[(MAX)] = '\0'; \ printf(" \""); \ fn_print(s, NULL); \ printf("\""); \ }#define DESTSERVEROUT() { unsigned long n1, n2, n3; \ TCHECK2(bp[0], sizeof(int32_t) * 3); \ n1 = EXTRACT_32BITS(bp); \ bp += sizeof(int32_t); \ n2 = EXTRACT_32BITS(bp); \ bp += sizeof(int32_t); \ n3 = EXTRACT_32BITS(bp); \ bp += sizeof(int32_t); \ printf(" server %d:%d:%d", (int) n1, (int) n2, (int) n3); \ }/* * Handle calls to the AFS file service (fs) */static voidfs_print(register const u_char *bp, int length){ int fs_op; unsigned long i; if (length <= (int)sizeof(struct rx_header)) return; if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) { goto trunc; } /* * Print out the afs call we're invoking. The table used here was * gleaned from fsint/afsint.xg */ fs_op = EXTRACT_32BITS(bp + sizeof(struct rx_header)); printf(" fs call %s", tok2str(fs_req, "op#%d", fs_op)); /* * Print out arguments to some of the AFS calls. This stuff is * all from afsint.xg */ bp += sizeof(struct rx_header) + 4; /* * Sigh. This is gross. Ritchie forgive me. */ switch (fs_op) { case 130: /* Fetch data */ FIDOUT(); printf(" offset"); UINTOUT(); printf(" length"); UINTOUT(); break; case 131: /* Fetch ACL */ case 132: /* Fetch Status */ case 143: /* Old set lock */ case 144: /* Old extend lock */ case 145: /* Old release lock */ case 156: /* Set lock */ case 157: /* Extend lock */ case 158: /* Release lock */ FIDOUT(); break; case 135: /* Store status */ FIDOUT(); STOREATTROUT(); break; case 133: /* Store data */ FIDOUT(); STOREATTROUT(); printf(" offset"); UINTOUT(); printf(" length"); UINTOUT(); printf(" flen"); UINTOUT(); break; case 134: /* Store ACL */ { char a[AFSOPAQUEMAX+1]; FIDOUT(); TCHECK2(bp[0], 4); i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); TCHECK2(bp[0], i); i = min(AFSOPAQUEMAX, i); strncpy(a, (char *) bp, i); a[i] = '\0'; acl_print((u_char *) a, sizeof(a), (u_char *) a + i); break; } case 137: /* Create file */ case 141: /* MakeDir */ FIDOUT(); STROUT(AFSNAMEMAX); STOREATTROUT(); break; case 136: /* Remove file */ case 142: /* Remove directory */ FIDOUT(); STROUT(AFSNAMEMAX); break; case 138: /* Rename file */ printf(" old"); FIDOUT(); STROUT(AFSNAMEMAX); printf(" new"); FIDOUT(); STROUT(AFSNAMEMAX); break; case 139: /* Symlink */ FIDOUT(); STROUT(AFSNAMEMAX); printf(" link to"); STROUT(AFSNAMEMAX); break; case 140: /* Link */ FIDOUT(); STROUT(AFSNAMEMAX); printf(" link to"); FIDOUT(); break; case 148: /* Get volume info */ STROUT(AFSNAMEMAX); break; case 149: /* Get volume stats */ case 150: /* Set volume stats */ printf(" volid"); UINTOUT(); break; case 154: /* New get volume info */ printf(" volname"); STROUT(AFSNAMEMAX); break; case 155: /* Bulk stat */ case 65536: /* Inline bulk stat */ { unsigned long j; TCHECK2(bp[0], 4); j = EXTRACT_32BITS(bp); bp += sizeof(int32_t); for (i = 0; i < j; i++) { FIDOUT(); if (i != j - 1) printf(","); } if (j == 0) printf(" <none!>"); } case 65537: /* Fetch data 64 */ FIDOUT(); printf(" offset"); UINT64OUT(); printf(" length"); UINT64OUT(); break; case 65538: /* Store data 64 */ FIDOUT(); STOREATTROUT(); printf(" offset"); UINT64OUT(); printf(" length"); UINT64OUT(); printf(" flen"); UINT64OUT(); break; case 65541: /* CallBack rx conn address */ printf(" addr"); UINTOUT(); default: ; } return;trunc: printf(" [|fs]");}/* * Handle replies to the AFS file service */static voidfs_reply_print(register const u_char *bp, int length, int32_t opcode){ unsigned long i; struct rx_header *rxh; if (length <= (int)sizeof(struct rx_header)) return; rxh = (struct rx_header *) bp; /* * Print out the afs call we're invoking. The table used here was * gleaned from fsint/afsint.xg */ printf(" fs reply %s", tok2str(fs_req, "op#%d", opcode)); bp += sizeof(struct rx_header); /* * If it was a data packet, interpret the response */ if (rxh->type == RX_PACKET_TYPE_DATA) { switch (opcode) { case 131: /* Fetch ACL */ { char a[AFSOPAQUEMAX+1]; TCHECK2(bp[0], 4); i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); TCHECK2(bp[0], i); i = min(AFSOPAQUEMAX, i); strncpy(a, (char *) bp, i); a[i] = '\0'; acl_print((u_char *) a, sizeof(a), (u_char *) a + i); break; } case 137: /* Create file */ case 141: /* MakeDir */ printf(" new"); FIDOUT(); break; case 151: /* Get root volume */ printf(" root volume"); STROUT(AFSNAMEMAX); break; case 153: /* Get time */ DATEOUT(); break; default: ; } } else if (rxh->type == RX_PACKET_TYPE_ABORT) { int i; /* * Otherwise, just print out the return code */ TCHECK2(bp[0], sizeof(int32_t)); i = (int) EXTRACT_32BITS(bp); bp += sizeof(int32_t); printf(" error %s", tok2str(afs_fs_errors, "#%d", i)); } else { printf(" strange fs reply of type %d", rxh->type); } return;trunc: printf(" [|fs]");}/* * Print out an AFS ACL string. An AFS ACL is a string that has the * following format: * * <positive> <negative> * <uid1> <aclbits1> * .... * * "positive" and "negative" are integers which contain the number of * positive and negative ACL's in the string. The uid/aclbits pair are * ASCII strings containing the UID/PTS record and and a ascii number * representing a logical OR of all the ACL permission bits */static voidacl_print(u_char *s, int maxsize, u_char *end){ int pos, neg, acl; int n, i; char *user; char fmt[1024]; if ((user = (char *)malloc(maxsize)) == NULL) return; if (sscanf((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2) goto finish; s += n; if (s > end) goto finish; /* * This wacky order preserves the order used by the "fs" command */#define ACLOUT(acl) \ if (acl & PRSFS_READ) \ printf("r"); \ if (acl & PRSFS_LOOKUP) \ printf("l"); \ if (acl & PRSFS_INSERT) \ printf("i"); \ if (acl & PRSFS_DELETE) \ printf("d"); \ if (acl & PRSFS_WRITE) \ printf("w"); \ if (acl & PRSFS_LOCK) \ printf("k"); \ if (acl & PRSFS_ADMINISTER) \ printf("a"); for (i = 0; i < pos; i++) { snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1); if (sscanf((char *) s, fmt, user, &acl, &n) != 2) goto finish; s += n; printf(" +{"); fn_print((u_char *)user, NULL); printf(" "); ACLOUT(acl); printf("}"); if (s > end) goto finish; } for (i = 0; i < neg; i++) { snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1); if (sscanf((char *) s, fmt, user, &acl, &n) != 2) goto finish; s += n; printf(" -{"); fn_print((u_char *)user, NULL); printf(" "); ACLOUT(acl); printf("}"); if (s > end) goto finish; }finish: free(user); return;}#undef ACLOUT/* * Handle calls to the AFS callback service */static voidcb_print(register const u_char *bp, int length){ int cb_op; unsigned long i; if (length <= (int)sizeof(struct rx_header)) return; if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) { goto trunc; } /* * Print out the afs call we're invoking. The table used here was * gleaned from fsint/afscbint.xg */ cb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header)); printf(" cb call %s", tok2str(cb_req, "op#%d", cb_op)); bp += sizeof(struct rx_header) + 4; /* * Print out the afs call we're invoking. The table used here was * gleaned from fsint/afscbint.xg */ switch (cb_op) { case 204: /* Callback */ { unsigned long j, t; TCHECK2(bp[0], 4); j = EXTRACT_32BITS(bp); bp += sizeof(int32_t); for (i = 0; i < j; i++) { FIDOUT(); if (i != j - 1) printf(","); } if (j == 0) printf(" <none!>"); j = EXTRACT_32BITS(bp); bp += sizeof(int32_t); if (j != 0) printf(";"); for (i = 0; i < j; i++) { printf(" ver"); INTOUT(); printf(" expires"); DATEOUT(); TCHECK2(bp[0], 4); t = EXTRACT_32BITS(bp); bp += sizeof(int32_t); tok2str(cb_types, "type %d", t); } } case 214: { printf(" afsuuid"); AFSUUIDOUT(); break; } default: ; } return;trunc: printf(" [|cb]");}/* * Handle replies to the AFS Callback Service */static voidcb_reply_print(register const u_char *bp, int length, int32_t opcode){ struct rx_header *rxh; if (length <= (int)sizeof(struct rx_header)) return; rxh = (struct rx_header *) bp; /* * Print out the afs call we're invoking. The table used here was * gleaned from fsint/afscbint.xg */ printf(" cb reply %s", tok2str(cb_req, "op#%d", opcode)); bp += sizeof(struct rx_header); /* * If it was a data packet, interpret the response. */ if (rxh->type == RX_PACKET_TYPE_DATA) switch (opcode) { case 213: /* InitCallBackState3 */ AFSUUIDOUT(); break; default: ; } else { /* * Otherwise, just print out the return code */ printf(" errcode"); INTOUT(); } return;trunc: printf(" [|cb]");}/* * Handle calls to the AFS protection database server */static voidprot_print(register const u_char *bp, int length){ unsigned long i; int pt_op; if (length <= (int)sizeof(struct rx_header)) return; if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) { goto trunc; } /* * Print out the afs call we're invoking. The table used here was * gleaned from ptserver/ptint.xg */ pt_op = EXTRACT_32BITS(bp + sizeof(struct rx_header)); printf(" pt"); if (is_ubik(pt_op)) { ubik_print(bp); return; } printf(" call %s", tok2str(pt_req, "op#%d", pt_op)); /* * Decode some of the arguments to the PT calls */ bp += sizeof(struct rx_header) + 4; switch (pt_op) { case 500: /* I New User */ STROUT(PRNAMEMAX); printf(" id"); INTOUT(); printf(" oldid"); INTOUT(); break; case 501: /* Where is it */ case 506: /* Delete */ case 508: /* Get CPS */ case 512: /* List entry */ case 514: /* List elements */ case 517: /* List owned */ case 518: /* Get CPS2 */ case 519: /* Get host CPS */ case 530: /* List super groups */ printf(" id"); INTOUT(); break; case 502: /* Dump entry */ printf(" pos"); INTOUT(); break; case 503: /* Add to group */ case 507: /* Remove from group */ case 515: /* Is a member of? */ printf(" uid"); INTOUT(); printf(" gid"); INTOUT(); break; case 504: /* Name to ID */ { unsigned long j; TCHECK2(bp[0], 4); j = EXTRACT_32BITS(bp); bp += sizeof(int32_t); /* * Who designed this chicken-shit protocol? * * Each character is stored as a 32-bit * integer! */ for (i = 0; i < j; i++) { VECOUT(PRNAMEMAX); } if (j == 0) printf(" <none!>"); } break; case 505: /* Id to name */ { unsigned long j; printf(" ids:"); TCHECK2(bp[0], 4); i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); for (j = 0; j < i; j++) INTOUT(); if (j == 0) printf(" <none!>"); } break; case 509: /* New entry */ STROUT(PRNAMEMAX); printf(" flag"); INTOUT(); printf(" oid"); INTOUT(); break; case 511: /* Set max */ printf(" id"); INTOUT(); printf(" gflag"); INTOUT(); break; case 513: /* Change entry */ printf(" id"); INTOUT(); STROUT(PRNAMEMAX); printf(" oldid"); INTOUT(); printf(" newid"); INTOUT(); break; case 520: /* Update entry */ printf(" id"); INTOUT(); STROUT(PRNAMEMAX); break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?