CapturePcap can be called by the application code compiled with tsnet to save a pcap of packets which the netstack within tsnet sees. This is expected to be useful during debugging, probably not useful for production. Packets will be written to the pcap until the process exits. The pcap needs a Lua
(ctx context.Context, pcapFile string)
| 2210 | // in this repository. |
| 2211 | // https://tailscale.com/docs/reference/troubleshooting/network-configuration/inspect-unencrypted-packets |
| 2212 | func (s *Server) CapturePcap(ctx context.Context, pcapFile string) error { |
| 2213 | stream, err := s.localClient.StreamDebugCapture(ctx) |
| 2214 | if err != nil { |
| 2215 | return err |
| 2216 | } |
| 2217 | |
| 2218 | f, err := os.OpenFile(pcapFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) |
| 2219 | if err != nil { |
| 2220 | stream.Close() |
| 2221 | return err |
| 2222 | } |
| 2223 | |
| 2224 | go func(stream io.ReadCloser, f *os.File) { |
| 2225 | defer stream.Close() |
| 2226 | defer f.Close() |
| 2227 | _, _ = io.Copy(f, stream) |
| 2228 | }(stream, f) |
| 2229 | |
| 2230 | return nil |
| 2231 | } |
| 2232 | |
| 2233 | // Sys returns a handle to the Tailscale subsystems of this node. |
| 2234 | // |