Skip to content

Commit c086df6

Browse files
landerverhacklansweeperkayoub5
authored andcommitted
fix: #518 limit length of hardware address on linux
1 parent 27d063a commit c086df6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: SharpPcap/LibPcap/Sockaddr.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ internal Sockaddr(IntPtr sockaddrPtr)
9797

9898
var saddr_ll = Marshal.PtrToStructure<sockaddr_ll>(sockaddrPtr);
9999

100-
var hwAddrBytes = new byte[saddr_ll.sll_halen];
100+
var hwAddrBytesLength = Math.Min(saddr_ll.sll_halen,(byte)8); // allow max length of 8 bytes (for exotic hardware that doesn't follow the linux standard)
101+
var hwAddrBytes = new byte[hwAddrBytesLength];
101102
Buffer.BlockCopy(saddr_ll.sll_addr, 0, hwAddrBytes, 0, hwAddrBytes.Length);
102103
hardwareAddress = new PhysicalAddress(hwAddrBytes); // copy into the PhysicalAddress class
103104
}

0 commit comments

Comments
 (0)