diff options
Diffstat (limited to 'dhcpv6/dhcpv6relay.go')
-rw-r--r-- | dhcpv6/dhcpv6relay.go | 13 |
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() } |