[Bro] Broadcast detection
Robin Sommer
robin at icir.org
Thu Aug 27 08:03:21 PDT 2015
On Wed, Aug 26, 2015 at 18:12 -0700, anthony kasza wrote:
> I'm looking to write a bif which does this. How can I access a subnet's
> prefix as an int?
snet->Prefix() yields an IPAddr. You don't easily get that as an int,
but it has a method for getting it as a sequence of bytes:
int GetBytes(const uint32_t** bytes)
That works for both IPv4 and v6.
That said, I think you can solve this more easily by combining some
other methods that IPAddr offers as well:
/**
* Masks out lower bits of the address.
[...]
*/
void Mask(int top_bits_to_keep);
/**
* Masks out top bits of the address.
[...]
*/
void ReverseMask(int top_bits_to_chop);
/**
* Bitwise OR operator returns the IP address resulting from the bitwise
* OR operation on the raw bytes of this address with another.
*/
IPAddr operator|(const IPAddr& other)
You'd mask out the lower bits of the prefix, mask out the upper bits
of 255.255.255.255 (for IPv4), and then "or" the two together.
Robin
--
Robin Sommer * ICSI/LBNL * robin at icir.org * www.icir.org/robin
More information about the Bro
mailing list