Skip to content

Commit

Permalink
Address family is a u8, not u16
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dswarbrick committed Nov 23, 2023
1 parent 966b8a0 commit f4b3540
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions neigh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit f4b3540

Please sign in to comment.