MCPcopy Index your code
hub / github.com/tailscale/tailscale / CapturePcap

Method CapturePcap

tsnet/tsnet.go:2212–2231  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2210// in this repository.
2211// https://tailscale.com/docs/reference/troubleshooting/network-configuration/inspect-unencrypted-packets
2212func (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//

Callers 1

TestCapturePcapFunction · 0.80

Calls 3

StreamDebugCaptureMethod · 0.80
CloseMethod · 0.65
OpenFileMethod · 0.45

Tested by 1

TestCapturePcapFunction · 0.64