in tcpdumpw/main.go [574:605]
func parseEphemeralPorts(ephemerals *string) *pcap.PcapEphemeralPorts {
// default ephemeral ports range
ephemeralPortRange := &pcap.PcapEphemeralPorts{
Min: pcap.PCAP_MIN_EPHEMERAL_PORT,
Max: pcap.PCAP_MAX_EPHEMERAL_PORT,
}
if *ephemerals == "" {
return ephemeralPortRange
}
ephemeralPorts := strings.SplitN(*ephemerals, ",", 2)
if len(ephemeralPorts) != 2 {
return ephemeralPortRange
}
for i, valueStr := range ephemeralPorts {
if value, err := strconv.ParseUint(valueStr, 10, 16); err != nil && value >= 0x0400 && value <= 0xFFFF {
// see: https://datatracker.ietf.org/doc/html/rfc6056#page-5
// a valid `ephemeral port` must be within RFC 6056 range: [1024/0x4000,65535/0xFFFF]
port := uint16(value)
if i == 0 && port < ephemeralPortRange.Max {
ephemeralPortRange.Min = uint16(value)
} else if port > ephemeralPortRange.Min {
ephemeralPortRange.Max = uint16(value)
}
}
}
return ephemeralPortRange
}