From: Denis Ovsienko Date: Mon, 14 Apr 2014 06:53:46 +0000 (+0400) Subject: NDOize the rest of util.c X-Git-Tag: tcpdump-4.6.0~89 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/24598ce6b7cfe72ada92aed48691fdf092d94fc7 NDOize the rest of util.c --- diff --git a/interface.h b/interface.h index 27563683..37053496 100644 --- a/interface.h +++ b/interface.h @@ -117,9 +117,6 @@ extern int32_t thiszone; /* seconds offset from gmt to local time */ /* Bail if "var" was not captured */ #define TCHECK(var) TCHECK2(var, sizeof(var)) -extern int fn_print(const u_char *, const u_char *); -extern int fn_printn(const u_char *, u_int, const u_char *); -extern int fn_printzp(const u_char *, u_int, const u_char *); extern int mask2plen(u_int32_t); extern const char *tok2strary_internal(const char **, int, const char *, int); #define tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i) diff --git a/netdissect.h b/netdissect.h index cbc8bbc1..f1374e44 100644 --- a/netdissect.h +++ b/netdissect.h @@ -255,8 +255,9 @@ struct netdissect_options { extern void ts_print(netdissect_options *, const struct timeval *); extern void relts_print(netdissect_options *, int); -extern int fn_print(const u_char *, const u_char *); -extern int fn_printn(const u_char *, u_int, const u_char *); +extern int fn_print(netdissect_options *, const u_char *, const u_char *); +extern int fn_printn(netdissect_options *, const u_char *, u_int, const u_char *); +extern int fn_printzp(netdissect_options *, const u_char *, u_int, const u_char *); extern const char *tok2str(const struct tok *, const char *, int); #if 0 diff --git a/print-802_11.c b/print-802_11.c index 45534041..c94cc0dd 100644 --- a/print-802_11.c +++ b/print-802_11.c @@ -697,7 +697,7 @@ struct radiotap_state #define PRINT_SSID(p) \ if (p.ssid_present) { \ ND_PRINT((ndo, " (")); \ - fn_print(p.ssid.ssid, NULL); \ + fn_print(ndo, p.ssid.ssid, NULL); \ ND_PRINT((ndo, ")")); \ } diff --git a/print-bootp.c b/print-bootp.c index 7d08e22e..5e7e9a99 100644 --- a/print-bootp.c +++ b/print-bootp.c @@ -131,7 +131,7 @@ bootp_print(netdissect_options *ndo, ND_TCHECK2(bp->bp_sname[0], 1); /* check first char only */ if (*bp->bp_sname) { ND_PRINT((ndo, "\n\t sname \"")); - if (fn_print(bp->bp_sname, ndo->ndo_snapend)) { + if (fn_print(ndo, bp->bp_sname, ndo->ndo_snapend)) { ND_PRINT((ndo, "\"")); ND_PRINT((ndo, "%s", tstr + 1)); return; @@ -141,7 +141,7 @@ bootp_print(netdissect_options *ndo, ND_TCHECK2(bp->bp_file[0], 1); /* check first char only */ if (*bp->bp_file) { ND_PRINT((ndo, "\n\t file \"")); - if (fn_print(bp->bp_file, ndo->ndo_snapend)) { + if (fn_print(ndo, bp->bp_file, ndo->ndo_snapend)) { ND_PRINT((ndo, "\"")); ND_PRINT((ndo, "%s", tstr + 1)); return; @@ -475,7 +475,7 @@ rfc1048_print(netdissect_options *ndo, case 'a': /* ascii strings */ ND_PRINT((ndo, "\"")); - if (fn_printn(bp, len, ndo->ndo_snapend)) { + if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) { ND_PRINT((ndo, "\"")); goto trunc; } @@ -617,7 +617,7 @@ rfc1048_print(netdissect_options *ndo, ND_PRINT((ndo, "%u/%u ", *bp, *(bp+1))); bp += 2; ND_PRINT((ndo, "\"")); - if (fn_printn(bp, len - 3, ndo->ndo_snapend)) { + if (fn_printn(ndo, bp, len - 3, ndo->ndo_snapend)) { ND_PRINT((ndo, "\"")); goto trunc; } @@ -639,7 +639,7 @@ rfc1048_print(netdissect_options *ndo, len--; if (type == 0) { ND_PRINT((ndo, "\"")); - if (fn_printn(bp, len, ndo->ndo_snapend)) { + if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) { ND_PRINT((ndo, "\"")); goto trunc; } @@ -684,7 +684,7 @@ rfc1048_print(netdissect_options *ndo, case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */ case AGENT_SUBOPTION_REMOTE_ID: case AGENT_SUBOPTION_SUBSCRIBER_ID: - fn_printn(bp, suboptlen, NULL); + fn_printn(ndo, bp, suboptlen, NULL); break; default: diff --git a/print-cdp.c b/print-cdp.c index 353ce4c1..bb27f0fd 100644 --- a/print-cdp.c +++ b/print-cdp.c @@ -130,7 +130,7 @@ cdp_print(netdissect_options *ndo, if (!ndo->ndo_vflag) ND_PRINT((ndo, ", Device-ID ")); ND_PRINT((ndo, "'")); - fn_printn(tptr, len, NULL); + fn_printn(ndo, tptr, len, NULL); ND_PRINT((ndo, "'")); break; case 0x02: /* Address */ @@ -139,7 +139,7 @@ cdp_print(netdissect_options *ndo, break; case 0x03: /* Port-ID */ ND_PRINT((ndo, "'")); - fn_printn(tptr, len, NULL); + fn_printn(ndo, tptr, len, NULL); ND_PRINT((ndo, "'")); break; case 0x04: /* Capabilities */ @@ -158,7 +158,7 @@ cdp_print(netdissect_options *ndo, break; case 0x06: /* Platform */ ND_PRINT((ndo, "'")); - fn_printn(tptr, len, NULL); + fn_printn(ndo, tptr, len, NULL); ND_PRINT((ndo, "'")); break; case 0x07: /* Prefixes */ @@ -169,7 +169,7 @@ cdp_print(netdissect_options *ndo, break; case 0x09: /* VTP Mgmt Domain - not documented */ ND_PRINT((ndo, "'")); - fn_printn(tptr, len, NULL); + fn_printn(ndo, tptr, len, NULL); ND_PRINT((ndo, "'")); break; case 0x0a: /* Native VLAN ID - not documented */ @@ -199,7 +199,7 @@ cdp_print(netdissect_options *ndo, break; case 0x14: /* System Name - not documented */ ND_PRINT((ndo, "'")); - fn_printn(tptr, len, NULL); + fn_printn(ndo, tptr, len, NULL); ND_PRINT((ndo, "'")); break; case 0x16: /* System Object ID - not documented */ @@ -210,7 +210,7 @@ cdp_print(netdissect_options *ndo, ND_PRINT((ndo, "0x%02x", *(tptr))); if (len > 1) { ND_PRINT((ndo, "/")); - fn_printn(tptr + 1, len - 1, NULL); + fn_printn(ndo, tptr + 1, len - 1, NULL); } break; default: diff --git a/print-domain.c b/print-domain.c index 00119568..45db5c73 100644 --- a/print-domain.c +++ b/print-domain.c @@ -205,7 +205,7 @@ ns_nprint(netdissect_options *ndo, return(NULL); } } else { - if (fn_printn(cp, l, ndo->ndo_snapend)) + if (fn_printn(ndo, cp, l, ndo->ndo_snapend)) return(NULL); } @@ -236,7 +236,7 @@ ns_cprint(netdissect_options *ndo, if (!ND_TTEST2(*cp, 1)) return (NULL); i = *cp++; - if (fn_printn(cp, i, ndo->ndo_snapend)) + if (fn_printn(ndo, cp, i, ndo->ndo_snapend)) return (NULL); return (cp + i); } @@ -535,7 +535,7 @@ ns_rprint(netdissect_options *ndo, case T_UNSPECA: /* One long string */ if (!ND_TTEST2(*cp, len)) return(NULL); - if (fn_printn(cp, len, ndo->ndo_snapend)) + if (fn_printn(ndo, cp, len, ndo->ndo_snapend)) return(NULL); break; diff --git a/print-hsrp.c b/print-hsrp.c index ddc912c9..9b8e70e4 100644 --- a/print-hsrp.c +++ b/print-hsrp.c @@ -121,7 +121,7 @@ hsrp_print(netdissect_options *ndo, register const u_int8_t *bp, register u_int relts_print(ndo, hp->hsrp_holdtime); ND_PRINT((ndo, " priority=%d", hp->hsrp_priority)); ND_PRINT((ndo, " auth=\"")); - if (fn_printn(hp->hsrp_authdata, sizeof(hp->hsrp_authdata), + if (fn_printn(ndo, hp->hsrp_authdata, sizeof(hp->hsrp_authdata), ndo->ndo_snapend)) { ND_PRINT((ndo, "\"")); goto trunc; diff --git a/print-ipx.c b/print-ipx.c index 32e38908..ea5a6545 100644 --- a/print-ipx.c +++ b/print-ipx.c @@ -178,7 +178,7 @@ ipx_sap_print(netdissect_options *ndo, const u_short *ipx, u_int length) for (i = 0; i < 8 && length > 0; i++) { ND_TCHECK(ipx[0]); ND_PRINT((ndo, " %s '", ipxsap_string(htons(EXTRACT_16BITS(&ipx[0]))))); - if (fn_printzp((u_char *)&ipx[1], 48, ndo->ndo_snapend)) { + if (fn_printzp(ndo, (u_char *)&ipx[1], 48, ndo->ndo_snapend)) { ND_PRINT((ndo, "'")); goto trunc; } diff --git a/print-nfs.c b/print-nfs.c index 6da4a316..79b194d6 100644 --- a/print-nfs.c +++ b/print-nfs.c @@ -500,7 +500,7 @@ parsefn(netdissect_options *ndo, /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */ dp += ((len + 3) & ~3) / sizeof(*dp); ND_PRINT((ndo, "\"")); - if (fn_printn(cp, len, ndo->ndo_snapend)) { + if (fn_printn(ndo, cp, len, ndo->ndo_snapend)) { ND_PRINT((ndo, "\"")); goto trunc; } diff --git a/print-ntp.c b/print-ntp.c index 93268ac0..d2f51460 100644 --- a/print-ntp.c +++ b/print-ntp.c @@ -261,7 +261,7 @@ ntp_print(netdissect_options *ndo, break; case PRIM_REF: - if (fn_printn((u_char *)&(bp->refid), 4, ndo->ndo_snapend)) + if (fn_printn(ndo, (u_char *)&(bp->refid), 4, ndo->ndo_snapend)) goto trunc; break; diff --git a/print-olsr.c b/print-olsr.c index 34300a44..f1b90032 100644 --- a/print-olsr.c +++ b/print-olsr.c @@ -591,7 +591,7 @@ olsr_print(netdissect_options *ndo, #endif ND_PRINT((ndo, ", address %s, name \"", ipaddr_string(ndo, msg_data))); - fn_printn(msg_data + addr_size, name_entry_len, NULL); + fn_printn(ndo, msg_data + addr_size, name_entry_len, NULL); ND_PRINT((ndo, "\"")); msg_data += addr_size + name_entry_len + name_entry_padding; diff --git a/print-openflow-1.0.c b/print-openflow-1.0.c index e8be4017..a26f2dc0 100644 --- a/print-openflow-1.0.c +++ b/print-openflow-1.0.c @@ -697,7 +697,7 @@ of10_phy_ports_print(netdissect_options *ndo, /* name */ ND_TCHECK2(*cp, OFP_MAX_PORT_NAME_LEN); ND_PRINT((ndo, ", name '")); - fn_print(cp, cp + OFP_MAX_PORT_NAME_LEN); + fn_print(ndo, cp, cp + OFP_MAX_PORT_NAME_LEN); ND_PRINT((ndo, "'")); cp += OFP_MAX_PORT_NAME_LEN; @@ -1363,31 +1363,31 @@ of10_desc_stats_reply_print(netdissect_options *ndo, /* mfr_desc */ ND_TCHECK2(*cp, DESC_STR_LEN); ND_PRINT((ndo, "\n\t mfr_desc '")); - fn_print(cp, cp + DESC_STR_LEN); + fn_print(ndo, cp, cp + DESC_STR_LEN); ND_PRINT((ndo, "'")); cp += DESC_STR_LEN; /* hw_desc */ ND_TCHECK2(*cp, DESC_STR_LEN); ND_PRINT((ndo, "\n\t hw_desc '")); - fn_print(cp, cp + DESC_STR_LEN); + fn_print(ndo, cp, cp + DESC_STR_LEN); ND_PRINT((ndo, "'")); cp += DESC_STR_LEN; /* sw_desc */ ND_TCHECK2(*cp, DESC_STR_LEN); ND_PRINT((ndo, "\n\t sw_desc '")); - fn_print(cp, cp + DESC_STR_LEN); + fn_print(ndo, cp, cp + DESC_STR_LEN); ND_PRINT((ndo, "'")); cp += DESC_STR_LEN; /* serial_num */ ND_TCHECK2(*cp, SERIAL_NUM_LEN); ND_PRINT((ndo, "\n\t serial_num '")); - fn_print(cp, cp + SERIAL_NUM_LEN); + fn_print(ndo, cp, cp + SERIAL_NUM_LEN); ND_PRINT((ndo, "'")); cp += SERIAL_NUM_LEN; /* dp_desc */ ND_TCHECK2(*cp, DESC_STR_LEN); ND_PRINT((ndo, "\n\t dp_desc '")); - fn_print(cp, cp + DESC_STR_LEN); + fn_print(ndo, cp, cp + DESC_STR_LEN); ND_PRINT((ndo, "'")); return cp + DESC_STR_LEN; @@ -1532,7 +1532,7 @@ of10_table_stats_reply_print(netdissect_options *ndo, /* name */ ND_TCHECK2(*cp, OFP_MAX_TABLE_NAME_LEN); ND_PRINT((ndo, ", name '")); - fn_print(cp, cp + OFP_MAX_TABLE_NAME_LEN); + fn_print(ndo, cp, cp + OFP_MAX_TABLE_NAME_LEN); ND_PRINT((ndo, "'")); cp += OFP_MAX_TABLE_NAME_LEN; /* wildcards */ diff --git a/print-ppp.c b/print-ppp.c index 0b70eed5..5a59195e 100644 --- a/print-ppp.c +++ b/print-ppp.c @@ -548,7 +548,7 @@ handle_ctrl_proto(netdissect_options *ndo, /* RFC 1661 says this is intended to be human readable */ if (len > 8) { ND_PRINT((ndo, "\n\t Message\n\t ")); - if (fn_printn(tptr + 4, len - 4, ndo->ndo_snapend)) + if (fn_printn(ndo, tptr + 4, len - 4, ndo->ndo_snapend)) goto trunc; } break; diff --git a/print-rx.c b/print-rx.c index af80c40d..24045755 100644 --- a/print-rx.c +++ b/print-rx.c @@ -759,7 +759,7 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, int sport, goto trunc; \ bp += sizeof(int32_t); \ ND_PRINT((ndo, " \"")); \ - if (fn_printn(bp, i, ndo->ndo_snapend)) \ + if (fn_printn(ndo, bp, i, ndo->ndo_snapend)) \ goto trunc; \ ND_PRINT((ndo, "\"")); \ bp += ((i + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t); \ @@ -857,7 +857,7 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, int sport, } \ s[(MAX)] = '\0'; \ ND_PRINT((ndo, " \"")); \ - fn_print(s, NULL); \ + fn_print(ndo, s, NULL); \ ND_PRINT((ndo, "\"")); \ } @@ -1179,7 +1179,7 @@ acl_print(netdissect_options *ndo, goto finish; s += n; ND_PRINT((ndo, " +{")); - fn_print((u_char *)user, NULL); + fn_print(ndo, (u_char *)user, NULL); ND_PRINT((ndo, " ")); ACLOUT(acl); ND_PRINT((ndo, "}")); @@ -1193,7 +1193,7 @@ acl_print(netdissect_options *ndo, goto finish; s += n; ND_PRINT((ndo, " -{")); - fn_print((u_char *)user, NULL); + fn_print(ndo, (u_char *)user, NULL); ND_PRINT((ndo, " ")); ACLOUT(acl); ND_PRINT((ndo, "}")); diff --git a/print-snmp.c b/print-snmp.c index 3b14f9ec..ba326018 100644 --- a/print-snmp.c +++ b/print-snmp.c @@ -782,7 +782,7 @@ asn1_print(netdissect_options *ndo, p = elem->data.str; if (printable) { ND_PRINT((ndo, "\"")); - if (fn_printn(p, asnlen, ndo->ndo_snapend)) { + if (fn_printn(ndo, p, asnlen, ndo->ndo_snapend)) { ND_PRINT((ndo, "\"")); goto trunc; } diff --git a/print-tftp.c b/print-tftp.c index 5f47d476..9b88e74f 100644 --- a/print-tftp.c +++ b/print-tftp.c @@ -136,7 +136,7 @@ tftp_print(netdissect_options *ndo, /* Print filename or first option */ if (opcode != OACK) ND_PRINT((ndo, "\"")); - i = fn_print(p, ndo->ndo_snapend); + i = fn_print(ndo, p, ndo->ndo_snapend); if (opcode != OACK) ND_PRINT((ndo, "\"")); @@ -147,7 +147,7 @@ tftp_print(netdissect_options *ndo, p++; if (*p != '\0') { ND_PRINT((ndo, " ")); - fn_print(p, ndo->ndo_snapend); + fn_print(ndo, p, ndo->ndo_snapend); } } @@ -167,7 +167,7 @@ tftp_print(netdissect_options *ndo, ND_PRINT((ndo, " %s \"", tok2str(err2str, "tftp-err-#%d \"", EXTRACT_16BITS(&tp->th_code)))); /* Print error message string */ - i = fn_print((const u_char *)tp->th_data, ndo->ndo_snapend); + i = fn_print(ndo, (const u_char *)tp->th_data, ndo->ndo_snapend); ND_PRINT((ndo, "\"")); if (i) goto trunc; diff --git a/print-timed.c b/print-timed.c index efbdd196..b3f53216 100644 --- a/print-timed.c +++ b/print-timed.c @@ -138,7 +138,7 @@ timed_print(netdissect_options *ndo, } ND_TCHECK(tsp->tsp_name); ND_PRINT((ndo, " name ")); - if (fn_print((u_char *)tsp->tsp_name, (u_char *)tsp->tsp_name + sizeof(tsp->tsp_name))) + if (fn_print(ndo, (u_char *)tsp->tsp_name, (u_char *)tsp->tsp_name + sizeof(tsp->tsp_name))) goto trunc; return; diff --git a/print-vrrp.c b/print-vrrp.c index 610a84a5..4e5da145 100644 --- a/print-vrrp.c +++ b/print-vrrp.c @@ -169,7 +169,7 @@ vrrp_print(netdissect_options *ndo, if (version == 2 && auth_type == VRRP_AUTH_SIMPLE) { /* simple text password */ ND_TCHECK(bp[7]); ND_PRINT((ndo, " auth \"")); - if (fn_printn(bp, 8, ndo->ndo_snapend)) { + if (fn_printn(ndo, bp, 8, ndo->ndo_snapend)) { ND_PRINT((ndo, "\"")); goto trunc; } diff --git a/print-wb.c b/print-wb.c index 3b7f11e2..29e82910 100644 --- a/print-wb.c +++ b/print-wb.c @@ -204,7 +204,7 @@ wb_id(netdissect_options *ndo, cp = (char *)(io + nid); if ((u_char *)cp + len <= ndo->ndo_snapend) { ND_PRINT((ndo, "\"")); - (void)fn_print((u_char *)cp, (u_char *)cp + len); + fn_print(ndo, (u_char *)cp, (u_char *)cp + len); ND_PRINT((ndo, "\"")); } diff --git a/util.c b/util.c index f71f0e8a..c07bc3a7 100644 --- a/util.c +++ b/util.c @@ -45,7 +45,8 @@ * Return true if truncated. */ int -fn_print(register const u_char *s, register const u_char *ep) +fn_print(netdissect_options *ndo, + register const u_char *s, register const u_char *ep) { register int ret; register u_char c; @@ -59,14 +60,13 @@ fn_print(register const u_char *s, register const u_char *ep) } if (!ND_ISASCII(c)) { c = ND_TOASCII(c); - putchar('M'); - putchar('-'); + ND_PRINT((ndo, "M-")); } if (!ND_ISPRINT(c)) { c ^= 0x40; /* DEL to ?, others to alpha */ - putchar('^'); + ND_PRINT((ndo, "^")); } - putchar(c); + ND_PRINT((ndo, "%c", c)); } return(ret); } @@ -77,8 +77,8 @@ fn_print(register const u_char *s, register const u_char *ep) * Return true if truncated. */ int -fn_printn(register const u_char *s, register u_int n, - register const u_char *ep) +fn_printn(netdissect_options *ndo, + register const u_char *s, register u_int n, register const u_char *ep) { register u_char c; @@ -87,14 +87,13 @@ fn_printn(register const u_char *s, register u_int n, c = *s++; if (!ND_ISASCII(c)) { c = ND_TOASCII(c); - putchar('M'); - putchar('-'); + ND_PRINT((ndo, "M-")); } if (!ND_ISPRINT(c)) { c ^= 0x40; /* DEL to ?, others to alpha */ - putchar('^'); + ND_PRINT((ndo, "^")); } - putchar(c); + ND_PRINT((ndo, "%c", c)); } return (n == 0) ? 0 : 1; } @@ -105,8 +104,9 @@ fn_printn(register const u_char *s, register u_int n, * Return true if truncated. */ int -fn_printzp(register const u_char *s, register u_int n, - register const u_char *ep) +fn_printzp(netdissect_options *ndo, + register const u_char *s, register u_int n, + register const u_char *ep) { register int ret; register u_char c; @@ -121,14 +121,13 @@ fn_printzp(register const u_char *s, register u_int n, } if (!ND_ISASCII(c)) { c = ND_TOASCII(c); - putchar('M'); - putchar('-'); + ND_PRINT((ndo, "M-")); } if (!ND_ISPRINT(c)) { c ^= 0x40; /* DEL to ?, others to alpha */ - putchar('^'); + ND_PRINT((ndo, "^")); } - putchar(c); + ND_PRINT((ndo, "%c", c)); } return (n == 0) ? 0 : ret; }