Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

address.h

Go to the documentation of this file.
00001 /*_############################################################################
00002   _## 
00003   _##  address.h  
00004   _##
00005   _##  SNMP++v3.2.15
00006   _##  -----------------------------------------------
00007   _##  Copyright (c) 2001-2004 Jochen Katz, Frank Fock
00008   _##
00009   _##  This software is based on SNMP++2.6 from Hewlett Packard:
00010   _##  
00011   _##    Copyright (c) 1996
00012   _##    Hewlett-Packard Company
00013   _##  
00014   _##  ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
00015   _##  Permission to use, copy, modify, distribute and/or sell this software 
00016   _##  and/or its documentation is hereby granted without fee. User agrees 
00017   _##  to display the above copyright notice and this license notice in all 
00018   _##  copies of the software and any documentation of the software. User 
00019   _##  agrees to assume all liability for the use of the software; 
00020   _##  Hewlett-Packard and Jochen Katz make no representations about the 
00021   _##  suitability of this software for any purpose. It is provided 
00022   _##  "AS-IS" without warranty of any kind, either express or implied. User 
00023   _##  hereby grants a royalty-free license to any and all derivatives based
00024   _##  upon this software code base. 
00025   _##  
00026   _##  Stuttgart, Germany, Tue Jan  4 21:42:42 CET 2005 
00027   _##  
00028   _##########################################################################*/
00029 /*
00030   Copyright (c) 1999
00031   Hewlett-Packard Company
00032 
00033   ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
00034   Permission to use, copy, modify, distribute and/or sell this software
00035   and/or its documentation is hereby granted without fee. User agrees
00036   to display the above copyright notice and this license notice in all
00037   copies of the software and any documentation of the software. User
00038   agrees to assume all liability for the use of the software; Hewlett-Packard
00039   makes no representations about the suitability of this software for any
00040   purpose. It is provided "AS-IS without warranty of any kind,either express
00041   or implied. User hereby grants a royalty-free license to any and all
00042   derivatives based upon this software code base.
00043 
00044 
00045   SNMP++ A D D R E S S . H
00046 
00047   ADDRESS CLASS DEFINITION
00048 
00049   DESIGN + AUTHOR:
00050   Peter E Mellquist
00051 
00052   LANGUAGE:
00053   ANSI C++
00054 
00055   OPERATING SYSTEMS:
00056   MS-Windows Win32
00057   BSD UNIX
00058 
00059   DESCRIPTION:
00060   Address class definition. Encapsulates various network
00061   addresses into easy to use, safe and portable classes.
00062 
00063 =====================================================================*/
00064 // $Id: address.h,v 1.9 2004/08/27 20:01:52 katz Exp $
00065 
00066 #ifndef _ADDRESS
00067 #define _ADDRESS
00068 
00069 
00070 //----[ includes ]-----------------------------------------------------
00071 #include <string.h>
00072 #include <memory.h>
00073 
00074 #include "snmp_pp/config_snmp_pp.h" // for _IPX_ADDRESS and _MAC_ADDRESS
00075 #include "snmp_pp/smival.h"
00076 #include "snmp_pp/collect.h"
00077 
00078 // include sockets header files
00079 // for Windows16 and Windows32 include Winsock
00080 // otherwise assume UNIX
00081 #ifdef __unix
00082 // The /**/ stuff below is meant to fool MS C++ into skipping these
00083 // files when creating its makefile.  8-Dec-95 TM
00084 #ifndef _AIX
00085 #include /**/ <unistd.h>
00086 #endif
00087 #include /**/ <sys/socket.h>
00088 #include /**/ <netinet/in.h>
00089 #include /**/ <netdb.h>
00090 #include /**/ <arpa/inet.h>
00091 #if defined _AIX
00092 #include <strings.h> // This is needed for FD_SET, bzero
00093 #endif
00094 
00095 #if !defined __CYGWIN32__ && !defined __hpux && !defined linux && !defined _AIX
00096 extern int h_errno;  // defined in WinSock header, but not for UX?!
00097 #endif
00098 #endif // __unix
00099 
00100 
00101 #ifdef WIN32
00102 #ifndef __unix         // __unix overrides WIN32 if both options are present
00103 #include <winsock.h>
00104 #endif
00105 #endif
00106 
00107 #ifdef SNMP_PP_NAMESPACE
00108 namespace Snmp_pp {
00109 #endif
00110 
00111 //----[ macros ]-------------------------------------------------------
00112 #define BUFSIZE 40     // worst case of address lens
00113 #define OUTBUFF 80     // worst case of output lens
00114 
00115 #define IPLEN      4
00116 #define IP6LEN     16
00117 #define UDPIPLEN   6
00118 #define UDPIP6LEN  18
00119 #define IPXLEN     10
00120 #define IPXSOCKLEN 12
00121 #define MACLEN     6
00122 #define MAX_FRIENDLY_NAME 80
00123 #define HASH0 19
00124 #define HASH1 13
00125 #define HASH2 7
00126 
00127 //---[ forward declarations ]-----------------------------------------
00128 class GenAddress;
00129 
00130 //----[ Address class ]-----------------------------------------------
00131 
00132 /**
00133  * Base class of all Address classes.
00134  */
00135 class DLLOPT Address : public SnmpSyntax
00136 {
00137   friend class GenAddress;
00138 
00139  public:
00140   //----[ enumerated types for address types ]---------------------------
00141   /**
00142    * Type returned by Address::get_type().
00143    */
00144   enum addr_type
00145   {
00146     type_ip,      ///< IpAddress (IPv4 or IPv6)
00147     type_ipx,     ///< IpxAddress
00148     type_udp,     ///< UdpAddress (IPv4 or IPv6)
00149     type_ipxsock, ///< IpxSockAddress
00150     type_mac,     ///< MacAddress
00151     type_invalid  ///< Used by GenAddress::get_type() if address is not valid
00152   };
00153 
00154   /**
00155    * Type returned by IpAddress::get_ip_version() and
00156    * UdpAddress::get_ip_version().
00157    */
00158   enum version_type
00159   {
00160     version_ipv4, ///< IPv4
00161     version_ipv6  ///< IPv6
00162   };
00163 
00164   /**
00165    * Default constructor, clears the buffer and sets valid flag to false.
00166    */
00167   Address();
00168 
00169   /**
00170    * Allow destruction of derived classes.
00171    */
00172   virtual ~Address() {};
00173 
00174   /// overloaded equivlence operator, are two addresses equal?
00175   DLLOPT friend int operator==(const Address &lhs,const Address &rhs);
00176 
00177   /// overloaded not equivlence operator, are two addresses not equal?
00178   DLLOPT friend int operator!=(const Address &lhs, const Address &rhs)
00179     { return !(lhs == rhs); };
00180 
00181   /// overloaded > operator, is a1 > a2
00182   DLLOPT friend int operator>(const Address &lhs,const Address &rhs);
00183 
00184   /// overloaded >= operator, is a1 >= a2
00185   DLLOPT friend int operator>=(const Address &lhs,const Address &rhs)
00186     { if ((lhs > rhs) || (lhs == rhs)) return true;  return false; };
00187 
00188   /// overloaded < operator, is a1 < a2
00189   DLLOPT friend int operator<(const Address &lhs,const Address &rhs);
00190 
00191   /// overloaded <= operator, is a1 <= a2
00192   DLLOPT friend int operator<=(const Address &lhs, const Address &rhs)
00193     { if ((lhs < rhs) || (lhs == rhs)) return true; return false; };
00194 
00195   /// equivlence operator overloaded, are an address and a string equal?
00196   DLLOPT friend int operator==(const Address &lhs,const char *rhs);
00197 
00198   /// overloaded not equivlence operator, are an address and string not equal?
00199   DLLOPT friend int operator!=(const Address &lhs,const char *rhs)
00200     { return !(lhs == rhs); };
00201 
00202   /// overloaded < , is an address greater than a string?
00203   DLLOPT friend int operator>(const Address &lhs,const char *rhs);
00204 
00205   /// overloaded >=, is an address greater than or equal to a string?
00206   DLLOPT friend int operator>=(const Address &lhs,const char *rhs);
00207 
00208   /// overloaded < , is an address less than a string?
00209   DLLOPT friend int operator<(const Address &lhs,const char *rhs);
00210 
00211   /// overloaded <=, is an address less than or equal to a string?
00212   DLLOPT friend int operator<=(const Address &lhs,const char *rhs);
00213 
00214   /**
00215    * Overloaded operator for streaming output.
00216    *
00217    * @return String containing the numerical address
00218    */
00219   virtual operator const char *() const = 0;
00220 
00221   /**
00222    * Return if the object contains a valid address.
00223    *
00224    * @return true if the object is valid
00225    */
00226   virtual bool valid() const { return valid_flag; };
00227 
00228   /**
00229    * Return the space needed for serialization.
00230    */
00231   virtual int get_asn1_length() const = 0;
00232 
00233   /**
00234    * Access as an array (read and write).
00235    * @note Only pass in values between 0 and get_length().
00236    *
00237    * @param position - pos to return
00238    * @return reference to the byte at the given position
00239    */
00240   unsigned char& operator[](const int position)
00241     { addr_changed = true; valid_flag = true;
00242       return (position < BUFSIZE) ? address_buffer[position]
00243                                   : address_buffer[0]; };
00244 
00245   /**
00246    * Access as an array (read only).
00247    * @note Only pass in values between 0 and get_length().
00248    *
00249    * @param position - pos to return
00250    * @return the byte at the given position
00251    */
00252   unsigned char operator[](const int position) const
00253     { return (position < BUFSIZE) ? address_buffer[ position] : 0; }
00254 
00255 
00256   /**
00257    * Get the length of the binary address (accessible through operator[]).
00258    */
00259   virtual int get_length() const = 0;
00260 
00261   /**
00262    * Get the type of the address.
00263    * @see Address::addr_type
00264    */
00265   virtual addr_type get_type() const = 0;
00266 
00267   /**
00268    * Overloaded assignment operator.
00269    */
00270   virtual SnmpSyntax& operator=(const SnmpSyntax &val) = 0;
00271 
00272   // return a hash key
00273   virtual unsigned int hashFunction() const { return 0;};
00274 
00275  protected:
00276   bool addr_changed;
00277   bool valid_flag;
00278   unsigned char address_buffer[BUFSIZE]; // internal representation
00279 
00280   // parse the address string
00281   // redefined for each specific address subclass
00282   virtual bool parse_address(const char * inaddr) = 0;
00283 
00284   // format the output
00285   // redefined for each specific address subclass
00286   virtual void format_output() const = 0;
00287 
00288   /**
00289    * Trim of whitespaces at the start and the end of the string.
00290    *
00291    * @param ptr - string to trim
00292    */
00293   void trim_white_space(char * ptr);
00294 
00295   /**
00296    * Is this a GenAddress object.
00297    */
00298   virtual bool is_gen_address() const { return false; };
00299 
00300   /**
00301    * Reset the object.
00302    */
00303   void clear();
00304 };
00305 
00306 
00307 //-----------------------------------------------------------------------
00308 //---------[ IP Address Class ]------------------------------------------
00309 //-----------------------------------------------------------------------
00310 class DLLOPT IpAddress : public Address
00311 {
00312  public:
00313   /**
00314    * Construct an empty invalid IP address.
00315    */
00316   IpAddress();
00317 
00318   /**
00319    * Construct an IP address from a string.
00320    *
00321    * The following formats can be used:
00322    * - hostname with or without domain ("www.agentpp.com", "printsrv")
00323    * - Numerical IPv4 address ("192.168.17.1")
00324    * - Numerical IPv6 address ("abcd:1234::a:b:1", "::abcd:1")
00325    *
00326    * @param inaddr - Hostname or IP address
00327    */
00328   IpAddress(const char *inaddr);
00329 
00330   /**
00331    * Construct an IP address from another IP address.
00332    *
00333    * @param ipaddr - address to copy
00334    */
00335   IpAddress(const IpAddress &ipaddr);
00336 
00337   /**
00338    * Construct an IP address from a GenAddress.
00339    *
00340    * @param genaddr - address to copy
00341    */
00342   IpAddress(const GenAddress &genaddr);
00343 
00344   /**
00345    * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
00346    */
00347   ~IpAddress() {};
00348 
00349   /**
00350    * Map other SnmpSyntax objects to IpAddress.
00351    */
00352   SnmpSyntax& operator=(const SnmpSyntax &val);
00353 
00354   /**
00355    * Overloaded assignment operator for other IP addresses.
00356    */
00357   IpAddress& operator=(const IpAddress &ipaddress);
00358 
00359   /**
00360    * Overloaded assignment operator for strings.
00361    */
00362   IpAddress& operator=(const char *inaddr);
00363 
00364   /**
00365    * Clone this object.
00366    *
00367    * @return Pointer to the newly created object (allocated through new).
00368    */
00369   SnmpSyntax *clone() const { return (SnmpSyntax *) new IpAddress(*this); };
00370 
00371   /**
00372    * Return the friendly name. Does a reverse DNS lookup for the IP address.
00373    *
00374    * @param status - The errno value for the lookup
00375    *
00376    * @return the friendly name or a zero length string (no null pointer)
00377    */
00378   char *friendly_name(int &status);
00379 
00380   /**
00381    * Get a printable ASCII value of the address.
00382    *
00383    * @return String containing the numerical address
00384    */
00385   virtual const char *get_printable() const
00386     { if (addr_changed) format_output(); return output_buffer; };
00387 
00388   /**
00389    * Overloaded operator for streaming output.
00390    *
00391    * @return String containing the numerical address
00392    */
00393   virtual operator const char *() const
00394     { if (addr_changed) format_output(); return output_buffer; };
00395 
00396   /**
00397    * Logically AND the address with the param.
00398    *
00399    * @param ipaddr - address to use as mask
00400    */
00401   void mask(const IpAddress &ipaddr);
00402 
00403   /**
00404    * Get the length of the binary address (accessible through operator[]).
00405    */
00406   virtual int get_length() const
00407     { return (ip_version == version_ipv4) ? IPLEN : IP6LEN; };
00408 
00409   /**
00410    * Return the type of the address.
00411    * @see Address::addr_type
00412    * @return Always Address:type_ip
00413    */
00414   virtual addr_type get_type() const { return type_ip; };
00415 
00416   /**
00417    * Return the syntax.
00418    *
00419    * @return This method always returns sNMP_SYNTAX_IPADDR.
00420    */
00421   virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_IPADDR; };
00422 
00423   /**
00424    * Return the space needed for serialization.
00425    */
00426   virtual int get_asn1_length() const
00427     { return (ip_version == version_ipv4) ? (IPLEN + 2) : (IP6LEN + 2); };
00428 
00429   /**
00430    * Return the IP version of the address.
00431    *
00432    * @return one of Address::version_type
00433    */
00434   virtual version_type get_ip_version() const { return ip_version; };
00435 
00436   /**
00437    * Map a IPv4 address to a IPv6 address.
00438    *
00439    * @return - TRUE if no error occured.
00440    */
00441   virtual int map_to_ipv6();
00442 
00443   /**
00444    * Reset the object.
00445    */
00446   void clear();
00447 
00448  protected:
00449   char output_buffer[OUTBUFF];           // output buffer
00450 
00451   // friendly name storage
00452   char iv_friendly_name[MAX_FRIENDLY_NAME];
00453   int  iv_friendly_name_status;
00454 
00455   // redefined parse address
00456   // specific to IP addresses
00457   virtual bool parse_address(const char *inaddr);
00458 
00459   // redefined format output
00460   // specific to IP addresses
00461   virtual void format_output() const;
00462 
00463   // parse a dotted string
00464   int parse_dotted_ipstring(const char *inaddr);
00465 
00466   // parse a coloned string
00467   int parse_coloned_ipstring(const char *inaddr);
00468 
00469   // using the currently defined address, do a DNS
00470   // and try to fill up the name
00471   int addr_to_friendly();
00472 
00473   // support both ipv4 and ipv6 addresses
00474   version_type ip_version;
00475 };
00476 
00477 //------------------------------------------------------------------------
00478 //---------[ UDP Address Class ]------------------------------------------
00479 //------------------------------------------------------------------------
00480 class DLLOPT UdpAddress : public IpAddress
00481 {
00482  public:
00483   /**
00484    * Construct an empty invalid UDP address.
00485    */
00486   UdpAddress();
00487 
00488   /**
00489    * Construct an UDP address from a string.
00490    *
00491    * The following formats can be used additional to those recognized by
00492    * IpAdress:
00493    * - Port added to IPv4 address with '/' or ':'
00494    *   ("192.168.17.1:161", "192.168.17.1/161", "printsrv/161")
00495    * - Port added to IPv6 address with '/' or using '[...]:'
00496    *   ("::1/162", "[::1]/162", "[::1]:162")
00497    *
00498    * @param inaddr - Hostname or IP address
00499    */
00500   UdpAddress(const char *inaddr);
00501 
00502   /**
00503    * Construct an UDP address from another UDP address.
00504    *
00505    * @param udpaddr - address to copy
00506    */
00507   UdpAddress(const UdpAddress &udpaddr);
00508 
00509   /**
00510    * Construct an UDP address from a GenAddress.
00511    *
00512    * @param genaddr - address to copy
00513    */
00514   UdpAddress(const GenAddress &genaddr);
00515 
00516   /**
00517    * Construct an UDP address from a IP address.
00518    * The port will be set to 0.
00519    *
00520    * @param ipaddr - address to copy
00521    */
00522   UdpAddress(const IpAddress &ipaddr);
00523 
00524   /**
00525    * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
00526    */
00527   ~UdpAddress() {};
00528 
00529   /**
00530    * Map other SnmpSyntax objects to UdpAddress.
00531    */
00532   SnmpSyntax& operator=(const SnmpSyntax &val);
00533 
00534   /**
00535    * Overloaded assignment operator for UdpAddress.
00536    */
00537   UdpAddress& operator=(const UdpAddress &udpaddr);
00538 
00539   /**
00540    * Overloaded assignment operator for IpAddress.
00541    */
00542   UdpAddress& operator=(const IpAddress &ipaddr);
00543 
00544   /**
00545    * Overloaded assignment operator for strings.
00546    */
00547   UdpAddress& operator=(const char *inaddr);
00548 
00549   /**
00550    * Return the syntax.
00551    *
00552    * @return This method always returns sNMP_SYNTAX_OCTETS.
00553    */
00554   SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
00555 
00556   /**
00557    * Return the space needed for serialization.
00558    */
00559   virtual int get_asn1_length() const
00560     { return (ip_version == version_ipv4) ? (UDPIPLEN + 2) : (UDPIP6LEN + 2);};
00561 
00562   /**
00563    * Clone this object.
00564    *
00565    * @return Pointer to the newly created object (allocated through new).
00566    */
00567   SnmpSyntax *clone() const { return (SnmpSyntax *) new UdpAddress(*this); };
00568 
00569   /**
00570    * Get a printable ASCII value of the address.
00571    *
00572    * @return String containing the numerical address
00573    */
00574   virtual const char *get_printable() const
00575     { if (addr_changed) format_output(); return output_buffer; };
00576 
00577   /**
00578    * Overloaded operator for streaming output.
00579    *
00580    * @return String containing the numerical address
00581    */
00582   virtual operator const char *() const
00583     { if (addr_changed) format_output(); return output_buffer; };
00584 
00585   /**
00586    * Set the port number.
00587    *
00588    * @note If the object is not valid(), the port may not be set.
00589    */
00590   void set_port(const unsigned short p);
00591 
00592   /**
00593    * Get the port number.
00594    *
00595    * @return The port number, or 0 is the object is not valid.
00596    */
00597   unsigned short get_port() const;
00598 
00599   /**
00600    * Get the length of the binary address (accessible through operator[]).
00601    */
00602   virtual int get_length() const
00603     { return (ip_version == version_ipv4) ? UDPIPLEN : UDPIP6LEN; };
00604 
00605   /**
00606    * Return the type of the address.
00607    * @see Address::addr_type
00608    * @return Always Address:type_udp
00609    */
00610   virtual addr_type get_type() const { return type_udp; };
00611 
00612   /**
00613    * Map a IPv4 UDP address to a IPv6 UDP address.
00614    *
00615    * @return - TRUE if no error occured.
00616    */
00617   virtual int map_to_ipv6();
00618 
00619   /**
00620    * Reset the object.
00621    */
00622   void clear()
00623     { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
00624 
00625  protected:
00626   char output_buffer[OUTBUFF];           // output buffer
00627   char sep;                              // separator
00628 
00629   // redefined parse address
00630   // specific to IP addresses
00631   virtual bool parse_address(const char *inaddr);
00632 
00633   // redefined format output
00634   // specific to IP addresses
00635   virtual void format_output() const;
00636 };
00637 
00638 #ifdef _MAC_ADDRESS
00639 //-------------------------------------------------------------------------
00640 //---------[ 802.3 MAC Address Class ]-------------------------------------
00641 //-------------------------------------------------------------------------
00642 class DLLOPT MacAddress : public Address {
00643 
00644 public:
00645   // constructor, no arguments
00646   MacAddress();
00647 
00648   // constructor with a string argument
00649   MacAddress(const char  *inaddr);
00650 
00651   // constructor with another MAC object
00652   MacAddress(const MacAddress  &macaddr);
00653 
00654   // construct a MacAddress with a GenAddress
00655   MacAddress(const GenAddress &genaddr);
00656 
00657   // destructor
00658   ~MacAddress() {};
00659 
00660   /**
00661    * Return the syntax.
00662    *
00663    * @return This method always returns sNMP_SYNTAX_OCTETS.
00664    */
00665   SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
00666 
00667   /**
00668    * Return the space needed for serialization.
00669    */
00670   virtual int get_asn1_length() const { return MACLEN + 2; };
00671 
00672   /**
00673    * Map other SnmpSyntax objects to MacAddress.
00674    */
00675   SnmpSyntax& operator=(const SnmpSyntax &val);
00676 
00677   // assignment to another IpAddress object overloaded
00678   MacAddress& operator=(const MacAddress &macaddress);
00679 
00680   /**
00681    * Clone this object.
00682    *
00683    * @return Pointer to the newly created object (allocated through new).
00684    */
00685   SnmpSyntax *clone() const { return (SnmpSyntax *) new MacAddress(*this); };
00686 
00687   /**
00688    * Get a printable ASCII value of the address.
00689    *
00690    * @return String containing the numerical address
00691    */
00692   virtual const char *get_printable() const
00693     { if (addr_changed) format_output(); return output_buffer; };
00694 
00695   /**
00696    * Overloaded operator for streaming output.
00697    *
00698    * @return String containing the numerical address
00699    */
00700   virtual operator const char *() const
00701     { if (addr_changed) format_output(); return output_buffer; };
00702 
00703   /**
00704    * Get the length of the binary address (accessible through operator[]).
00705    */
00706   virtual int get_length() const { return MACLEN; };
00707 
00708   /**
00709    * Return the type of the address.
00710    * @see Address::addr_type
00711    * @return Always Address:type_mac
00712    */
00713   virtual addr_type get_type() const { return type_mac; };
00714 
00715   // return a hash key
00716   unsigned int hashFunction() const;
00717 
00718   /**
00719    * Reset the object.
00720    */
00721   void clear()
00722     { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
00723 
00724  protected:
00725   char output_buffer[OUTBUFF];           // output buffer
00726 
00727   // redefined parse address for macs
00728   virtual bool parse_address(const char *inaddr);
00729 
00730   // redefined format output for MACs
00731   virtual void format_output() const;
00732 };
00733 #endif // _MAC_ADDRESS
00734 
00735 #ifdef _IPX_ADDRESS
00736 //------------------------------------------------------------------------
00737 //---------[ IPX Address Class ]------------------------------------------
00738 //------------------------------------------------------------------------
00739 class DLLOPT IpxAddress : public Address {
00740 
00741 public:
00742   // constructor no args
00743   IpxAddress();
00744 
00745   // constructor with a string arg
00746   IpxAddress(const char  *inaddr);
00747 
00748   // constructor with another ipx object
00749   IpxAddress(const IpxAddress  &ipxaddr);
00750 
00751   // construct with a GenAddress
00752   IpxAddress(const GenAddress &genaddr);
00753 
00754   // destructor
00755   ~IpxAddress() {};
00756 
00757   /**
00758    * Return the syntax.
00759    *
00760    * @return This method always returns sNMP_SYNTAX_OCTETS.
00761    */
00762   virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
00763 
00764   /**
00765    * Return the space needed for serialization.
00766    */
00767   virtual int get_asn1_length() const  { return IPXLEN + 2; };
00768 
00769   /**
00770    * Map other SnmpSyntax objects to IpxAddress.
00771    */
00772   SnmpSyntax& operator=(const SnmpSyntax &val);
00773 
00774   // assignment to another IpAddress object overloaded
00775   IpxAddress& operator=(const IpxAddress &ipxaddress);
00776 
00777 #ifdef _MAC_ADDRESS
00778   // get the host id portion of an ipx address
00779   int get_hostid(MacAddress& mac) const;
00780 #endif
00781 
00782   /**
00783    * Clone this object.
00784    *
00785    * @return Pointer to the newly created object (allocated through new).
00786    */
00787   SnmpSyntax *clone() const { return (SnmpSyntax *) new IpxAddress(*this); };
00788 
00789   /**
00790    * Get a printable ASCII value of the address.
00791    *
00792    * @return String containing the numerical address
00793    */
00794   virtual const char *get_printable() const
00795     { if (addr_changed) format_output(); return output_buffer; };
00796 
00797   /**
00798    * Overloaded operator for streaming output.
00799    *
00800    * @return String containing the numerical address
00801    */
00802   virtual operator const char *() const
00803     { if (addr_changed) format_output(); return output_buffer; };
00804 
00805   /**
00806    * Get the length of the binary address (accessible through operator[]).
00807    */
00808   virtual int get_length() const { return IPXLEN; };
00809 
00810   /**
00811    * Return the type of the address.
00812    * @see Address::addr_type
00813    * @return Always Address:type_ipx
00814    */
00815   virtual addr_type get_type() const { return type_ipx; };
00816 
00817   /**
00818    * Reset the object.
00819    */
00820   void clear()
00821     { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
00822 
00823  protected:
00824   // ipx format separator
00825   char separator;
00826   char output_buffer[OUTBUFF];           // output buffer
00827 
00828   // redefined parse address for ipx strings
00829   virtual bool parse_address(const char  *inaddr);
00830 
00831   // redefined format output for ipx strings
00832   // uses same separator as when constructed
00833   virtual void format_output() const;
00834 
00835 };
00836 
00837 
00838 
00839 //------------------------------------------------------------------------
00840 //---------[ IpxSock Address Class ]--------------------------------------
00841 //------------------------------------------------------------------------
00842 class DLLOPT IpxSockAddress : public IpxAddress {
00843 
00844 public:
00845   // constructor, no args
00846   IpxSockAddress();
00847 
00848   // constructor with a dotted string
00849   IpxSockAddress(const char *inaddr);
00850 
00851   // construct an Udp address with another Udp address
00852   IpxSockAddress(const IpxSockAddress &ipxaddr);
00853 
00854   //constructor with a GenAddress
00855   IpxSockAddress(const GenAddress &genaddr);
00856 
00857   //constructor with a IpxAddress
00858   // default socket # is 0
00859   IpxSockAddress(const IpxAddress &ipxaddr);
00860 
00861   // destructor
00862   ~IpxSockAddress() {};
00863 
00864   // syntax type
00865   //virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
00866 
00867   /**
00868    * Return the space needed for serialization.
00869    */
00870   virtual int get_asn1_length() const { return IPXSOCKLEN + 2; };
00871 
00872   /**
00873    * Map other SnmpSyntax objects to IpxSockAddress.
00874    */
00875   SnmpSyntax& operator=(const SnmpSyntax &val);
00876 
00877   // assignment to another IpAddress object overloaded
00878   IpxSockAddress& operator=(const IpxSockAddress &ipxaddr);
00879 
00880   /**
00881    * Clone this object.
00882    *
00883    * @return Pointer to the newly created object (allocated through new).
00884    */
00885   SnmpSyntax *clone() const { return (SnmpSyntax *)new IpxSockAddress(*this); };
00886 
00887   // set the socket number
00888   void set_socket(const unsigned short s);
00889 
00890   // get the socket number
00891   unsigned short get_socket() const;
00892 
00893   /**
00894    * Get a printable ASCII value of the address.
00895    *
00896    * @return String containing the numerical address
00897    */
00898   virtual const char *get_printable() const
00899     { if (addr_changed) format_output(); return output_buffer; };
00900 
00901   /**
00902    * Overloaded operator for streaming output.
00903    *
00904    * @return String containing the numerical address
00905    */
00906   virtual operator const char *() const
00907     { if (addr_changed) format_output(); return output_buffer; };
00908 
00909   /**
00910    * Get the length of the binary address (accessible through operator[]).
00911    */
00912   virtual int get_length() const { return IPXSOCKLEN; };
00913 
00914   /**
00915    * Return the type of the address.
00916    * @see Address::addr_type
00917    * @return Always Address:type_ipxsock
00918    */
00919   virtual addr_type get_type() const { return type_ipxsock; };
00920 
00921   /**
00922    * Reset the object.
00923    */
00924   void clear()
00925     { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
00926 
00927  protected:
00928   char output_buffer[OUTBUFF];           // output buffer
00929 
00930   // redefined parse address for ipx strings
00931   virtual bool parse_address(const char  *inaddr);
00932 
00933   // redefined format output
00934   // specific to IP addresses
00935   virtual void format_output() const;
00936 };
00937 #endif // _IPX_ADDRESS
00938 
00939 
00940 
00941 
00942 //-------------------------------------------------------------------------
00943 //--------[ Generic Address ]----------------------------------------------
00944 //-------------------------------------------------------------------------
00945 class DLLOPT GenAddress : public Address
00946 {
00947  public:
00948   /**
00949    * Construct an empty invalid generic address object.
00950    */
00951   GenAddress();
00952 
00953   /**
00954    * Construct a generic address from a string.
00955    *
00956    * To optimize the speed of the parsing method, use_type can be used
00957    * to indicate that the address string is of the specified type.
00958    *
00959    * @param addr     - address string
00960    * @param use_type - if this value is set, the input string is only
00961    *                   parsed for the given type 
00962    */
00963   GenAddress(const char *addr,
00964              const Address::addr_type use_type = Address::type_invalid);
00965 
00966   /**
00967    * Construct a generic address from an Address object.
00968    *
00969    * @param addr - Any address object
00970    */
00971   GenAddress(const Address &addr);
00972 
00973   /**
00974    * Construct a generic address from another generic address object.
00975    *
00976    * @param addr - Generic address object to copy
00977    */
00978   GenAddress(const GenAddress &addr);
00979 
00980   /**
00981    * Destructor, free memory.
00982    */
00983   ~GenAddress() { if (address) delete address; };
00984 
00985   /**
00986    * Return the syntax.
00987    *
00988    * @return This method returns sNMP_SYNTAX_IPADDR, sNMP_SYNTAX_OCTETS
00989    *         or sNMP_SYNTAX_NULL if the generic address does not have
00990    *         an address object.
00991    */
00992   SmiUINT32 get_syntax() const
00993     { return address ? address->get_syntax() : sNMP_SYNTAX_NULL; };
00994 
00995   /**
00996    * Return the space needed for serialization.
00997    */
00998   virtual int get_asn1_length() const
00999     { return address ? address->get_asn1_length() : 2; };
01000 
01001   /**
01002    * Clone this object.
01003    *
01004    * @return Pointer to the newly created object (allocated through new).
01005    */
01006   SnmpSyntax *clone() const { return (SnmpSyntax *)new GenAddress(*this); };
01007 
01008   /**
01009    * Overloaded assignment operator for a GenAddress.
01010    */
01011   GenAddress& operator=(const GenAddress &addr);
01012 
01013   /**
01014    * Overloaded assignment operator for a Address.
01015    */
01016   GenAddress& operator=(const Address &addr);
01017 
01018   /**
01019    * Map other SnmpSyntax objects to GenAddress.
01020    */
01021   SnmpSyntax& operator=(const SnmpSyntax &val);
01022 
01023   /**
01024    * Get a printable ASCII value of the address.
01025    *
01026    * @return String containing the numerical address
01027    */
01028   virtual const char *get_printable() const
01029     { return (address) ? address->get_printable() : output_buffer; };
01030 
01031   /**
01032    * Overloaded operator for streaming output.
01033    *
01034    * @return String containing the numerical address
01035    */
01036   virtual operator const char *() const
01037     { return address ? (const char *)*address : output_buffer; };
01038 
01039   /**
01040    * Get the length of the binary address (accessible through operator[]).
01041    */
01042   virtual int get_length() const
01043     { return (address) ? address->get_length() : 0; };
01044 
01045   /**
01046    * Reset the object.
01047    */
01048   void clear() { if (address) address->clear(); };
01049 
01050   /**
01051    * Return the type of the address.
01052    * @see Address::addr_type
01053    * @return Type of the contained address object or Address::type_invalid
01054    *         if it is not valid().
01055    */
01056   virtual addr_type get_type() const
01057     { return (valid()) ? address->get_type() : type_invalid; };
01058 
01059   /**
01060    * Access the protected address.
01061    * The caller must make sure that this GenAddress object ist valid()
01062    * and is of the right type (get_type()).
01063    */
01064   const IpAddress  &cast_ipaddress()  const { return (IpAddress& )*address; };
01065 
01066   /**
01067    * Access the protected address.
01068    * The caller must make sure that this GenAddress object ist valid()
01069    * and is of the right type (get_type()).
01070    */
01071   const UdpAddress &cast_udpaddress() const { return (UdpAddress&)*address; };
01072 
01073 #ifdef _MAC_ADDRESS
01074   /**
01075    * Access the protected address.
01076    * The caller must make sure that this GenAddress object ist valid()
01077    * and is of the right type (get_type()).
01078    */
01079   const MacAddress &cast_macaddress() const { return (MacAddress&)*address; };
01080 #endif
01081 
01082 #ifdef _IPX_ADDRESS
01083   /**
01084    * Access the protected address.
01085    * The caller must make sure that this GenAddress object ist valid()
01086    * and is of the right type (get_type()).
01087    */
01088   const IpxAddress &cast_ipxaddress() const { return (IpxAddress&)*address; };
01089 
01090   /**
01091    * Access the protected address.
01092    * The caller must make sure that this GenAddress object ist valid()
01093    * and is of the right type (get_type()).
01094    */
01095   const IpxSockAddress &cast_ipxsockaddress() const
01096     { return (IpxSockAddress&)*address; };
01097 #endif
01098 
01099 protected:
01100   // pointer to a concrete address
01101   Address *address;
01102   char output_buffer[1];           // output buffer
01103 
01104   // redefined parse address for generic address
01105   virtual bool parse_address(const char *addr)
01106     { return parse_address(addr, Address::type_invalid); };
01107 
01108   virtual bool parse_address(const char *addr,
01109                              const Address::addr_type use_type);
01110 
01111   // format output for a generic address
01112   virtual void format_output() const {};
01113 
01114   /**
01115    * Is this a GenAddress object.
01116    */
01117   virtual bool is_gen_address() const { return true; };
01118 };
01119 
01120 // create AddressCollection type
01121 typedef SnmpCollection <GenAddress> AddressCollection;
01122 typedef SnmpCollection <UdpAddress> UdpAddressCollection;
01123 
01124 #ifdef SNMP_PP_NAMESPACE
01125 }; // end of namespace Snmp_pp
01126 #endif 
01127 
01128 #endif  //_ADDRESS

Generated on Tue Jan 4 22:42:13 2005 for SNMP++ by doxygen 1.3.2