//=========================================================================== // $Name: $ // $Id: ArtsPortChooser.hh,v 1.1.1.1 2000/03/29 22:54:00 kkeys Exp $ //=========================================================================== // CAIDA Copyright Notice // // By accessing this software, arts++, you are duly informed // of and agree to be bound by the conditions described below in this // notice: // // This software product, arts++, is developed by Daniel W. McRobb, and // copyrighted(C) 1998 by the University of California, San Diego // (UCSD), with all rights reserved. UCSD administers the CAIDA grant, // NCR-9711092, under which part of this code was developed. // // There is no charge for arts++ software. You can redistribute it // and/or modify it under the terms of the GNU General Public License, // v. 2 dated June 1991 which is incorporated by reference herein. // arts++ is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that the use // of it will not infringe on any third party's intellectual property // rights. // // You should have received a copy of the GNU GPL along with arts++. // Copies can also be obtained from: // // http://www.gnu.org/copyleft/gpl.html // // or by writing to: // // University of California, San Diego // // SDSC/CAIDA // 9500 Gilman Dr., MS-0505 // La Jolla, CA 92093 - 0505 USA // // Or contact: // // info@caida.org //=========================================================================== #ifndef _ARTSPORTCHOOSER_HH_ #define _ARTSPORTCHOOSER_HH_ extern "C" { #include "caida_t.h" } #include #include "ArtsPortChoice.hh" //--------------------------------------------------------------------------- // class ArtsPortChooser //--------------------------------------------------------------------------- // This class abstracts a port chooser, which permits selection of a // number of ports by range and by singular value. This is really // just a wrapper around a vector of ArtsPortChoice objects. //--------------------------------------------------------------------------- class ArtsPortChooser { public: //------------------------------------------------------------------------- // ArtsPortChooser() //......................................................................... // constructor //------------------------------------------------------------------------- ArtsPortChooser(); //------------------------------------------------------------------------- // uint16_t AddPort(uint16_t port) //......................................................................... // Adds a single port value to the chooser. Returns the port value. //------------------------------------------------------------------------- uint16_t AddPort(uint16_t port); //------------------------------------------------------------------------- // const ArtsPortChoice::value_type & AddPortRange(uint16_t firstPort, // uint16_t lastPort) //......................................................................... // Adds a port range choice to the chooser. Returns a reference // to the port range choice. //------------------------------------------------------------------------- const ArtsPortChoice::value_type & AddPortRange(uint16_t firstPort, uint16_t lastPort); //------------------------------------------------------------------------- // bool Matches(uint16_t port) const //......................................................................... // Returns true if port is in our port chooser (in a range or matching // one of our signel port values), else returns false. //------------------------------------------------------------------------- bool Matches(uint16_t port) const; //------------------------------------------------------------------------- // inline vector & PortChoices() const //......................................................................... // Returns a reference to the vector of port choices. //------------------------------------------------------------------------- inline vector & PortChoices() const { return(this->_portChoices); } //------------------------------------------------------------------------- // uint32_t Length(uint8_t version = 0) const; //......................................................................... // Returns the length (in bytes) required to store the // ArtsPortChooser object on disk. //------------------------------------------------------------------------- uint32_t Length(uint8_t version = 0) const; //------------------------------------------------------------------------- // istream & read(istream & is) //......................................................................... // Reads the contents of a port chooser from an istream. Returns the // istream. //------------------------------------------------------------------------- istream & read(istream & is); //------------------------------------------------------------------------- // int read(int fd) //......................................................................... // Reads the contents of a port chooser from a file descriptor. // Returns the number of bytes read on success, -1 on failure. //------------------------------------------------------------------------- int read(int fd); //------------------------------------------------------------------------- // ostream & write(ostream & os) const //......................................................................... // Writes the contents of a port chooser to an ostream. Returns the // ostream. //------------------------------------------------------------------------- ostream & write(ostream & os) const; //------------------------------------------------------------------------- // int write(int fd) const //......................................................................... // Writes the contents of a port chooser to a file descriptor. // Returns the number of bytes written on success, -1 on failure. //------------------------------------------------------------------------- int write(int fd) const; //------------------------------------------------------------------------- // bool operator == (const ArtsPortChooser & portChooser) const //......................................................................... // Compares two ArtsPortChooser objects, independent of the order // of their port choices. It uses sort(), unique() and the vector // == operator to do this. //------------------------------------------------------------------------- bool operator == (const ArtsPortChooser & portChooser) const; //------------------------------------------------------------------------- // friend ostream & operator << (ostream& os, // const ArtsPortChooser & portChooser) //......................................................................... // Overloaded ostream << operator to dump to an ostream in // human-readable form. //------------------------------------------------------------------------- friend ostream & operator << (ostream& os, const ArtsPortChooser & portChooser); private: mutable vector _portChoices; }; #endif // _ARTSPORTCHOOSER_HH_