begin adding packet capture functionality

This commit is contained in:
soypat
2025-06-01 13:04:43 -03:00
parent a29bad9ac9
commit 55bc765d92
4 changed files with 428 additions and 2 deletions
+1
View File
@@ -14,6 +14,7 @@ var (
errARPBufferFull = errors.New("ARP client need handling:too many ops pending")
errShortARP = errors.New("packet too short to be ARP")
errARPUnsupported = errors.New("ARP not supprortedf")
errLargeSizes = errors.New("size of ARP protocol+hardware is unusually large")
)
// Operation represents the type of ARP packet, either request or reply/response.
+3 -1
View File
@@ -138,9 +138,11 @@ func (afrm Frame) SwapTargetSender() {
func (afrm Frame) ValidateSize(v *lneto.Validator) {
_, hlen := afrm.Hardware()
_, ilen := afrm.Protocol()
minLen := 8 + 2*(hlen+ilen)
minLen := 8 + 2*(int(hlen)+int(ilen))
if len(afrm.buf) < int(minLen) {
v.AddError(errShortARP)
} else if minLen > 255 {
v.AddError(errLargeSizes) // We don't want a uint8 overflow somewhere. This is probably a maliciously crafted packet.
}
}