diff options
author | KonnovKM <boneyandoom@gmail.com> | 2023-07-31 15:28:32 +0300 |
---|---|---|
committer | KonnovKM <boneyandoom@gmail.com> | 2023-07-31 15:31:17 +0300 |
commit | 5771e168857a17094174b2c31c44fe7779ca0b75 (patch) | |
tree | 68c7fc3019ba996f20414570f2bbef0339ecce3f | |
parent | 5d50c4b48aaac59c1c09b9174c8a7fd014c6eb75 (diff) |
stylistic changes
Signed-off-by: KonnovKM <boneyandoom@gmail.com>
-rw-r--r-- | dhcpv4/nclient4/ipv4.go | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/dhcpv4/nclient4/ipv4.go b/dhcpv4/nclient4/ipv4.go index 3a3427a..f2bfb65 100644 --- a/dhcpv4/nclient4/ipv4.go +++ b/dhcpv4/nclient4/ipv4.go @@ -27,17 +27,16 @@ import ( ) const ( - versIHL = 0 - tos = 1 - totalLen = 2 - id = 4 - flagsFO = 6 - ttl = 8 - protocol = 9 - checksumOff = 10 - srcAddr = 12 - dstAddr = 16 - ipVersionShift = 4 + versIHL = 0 + tos = 1 + totalLen = 2 + id = 4 + flagsFO = 6 + ttl = 8 + protocol = 9 + checksumOff = 10 + srcAddr = 12 + dstAddr = 16 ) // transportProtocolNumber is the number of a transport protocol. @@ -102,7 +101,7 @@ const ( ipv4Version = 4 ) -// IPVersion returns the version of IP used in the given packet. It returns -1 +// ipVersion returns the version of IP used in the given packet. It returns -1 // if the packet is not large enough to contain the version field. func ipVersion(b []byte) int { // Length must be at least offset+length of version field. @@ -112,24 +111,9 @@ func ipVersion(b []byte) int { return int(b[versIHL] >> ipVersionShift) } -// IsValid performs basic validation on the packet. -func (b ipv4) isValid(pktSize int) bool { - if len(b) < ipv4MinimumSize { - return false - } - - hlen := int(b.headerLength()) - tlen := int(b.totalLength()) - if hlen < ipv4MinimumSize || hlen > tlen || tlen > pktSize { - return false - } - - if ipVersion(b) != ipv4Version { - return false - } - - return true -} +const ( + ipVersionShift = 4 +) // headerLength returns the value of the "header length" field of the ipv4 // header. @@ -204,6 +188,25 @@ func (b ipv4) encode(i *ipv4Fields) { copy(b[dstAddr:dstAddr+ipv4AddressSize], i.DstAddr) } +// isValid performs basic validation on the packet. +func (b ipv4) isValid(pktSize int) bool { + if len(b) < ipv4MinimumSize { + return false + } + + hlen := int(b.headerLength()) + tlen := int(b.totalLength()) + if hlen < ipv4MinimumSize || hlen > tlen || tlen > pktSize { + return false + } + + if ipVersion(b) != ipv4Version { + return false + } + + return true +} + const ( udpSrcPort = 0 udpDstPort = 2 |