subnet_calculator.h

Go to the documentation of this file.
00001 #ifndef SUBNET_CALCULATOR_CLASS
00002 #define SUBNET_CALCULATOR_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : subnet_calculator                                                 *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *    Provides an easy way to determine the range of a subnet given the        *
00012 *  subnet mask and a sample IP address.                                       *
00013 *                                                                             *
00014 *******************************************************************************
00015 * Copyright (c) 1997-$now By Author.  This program is free software; you can  *
00016 * redistribute it and/or modify it under the terms of the GNU General Public  *
00017 * License as published by the Free Software Foundation; either version 2 of   *
00018 * the License or (at your option) any later version.  This is online at:      *
00019 *     http://www.fsf.org/copyleft/gpl.html                                    *
00020 * Please send any updates to: fred@gruntose.com                               *
00021 \*****************************************************************************/
00022 
00023 #include "sockets_dll.h"
00024 
00025 class SOCKETS_CLASS_STYLE subnet_calculator
00026 {
00027 public:
00028   subnet_calculator(const istring &subnet_mask, const istring &ip_address);
00029   ~subnet_calculator();
00030 
00031   istring convert(u_int num_format);
00032   u_int convert(const istring &ip_format);
00033     // converts between the numerical and string forms of the ip address.
00034 
00035   // these two functions return the computed low / high range of the subnet.
00036   // they ensure that the subnet calculator is valid by calling the calculate
00037   // method if it hasn't already been called.
00038   const istring &low_end();
00039   const istring &high_end();
00040 
00041   // these allow observation and modification of the parameters that are needed
00042   // to calculate the subnet range.
00043   const istring &subnet_mask() const;
00044   void subnet_mask(const istring &new_mask);
00045   const istring &ip_address() const;
00046   void ip_address(const istring &new_address);
00047 
00048   bool valid() const { return _valid; }
00049     // returns whether the object has recalculated its mask information yet
00050     // or not.  the object should always be valid until the mask or address
00051     // are changed.  once the two range methods are called, the object should 
00052     // be valid afterwards.
00053 
00054 private:
00055   bool _valid;  // is this object valid yet (has calculate been called)?
00056   istring *_subnet_mask;  // the mask used for the subnets in question.
00057   istring *_ip_address;  // internet address of an example host on the subnet.
00058   istring *_low_end;  // lower bound and
00059   istring *_high_end;   // upper bound of the subnet.
00060 
00061   void calculate();
00062     // performs the main action of determining the lower and upper bounds
00063     // of the subnet's range.
00064 };
00065 
00066 #endif
00067 

Generated on Fri Nov 21 04:29:17 2008 for HOOPLE Libraries by  doxygen 1.5.1