1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#include <u.h>
#include <libc.h>
#include <oventi.h>
#include "session.h"
void vtDumpSome(Packet*);
void
vtDebug(VtSession *s, char *fmt, ...)
{
va_list arg;
if(!s->debug)
return;
va_start(arg, fmt);
vfprint(2, fmt, arg);
va_end(arg);
}
void
vtDebugMesg(VtSession *z, Packet *p, char *s)
{
int op;
int tid;
int n;
uchar buf[100], *b;
if(!z->debug)
return;
n = packetSize(p);
if(n < 2) {
fprint(2, "runt packet%s", s);
return;
}
b = packetPeek(p, buf, 0, 2);
op = b[0];
tid = b[1];
fprint(2, "%c%d[%d] %d", ((op&1)==0)?'R':'Q', op, tid, n);
vtDumpSome(p);
fprint(2, "%s", s);
}
void
vtDumpSome(Packet *pkt)
{
int printable;
int i, n;
char buf[200], *q, *eq;
uchar data[32], *p;
n = packetSize(pkt);
printable = 1;
q = buf;
eq = buf + sizeof(buf);
q = seprint(q, eq, "(%d) '", n);
if(n > sizeof(data))
n = sizeof(data);
p = packetPeek(pkt, data, 0, n);
for(i=0; i<n && printable; i++)
if((p[i]<32 && p[i] !='\n' && p[i] !='\t') || p[i]>127)
printable = 0;
if(printable) {
for(i=0; i<n; i++)
q = seprint(q, eq, "%c", p[i]);
} else {
for(i=0; i<n; i++) {
if(i>0 && i%4==0)
q = seprint(q, eq, " ");
q = seprint(q, eq, "%.2X", p[i]);
}
}
seprint(q, eq, "'");
fprint(2, "%s", buf);
}
|