Cleaner HTML output.
[rsc] --rw-rw-r-- M 667885 glenda sys 14527 Oct 1 11:13 sys/src/cmd/wikifs/tohtml.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:177,187 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:177,223
return p;
}
+ int okayinlist[Nwtxt] =
+ {
+ [Wbullet] 1,
+ [Wlink] 1,
+ [Wman] 1,
+ [Wplain] 1,
+ };
+
+ int okayinpre[Nwtxt] =
+ {
+ [Wlink] 1,
+ [Wman] 1,
+ [Wpre] 1,
+ };
+
+ int okayinpara[Nwtxt] =
+ {
+ [Wpara] 1,
+ [Wlink] 1,
+ [Wman] 1,
+ [Wplain] 1,
+ };
+
+ char*
+ nospaces(char *s)
+ {
+ char *q;
+ s = strdup(s);
+ if(s == nil)
+ return nil;
+ for(q=s; *q; q++)
+ if(*q == ' ')
+ *q = '_';
+ return s;
+ }
+
String*
pagehtml(String *s, Wpage *wtxt, int ty)
{
- int inlist, inpre, inpara;
char *p, tmp[40];
+ int inlist, inpara, inpre, t, tnext;
Wpage *w;
inlist = 0;
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:189,242 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:225,278
inpara = 0;
for(w=wtxt; w; w=w->next){
- switch(w->type){
+ t = w->type;
+ tnext = Whr;
+ if(w->next)
+ tnext = w->next->type;
+
+ if(inlist && !okayinlist[t]){
+ inlist = 0;
+ s = s_append(s, "\n\n\n");
+ }
+ if(inpre && !okayinpre[t]){
+ inpre = 0;
+ s = s_append(s, "\n");
+ }
+
+ switch(t){
case Wheading:
- /*
- if(!inpara){
- inpara = 1;
- s = s_append(s, "\n
\n");
- }
- */
- s = s_appendlist(s, "
\ntext,"\" />", w->text, "
\n", nil);
+ p = nospaces(w->text);
+ s = s_appendlist(s,
+ "\n
",
+ w->text, "
\n", nil);
+ free(p);
break;
case Wpara:
- if(inlist){
- inlist = 0;
- s = s_append(s, "\n\n");
+ if(inpara){
+ s = s_append(s, "\n\n");
+ inpara = 0;
}
- if(inpre){
- inpre = 0;
- s = s_append(s, "\n");
- }
- if(!inpara){
+ if(okayinpara[tnext]){
+ s = s_append(s, "\n\n");
inpara = 1;
- s = s_append(s, "\n
\n");
}
break;
case Wbullet:
- if(inpre){
- inpre = 0;
- s = s_append(s, "\n");
- }
if(!inlist){
inlist = 1;
s = s_append(s, "\n
\n");
- }
- if(inpara)
- inpara = 0;
+ }else
+ s = s_append(s, "\n\n");
s = s_append(s, "\n- \n");
break;
case Wlink:
- if(inpara)
- inpara = 0;
if(w->url == nil)
p = mkurl(w->text, ty);
else
p = w->url;
-
s = s_appendlist(s, "", nil);
s = s_escappend(s, w->text, 0);
s = s_append(s, "");
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:245,253 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:281,286
break;
case Wman:
- if(inpara)
- inpara = 0;
-
sprint(tmp, "%d", w->section);
s = s_appendlist(s,
"\n");
- }
if(!inpre){
inpre = 1;
s = s_append(s, "\n
\n");
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:275,312 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:302,321
break;
case Wplain:
- if(inpre){
- inpre = 0;
- s = s_append(s, "
\n");
- }
- if(inpara)
- inpara = 0;
s = s_escappend(s, w->text, 0);
break;
}
}
if(inlist)
- s = s_append(s, "\n
\n");
+ s = s_append(s, "\n\n\n");
if(inpre)
s = s_append(s, "\n");
- if(!inpara)
- s = s_append(s, "\n\n");
+ if(inpara)
+ s = s_append(s, "\n
\n");
return s;
}
static String*
- grey(String *s)
- {
- return s_append(s, "");
- }
-
- static String*
- ungrey(String *s)
- {
- return s_append(s, "");
- }
-
- static String*
copythru(String *s, char **newp, int *nlinep, int l)
{
char *oq, *q, *r;
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:394,418 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:403,429
p[Blinelen(&b)-1] = '\0';
if((q = strpbrk(p, "acd")) == nil)
continue;
+ n1 = atoi(q+1);
+ if(q = strchr(q, ','))
+ n2 = atoi(q+1);
+ else
+ n2 = n1;
switch(*q){
case 'a':
case 'c':
- n1 = atoi(q+1);
- if(q = strchr(q, ','))
- n2 = atoi(q+1);
- else
- n2 = n1;
- s = grey(s);
+ s = s_append(s, "");
s = copythru(s, &pnew, &nline, n1-1);
- s = ungrey(s);
+ s = s_append(s, "");
s = copythru(s, &pnew, &nline, n2);
+ s = s_append(s, "");
break;
}
}
close(fdiff);
- s = grey(s);
+ s = s_append(s, "");
s = s_append(s, pnew);
- s = ungrey(s);
+ s = s_append(s, "");
+
}
s_free(new);
s_free(old);
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:429,435 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:440,446
char *atime;
for(i=h->ndoc-1; i>=0; i--){
- s = s_append(s, "
\n");
+ s = s_append(s, "
\n");
if(i==h->current)
sprint(tmp, "index.html");
else
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:445,452 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:456,463
s = s_append(s, ", conflicting write");
s = s_append(s, "\n");
if(h->doc[i].comment)
- s = s_appendlist(s, "
", h->doc[i].comment, "\n", nil);
- s = s_append(s, "
");
+ s = s_appendlist(s, "
", h->doc[i].comment, "\n", nil);
+ s = s_append(s, "
");
s = s_diff(s, h, i, i-1);
}
s = s_append(s, "
");
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/tohtml.c:564,570 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/tohtml.c:575,581
break;
x = e; l=LINELEN;
while(l--)
- x+=chartorune(&r,x);
+ x+=chartorune(&r, x);
x = strchr(x, ' ');
if(x){
*x = '\0';
[rsc] --rw-rw-r-- M 667885 glenda sys 916 Oct 1 10:22 sys/src/cmd/wikifs/wiki2html.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/wiki2html.c:10,16 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/wiki2html.c:10,16
void
usage(void)
{
- fprint(2, "usage: wiki2html [-d dir] wikifile\n");
+ fprint(2, "usage: wiki2html [-hoDP ] [-d dir] wikifile\n");
exits("usage");
}
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/wiki2html.c:18,23 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/wiki2html.c:18,24
main(int argc, char **argv)
{
int t;
+ int parse;
String *h;
Whist *doc;
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/wiki2html.c:39,44 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/wiki2html.c:40,47
case 'D':
t = Tdiff;
break;
+ case 'P':
+ parse = 1;
}ARGEND
if(argc != 1)
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/wikifs/wiki2html.c:52,57 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/wikifs/wiki2html.c:55,64
if(doc == nil)
sysfatal("doc: %r");
+ if(parse){
+ printpage(doc->doc->wtxt);
+ exits(0);
+ }
if((h = tohtml(doc, doc->doc+doc->ndoc-1, t)) == nil)
sysfatal("wiki2html: %r");
[rsc] --rw-rw-r-- M 667885 glenda sys 14527 Oct 1 11:13 sys/src/cmd/wikifs/tohtml.c
[sys] --rwxrwxr-x M 667885 glenda sys 202486 Oct 1 23:08 386/bin/wikifs
/sys/src/cmd/wikifs/tohtml.c:diffhtml
/sys/src/cmd/wikifs/tohtml.c:doctext
/sys/src/cmd/wikifs/tohtml.c:dodiff
/sys/src/cmd/wikifs/tohtml.c:grey
/sys/src/cmd/wikifs/tohtml.c:historyhtml
/sys/src/cmd/wikifs/tohtml.c:historytext
/sys/src/cmd/wikifs/tohtml.c:nospaces
/sys/src/cmd/wikifs/tohtml.c:pagehtml
/sys/src/cmd/wikifs/tohtml.c:pagetext
/sys/src/cmd/wikifs/tohtml.c:s_appendbrk
/sys/src/cmd/wikifs/tohtml.c:s_diff
/sys/src/cmd/wikifs/tohtml.c:s_endline
/sys/src/cmd/wikifs/tohtml.c:tohtml
/sys/src/cmd/wikifs/tohtml.c:totext
/sys/src/cmd/wikifs/tohtml.c:ungrey
Add 802.1x protocols from Axel Belinfante.
Clean up help output.
[rsc] --rw-rw-r-- M 667885 glenda sys 4054 Oct 1 11:11 sys/man/8/snoopy
/n/sourcesdump/2005/1001/plan9/sys/man/8/snoopy:4,21 -
/n/sourcesdump/2005/1002/plan9/sys/man/8/snoopy:4,27
.SH SYNOPSIS
.B snoopy
[
- .B -?stdCp
+ .B -CDdpst
] [
- .B -f
- .I filter-expression
- ] [
.B -N
.I n
] [
+ .B -f
+ .I filter-expression
+ ] [
.B -h first-header
] [
packet-file
]
+ .PP
+ .B snoopy
+ .B -?
+ [
+ .I proto...
+ ]
.SH DESCRIPTION
.PP
.I Snoopy
/n/sourcesdump/2005/1001/plan9/sys/man/8/snoopy:33,46 -
/n/sourcesdump/2005/1002/plan9/sys/man/8/snoopy:39,52
contains the dump of any contained data. For example, a
.SM BOOTP
packet would look like:
- .sp
+ .IP
.EX
324389 ms
- ether(s=0000929b1b54 d=ffffffffffff pr=0800 ln=342)
- ip(s=135.104.9.62 d=255.255.255.255 id=5099 frag=0000...
- udp(s=68 d=67 ck=d151 ln= 308)
- bootp(t=Req ht=1 hl=16 hp=0 xid=217e5f27 sec=0 fl=800...
- dhcp(t=Request clientid=0152415320704e7266238ebf01030...
+ ether(s=0000929b1b54 d=ffffffffffff pr=0800 ln=342)
+ ip(s=135.104.9.62 d=255.255.255.255 id=5099 frag=0000...
+ udp(s=68 d=67 ck=d151 ln= 308)
+ bootp(t=Req ht=1 hl=16 hp=0 xid=217e5f27 sec=0 fl=800...
+ dhcp(t=Request clientid=0152415320704e7266238ebf01030...
.EE
.PP
The binary format consists of:
/n/sourcesdump/2005/1001/plan9/sys/man/8/snoopy:54,94 -
/n/sourcesdump/2005/1002/plan9/sys/man/8/snoopy:60,106
Filters are expressions specifying protocols to be traced
and specific values for fields in the protocol headers.
The grammar is:
- .sp
+ .IP
.EX
- expr : protocol
- | field '=' value
- | protocol '(' expr ')'
- | '(' expr ')'
- | expr '||' expr
- | expr '&&' expr
- | '!' expr
+ \fIexpr\fP: \fIprotocol\fP
+ | \fIfield\fP '=' \fIvalue\fP
+ | \fIprotocol\fP '(' \fIexpr\fP ')'
+ | '(' \fIexpr\fP ')'
+ | \fIexpr\fP '||' \fIexpr\fP
+ | \fIexpr\fP '&&' \fIexpr\fP
+ | '!' \fIexpr\fP
.EE
.PP
- The values for and can
+ The values for
+ .I protocol
+ and
+ .I field
+ can
be obtained using the
.B -?
- option. It will list each known protocol,
+ option. With no arguments, it lists the known protocols.
+ Otherwise it prints, for each protocol specified,
which subprotocols it can multiplex to,
and which fields can be used for filtering.
For example, the listing for ethernet is currently:
- .sp
+ .IP
.EX
- ether's filter attr:
- s - source address
- d - destination address
- a - source|destination address
- t - type
+ ether's filter attributes:
+ s - source address
+ d - destination address
+ a - source|destination address
+ sd - source|destination address
+ t - type
ether's subprotos:
- ip
- arp
- rarp
- ip6
- pppoe_disc
- pppoe_sess
+ 0x0800 ip 0x8863 pppoe_disc
+ 0x0806 arp 0x8864 pppoe_sess
+ 0x0806 rarp 0x888e eapol
+ 0x86dd ip6
.EE
.PP
- The format of depends on context. In general,
+ The format of
+ .I value
+ depends on context. In general,
ethernet addresses are entered as a string of hex
digits; IP numbers in the canonical `.' format for v4 and `:' format
for v6; and ports in decimal.
/n/sourcesdump/2005/1001/plan9/sys/man/8/snoopy:96,125 -
/n/sourcesdump/2005/1002/plan9/sys/man/8/snoopy:108,140
.IR Snoopy 's
options are:
.TP
- .B -t
- input is a binary trace file. The default assumes
- a packet device, one packet per read.
- .TP
- .B -d
- output will be a binary trace file. The default is
- human readable.
- .TP
- .B -s
- force one output line per packet. The
- default is multiline.
- .TP
.B -C
- compute correct checksums and if doesn't match
- the contained one, add a field
+ compute the correct checksum for each packet;
+ on mismatch, add a field
.B !ck=\fIxxxx\fP
where
.I xxxx
is the correct checksum.
.TP
+ .B -D
+ output will be a binary trace file in Unix pcap format.
+ .TP
+ .B -d
+ output will be a binary trace file.
+ .TP
+ .B -t
+ input is a binary trace file as generated with the
+ .B -d
+ option.
+ .TP
.B -p
do not enter promiscuous mode. Only packets to
this interface will be seen.
.TP
+ .B -s
+ force one output line per packet. The
+ default is multiline.
+ .TP
.B -N
dump
.I n
/n/sourcesdump/2005/1001/plan9/sys/man/8/snoopy:137,151 -
/n/sourcesdump/2005/1002/plan9/sys/man/8/snoopy:152,166
The default is
.IR ether .
.SH EXAMPLES
- the following would display only
+ To display only
.SM BOOTP
and
.SM ARP
packets:
- .sp
+ .IP
.EX
% snoopy -f 'arp || bootp'
- after optimize: ether( arp || ip( udp( bootp ) ) )
+ after optimize: ether(arp || ip(udp(bootp)))
.EE
.PP
The first line of output shows the completed filter
/n/sourcesdump/2005/1001/plan9/sys/man/8/snoopy:157,163 -
/n/sourcesdump/2005/1002/plan9/sys/man/8/snoopy:172,178
.PP
To save all packets between 135.104.9.2 to 135.104.9.6 and
later display those to/from TCP port 80:
- .sp
+ .IP
.EX
% ramfs
% snoopy -df 'ip(s=135.104.9.2 && d=135.104.9.6) ||\\
/n/sourcesdump/2005/1001/plan9/sys/man/8/snoopy:172,177 -
/n/sourcesdump/2005/1002/plan9/sys/man/8/snoopy:187,192
.SH SOURCE
.B /sys/src/cmd/ip/snoopy
.SH BUGS
- At the moment it only dumps ethernet packets because there's
- no device to get IP packets without the media header. This will
- be corrected soon.
+ .I Snoopy
+ only dumps ethernet packets, because there's
+ no device to get IP packets without a media header.
[rsc] --rw-rw-r-- M 667885 glenda sys 1914 Oct 1 11:12 sys/src/cmd/ip/snoopy/arp.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/arp.c:112,117 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/arp.c:112,118
p_filter,
p_seprint,
nil,
+ nil,
p_fields,
defaultframer,
};
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/arp.c:122,127 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/arp.c:123,129
p_compile,
p_filter,
p_seprint,
+ nil,
nil,
p_fields,
defaultframer,
[rsc] --rw-rw-r-- M 667885 glenda sys 3440 Oct 1 11:12 sys/src/cmd/ip/snoopy/bootp.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/bootp.c:171,176 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/bootp.c:171,177
p_filter,
p_seprint,
p_mux,
+ "%#.8lux",
p_fields,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 glenda sys 1915 Oct 1 11:12 sys/src/cmd/ip/snoopy/dat.h
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/dat.h:18,23 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/dat.h:18,24
int (*filter)(Filter*, Msg*);
int (*seprint)(Msg*);
Mux* mux;
+ char* valfmt;
Field* field;
int (*framer)(int, uchar*, int);
};
[rsc] --rw-rw-r-- M 667885 glenda sys 9104 Oct 1 11:12 sys/src/cmd/ip/snoopy/dhcp.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/dhcp.c:476,481 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/dhcp.c:476,482
p_seprint,
nil,
nil,
+ nil,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 glenda sys 1136 Oct 1 11:12 sys/src/cmd/ip/snoopy/dump.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/dump.c:85,89 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/dump.c:85,90
p_seprint,
nil,
nil,
+ nil,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 rsc sys 3996 Oct 1 11:12 sys/src/cmd/ip/snoopy/eap.c
[rsc] --rw-rw-r-- M 667885 rsc sys 50 Oct 1 11:12 sys/src/cmd/ip/snoopy/eap_identity.c
[rsc] --rw-rw-r-- M 667885 rsc sys 1890 Oct 1 11:12 sys/src/cmd/ip/snoopy/eapol.c
[rsc] --rw-rw-r-- M 667885 rsc sys 2025 Oct 1 11:12 sys/src/cmd/ip/snoopy/eapol_key.c
[rsc] --rw-rw-r-- M 667885 glenda sys 2013 Oct 1 11:12 sys/src/cmd/ip/snoopy/ether.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ether.c:23,28 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ether.c:23,29
{"ip6", 0x86dd, } ,
{"pppoe_disc", 0x8863, },
{"pppoe_sess", 0x8864, },
+ {"eapol", 0x888e, },
{0}
};
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ether.c:116,121 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ether.c:117,123
p_filter,
p_seprint,
p_mux,
+ "%#.4lux",
p_fields,
defaultframer
};
[rsc] --rw-rw-r-- M 667885 rsc sys 4285 Oct 1 11:12 sys/src/cmd/ip/snoopy/hdlc.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/hdlc.c:169,174 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/hdlc.c:169,175
p_filter,
p_seprint,
p_mux,
+ "%#.4lux",
nil,
p_framer,
};
[rsc] --rw-rw-r-- M 667885 glenda sys 2969 Oct 1 11:12 sys/src/cmd/ip/snoopy/icmp.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/icmp.c:191,196 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/icmp.c:191,197
p_filter,
p_seprint,
p_mux,
+ "%lud",
p_fields,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 glenda sys 7736 Oct 1 11:12 sys/src/cmd/ip/snoopy/icmp6.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/icmp6.c:423,428 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/icmp6.c:423,429
p_filter,
p_seprint,
p_mux,
+ "%lud",
p_fields,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 glenda sys 2255 Oct 1 11:12 sys/src/cmd/ip/snoopy/il.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/il.c:142,147 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/il.c:142,148
p_filter,
p_seprint,
p_mux,
+ "%lud",
p_fields,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 glenda sys 4300 Oct 1 11:12 sys/src/cmd/ip/snoopy/ip.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ip.c:231,236 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ip.c:231,237
p_filter,
p_seprint,
p_mux,
+ "%lud",
p_fields,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 glenda sys 5371 Oct 1 11:12 sys/src/cmd/ip/snoopy/ip6.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ip6.c:304,309 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ip6.c:304,310
p_filter,
p_seprint,
p_mux,
+ "%lud",
p_fields,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 glenda sys 15408 Oct 1 11:12 sys/src/cmd/ip/snoopy/main.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/main.c:35,48 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/main.c:35,55
Proto* findproto(char *name);
Filter* compile(Filter *f);
void printfilter(Filter *f, char *tag);
- void printhelp(void);
+ void printhelp(char*);
void tracepkt(uchar*, int);
void pcaphdr(void);
void
+ printusage(void)
+ {
+ fprint(2, "usage: %s [-CDdpst] [-N n] [-f filter] [-h first-header] path\n", argv0);
+ fprint(2, " for protocol help: %s -? [proto]\n", argv0);
+ }
+
+ void
usage(void)
{
- fprint(2, "usage: %s [-std?] [-c] [-N n] [-f filter] [-h first-header] path", argv0);
+ printusage();
exits("usage");
}
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/main.c:74,93 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/main.c:81,99
mkprotograph();
ARGBEGIN{
+ default:
+ usage();
case '?':
- printhelp();
+ printusage();
+ printhelp(ARGF());
exits(0);
break;
case 'N':
- p = ARGF();
- if(p == nil)
- usage();
+ p = EARGF(usage());
Nflag = atoi(p);
break;
case 'f':
- p = ARGF();
- if(p == nil)
- usage();
+ p = EARGF(usage());
yyinit(p);
yyparse();
break;
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/main.c:95,103 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/main.c:101,107
sflag = 1;
break;
case 'h':
- p = ARGF();
- if(p == nil)
- usage();
+ p = EARGF(usage());
root = findproto(p);
if(root == nil)
sysfatal("unknown protocol: %s", p);
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/main.c:770,778 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/main.c:774,782
case WORD:
fprint(2, "%s", f->s);
if(f->l != nil){
- fprint(2, "( ");
+ fprint(2, "(");
_pf(f->l);
- fprint(2, " )");
+ fprint(2, ")");
}
break;
case LAND:
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/main.c:805,828 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/main.c:809,904
}
void
- printhelp(void)
+ cat(void)
{
+ char buf[1024];
+ int n;
+
+ while((n = read(0, buf, sizeof buf)) > 0)
+ write(1, buf, n);
+ }
+
+ static int fd1 = -1;
+ void
+ startmc(void)
+ {
+ int p[2];
+
+ if(fd1 == -1)
+ fd1 = dup(1, -1);
+
+ if(pipe(p) < 0)
+ return;
+ switch(fork()){
+ case -1:
+ return;
+ default:
+ close(p[0]);
+ dup(p[1], 1);
+ if(p[1] != 1)
+ close(p[1]);
+ return;
+ case 0:
+ close(p[1]);
+ dup(p[0], 0);
+ if(p[0] != 0)
+ close(p[0]);
+ execl("/bin/mc", "mc", nil);
+ cat();
+ _exits(0);
+ }
+ }
+
+ void
+ stopmc(void)
+ {
+ close(1);
+ dup(fd1, 1);
+ waitpid();
+ }
+
+ void
+ printhelp(char *name)
+ {
+ int len;
Proto *pr, **l;
Mux *m;
Field *f;
-
- for(l = protos; *l != nil; l++){
- pr = *l;
- if(pr->field != nil){
- print("%s's filter attr:\n", pr->name);
- for(f = pr->field; f->name != nil; f++)
- print("\t%s\t- %s\n", f->name, f->help);
- }
- if(pr->mux != nil){
- print("%s's subprotos:\n", pr->name);
- for(m = pr->mux; m->name != nil; m++)
- print("\t%s\n", m->name);
- }
+ char fmt[40];
+
+ if(name == nil){
+ print("protocols:\n");
+ startmc();
+ for(l=protos; (pr=*l) != nil; l++)
+ print(" %s\n", pr->name);
+ stopmc();
+ return;
+ }
+
+ pr = findproto(name);
+ if(pr == nil){
+ print("unknown protocol %s\n", name);
+ return;
+ }
+
+ if(pr->field){
+ print("%s's filter attributes:\n", pr->name);
+ len = 0;
+ for(f=pr->field; f->name; f++)
+ if(len < strlen(f->name))
+ len = strlen(f->name);
+ startmc();
+ for(f=pr->field; f->name; f++)
+ print(" %-*s - %s\n", len, f->name, f->help);
+ stopmc();
+ }
+ if(pr->mux){
+ print("%s's subprotos:\n", pr->name);
+ startmc();
+ snprint(fmt, sizeof fmt, " %s %%s\n", pr->valfmt);
+ for(m=pr->mux; m->name != nil; m++)
+ print(fmt, m->val, m->name);
+ stopmc();
}
}
[rsc] --rw-rw-r-- M 667885 glenda sys 849 Oct 1 11:12 sys/src/cmd/ip/snoopy/mkfile
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/mkfile:2,32 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/mkfile:2,38
TARG=snoopy
PROTOS=\
- ether\
- ip\
- ip6\
- dump\
arp\
- rarp\
- udp\
bootp\
dhcp\
+ dump\
+ eap\
+ eap_identity\
+ eapol\
+ eapol_key\
+ ether\
hdlc\
- rtp\
- rtcp\
- tcp\
- il\
- icmp\
icmp6\
+ icmp\
+ il\
+ ip6\
+ ip\
ninep\
ospf\
ppp\
ppp_ccp\
- ppp_lcp\
ppp_chap\
ppp_ipcp\
- pppoe_sess\
+ ppp_lcp\
pppoe_disc\
+ pppoe_sess\
+ rarp\
+ rc4keydesc\
+ rtcp\
+ rtp\
+ tcp\
+ ttls\
+ udp\
POBJS=${PROTOS:%=%.$O}
[rsc] --rw-rw-r-- M 667885 glenda sys 701 Oct 1 11:12 sys/src/cmd/ip/snoopy/ninep.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ninep.c:49,53 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ninep.c:49,54
p_seprint,
nil,
nil,
+ nil,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 glenda sys 7522 Oct 1 11:12 sys/src/cmd/ip/snoopy/ospf.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ospf.c:397,401 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ospf.c:397,402
p_seprint,
nil,
nil,
+ nil,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 glenda sys 10544 Oct 1 11:12 sys/src/cmd/ip/snoopy/ppp.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ppp.c:569,574 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ppp.c:569,575
p_filter,
p_seprint,
p_mux,
+ "%#.4lux",
nil,
defaultframer,
};
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ppp.c:581,586 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ppp.c:582,588
p_seprintipcp,
nil,
nil,
+ nil,
defaultframer,
};
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ppp.c:592,597 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ppp.c:594,600
p_seprintlcp,
nil,
nil,
+ nil,
defaultframer,
};
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ppp.c:603,608 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ppp.c:606,612
p_seprintccp,
nil,
nil,
+ nil,
defaultframer,
};
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ppp.c:614,619 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ppp.c:618,624
p_seprintchap,
nil,
nil,
+ nil,
defaultframer,
};
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/ppp.c:623,628 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/ppp.c:628,634
p_compile,
p_filter,
p_seprintcomp,
+ nil,
nil,
nil,
defaultframer,
[rsc] --rw-rw-r-- M 667885 rsc sys 2513 Oct 1 11:12 sys/src/cmd/ip/snoopy/pppoe_disc.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/pppoe_disc.c:155,160 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/pppoe_disc.c:155,161
p_filter,
p_seprintdisc,
p_mux,
+ "%lud",
p_fields,
defaultframer
};
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/pppoe_disc.c:166,171 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/pppoe_disc.c:167,173
p_filter,
p_seprintsess,
p_mux,
+ "%lud",
p_fields,
defaultframer
};
[rsc] --rw-rw-r-- M 667885 rsc sys 56 Oct 1 11:12 sys/src/cmd/ip/snoopy/rc4keydesc.c
[rsc] --rw-rw-r-- M 667885 jmk sys 1964 Oct 1 11:12 sys/src/cmd/ip/snoopy/rtcp.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/rtcp.c:91,95 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/rtcp.c:91,96
p_seprint,
nil,
nil,
+ nil,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 jmk sys 1166 Oct 1 11:12 sys/src/cmd/ip/snoopy/rtp.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/rtp.c:70,74 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/rtp.c:70,75
p_seprint,
nil,
nil,
+ nil,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 glenda sys 3602 Oct 1 11:12 sys/src/cmd/ip/snoopy/tcp.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/tcp.c:216,221 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/tcp.c:216,222
p_filter,
p_seprint,
p_mux,
+ "%lud",
p_fields,
defaultframer,
};
[rsc] --rw-rw-r-- M 667885 rsc sys 1451 Oct 1 11:12 sys/src/cmd/ip/snoopy/ttls.c
[rsc] --rw-rw-r-- M 667885 glenda sys 1999 Oct 1 11:12 sys/src/cmd/ip/snoopy/udp.c
/n/sourcesdump/2005/1001/plan9/sys/src/cmd/ip/snoopy/udp.c:126,131 -
/n/sourcesdump/2005/1002/plan9/sys/src/cmd/ip/snoopy/udp.c:126,132
p_filter,
p_seprint,
p_mux,
+ "%lud",
p_fields,
defaultframer,
};
[sys] --rwxrwxr-x M 667885 glenda sys 168209 Oct 1 23:08 386/bin/snoopy
/sys/src/cmd/ip/snoopy/eap.c:op
/sys/src/cmd/ip/snoopy/eap.c:p_compile
/sys/src/cmd/ip/snoopy/eap.c:p_filter
/sys/src/cmd/ip/snoopy/eap.c:p_seprint
/sys/src/cmd/ip/snoopy/eap.c:p_seprintidentity
/sys/src/cmd/ip/snoopy/eap.c:subop
/sys/src/cmd/ip/snoopy/eapol.c:op
/sys/src/cmd/ip/snoopy/eapol.c:p_compile
/sys/src/cmd/ip/snoopy/eapol.c:p_filter
/sys/src/cmd/ip/snoopy/eapol.c:p_seprint
/sys/src/cmd/ip/snoopy/eapol_key.c:op
/sys/src/cmd/ip/snoopy/eapol_key.c:p_compile
/sys/src/cmd/ip/snoopy/eapol_key.c:p_filter
/sys/src/cmd/ip/snoopy/eapol_key.c:p_seprint
/sys/src/cmd/ip/snoopy/eapol_key.c:p_seprintrc4
/sys/src/cmd/ip/snoopy/ether.c:p_compile
/sys/src/cmd/ip/snoopy/ether.c:p_seprint
/sys/src/cmd/ip/snoopy/filter.y:yylex1
/sys/src/cmd/ip/snoopy/filter.y:yytokname
/sys/src/cmd/ip/snoopy/main.c:_compile
/sys/src/cmd/ip/snoopy/main.c:_filterpkt
/sys/src/cmd/ip/snoopy/main.c:_pf
/sys/src/cmd/ip/snoopy/main.c:addproto
/sys/src/cmd/ip/snoopy/main.c:cat
/sys/src/cmd/ip/snoopy/main.c:compile
/sys/src/cmd/ip/snoopy/main.c:compile_cmp
/sys/src/cmd/ip/snoopy/main.c:complete
/sys/src/cmd/ip/snoopy/main.c:findbogus
/sys/src/cmd/ip/snoopy/main.c:main
/sys/src/cmd/ip/snoopy/main.c:newfilter
/sys/src/cmd/ip/snoopy/main.c:printfilter
/sys/src/cmd/ip/snoopy/main.c:printhelp
/sys/src/cmd/ip/snoopy/main.c:printpkt
/sys/src/cmd/ip/snoopy/main.c:printusage
/sys/src/cmd/ip/snoopy/main.c:startmc
/sys/src/cmd/ip/snoopy/main.c:stopmc
/sys/src/cmd/ip/snoopy/main.c:usage
/sys/src/cmd/ip/snoopy/ttls.c:flags
/sys/src/cmd/ip/snoopy/ttls.c:p_seprint
/sys/src/libc/9sys/fork.c:fork
/sys/src/libc/9sys/waitpid.c:waitpid
/sys/src/libc/9syscall/await.s:await
/sys/src/libc/9syscall/dup.s:dup
/sys/src/libc/9syscall/exec.s:exec
/sys/src/libc/9syscall/pipe.s:pipe
/sys/src/libc/9syscall/rfork.s:rfork
/sys/src/libc/fmt/fmt.c:_fmtinstall
/sys/src/libc/port/execl.c:execl
/sys/src/libc/port/tokenize.c:etoken
/sys/src/libc/port/tokenize.c:gettokens
/sys/src/libc/port/tokenize.c:qtoken
/sys/src/libc/port/tokenize.c:tokenize
/sys/src/libc/port/utfrune.c:utfrune