Skip to content

Commit b63452f

Browse files
committed
📃 clarify IP internal vars
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
1 parent fed121a commit b63452f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

llx/builtin_ip.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414

1515
type IP struct {
1616
net.IP
17-
Version int8
18-
PrefixLength int
17+
Version uint8 // 4 and 6, 0 == unset
18+
PrefixLength int // -1 = unset
1919
}
2020

2121
func ParseIP(s string) IP {
@@ -43,8 +43,8 @@ func ParseIP(s string) IP {
4343
}
4444
}
4545

46-
func ipVersionMask(ip net.IP, mask int) (int8, int) {
47-
var version int8
46+
func ipVersionMask(ip net.IP, mask int) (uint8, int) {
47+
var version uint8
4848
if ip.To4() != nil {
4949
version = 4
5050
if mask == -1 {
@@ -276,7 +276,7 @@ func (i IP) Cmp(other IP) int {
276276
}
277277

278278
func (i IP) CIDR() string {
279-
return i.IP.String() + "/" + strconv.Itoa(i.PrefixLength)
279+
return i.IP.String() + "/" + strconv.Itoa(int(i.PrefixLength))
280280
}
281281

282282
func (i IP) Marshal() ([]byte, error) {
@@ -296,7 +296,7 @@ func UnmarshalIP(data []byte) (*IP, error) {
296296
return nil, errors.New("incorrect storage of IP value, expected at least 3 bytes")
297297
}
298298
return &IP{
299-
Version: int8(data[0]),
299+
Version: uint8(data[0]),
300300
PrefixLength: int(bytes2int(data[1:3])),
301301
IP: data[3:],
302302
}, nil

0 commit comments

Comments
 (0)