#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.95.2.2 2005-04-26 03:44:36 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.95.2.6 2006-02-08 01:40:09 hannes Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "interface.h"
/*
- * Print out a filename (or other ascii string).
+ * Print out a null-terminated filename (or other ascii string).
* If ep is NULL, assume no truncation check is needed.
* Return true if truncated.
*/
return (n == 0) ? 0 : 1;
}
+/*
+ * Print out a null-padded filename (or other ascii string).
+ * If ep is NULL, assume no truncation check is needed.
+ * Return true if truncated.
+ */
+int
+fn_printzp(register const u_char *s, register u_int n,
+ register const u_char *ep)
+{
+ register int ret;
+ register u_char c;
+
+ ret = 1; /* assume truncated */
+ while (n > 0 && (ep == NULL || s < ep)) {
+ n--;
+ c = *s++;
+ if (c == '\0') {
+ ret = 0;
+ break;
+ }
+ if (!isascii(c)) {
+ c = toascii(c);
+ putchar('M');
+ putchar('-');
+ }
+ if (!isprint(c)) {
+ c ^= 0x40; /* DEL to ?, others to alpha */
+ putchar('^');
+ }
+ putchar(c);
+ }
+ return (n == 0) ? 0 : ret;
+}
+
/*
* Print the timestamp
*/
int
print_unknown_data(const u_char *cp,const char *ident,int len)
{
+ if (len < 0) {
+ printf("%sDissector error: print_unknown_data called with negative length",
+ ident);
+ return(0);
+ }
if (snapend - cp < len)
len = snapend - cp;
+ if (len < 0) {
+ printf("%sDissector error: print_unknown_data called with pointer past end of packet",
+ ident);
+ return(0);
+ }
hex_print(ident,cp,len);
return(1); /* everything is ok */
}
}
void
-safeputs(const char *s)
+safeputs(const char *s, int maxlen)
{
- while (*s) {
+ int idx = 0;
+ while (*s && idx < maxlen) {
safeputchar(*s);
+ idx++;
s++;
}
}