📄 print_util.c
字号:
cp += sizeof(uint); break; case LR_END_BASE: case LR_END_SCRIPT_BASE: cp++; break; default: cp++; break; } /* end switch */ } /* end while */ return;}void print_discrete_links_buf(struct links_chars *chars, char *title){ int indx = 0; struct linkrec lp; printf(" %s:-\n", title); while (indx < chars->totchars) { indx = _get_next_link_rec(&lp, indx, chars); printf("\t%30s \t%u\n", lp.url, lp.reltm/1000); } return;}char *icmp_type_string(unsigned char type){ switch (type) { /* add as needed */ case ICMP_UNREACH: return "destination unreachable"; break; default: return "other ICMP type"; break; }}char *icmp_code_string(unsigned char code){ switch (code) { /* add as needed */ case ICMP_UNREACH_NET: return "network unreachable"; break; case ICMP_UNREACH_HOST: return "host unreachable"; break; case ICMP_UNREACH_PROTOCOL: return "protocol unreachable"; break; case ICMP_UNREACH_PORT: return "port unreachable"; break; case ICMP_UNREACH_NEEDFRAG: return "fragmentation"; break; case ICMP_UNREACH_SRCFAIL: return "src route failed"; break; case ICMP_UNREACH_NET_UNKNOWN: return "unknown network"; break; case ICMP_UNREACH_HOST_UNKNOWN: return "unknown host"; break; case ICMP_UNREACH_ISOLATED: return "src host isolated"; break; case ICMP_UNREACH_NET_PROHIB: return "network denied"; break; case ICMP_UNREACH_HOST_PROHIB: return "host denied"; break; case ICMP_UNREACH_TOSNET: return "bad tos for net"; break; case ICMP_UNREACH_TOSHOST: return "bad tos for host"; break; case ICMP_UNREACH_FILTER_PROHIB: return "admin prohibited"; break; case ICMP_UNREACH_HOST_PRECEDENCE: return "host precedence violation"; break; case ICMP_UNREACH_PRECEDENCE_CUTOFF: return "precedence cutoff"; break; default: return "unknown code"; break; }} #endif /* ifdef WREAD */ #define LINE_LEN 64 #ifdef PRINT_OUTvoid print_content(const unsigned char *start, const unsigned char *end, FILE *f){ int i = 0; int zflag = 2; unsigned char *cp = (unsigned char *)start; while(cp < end) { if (i >= LINE_LEN) { fprintf(f, "\n\t"); i = 0; } if (isprint(*cp)) { if (zflag > 1) fprintf(f, "%s%c%s", csf_bld, *cp, csb_def); else fprintf(f, "%c", *cp); i++; } else if (*cp == 0x0a) { fprintf(f, "<NL>\n\t"); /* explicitly show nl */ i = 0; } else if (*cp == 0x0d) { fprintf(f, "<CR>"); /* explicitly show cr */ i += 4; } else if (*cp == 0x09) { fprintf(f, "<tab>"); /* explicitly show tab */ i += 5; } else { fprintf(f, "[%02x]", *cp); i += 4; } cp++; }}#ifdef TCPDUMP_FEDvoid print_http(char *start, int len, int trunc, tcp_conn_t *tconnp, FILE *f, int way)#elseprint_http(char *start, int len, tcp_conn_t *tconnp, FILE *f, int way)#endif{ int trunc_by = 0; char http_delim[] = {0x0d, 0x0a, 0x0d, 0x0a, '\0'}; u_char *http_end = (u_char *)seqstr_l(start, http_delim, len);#ifdef TCPDUMP_FED trunc_by = trunc;#endif#ifdef HTTP_PARSE_DEBUG if (HTTP_STATUS & HTTP_GOT_REQ_HDR) { fprintf(f, "+req hdr: method %s ", method_string(HTTP_METH)); if (strlen(HTTP_REQSTR)) fprintf(f, "%s\n", HTTP_REQSTR); } if (HTTP_STATUS & HTTP_GOT_REP_HDR) { fprintf(f, "+rep hdr "); fprintf(f, "content type %s ", content_type_string(HTTP_REP_CONTENT_T)); if (HTTP_REP_BODY_LEN >= 0) fprintf(f, "len %d ", HTTP_REP_BODY_LEN); else fprintf(f, "len ? "); } print_http_versions(HTTP_VERSIONS, f); fprintf(f, "connection %s ", HTTP_STATUS & HTTP_KEEP_ALIVE ? "Keep alive" : HTTP_STATUS & HTTP_CLOSE ? "Close" : "Unknown"); fprintf(f, "\n");#endif fprintf(f, "\n\t"); if (http_end) /* header */ { http_end += 4; /* print delim seq as part of hdr */ print_content(start, http_end, f); /* HTTP header */ len -= (http_end - (u_char *)start); start = http_end; } if (way == SERVER && len + trunc_by > 0) { if (HTTP_REP_CONTENT_T & CT_TEXT_HTML) print_content(start, start + len, f); else fprintf(f, "[%d octets of content type %s]", len + trunc_by, content_type_string(HTTP_REP_CONTENT_T)); }#ifdef TCPDUMP_FED if (trunc) fprintf(f, "[truncated by %d octets]\n", trunc);#endif fprintf(f, "\n"); fflush(f);}#endif /* ifdef PRINT_OUT *//* Aid for debugging */void print_content(prec_t *pp){ int i = 0; char *cp = pp->buf; char *end = pp->buf + pp->len; printf("\t"); while(cp < end) { if (i >= LINE_LEN) { printf("\n\t"); i = 0; } if (isprint(*cp)) { printf("%c", *cp); i++; } else if (*cp == 0x0a) { printf("<NL>\n\t"); /* explicitly show nl */ i = 0; } else if (*cp == 0x0d) { printf("<CR>"); /* explicitly show cr */ i += 4; } else if (*cp == 0x09) { printf("<tab>"); /* explicitly show tab */ i += 5; } else { printf("[%02x]", *cp); i += 4; } cp++; } return;}/* * DNS stuff *//* Compatibility */#ifndef T_TXT#define T_TXT 16 /* text strings */#endif#ifndef T_RP#define T_RP 17 /* responsible person */#endif#ifndef T_AFSDB#define T_AFSDB 18 /* AFS cell database */#endif#ifndef T_X25#define T_X25 19 /* X_25 calling address */#endif#ifndef T_ISDN#define T_ISDN 20 /* ISDN calling address */#endif#ifndef T_RT#define T_RT 21 /* router */#endif#ifndef T_NSAP#define T_NSAP 22 /* NSAP address */#endif#ifndef T_NSAP_PTR#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */#endif#ifndef T_SIG#define T_SIG 24 /* security signature */#endif#ifndef T_KEY#define T_KEY 25 /* security key */#endif#ifndef T_PX#define T_PX 26 /* X.400 mail mapping */#endif#ifndef T_GPOS#define T_GPOS 27 /* geographical position (withdrawn) */#endif#ifndef T_AAAA#define T_AAAA 28 /* IP6 Address */#endif#ifndef T_LOC#define T_LOC 29 /* Location Information */#endif#ifndef T_UNSPEC#define T_UNSPEC 103 /* Unspecified format (binary data) */#endif#ifndef T_UNSPECA#define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */#endif#ifndef C_CHAOS#define C_CHAOS 3 /* for chaos net (MIT) */#endif#ifndef C_HS#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */#endifchar *ns_ops[] = { "q", " inv_q", " stat", " op3", " notify", " op5", " op6", " op7", " op8", " updataA", " updateD", " updateDA", " updateM", " updateMA", " zoneInit", " zoneRef",};char *ns_resp[] = { "", " FormErr", " ServFail", " NXDomain", " NotImp", " Refused", " Resp6", " Resp7", " Resp8", " Resp9", " Resp10", " Resp11", " Resp12", " Resp13", " Resp14", " NoChange",};struct tok class2str[] = { { C_IN, "IN" }, /* Not used */ { C_CHAOS, "CHAOS)" }, { C_HS, "HS" }, { C_ANY, "ANY" }, { 0, NULL }};struct tok type2str[] = { { T_A, "A" }, { T_NS, "NS" }, { T_MD, "MD" }, { T_MF, "MF" }, { T_CNAME, "CNAME" }, { T_SOA, "SOA" }, { T_MB, "MB" }, { T_MG, "MG" }, { T_MR, "MR" }, { T_NULL, "NULL" }, { T_WKS, "WKS" }, { T_PTR, "PTR" }, { T_HINFO, "HINFO" }, { T_MINFO, "MINFO" }, { T_MX, "MX" }, { T_TXT, "TXT" }, { T_RP, "RP" }, { T_AFSDB, "AFSDB" }, { T_X25, "X25" }, { T_ISDN, "ISDN" }, { T_RT, "RT" }, { T_NSAP, "NSAP" }, { T_NSAP_PTR, "NSAP_PTR" }, { T_SIG, "SIG" }, { T_KEY, "KEY" }, { T_PX, "PX" }, { T_GPOS, "GPOS" }, { T_AAAA, "AAAA" }, { T_LOC , "LOC " },#ifndef T_UINFO#define T_UINFO 100#endif { T_UINFO, "UINFO" },#ifndef T_UID#define T_UID 101#endif { T_UID, "UID" },#ifndef T_GID#define T_GID 102#endif { T_GID, "GID" }, { T_UNSPEC, "UNSPEC" }, { T_UNSPECA, "UNSPECA" }, { T_AXFR, "AXFR" }, { T_MAILB, "MAILB" }, { T_MAILA, "MAILA" }, { T_ANY, "ANY" }, { 0, NULL }};/* * For debugging */#define LINE_LEN 64voidnsbuf(ns_fullrec_t *nfp){ int i = 0; unsigned char *cp = nfp->rrbuf; unsigned char *end = cp + nfp->ns_rec.buflen; printf("\nBuff contents\n"); while(cp < end) { if (i >= LINE_LEN) { printf("\n\t"); i = 0; } if (isprint(*cp)) { printf("%c", *cp); i++; } else if (*cp == 0x0a) { printf("<NL>\n\t"); /* explicitly show nl */ i = 0; } else if (*cp == 0x0d) { printf("<CR>"); /* explicitly show cr */ i += 4; } else if (*cp == 0x09) { printf("<tab>"); /* explicitly show tab */ i += 5; } else { printf("[%02x]", *cp); i += 4; } cp++; } printf("\n"); fflush(stdout);}/* * Convert a token value to a string; use "fmt" if not found. */const char *tok2str(struct tok *lp, char *fmt, int v){ static char buf[128]; while (lp->s != NULL) { if (lp->v == v) return (lp->s); ++lp; } if (fmt == NULL) fmt = "#%d"; (void)sprintf(buf, fmt, v); return (buf);}/* * end print_util.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -