diff options
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp.go | 4 | ||||
-rw-r--r-- | packet/bgp_test.go | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index 505212b4..ae222a34 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -469,6 +469,10 @@ func (r *IPAddrPrefixDefault) Len() int { return int(1 + ((r.Length + 7) / 8)) } +func (r *IPAddrPrefixDefault) String() string { + return fmt.Sprintf("%s/%d", r.Prefix.String(), r.Length) +} + type IPAddrPrefix struct { IPAddrPrefixDefault addrlen uint8 diff --git a/packet/bgp_test.go b/packet/bgp_test.go index 46ff293d..2cc36a85 100644 --- a/packet/bgp_test.go +++ b/packet/bgp_test.go @@ -2,6 +2,7 @@ package bgp import ( "bytes" + "github.com/stretchr/testify/assert" "net" "testing" ) @@ -131,3 +132,12 @@ func Test_Message(t *testing.T) { } } } + +func Test_IPAddrPrefixString(t *testing.T) { + ipv4 := NewIPAddrPrefix(24, "129.6.10.0") + assert.Equal(t, "129.6.10.0/24", ipv4.String()) + ipv6 := NewIPv6AddrPrefix(18, "3343:faba:3903::1") + assert.Equal(t, "3343:faba:3903::1/18", ipv6.String()) + ipv6 = NewIPv6AddrPrefix(18, "3343:faba:3903::0") + assert.Equal(t, "3343:faba:3903::/18", ipv6.String()) +} |