snoopy 4.2 KB

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