1
0

snoopy 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. | \fIprotocol\fP '(' \fIexpr\fP ')'
  68. | '(' \fIexpr\fP ')'
  69. | \fIexpr\fP '||' \fIexpr\fP
  70. | \fIexpr\fP '&&' \fIexpr\fP
  71. | '!' \fIexpr\fP
  72. .EE
  73. .PP
  74. The values for
  75. .I protocol
  76. and
  77. .I field
  78. can
  79. be obtained using the
  80. .B -?
  81. option. With no arguments, it lists the known protocols.
  82. Otherwise it prints, for each protocol specified,
  83. which subprotocols it can multiplex to,
  84. and which fields can be used for filtering.
  85. For example, the listing for ethernet is currently:
  86. .IP
  87. .EX
  88. ether's filter attributes:
  89. s - source address
  90. d - destination address
  91. a - source|destination address
  92. sd - source|destination address
  93. t - type
  94. ether's subprotos:
  95. 0x0800 ip 0x8863 pppoe_disc
  96. 0x0806 arp 0x8864 pppoe_sess
  97. 0x0806 rarp 0x888e eapol
  98. 0x86dd ip6
  99. .EE
  100. .PP
  101. The format of
  102. .I value
  103. depends on context. In general,
  104. ethernet addresses are entered as a string of hex
  105. digits; IP numbers in the canonical `.' format for v4 and `:' format
  106. for v6; and ports in decimal.
  107. .PP
  108. .IR Snoopy 's
  109. options are:
  110. .TP
  111. .B -C
  112. compute the correct checksum for each packet;
  113. on mismatch, add a field
  114. .B !ck=\fIxxxx\fP
  115. where
  116. .I xxxx
  117. is the correct checksum.
  118. .TP
  119. .B -D
  120. output will be a binary trace file in Unix pcap format.
  121. .TP
  122. .B -d
  123. output will be a binary trace file.
  124. .TP
  125. .B -t
  126. input is a binary trace file as generated with the
  127. .B -d
  128. option.
  129. .TP
  130. .B -p
  131. do not enter promiscuous mode. Only packets to
  132. this interface will be seen.
  133. .TP
  134. .B -s
  135. force one output line per packet. The
  136. default is multiline.
  137. .TP
  138. .B -N
  139. dump
  140. .I n
  141. data bytes per packet. The default is 32.
  142. .TP
  143. .B -f
  144. use
  145. .I filter-expression
  146. to filter the packet stream. The default is
  147. to match all packets.
  148. .TP
  149. .B -h
  150. assume the first header per packet to be
  151. .IR first-header .
  152. The default is
  153. .IR ether .
  154. .SH EXAMPLES
  155. To display only
  156. .SM BOOTP
  157. and
  158. .SM ARP
  159. packets:
  160. .IP
  161. .EX
  162. % snoopy -f 'arp || bootp'
  163. after optimize: ether(arp || ip(udp(bootp)))
  164. .EE
  165. .PP
  166. The first line of output shows the completed filter
  167. expression.
  168. .I Snoopy
  169. will fill in other protocols as necessary to complete
  170. the filter and then optimize to remove redundant
  171. comparisons.
  172. .PP
  173. To save all packets between 135.104.9.2 to 135.104.9.6 and
  174. later display those to/from TCP port 80:
  175. .IP
  176. .EX
  177. % ramfs
  178. % snoopy -df 'ip(s=135.104.9.2 && d=135.104.9.6) ||\\
  179. ip(s=135.104.9.6 && d=135.104.9.2)' > /tmp/quux
  180. <interrupt from the keyboard>
  181. % snoopy -tf 'tcp(sd=80)' /tmp/quux
  182. .EE
  183. .SH FILES
  184. .TP
  185. .B /net/ether
  186. Ethernet device
  187. .SH SOURCE
  188. .B /sys/src/cmd/ip/snoopy
  189. .SH BUGS
  190. .I Snoopy
  191. only dumps ethernet packets, because there's
  192. no device to get IP packets without a media header.