mihomo/rules/ipcidr.go

39 lines
544 B
Go
Raw Permalink Normal View History

2018-06-10 22:50:03 +08:00
package rules
import (
"net"
C "github.com/Dreamacro/clash/constant"
)
type IPCIDR struct {
ipnet *net.IPNet
adapter string
}
func (i *IPCIDR) RuleType() C.RuleType {
return C.IPCIDR
}
func (i *IPCIDR) IsMatch(addr *C.Addr) bool {
2018-06-11 18:36:39 +08:00
if addr.IP == nil {
2018-06-10 22:50:03 +08:00
return false
}
2018-06-11 18:36:39 +08:00
return i.ipnet.Contains(*addr.IP)
2018-06-10 22:50:03 +08:00
}
func (g *IPCIDR) Adapter() string {
return g.adapter
}
func NewIPCIDR(s string, adapter string) *IPCIDR {
_, ipnet, err := net.ParseCIDR(s)
if err != nil {
}
return &IPCIDR{
ipnet: ipnet,
adapter: adapter,
}
}