Skip to content

Commit

Permalink
fix: IPv4 to string on 32-bit
Browse files Browse the repository at this point in the history
  • Loading branch information
maeb committed May 21, 2024
1 parent cdc8ce1 commit dedeef9
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions url/hostparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func (p *parser) parseIPv4(u *Url, input string) (string, error) {
for counter, n := range numbers {
ipv4 += IPv4Addr(n * int64(math.Pow(256, float64(3-counter))))
}

u.isIPv4 = true
return ipv4.String(), nil
}
Expand Down Expand Up @@ -419,17 +418,11 @@ func (address *IPv6Addr) String() string {

type IPv4Addr uint32

func (address *IPv4Addr) String() string {
output := ""
n := int(*address)
for i := 1; i <= 4; i++ {
output = strconv.Itoa(n%256) + output
if i != 4 {
output = "." + output
}
n = n / 256
}
return output
func (address IPv4Addr) String() string {
return strconv.Itoa(int(address>>24)) + "." +
strconv.Itoa(int((address>>16)&0xFF)) + "." +
strconv.Itoa(int((address>>8)&0xFF)) + "." +
strconv.Itoa(int(address&0xFF))
}

var idnaProfile = idna.New(
Expand Down

0 comments on commit dedeef9

Please sign in to comment.