28 using namespace basis;
32 subnet_calculator::subnet_calculator(
const astring &mask,
const astring &samp)
34 _subnet_mask(new
astring(mask)),
56 *_subnet_mask = new_mask;
62 *_ip_address = new_address;
81 for (
int i = 0; i < 4; i++) {
83 to_return =
astring(
".") + to_return;
87 to_return =
astring(astring::SPRINTF,
"%d", new_byte) + to_return;
96 for (
int i = 0; i < 3; i++) {
97 int indy = ip_temp.
find(
".");
98 if (indy < 0)
return to_return;
101 to_return += this_piece.
convert(0);
102 ip_temp.
zap(0, indy);
107 to_return += ip_temp.
convert(0);
113 void subnet_calculator::calculate()
129 while (temp_sub && !(temp_sub % 2)) {
133 if (!sub) bits_to_add = 32;
138 for (
int i = 0; i < bits_to_add; i++) {
139 add_in_for_bcast <<= 1;
Provides a dynamically resizable ASCII character string.
bool t() const
t() is a shortcut for the string being "true", as in non-empty.
int convert(int default_value) const
Converts the string into a corresponding integer.
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
bool substring(astring &target, int start, int end) const
a version that stores the substring in an existing "target" string.
int length() const
Returns the current length of the string.
int find(char to_find, int position=0, bool reverse=false) const
Locates "to_find" in "this".
const basis::astring & low_end()
const basis::astring & high_end()
basis::astring convert(basis::un_int num_format)
const basis::astring & ip_address() const
const basis::astring & subnet_mask() const
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
unsigned int un_int
Abbreviated name for unsigned integers.
Provides access to the operating system's socket methods.