Skip to content

Commit

Permalink
Chore: optimizing IPtoPTR function implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fxzxmicah authored Mar 7, 2024
1 parent 62020bc commit 0e66644
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dns/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"crypto/tls"
"errors"
"fmt"
"net"
"strcon"

Check failure on line 8 in dns/util.go

View workflow job for this annotation

GitHub Actions / build

package strcon is not in GOROOT (C:\hostedtoolcache\windows\go\1.20.14\x64\src\strcon)
"strings"
"time"
"unicode/utf8"
Expand Down Expand Up @@ -159,13 +159,13 @@ func containNonASCII(s string) bool {
func IPtoPTR(ip net.IP) string {
if v4 := ip.To4(); v4 != nil {
// IPv4
return fmt.Sprintf("%d.%d.%d.%d.in-addr.arpa", v4[3], v4[2], v4[1], v4[0])
return strconv.Itoa(int(v4[3])) + "." + strconv.Itoa(int(v4[2])) + "." + strconv.Itoa(int(v4[1])) + "." + strconv.Itoa(int(v4[0])) + ".in-addr.arpa"
} else {
// IPv6
ptr := make([]string, len(ip)*2)
for i := 0; i < len(ip); i++ {
ptr[i*2] = fmt.Sprintf("%x", ip[len(ip)-i-1]&0xF)
ptr[i*2+1] = fmt.Sprintf("%x", ip[len(ip)-i-1]>>4)
ptr[i*2] = strconv.FormatInt(int64(ip[len(ip)-i-1]&0xF), 16)
ptr[i*2+1] = strconv.FormatInt(int64(ip[len(ip)-i-1]>>4), 16)
}
return strings.Join(ptr, ".") + ".ip6.arpa"
}
Expand Down

0 comments on commit 0e66644

Please sign in to comment.