diff options
author | KonnovKM <boneyandoom@gmail.com> | 2023-07-27 14:46:22 +0300 |
---|---|---|
committer | KonnovKM <boneyandoom@gmail.com> | 2023-07-27 14:56:14 +0300 |
commit | 5d50c4b48aaac59c1c09b9174c8a7fd014c6eb75 (patch) | |
tree | 8e3d14ecb7a45401006a166163446b8e5ead4681 /dhcpv4/nclient4/conn_unix.go | |
parent | 62a3d49e6e91a1b44fcfd48242c5ace47e5a8b96 (diff) |
isValid() method
Signed-off-by: KonnovKM <boneyandoom@gmail.com>
Diffstat (limited to 'dhcpv4/nclient4/conn_unix.go')
-rw-r--r-- | dhcpv4/nclient4/conn_unix.go | 16 |
1 files changed, 4 insertions, 12 deletions
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) { |