func()

in tcpdumpw/pkg/filter/dns_filter_provider.go [48:83]


func (p *DNSFilterProvider) hostsToIPs(ctx context.Context) (mapset.Set[string], bool) {
	if *p.Raw == "" ||
		strings.EqualFold(*p.Raw, "ALL") ||
		strings.EqualFold(*p.Raw, "ANY") {
		return nil, false
	}

	hosts := strings.Split(*p.Raw, ",")
	if len(hosts) == 0 || (len(hosts) == 1 && hosts[0] == "") {
		return nil, false
	}

	ipSet := mapset.NewThreadUnsafeSet[string]()
	for _, host := range hosts {
		if host == "" ||
			strings.EqualFold(host, "ALL") ||
			strings.EqualFold(host, "ANY") {
			continue
		}

		if IPs, ok := p.hostToIPs(ctx, &host); ok {
			for _, IP := range IPs {
				if addr, err := netip.ParseAddr(IP); err == nil {
					ipSet.Add(addr.String())
					if addr.Is4() {
						p.compatFilters.AddIPv4s(IP)
					} else {
						p.compatFilters.AddIPv6s(IP)
					}
				}
			}
		}
	}

	return ipSet, true
}