1 #ifndef SUBNET_CALCULATOR_CLASS
2 #define SUBNET_CALCULATOR_CLASS
4 /*****************************************************************************\
6 * Name : subnet_calculator *
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 1997-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 #include <basis/astring.h>
22 //! Provides an easy way to determine the range of a subnet given the subnet mask and a sample IP address.
24 class subnet_calculator : public basis::root_object
27 subnet_calculator(const basis::astring &subnet_mask, const basis::astring &ip_address);
30 basis::astring convert(basis::un_int num_format);
31 basis::un_int convert(const basis::astring &ip_format);
32 // converts between the numerical and string forms of the ip address.
34 // these two functions return the computed low / high range of the subnet.
35 // they ensure that the subnet calculator is valid by calling the calculate
36 // method if it hasn't already been called.
37 const basis::astring &low_end();
38 const basis::astring &high_end();
40 // these allow observation and modification of the parameters that are needed
41 // to calculate the subnet range.
42 const basis::astring &subnet_mask() const;
43 void subnet_mask(const basis::astring &new_mask);
44 const basis::astring &ip_address() const;
45 void ip_address(const basis::astring &new_address);
47 bool valid() const { return _valid; }
48 // returns whether the object has recalculated its mask information yet
49 // or not. the object should always be valid until the mask or address
50 // are changed. once the two range methods are called, the object should
51 // be valid afterwards.
54 bool _valid; // is this object valid yet (has calculate been called)?
55 basis::astring *_subnet_mask; // the mask used for the subnets in question.
56 basis::astring *_ip_address; // internet address of an example host on the subnet.
57 basis::astring *_low_end; // lower bound and
58 basis::astring *_high_end; // upper bound of the subnet.
61 // performs the main action of determining the lower and upper bounds
62 // of the subnet's range.