MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / AddIsInNet

Function AddIsInNet

jsext/addrutil.go:130–152  ·  view source on GitHub ↗
(vm *goja.Runtime)

Source from the content-addressed store, hash-verified

128}
129
130func AddIsInNet(vm *goja.Runtime) error {
131 return vm.GlobalObject().Set("isInNet", func(call goja.FunctionCall) goja.Value {
132 if len(call.Arguments) != 3 {
133 panic(vm.NewTypeError("isInNet expects exactly 3 arguments"))
134 }
135 res := dnsResolve(call.Argument(0).String())
136 if !res.IsValid() {
137 return vm.ToValue(false)
138 }
139 pattern, err := netip.ParseAddr(call.Argument(1).String())
140 if err != nil || !pattern.Is4() {
141 return vm.ToValue(false)
142 }
143 mask, err := netip.ParseAddr(call.Argument(2).String())
144 if err != nil || !pattern.Is4() {
145 return vm.ToValue(false)
146 }
147 m := ipv4ToUint32(mask)
148 p := ipv4ToUint32(pattern)
149 r := ipv4ToUint32(res)
150 return vm.ToValue(r&m == p&m)
151 })
152}
153
154func myIPAddressEx() []netip.Addr {
155 addrs, err := net.InterfaceAddrs()

Callers

nothing calls this directly

Calls 4

dnsResolveFunction · 0.85
ipv4ToUint32Function · 0.85
SetMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected