snoopy 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. .TH SNOOPY 8
  2. .SH NAME
  3. snoopy \- spy on network packets
  4. .SH SYNOPSIS
  5. .B snoopy
  6. [
  7. .B -CDdpst
  8. ] [
  9. .B -N
  10. .I n
  11. ] [
  12. .B -f
  13. .I filter-expression
  14. ] [
  15. .B -h first-header
  16. ] [
  17. packet-file
  18. ]
  19. .PP
  20. .B snoopy
  21. .B -?
  22. [
  23. .I proto...
  24. ]
  25. .SH DESCRIPTION
  26. .PP
  27. .I Snoopy
  28. reads packets from a packet source (default
  29. .BR /net/ether0 ),
  30. matches them to a filter (by default anything matches), and writes
  31. matching packets to standard output either in human readable form (default)
  32. or in a binary trace format that can be reinput to
  33. .IR snoopy .
  34. .PP
  35. The human readable format consists of multiple lines per packet.
  36. The first line contains the milliseconds since the
  37. trace was started. Subsequent ones are indented with a tab
  38. and each contains the dump of a single protocol header. The last line
  39. contains the dump of any contained data. For example, a
  40. .SM BOOTP
  41. packet would look like:
  42. .IP
  43. .EX
  44. 324389 ms
  45. ether(s=0000929b1b54 d=ffffffffffff pr=0800 ln=342)
  46. ip(s=135.104.9.62 d=255.255.255.255 id=5099 frag=0000...
  47. udp(s=68 d=67 ck=d151 ln= 308)
  48. bootp(t=Req ht=1 hl=16 hp=0 xid=217e5f27 sec=0 fl=800...
  49. dhcp(t=Request clientid=0152415320704e7266238ebf01030...
  50. .EE
  51. .PP
  52. The binary format consists of:
  53. .IP
  54. 2 bytes of packet length, msb first
  55. .IP
  56. 8 bytes of nanosecond time, msb first
  57. .IP
  58. the packet
  59. .PP
  60. Filters are expressions specifying protocols to be traced
  61. and specific values for fields in the protocol headers.
  62. The grammar is:
  63. .IP
  64. .EX
  65. \fIexpr\fP: \fIprotocol\fP
  66. | \fIfield\fP '=' \fIvalue\fP
  67. | \fIfield\fP '!=' \fIvalue\fP
  68. | \fIprotocol\fP '(' \fIexpr\fP ')'
  69. | '(' \fIexpr\fP ')'
  70. | \fIexpr\fP '||' \fIexpr\fP
  71. | \fIexpr\fP '&&' \fIexpr\fP
  72. | '!' \fIexpr\fP
  73. .EE
  74. .PP
  75. The values for
  76. .I protocol
  77. and
  78. .I field
  79. can
  80. be obtained using the
  81. .B -?
  82. option. With no arguments, it lists the known protocols.
  83. Otherwise it prints, for each protocol specified,
  84. which subprotocols it can multiplex to,
  85. and which fields can be used for filtering.
  86. For example, the listing for ethernet is currently:
  87. .IP
  88. .EX
  89. ether's filter attributes:
  90. s - source address
  91. d - destination address
  92. a - source|destination address
  93. sd - source|destination address
  94. t - type
  95. ether's subprotos:
  96. 0x0800 ip 0x8863 pppoe_disc
  97. 0x0806 arp 0x8864 pppoe_sess
  98. 0x0806 rarp 0x888e eapol
  99. 0x86dd ip6
  100. .EE
  101. .PP
  102. The format of
  103. .I value
  104. depends on context. In general,
  105. ethernet addresses are entered as a string of hex
  106. digits; IP numbers in the canonical `.' format for v4 and `:' format
  107. for v6; and ports in decimal.
  108. .PP
  109. .IR Snoopy 's
  110. options are:
  111. .TP
  112. .B -C
  113. compute the correct checksum for each packet;
  114. on mismatch, add a field
  115. .B !ck=\fIxxxx\fP
  116. where
  117. .I xxxx
  118. is the correct checksum.
  119. .TP
  120. .B -D
  121. output will be a binary trace file in Unix pcap format.
  122. .TP
  123. .B -d
  124. output will be a binary trace file.
  125. .TP
  126. .B -t
  127. input is a binary trace file as generated with the
  128. .B -d
  129. option.
  130. .TP
  131. .B -p
  132. do not enter promiscuous mode. Only packets to
  133. this interface will be seen.
  134. .TP
  135. .B -s
  136. force one output line per packet. The
  137. default is multiline.
  138. .TP
  139. .B -N
  140. dump
  141. .I n
  142. data bytes per packet. The default is 32.
  143. .TP
  144. .B -f
  145. use
  146. .I filter-expression
  147. to filter the packet stream. The default is
  148. to match all packets.
  149. .TP
  150. .B -h
  151. assume the first header per packet to be
  152. .IR first-header .
  153. The default is
  154. .IR ether .
  155. .SH EXAMPLES
  156. To display only
  157. .SM BOOTP
  158. and
  159. .SM ARP
  160. packets:
  161. .IP
  162. .EX
  163. % snoopy -f 'arp || bootp'
  164. after optimize: ether(arp || ip(udp(bootp)))
  165. .EE
  166. .PP
  167. The first line of output shows the completed filter
  168. expression.
  169. .I Snoopy
  170. will fill in other protocols as necessary to complete
  171. the filter and then optimize to remove redundant
  172. comparisons.
  173. .PP
  174. To save all packets between 135.104.9.2 to 135.104.9.6 and
  175. later display those to/from TCP port 80:
  176. .IP
  177. .EX
  178. % ramfs
  179. % snoopy -df 'ip(s=135.104.9.2 && d=135.104.9.6) ||\\
  180. ip(s=135.104.9.6 && d=135.104.9.2)' > /tmp/quux
  181. <interrupt from the keyboard>
  182. % snoopy -tf 'tcp(sd=80)' /tmp/quux
  183. .EE
  184. .SH FILES
  185. .TP
  186. .B /net/ether
  187. Ethernet device
  188. .SH SOURCE
  189. .B /sys/src/cmd/ip/snoopy
  190. .SH BUGS
  191. .I Snoopy
  192. only dumps ethernet packets, because there's
  193. no device to get IP packets without a media header.