Closed NickChillClub closed 2 years ago
Thanks for the PR! 🙌
I think I might not understand this well (apologies for that!), but I worry a bit about the overall readability of HostsInCIDR
after this change. Is there a specific problem this solves for CIDR calculation?
The rest of the changes look 👌 !
There is no specific problem other than it's faster.
I'm a big fan of optimising, faster code and better use of the Golang standard packages.
This is more efficient, cleaner and the same method is used in the other code languages for ages. To get the range of a cidr the easiest way is to convert it to integer. Then only what you have to do is increment. To check if it's a network or broadcast address you can check if the least significant byte is set to 0, in the last octet, with 0xFF and ignore if the result is 0 or 255.
Changed the code for HostsInCIDR, It's easier from byte level. Changed info on the scan flags you are able to do comma separated as well. Changed a few lines to Sprintf as it's better to read.