Files
mediamtx/internal/packetdumper/dial_context.go
T
Alessandro RosandGitHub 35e1f486c9 add integrated packet dumper (#5488)
this allows to dump any incoming and outgoing packet, to disk, in
pcapng format.
2026-02-22 13:34:05 +01:00

33 lines
632 B
Go

package packetdumper
import (
"context"
"net"
)
// DialContext is a wrapper around net.Dialer.DialContext that dumps packets to disk.
type DialContext struct {
Prefix string
DialContext func(ctx context.Context, network, address string) (net.Conn, error)
}
// Do mimics net.Dialer.DialContext.
func (d *DialContext) Do(ctx context.Context, network, address string) (net.Conn, error) {
conn, err := d.DialContext(ctx, network, address)
if err != nil {
return nil, err
}
c := &Conn{
Prefix: d.Prefix,
Conn: conn,
}
err = c.Initialize()
if err != nil {
conn.Close()
return nil, err
}
return c, nil
}