forked from fiorix/go-diameter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipv6.go
49 lines (40 loc) · 1014 Bytes
/
ipv6.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2013-2019 go-diameter authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package datatype
import (
"fmt"
"net"
)
// IPv6 data type for Framed-IP-Address AVP.
type IPv6 net.IP
// DecodeIPv6 decodes an IPv4 data type from byte array.
func DecodeIPv6(b []byte) (Type, error) {
if len(b) != net.IPv6len {
return IPv6(make(net.IP, net.IPv6len)), nil
}
return IPv6(b), nil
}
// Serialize implements the Type interface.
func (ip IPv6) Serialize() []byte {
if ip6 := net.IP(ip).To16(); ip6 != nil {
return ip6
}
return ip
}
// Len implements the Type interface.
func (ip IPv6) Len() int {
return net.IPv6len
}
// Padding implements the Type interface.
func (ip IPv6) Padding() int {
return 0
}
// Type implements the Type interface.
func (ip IPv6) Type() TypeID {
return IPv6Type
}
// String implements the Type interface.
func (ip IPv6) String() string {
return fmt.Sprintf("IPv6{%s}", net.IP(ip))
}