MCPcopy Index your code
hub / github.com/foxcpp/maddy / queryString

Function queryString

internal/check/dnsbl/common.go:248–280  ·  view source on GitHub ↗
(ip net.IP)

Source from the content-addressed store, hash-verified

246}
247
248func queryString(ip net.IP) string {
249 ipv6 := true
250 if ipv4 := ip.To4(); ipv4 != nil {
251 ip = ipv4
252 ipv6 = false
253 }
254
255 res := strings.Builder{}
256 if ipv6 {
257 res.Grow(63) // 0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0
258 } else {
259 res.Grow(15) // 000.000.000.000
260 }
261
262 for i := len(ip) - 1; i >= 0; i-- {
263 octet := ip[i]
264
265 if ipv6 {
266 // X.X
267 res.WriteString(strconv.FormatInt(int64(octet&0xf), 16))
268 res.WriteRune('.')
269 res.WriteString(strconv.FormatInt(int64((octet&0xf0)>>4), 16))
270 } else {
271 // X
272 res.WriteString(strconv.Itoa(int(octet)))
273 }
274
275 if i != 0 {
276 res.WriteRune('.')
277 }
278 }
279 return res.String()
280}

Callers 2

TestQueryStringFunction · 0.85
checkIPFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by 1

TestQueryStringFunction · 0.68