/*
** SellaNMS
** $Id: netblock.h,v 1.3 2006/01/24 07:08:09 sella Exp $
** Copyright (c) 2001-2005 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

#ifndef __DGS_COMMON_NETBLOCK_H
#define __DGS_COMMON_NETBLOCK_H

#ifdef HAVE_CONFIG_H
	#include "config.h"
#endif

#include "defaults.h"
#include <stl/string>

class Netblock {
	public:
		Netblock();
		Netblock(const string netblock);
		Netblock(Netblock const &);
		void clear();
		RESULT setNetblock(const string netblock); /* Cidr Notation */
		RESULT setNetblock(const string netblock, const string netmask); /* Dotted Notation */
		RESULT getNetworkAddress(char* result);
		RESULT getNetworkAddress(unsigned long &network);
		RESULT getNetworkCidrAddress(char* result);
		RESULT getBroadcastAddress(char* result);
		RESULT getNetmask(char *result);
		RESULT getNetmask(unsigned long &netmask);
		RESULT getPrefixLength(unsigned long &length);
		RESULT getIPAddress(char* result, unsigned long item);
		RESULT compare(const Netblock &n1);
		RESULT compare(const string netblock); /* Compare against passed netblock. */
		unsigned long isValid();

		char* operator[](unsigned long item);
		Netblock const& operator=(Netblock const &src);

	private:
		RESULT octetToInteger(const string octet, unsigned long &address);

		unsigned long is_valid;
		unsigned long network;
		unsigned long netmask;
};

#endif

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim:
** vim: noet ts=3 sw=3
*/
