From 5d50c4b48aaac59c1c09b9174c8a7fd014c6eb75 Mon Sep 17 00:00:00 2001 From: KonnovKM Date: Thu, 27 Jul 2023 14:46:22 +0300 Subject: isValid() method Signed-off-by: KonnovKM --- dhcpv4/nclient4/conn_unix.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'dhcpv4/nclient4/conn_unix.go') diff --git a/dhcpv4/nclient4/conn_unix.go b/dhcpv4/nclient4/conn_unix.go index 239d007..1495dc2 100644 --- a/dhcpv4/nclient4/conn_unix.go +++ b/dhcpv4/nclient4/conn_unix.go @@ -99,24 +99,16 @@ func (upc *BroadcastRawUDPConn) ReadFrom(b []byte) (int, net.Addr, error) { pkt = pkt[:n] buf := uio.NewBigEndianBuffer(pkt) - // To read the header length, access data directly. - if !buf.Has(ipv4MinimumSize) { - continue - } - ipHdr := ipv4(buf.Data()) - headerLength := ipHdr.headerLength() - if !buf.Has(int(headerLength)) { + if !ipHdr.isValid(n) { continue } - ipHdr = ipv4(buf.Consume(int(headerLength))) + ipHdr = ipv4(buf.Consume(int(ipHdr.headerLength()))) - if headerLength > protocol { - if ipHdr.transportProtocol() != udpProtocolNumber { - continue - } + if ipHdr.transportProtocol() != udpProtocolNumber { + continue } if !buf.Has(udpHdrLen) { -- cgit v1.2.3