FBB::Cidr(3bobcat)
π FBB::Cidr π
okay so bestie, we're talking about FBB::Cidr, from the bobcat manual (section <cyan>3bobcat</cyan>, and the manual's whole vibe is CIDR matching) β it's the little class that checks whether an IP4 address is living inside a CIDR block. no cap. π¦
β¨ NAME β¨
FBB::Cidr β compares IP4 addresses to CIDR specifications π
π SYNOPSIS π
#include <bobcat/cidr>
Linking option: -lbobcat
πΈ DESCRIPTION πΈ
okay so, objects of the class Cidr are your little test-your-address besties: they check whether IP4 Internet addresses belong to address ranges defined by Classless Inter-Domain Routing (CIDR) address block specifications. CIDR blocks get written as a.b.c.d/m where a.b.c.d are the four octets of a dotted decimal IP4 address specification (like, say, 129.125.14.80) and m is a mask-size β ranging from 0 to 32 β that tells you how many of the most significant bits stay exactly as-is. so the CIDR specification 129.125.14.80/16 defines a class B network, with addresses ranging from 129.125.0.0 to 129.125.255.255. iconic. π
and the mask size does not have to be a multiple of 8. like, when you specify 129.125.14.80/5 only the most significant 5 bits of the first octet are fixed, which gives you an address range from 128.0.0.0 to 135.255.255.255. the way that math just works π§
CIDR specifications you hand to a Cidr object must be of the form a.b.c.d or a.b.c.d/m. if the mask isn't specified, a mask-size of 32 is used, effectively defining an address range of only one address. Mask values of 0 are ignored. Mask values of 0 are ignored by Cidr objects. (yes bestie, both of those lines are in there, so you get both from me too π«Ά)
when you're specifying CIDRs on a stream, empty lines and comment lines get ignored β comment lines being the ones that have a hash-character (#) as their first non-blank character. non-empty lines must start with a CIDR specification, and the Cidr object will ignore all information on a line trailing a CIDR specification. trailing nonsense? not her problem. π
π NAMESPACE π
FBB
all constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. periodt.
π¦ INHERITS FROM π¦
-
(that's it. that's the whole inheritance tree. she stands alone, main character energy β)
π CONSTRUCTORS π
Cidr(std::string const &cidrPattern)β theCidrobject gets initialized with a single CIDR specification. one and done, bestie.Cidr(std::istream &cidrStream)β theCidrobject gets initialized with CIDR specifications read from thestd::istreamcidrStream.
default, copy and move constructors and the copy and move assignment operators are available. so many options and every single one of them slays π
π MEMBER FUNCTIONS π
heads up bestie: the return values of the accessors (i.e., the const members) are only defined following a successful match (see below, the match members). don't be reading them before the match, it's giving undefined. π
std::string const &address() constβ returns the address matching a CIDR.std::string cidr() constβ returns the CIDR containing a specified address.std::string first() constβ returns the first address of the range of addresses defined by the CIDR specification.std::string last() constβ returns the last address of the range of addresses defined by the CIDR specification. note thatfirst,lastdo not define an iterator range. the address returned bylaststill belongs to the CIDR-range. inclusive bestie, we love to see it π«Άbool match(std::istream &in)βtruegets returned when an IP4 address found in the lines ofinbelongs to a CIDR range inspected by theCidrobject. thematchfunction returnstrueat the first matching address. e.g., if a line contains the text
This is address 1.2.3.4 and this is 5.6.7.8
and the CIDR specifications
5.1.1.1/8
1.2.1.1/16
were provided to the Cidr object, then the object will report a match for 5.6.7.8.
as soon as a match is found match returns true. if none of the addresses found in the lines of in matches any of the object's CIDR specifications, false is returned.
std::string mask() constβ returns the mask used by the CIDR specification.bool match(std::string const &line)βtruegets returned when an IP4 address found inlinebelongs to a CIDR range inspected by theCidrobject. thematchfunction returnstrueat the first matching address.
if none of the addresses found in line matches any of the object's CIDR specifications, false is returned.
void setCidr(std::istream &cidrStream)β a new set of CIDR specification is loaded into theCidrobject, reading the specifications fromcidrStream.void setCidr(std::string const &cidrPattern)β a new CIDR specification is loaded into theCidrobject, using the specification found incidrPattern. theCidrobject is initialized with a single CIDR specification which must be of the forma.b.c.dora.b.c.d/m. if the mask is not specified a mask-size of32is used, effectively defining an address range of only one address. mask values of0are ignored.void swap(Cidr &other)β the current andotherobject are swapped. trading places, very freaky friday of them π§
β STATIC MEMBERS β
size_t dotted2binary(std::string const &dotted)β converts"a.b.c.d"to a 32-bits value.std::string binary2dotted(size_t binary)β converts a 32-bits value to a dotted decimal IP4 address.
π₯ EXAMPLE π₯
#include <fstream>
#include <iostream>
#include <bobcat/exception>
#ifdef BOBCAT
#include <bobcat/cidr>
#else
#include "cidr"
#endif
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
{
enum Spec
{
NONE,
FILE,
CIN
};
Spec spec = CIN;
ifstream in;
if (argc > 1)
{
Exception::open(in, argv[1]); // file containing cidr-specs
spec = FILE;
}
while (true)
{
string cidrSpec;
if (spec == CIN)
{
cout << "Specify cidr (empty to quit): ";
if (!getline(cin, cidrSpec) || cidrSpec.empty())
break;
}
try
{
Cidr cidr;
switch (spec)
{
case NONE:
return 0;
case FILE:
cidr.setCidr(in);
spec = NONE;
break;
case CIN:
cidr.setCidr(cidrSpec);
}
while (true)
{
cout << "Specify address to test (empty to " <<
(spec == CIN ? "respec. CIDR" : "quit") << "): ";
string address;
if (!getline(cin, address) || address.empty())
break;
if (!cidr.match(address))
{
cout << "Address " << address << " not in ";
if (spec == CIN)
cout << cidrSpec << β\nβ;
else
cout << "specifications in " << argv[1] << β\nβ;
}
else
cout << "Address " << address << " in " << cidr.cidr() <<
"\n"
"Lowest address: " << cidr.first() << "\n"
"Highest address: " << cidr.last() << "\n"
"CIDR mask: " << cidr.mask() << "\n"
"Address: " << cidr.address() << β\nβ;
}
}
catch (exception const &err)
{
cout << "Oops... " << err.what() << "\n"
"Try again...\n";
}
}
}
π FILES π
bobcat/cidr β defines the class interface
π SEE ALSO π
π BUGS π
members of Cidr use static data. the current implementation of Cidr is therefore not thread-safe. bestie, do not be sharing her across threads. she will not survive it. π
π BOBCAT PROJECT FILES π
- https://fbb-git.gitlab.io/bobcat/ : gitlab project page;
Debian Bobcat project files:
libbobcat6: debian package containing the shared library, changelog and copyright note;libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;
π BOBCAT π
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. ate. π
π COPYRIGHT π
this is free software, distributed under the terms of the GNU General Public License (GPL).
πΈ AUTHOR πΈ
Frank B. Brokken (f.b.brokken@rug.nl).
okay so that's the whole thing, and like β this page is from libbobcat-dev_6.15.01, dated 2005-2026, and it's page FBB::Cidr(3bobcat) in the manual. go forth and match some addresses bestie, ily, no cap π«Άβ¨π
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms