aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ip/snoopy/dump.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/ip/snoopy/dump.c')
-rwxr-xr-xsrc/cmd/ip/snoopy/dump.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/cmd/ip/snoopy/dump.c b/src/cmd/ip/snoopy/dump.c
new file mode 100755
index 00000000..5174e4fc
--- /dev/null
+++ b/src/cmd/ip/snoopy/dump.c
@@ -0,0 +1,92 @@
+#include <u.h>
+#include <libc.h>
+#include <ip.h>
+#include <ctype.h>
+#include "dat.h"
+#include "protos.h"
+
+static void
+p_compile(Filter *f)
+{
+ USED(f);
+}
+
+static int
+p_filter(Filter *f, Msg *m)
+{
+ USED(f);
+ USED(m);
+ return 0;
+}
+
+static char tohex[16] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'a', 'b', 'c', 'd', 'e', 'f'
+};
+
+static int
+p_seprint(Msg *m)
+{
+ int c, i, n, isstring;
+ uchar *ps = m->ps;
+ char *p = m->p;
+ char *e = m->e;
+
+ n = m->pe - ps;
+ if(n > Nflag)
+ n = Nflag;
+
+ isstring = 1;
+ for(i = 0; i < n; i++){
+ c = ps[i];
+ if(!isprint(c) && !isspace(c)){
+ isstring = 0;
+ break;
+ }
+ }
+
+ if(isstring){
+ for(i = 0; i < n && p+1<e; i++){
+ c = ps[i];
+ switch(c){
+ case '\t':
+ *p++ = '\\';
+ *p++ = 't';
+ break;
+ case '\r':
+ *p++ = '\\';
+ *p++ = 'r';
+ break;
+ case '\n':
+ *p++ = '\\';
+ *p++ = 'n';
+ break;
+ default:
+ *p++ = c;
+ }
+ }
+ } else {
+ for(i = 0; i < n && p+1<e; i++){
+ c = ps[i];
+ *p++ = tohex[c>>4];
+ *p++ = tohex[c&0xf];
+ }
+ }
+
+ m->pr = nil;
+ m->p = p;
+ m->ps = ps;
+
+ return 0;
+}
+
+Proto dump =
+{
+ "dump",
+ p_compile,
+ p_filter,
+ p_seprint,
+ nil,
+ nil,
+ defaultframer,
+};