summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/dhcpv6relay.go
diff options
context:
space:
mode:
authorPablo Mazzini <pmazzini@gmail.com>2020-03-09 19:48:51 +0000
committerGitHub <noreply@github.com>2020-03-09 19:48:51 +0000
commit030b5b237deb0bb0c4d821dde661af87e9f0263c (patch)
tree2657c611cc944321182aa37db73bc2430b9d402e /dhcpv6/dhcpv6relay.go
parentbd34b7c6963c8c124b45759423d41987d428668e (diff)
parent27111faab6c0ca7834f2078eb9a14615c8f4fa59 (diff)
Merge pull request #365 from hugelgupf/write16
dhcpv6: always write 16-byte IPs
Diffstat (limited to 'dhcpv6/dhcpv6relay.go')
-rw-r--r--dhcpv6/dhcpv6relay.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/dhcpv6/dhcpv6relay.go b/dhcpv6/dhcpv6relay.go
index 02ed9bb..209cc71 100644
--- a/dhcpv6/dhcpv6relay.go
+++ b/dhcpv6/dhcpv6relay.go
@@ -20,6 +20,15 @@ type RelayMessage struct {
Options Options
}
+func write16(b *uio.Lexer, ip net.IP) {
+ if ip == nil || ip.To16() == nil {
+ var zeros [net.IPv6len]byte
+ b.WriteBytes(zeros[:])
+ } else {
+ b.WriteBytes(ip.To16())
+ }
+}
+
// Type is this relay message's types.
func (r *RelayMessage) Type() MessageType {
return r.MessageType
@@ -58,8 +67,8 @@ func (r *RelayMessage) ToBytes() []byte {
buf := uio.NewBigEndianBuffer(make([]byte, 0, RelayHeaderSize))
buf.Write8(byte(r.MessageType))
buf.Write8(r.HopCount)
- buf.WriteBytes(r.LinkAddr.To16())
- buf.WriteBytes(r.PeerAddr.To16())
+ write16(buf, r.LinkAddr)
+ write16(buf, r.PeerAddr)
buf.WriteBytes(r.Options.ToBytes())
return buf.Data()
}