From: Denis Ovsienko Date: Tue, 1 Apr 2014 13:29:55 +0000 (+0400) Subject: NDOize safeputs() and safeputchar() X-Git-Tag: tcpdump-4.6.0~122 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/51670d19496d42a99ced7358dab6fbdce94b7708 NDOize safeputs() and safeputchar() --- diff --git a/interface.h b/interface.h index 6a0978e1..47f03500 100644 --- a/interface.h +++ b/interface.h @@ -144,9 +144,6 @@ extern void warning(const char *, ...) extern char *read_infile(char *); extern char *copy_argv(char **); -extern void safeputchar(int); -extern void safeputs(const char *, int); - extern const char *isonsap_string(const u_char *, register u_int); extern const char *protoid_string(const u_char *); extern const char *ipxsap_string(u_short); diff --git a/netdissect.h b/netdissect.h index 9a34e622..1cfc6fd9 100644 --- a/netdissect.h +++ b/netdissect.h @@ -278,8 +278,8 @@ extern char *copy_argv(netdissect_options *, char **); #define ND_ISGRAPH(c) ((c) > 0x20 && (c) <= 0x7E) #define ND_TOASCII(c) ((c) & 0x7F) -extern void safeputchar(int); -extern void safeputs(const char *, int); +extern void safeputchar(netdissect_options *, const u_char); +extern void safeputs(netdissect_options *, const u_char *, const u_int); #ifdef LBL_ALIGN /* diff --git a/print-cfm.c b/print-cfm.c index 2dba46a7..2f43d613 100644 --- a/print-cfm.c +++ b/print-cfm.c @@ -372,7 +372,7 @@ cfm_print(register const u_char *pptr, register u_int length) { switch (msg_ptr.cfm_ccm->md_nameformat) { case CFM_CCM_MD_FORMAT_DNS: case CFM_CCM_MD_FORMAT_CHAR: - safeputs((const char *)msg_ptr.cfm_ccm->md_name, msg_ptr.cfm_ccm->md_namelength); + safeputs(gndo, msg_ptr.cfm_ccm->md_name, msg_ptr.cfm_ccm->md_namelength); break; case CFM_CCM_MD_FORMAT_MAC: @@ -405,7 +405,7 @@ cfm_print(register const u_char *pptr, register u_int length) { printf("\n\t MA Name: "); switch (*ma_nameformat) { case CFM_CCM_MA_FORMAT_CHAR: - safeputs((const char *)ma_name, *ma_namelength); + safeputs(gndo, ma_name, *ma_namelength); break; /* FIXME add printers for those MA formats - hexdump for now */ @@ -582,7 +582,7 @@ cfm_print(register const u_char *pptr, register u_int length) { case CFM_CHASSIS_ID_LOCAL: case CFM_CHASSIS_ID_CHASSIS_COMPONENT: case CFM_CHASSIS_ID_PORT_COMPONENT: - safeputs((const char *)tptr+1, chassis_id_length); + safeputs(gndo, tptr + 1, chassis_id_length); break; default: diff --git a/print-decnet.c b/print-decnet.c index 83c1518c..6a21684e 100644 --- a/print-decnet.c +++ b/print-decnet.c @@ -886,7 +886,7 @@ pdata(u_char *dp, u_int maxlen) while (x-- > 0) { c = *dp++; - safeputchar(c); + safeputchar(gndo, c); } } #endif diff --git a/print-eap.c b/print-eap.c index 7b58851b..fba40e27 100644 --- a/print-eap.c +++ b/print-eap.c @@ -209,14 +209,14 @@ eap_print(netdissect_options *ndo _U_, case EAP_TYPE_IDENTITY: if (len - 5 > 0) { printf(", Identity: "); - safeputs((const char *)tptr+5, len-5); + safeputs(gndo, tptr + 5, len - 5); } break; case EAP_TYPE_NOTIFICATION: if (len - 5 > 0) { printf(", Notification: "); - safeputs((const char *)tptr+5, len-5); + safeputs(gndo, tptr + 5, len - 5); } break; diff --git a/print-fr.c b/print-fr.c index d49879b1..093d526e 100644 --- a/print-fr.c +++ b/print-fr.c @@ -461,7 +461,7 @@ mfr_print(netdissect_options *ndo, case MFR_CTRL_IE_LINK_ID: for (idx = 0; idx < ie_len && idx < MFR_ID_STRING_MAXLEN; idx++) { if (*(tptr+idx) != 0) /* don't print null termination */ - safeputchar(*(tptr+idx)); + safeputchar(ndo, *(tptr + idx)); else break; } diff --git a/print-icmp6.c b/print-icmp6.c index 7b5f3f3c..a29a4f76 100644 --- a/print-icmp6.c +++ b/print-icmp6.c @@ -1556,7 +1556,7 @@ dnsname_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) break; } while (i-- && cp < ep) { - safeputchar(*cp); + safeputchar(ndo, *cp); cp++; } if (cp + 1 < ep && *cp) @@ -1678,7 +1678,7 @@ icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp, cp++; ND_PRINT((ndo,", \"")); while (cp < ep) { - safeputchar(*cp); + safeputchar(ndo, *cp); cp++; } ND_PRINT((ndo,"\"")); @@ -1774,7 +1774,7 @@ icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp, cp++; ND_PRINT((ndo,", \"")); while (cp < ep) { - safeputchar(*cp); + safeputchar(ndo, *cp); cp++; } ND_PRINT((ndo,"\"")); diff --git a/print-isakmp.c b/print-isakmp.c index 2ebe083b..09e3c544 100644 --- a/print-isakmp.c +++ b/print-isakmp.c @@ -1397,7 +1397,7 @@ ikev1_id_print(netdissect_options *ndo, u_char tpay _U_, int i; ND_PRINT((ndo," len=%d ", len)); for (i = 0; i < len; i++) - safeputchar(data[i]); + safeputchar(ndo, data[i]); len = 0; break; } diff --git a/print-ldp.c b/print-ldp.c index d699db04..c7e6baf9 100644 --- a/print-ldp.c +++ b/print-ldp.c @@ -433,7 +433,7 @@ ldp_tlv_print(netdissect_options *ndo, case LDP_FEC_MARTINI_IFPARM_DESC: ND_PRINT((ndo, ": ")); for (idx = 2; idx < vc_info_tlv_len; idx++) - safeputchar(*(tptr+idx)); + safeputchar(ndo, *(tptr + idx)); break; case LDP_FEC_MARTINI_IFPARM_VCCV: diff --git a/print-lldp.c b/print-lldp.c index e6cad7eb..f569da1e 100644 --- a/print-lldp.c +++ b/print-lldp.c @@ -679,7 +679,7 @@ lldp_private_8021_print(const u_char *tptr, u_int tlv_len) return hexdump; } printf("\n\t vlan name: "); - safeputs((const char *)tptr+7, sublen); + safeputs(gndo, tptr + 7, sublen); break; case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY: if (tlv_len < 5) { @@ -690,7 +690,7 @@ lldp_private_8021_print(const u_char *tptr, u_int tlv_len) return hexdump; } printf("\n\t protocol identity: "); - safeputs((const char *)tptr+5, sublen); + safeputs(gndo, tptr + 5, sublen); break; case LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION: if(tlv_lenospf_authdata, OSPF_AUTH_SIMPLE_LEN); + safeputs(gndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN); break; case OSPF_AUTH_MD5: diff --git a/print-ppp.c b/print-ppp.c index c442cb5f..4c07bb63 100644 --- a/print-ppp.c +++ b/print-ppp.c @@ -880,7 +880,7 @@ handle_chap(const u_char *p, int length) printf(", Name "); for (i = 0; i < name_size; i++) { TCHECK(*p); - safeputchar(*p++); + safeputchar(gndo, *p++); } break; case CHAP_SUCC: @@ -889,7 +889,7 @@ handle_chap(const u_char *p, int length) printf(", Msg "); for (i = 0; i< msg_size; i++) { TCHECK(*p); - safeputchar(*p++); + safeputchar(gndo, *p++); } break; } @@ -955,7 +955,7 @@ handle_pap(const u_char *p, int length) printf(", Peer "); for (i = 0; i < peerid_len; i++) { TCHECK(*p); - safeputchar(*p++); + safeputchar(gndo, *p++); } if (length - (p - p0) < 1) @@ -968,7 +968,7 @@ handle_pap(const u_char *p, int length) printf(", Name "); for (i = 0; i < passwd_len; i++) { TCHECK(*p); - safeputchar(*p++); + safeputchar(gndo, *p++); } break; case PAP_AACK: @@ -983,7 +983,7 @@ handle_pap(const u_char *p, int length) printf(", Msg "); for (i = 0; i< msg_len; i++) { TCHECK(*p); - safeputchar(*p++); + safeputchar(gndo, *p++); } break; } diff --git a/print-rsvp.c b/print-rsvp.c index 8d2f0264..adf1829b 100644 --- a/print-rsvp.c +++ b/print-rsvp.c @@ -1143,7 +1143,7 @@ _U_ return-1; printf("%s Session Name: ", ident); for (i = 0; i < namelen; i++) - safeputchar(*(obj_tptr+4+i)); + safeputchar(gndo, *(obj_tptr + 4 + i)); printf("%s Setup Priority: %u, Holding Priority: %u, Flags: [%s] (%#x)", ident, (int)*obj_tptr, diff --git a/print-sip.c b/print-sip.c index a73e70a1..71d1bc34 100644 --- a/print-sip.c +++ b/print-sip.c @@ -39,7 +39,7 @@ sip_print(register const u_char *pptr, register u_int len) for (idx = 0; idx < len; idx++) { TCHECK2(*(pptr+idx), 2); if (EXTRACT_16BITS(pptr+idx) != 0x0d0a) { /* linefeed ? */ - safeputchar(*(pptr+idx)); + safeputchar(gndo, *(pptr + idx)); } else { printf("\n\t"); idx+=1; diff --git a/print-syslog.c b/print-syslog.c index 40c8a924..d332f67f 100644 --- a/print-syslog.c +++ b/print-syslog.c @@ -133,7 +133,7 @@ syslog_print(register const u_char *pptr, register u_int len) /* print the syslog text in verbose mode */ for (; msg_off < len; msg_off++) { TCHECK2(*(pptr+msg_off), 1); - safeputchar(*(pptr+msg_off)); + safeputchar(gndo, *(pptr + msg_off)); } if (vflag > 1) diff --git a/print-tcp.c b/print-tcp.c index 32ea7246..4e970038 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -777,7 +777,7 @@ print_tcp_rst_data(register const u_char *sp, u_int length) putchar(' '); while (length-- && sp <= snapend) { c = *sp++; - safeputchar(c); + safeputchar(gndo, c); } putchar(']'); } diff --git a/print-vqp.c b/print-vqp.c index bf25bf7a..e583f445 100644 --- a/print-vqp.c +++ b/print-vqp.c @@ -179,7 +179,7 @@ vqp_print(netdissect_options *ndo, register const u_char *pptr, register u_int l case VQP_OBJ_VLAN_NAME: case VQP_OBJ_VTP_DOMAIN: case VQP_OBJ_ETHERNET_PKT: - safeputs((const char *)tptr, vqp_obj_len); + safeputs(ndo, tptr, vqp_obj_len); break; /* those objects have similar semantics - fall through */ case VQP_OBJ_MAC_ADDRESS: diff --git a/smbutil.c b/smbutil.c index da861232..f6917c02 100644 --- a/smbutil.c +++ b/smbutil.c @@ -245,7 +245,7 @@ print_asc(const unsigned char *buf, int len) { int i; for (i = 0; i < len; i++) - safeputchar(buf[i]); + safeputchar(gndo, buf[i]); } static const char * diff --git a/util.c b/util.c index ff406025..822b60e5 100644 --- a/util.c +++ b/util.c @@ -578,27 +578,23 @@ read_infile(char *fname) } void -safeputs(const char *s, int maxlen) +safeputs(netdissect_options *ndo, + const u_char *s, const u_int maxlen) { - int idx = 0; + u_int idx = 0; while (*s && idx < maxlen) { - safeputchar(*s); - idx++; + safeputchar(ndo, *s); + idx++; s++; } } void -safeputchar(int c) +safeputchar(netdissect_options *ndo, + const u_char c) { - unsigned char ch; - - ch = (unsigned char)(c & 0xff); - if (ch < 0x80 && ND_ISPRINT(ch)) - printf("%c", ch); - else - printf("\\0x%02x", ch); + ND_PRINT((ndo, (c < 0x80 && ND_ISPRINT(c)) ? "%c" : "\\0x%02x", c)); } #ifdef LBL_ALIGN