From f4b35408740802e92ad48de22420d7e2dcbc1bb2 Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Thu, 23 Nov 2023 18:02:45 +0100 Subject: [PATCH] Address family is a u8, not u16 As per definition of ndmsg in kernel source: struct ndmsg { __u8 ndm_family; __u8 ndm_pad1; __u16 ndm_pad2; __s32 ndm_ifindex; __u16 ndm_state; __u8 ndm_flags; __u8 ndm_type; }; Signed-off-by: Daniel Swarbrick --- neigh.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/neigh.go b/neigh.go index d167c7c..cf5e60c 100644 --- a/neigh.go +++ b/neigh.go @@ -45,8 +45,8 @@ type NeighMessage struct { func (m *NeighMessage) MarshalBinary() ([]byte, error) { b := make([]byte, unix.SizeofNdMsg) - nativeEndian.PutUint16(b[0:2], m.Family) - // bytes 3 and 4 are padding + b[0] = uint8(m.Family) + // bytes 2-4 are padding nativeEndian.PutUint32(b[4:8], m.Index) nativeEndian.PutUint16(b[8:10], m.State) b[10] = m.Flags @@ -77,7 +77,7 @@ func (m *NeighMessage) UnmarshalBinary(b []byte) error { return errInvalidNeighMessage } - m.Family = nativeEndian.Uint16(b[0:2]) + m.Family = uint16(b[0]) m.Index = nativeEndian.Uint32(b[4:8]) m.State = nativeEndian.Uint16(b[8:10]) m.Flags = b[10]