]> git.stg.codes - ssmd.git/blob - 3rdparty/snmp++/include/snmp_pp/address.h
Fix build on osx.
[ssmd.git] / 3rdparty / snmp++ / include / snmp_pp / address.h
1 /*_############################################################################
2   _## 
3   _##  address.h  
4   _##
5   _##  SNMP++v3.2.25
6   _##  -----------------------------------------------
7   _##  Copyright (c) 2001-2010 Jochen Katz, Frank Fock
8   _##
9   _##  This software is based on SNMP++2.6 from Hewlett Packard:
10   _##  
11   _##    Copyright (c) 1996
12   _##    Hewlett-Packard Company
13   _##  
14   _##  ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
15   _##  Permission to use, copy, modify, distribute and/or sell this software 
16   _##  and/or its documentation is hereby granted without fee. User agrees 
17   _##  to display the above copyright notice and this license notice in all 
18   _##  copies of the software and any documentation of the software. User 
19   _##  agrees to assume all liability for the use of the software; 
20   _##  Hewlett-Packard and Jochen Katz make no representations about the 
21   _##  suitability of this software for any purpose. It is provided 
22   _##  "AS-IS" without warranty of any kind, either express or implied. User 
23   _##  hereby grants a royalty-free license to any and all derivatives based
24   _##  upon this software code base. 
25   _##  
26   _##  Stuttgart, Germany, Thu Sep  2 00:07:47 CEST 2010 
27   _##  
28   _##########################################################################*/
29 /*
30   Copyright (c) 1999
31   Hewlett-Packard Company
32
33   ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
34   Permission to use, copy, modify, distribute and/or sell this software
35   and/or its documentation is hereby granted without fee. User agrees
36   to display the above copyright notice and this license notice in all
37   copies of the software and any documentation of the software. User
38   agrees to assume all liability for the use of the software; Hewlett-Packard
39   makes no representations about the suitability of this software for any
40   purpose. It is provided "AS-IS without warranty of any kind,either express
41   or implied. User hereby grants a royalty-free license to any and all
42   derivatives based upon this software code base.
43
44
45   SNMP++ A D D R E S S . H
46
47   ADDRESS CLASS DEFINITION
48
49   DESIGN + AUTHOR:   Peter E Mellquist
50
51   DESCRIPTION:
52   Address class definition. Encapsulates various network
53   addresses into easy to use, safe and portable classes.
54
55 =====================================================================*/
56 // $Id: address.h 307 2007-09-14 20:01:45Z katz $
57
58 #ifndef _ADDRESS
59 #define _ADDRESS
60
61
62 //----[ includes ]-----------------------------------------------------
63 #include <string.h>
64
65 #if defined (CPU) && CPU == PPC603
66 #undef HASH1
67 #undef HASH2
68 #else
69 #include <memory.h>
70 #endif
71
72 #include "snmp_pp/config_snmp_pp.h" // for _IPX_ADDRESS and _MAC_ADDRESS
73 #include "snmp_pp/smival.h"
74 #include "snmp_pp/collect.h"
75 #include "snmp_pp/reentrant.h"
76
77 // include sockets header files
78 // for Windows16 and Windows32 include Winsock
79 // otherwise assume UNIX
80 #if defined (CPU) && CPU == PPC603
81 #include <inetLib.h>
82 #include <hostLib.h>
83 #endif
84
85 #ifdef __unix
86 #if !defined(_AIX) && !defined(__QNX_NEUTRINO)
87 #include <unistd.h>
88 #endif
89 #include <sys/socket.h>
90 #include <netinet/in.h>
91 #include <netdb.h>
92 #include <arpa/inet.h>
93 #if defined _AIX
94 #include <strings.h> // This is needed for FD_SET, bzero
95 #endif
96
97 #if !defined __CYGWIN32__ && !defined __hpux && !defined linux && !defined _AIX
98 extern int h_errno;  // defined in WinSock header, but not for UX?!
99 #endif
100 #endif // __unix
101
102 #ifdef SNMP_PP_NAMESPACE
103 namespace Snmp_pp {
104 #endif
105
106 //----[ macros ]-------------------------------------------------------
107 #define ADDRBUF 50     // worst case of address lens
108 #define OUTBUFF 80     // worst case of output lens
109
110 #define IPLEN      4
111 #define UDPIPLEN   6
112 #define IP6LEN_NO_SCOPE   16
113 #define IP6LEN_WITH_SCOPE 20
114 #define UDPIP6LEN_NO_SCOPE   18
115 #define UDPIP6LEN_WITH_SCOPE 22
116 #define IS_IP6LEN(n) ((n==16) || (n==20))
117 #define IS_UDPIP6LEN(n) ((n==18) || (n==22))
118 #define IPXLEN     10
119 #define IPXSOCKLEN 12
120 #define MACLEN     6
121 #define MAX_FRIENDLY_NAME 80
122 #define HASH0 19
123 #define HASH1 13
124 #define HASH2 7
125
126 //---[ forward declarations ]-----------------------------------------
127 class GenAddress;
128
129 //----[ Address class ]-----------------------------------------------
130
131 /**
132  * Base class of all Address classes.
133  */
134 class DLLOPT Address : public SnmpSyntax
135 {
136   friend class GenAddress;
137
138  public:
139   //----[ enumerated types for address types ]---------------------------
140   /**
141    * Type returned by Address::get_type().
142    */
143   enum addr_type
144   {
145     type_ip,      ///< IpAddress (IPv4 or IPv6)
146     type_ipx,     ///< IpxAddress
147     type_udp,     ///< UdpAddress (IPv4 or IPv6)
148     type_ipxsock, ///< IpxSockAddress
149     type_mac,     ///< MacAddress
150     type_invalid  ///< Used by GenAddress::get_type() if address is not valid
151   };
152
153   /**
154    * Type returned by IpAddress::get_ip_version() and
155    * UdpAddress::get_ip_version().
156    */
157   enum version_type
158   {
159     version_ipv4, ///< IPv4
160     version_ipv6  ///< IPv6
161   };
162
163   /**
164    * Default constructor, clears the buffer and sets valid flag to false.
165    */
166   Address();
167
168   /**
169    * Allow destruction of derived classes.
170    */
171   virtual ~Address() {};
172
173   /// overloaded equivlence operator, are two addresses equal?
174   DLLOPT friend int operator==(const Address &lhs,const Address &rhs);
175
176   /// overloaded not equivlence operator, are two addresses not equal?
177   DLLOPT friend int operator!=(const Address &lhs, const Address &rhs)
178     { return !(lhs == rhs); };
179
180   /// overloaded > operator, is a1 > a2
181   DLLOPT friend int operator>(const Address &lhs,const Address &rhs);
182
183   /// overloaded >= operator, is a1 >= a2
184   DLLOPT friend int operator>=(const Address &lhs,const Address &rhs)
185     { if ((lhs > rhs) || (lhs == rhs)) return true;  return false; };
186
187   /// overloaded < operator, is a1 < a2
188   DLLOPT friend int operator<(const Address &lhs,const Address &rhs);
189
190   /// overloaded <= operator, is a1 <= a2
191   DLLOPT friend int operator<=(const Address &lhs, const Address &rhs)
192     { if ((lhs < rhs) || (lhs == rhs)) return true; return false; };
193
194   /// equivlence operator overloaded, are an address and a string equal?
195   DLLOPT friend int operator==(const Address &lhs,const char *rhs);
196
197   /// overloaded not equivlence operator, are an address and string not equal?
198   DLLOPT friend int operator!=(const Address &lhs,const char *rhs)
199     { return !(lhs == rhs); };
200
201   /// overloaded < , is an address greater than a string?
202   DLLOPT friend int operator>(const Address &lhs,const char *rhs);
203
204   /// overloaded >=, is an address greater than or equal to a string?
205   DLLOPT friend int operator>=(const Address &lhs,const char *rhs);
206
207   /// overloaded < , is an address less than a string?
208   DLLOPT friend int operator<(const Address &lhs,const char *rhs);
209
210   /// overloaded <=, is an address less than or equal to a string?
211   DLLOPT friend int operator<=(const Address &lhs,const char *rhs);
212
213   /**
214    * Overloaded operator for streaming output.
215    *
216    * @return String containing the numerical address
217    */
218   virtual operator const char *() const = 0;
219
220   /**
221    * Return if the object contains a valid address.
222    *
223    * @return true if the object is valid
224    */
225   virtual bool valid() const { return valid_flag; };
226
227   /**
228    * Return the space needed for serialization.
229    */
230   virtual int get_asn1_length() const = 0;
231
232   /**
233    * Access as an array (read and write).
234    * @note Only pass in values between 0 and get_length().
235    *
236    * @param position - pos to return
237    * @return reference to the byte at the given position
238    */
239   unsigned char& operator[](const int position)
240     { addr_changed = true; valid_flag = true;
241       return (position < ADDRBUF) ? address_buffer[position]
242                                   : address_buffer[0]; };
243
244   /**
245    * Access as an array (read only).
246    * @note Only pass in values between 0 and get_length().
247    *
248    * @param position - pos to return
249    * @return the byte at the given position
250    */
251   unsigned char operator[](const int position) const
252     { return (position < ADDRBUF) ? address_buffer[ position] : 0; }
253
254
255   /**
256    * Get the length of the binary address (accessible through operator[]).
257    */
258   virtual int get_length() const = 0;
259
260   /**
261    * Get the type of the address.
262    * @see Address::addr_type
263    */
264   virtual addr_type get_type() const = 0;
265
266   /**
267    * Overloaded assignment operator.
268    */
269   virtual SnmpSyntax& operator=(const SnmpSyntax &val) = 0;
270
271   // return a hash key
272   virtual unsigned int hashFunction() const { return 0;};
273
274  protected:
275   SNMP_PP_MUTABLE bool addr_changed;
276   bool valid_flag;
277   unsigned char address_buffer[ADDRBUF]; // internal representation
278
279   // parse the address string
280   // redefined for each specific address subclass
281   virtual bool parse_address(const char * inaddr) = 0;
282
283   // format the output
284   // redefined for each specific address subclass
285   virtual void format_output() const = 0;
286
287   /**
288    * Trim of whitespaces at the start and the end of the string.
289    *
290    * @param ptr - string to trim
291    */
292   void trim_white_space(char * ptr);
293
294   /**
295    * Is this a GenAddress object.
296    */
297   virtual bool is_gen_address() const { return false; };
298
299   /**
300    * Reset the object.
301    */
302   void clear();
303
304 #if !defined HAVE_GETHOSTBYNAME_R || !defined HAVE_GETHOSTBYADDR_R || !defined HAVE_REENTRANT_GETHOSTBYNAME || !defined HAVE_REENTRANT_GETHOSTBYADDR
305 #ifdef _THREADS
306   static SnmpSynchronized syscall_mutex;
307 #endif
308 #endif
309
310 };
311
312
313 //-----------------------------------------------------------------------
314 //---------[ IP Address Class ]------------------------------------------
315 //-----------------------------------------------------------------------
316 class DLLOPT IpAddress : public Address
317 {
318  public:
319   /**
320    * Construct an empty invalid IP address.
321    */
322   IpAddress();
323
324   /**
325    * Construct an IP address from a string.
326    *
327    * The following formats can be used:
328    * - hostname with or without domain ("www.agentpp.com", "printsrv")
329    * - Numerical IPv4 address ("192.168.17.1")
330    * - Numerical IPv6 address ("abcd:1234::a:b:1", "::abcd:1")
331    * - Numerical IPv6 address with scope ("abcd:1234::a:b:1%3", "::abcd:1%1")
332    *
333    * @param inaddr - Hostname or IP address
334    */
335   IpAddress(const char *inaddr);
336
337   /**
338    * Construct an IP address from another IP address.
339    *
340    * @param ipaddr - address to copy
341    */
342   IpAddress(const IpAddress &ipaddr);
343
344   /**
345    * Construct an IP address from a GenAddress.
346    *
347    * @param genaddr - address to copy
348    */
349   IpAddress(const GenAddress &genaddr);
350
351   /**
352    * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
353    */
354   ~IpAddress() {};
355
356   /**
357    * Map other SnmpSyntax objects to IpAddress.
358    */
359   SnmpSyntax& operator=(const SnmpSyntax &val);
360
361   /**
362    * Overloaded assignment operator for other IP addresses.
363    */
364   IpAddress& operator=(const IpAddress &ipaddress);
365
366   /**
367    * Overloaded assignment operator for strings.
368    */
369   IpAddress& operator=(const char *inaddr);
370
371   /**
372    * Clone this object.
373    *
374    * @return Pointer to the newly created object (allocated through new).
375    */
376   SnmpSyntax *clone() const { return (SnmpSyntax *) new IpAddress(*this); };
377
378   /**
379    * Return the friendly name. Does a reverse DNS lookup for the IP address.
380    *
381    * @param status - The errno value for the lookup
382    *
383    * @return the friendly name or a zero length string (no null pointer)
384    */
385   char *friendly_name(int &status);
386
387   /**
388    * Get a printable ASCII value of the address.
389    *
390    * @return String containing the numerical address
391    */
392   virtual const char *get_printable() const
393     { if (addr_changed) format_output(); return output_buffer; };
394
395   /**
396    * Overloaded operator for streaming output.
397    *
398    * @return String containing the numerical address
399    */
400   virtual operator const char *() const
401     { if (addr_changed) format_output(); return output_buffer; };
402
403   /**
404    * Logically AND the address with the param.
405    *
406    * @param ipaddr - address to use as mask
407    */
408   void mask(const IpAddress &ipaddr);
409
410
411   /**
412    * Get the count of matching bits from the left.
413    *
414    * @param match_ip - address to match with
415    */
416   int get_match_bits(const IpAddress match_ip) const;
417
418   /**
419    * Get the length of the binary address (accessible through operator[]).
420    */
421   virtual int get_length() const
422     { return (ip_version == version_ipv4) ? IPLEN : 
423              (have_ipv6_scope ? IP6LEN_WITH_SCOPE : IP6LEN_NO_SCOPE); };
424
425   /**
426    * Return the type of the address.
427    * @see Address::addr_type
428    * @return Always Address:type_ip
429    */
430   virtual addr_type get_type() const { return type_ip; };
431
432   /**
433    * Return the syntax.
434    *
435    * @return This method always returns sNMP_SYNTAX_IPADDR.
436    */
437   virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_IPADDR; };
438
439   /**
440    * Return the space needed for serialization.
441    */
442   virtual int get_asn1_length() const
443     { return get_length() + 2; };
444
445   /**
446    * Return the IP version of the address.
447    *
448    * @return one of Address::version_type
449    */
450   virtual version_type get_ip_version() const { return ip_version; };
451
452   /**
453    * Map a IPv4 address to a IPv6 address.
454    *
455    * @return - TRUE if no error occured.
456    */
457   virtual int map_to_ipv6();
458
459   /**
460    * Get the IPv6 scope
461    */
462   virtual unsigned int get_scope() const;
463
464   /**
465    * Set the IPv6 scope
466    */
467   virtual bool set_scope(const unsigned int scope);
468
469   /**
470    * Reset the object.
471    */
472   void clear();
473
474   bool has_ipv6_scope() const
475       { return (ip_version == version_ipv6) && have_ipv6_scope; };
476
477  protected:
478   SNMP_PP_MUTABLE char output_buffer[OUTBUFF];           // output buffer
479
480   // friendly name storage
481   char iv_friendly_name[MAX_FRIENDLY_NAME];
482   int  iv_friendly_name_status;
483
484   // redefined parse address
485   // specific to IP addresses
486   virtual bool parse_address(const char *inaddr);
487
488   // redefined format output
489   // specific to IP addresses
490   virtual void format_output() const;
491
492   // parse a dotted string
493   int parse_dotted_ipstring(const char *inaddr);
494
495   // parse a coloned string
496   int parse_coloned_ipstring(const char *inaddr);
497
498   // using the currently defined address, do a DNS
499   // and try to fill up the name
500   int addr_to_friendly();
501
502   // support both ipv4 and ipv6 addresses
503   version_type ip_version;
504
505   bool have_ipv6_scope;
506 };
507
508 //------------------------------------------------------------------------
509 //---------[ UDP Address Class ]------------------------------------------
510 //------------------------------------------------------------------------
511 class DLLOPT UdpAddress : public IpAddress
512 {
513  public:
514   /**
515    * Construct an empty invalid UDP address.
516    */
517   UdpAddress();
518
519   /**
520    * Construct an UDP address from a string.
521    *
522    * The following formats can be used additional to those recognized by
523    * IpAdress:
524    * - Port added to IPv4 address with '/' or ':'
525    *   ("192.168.17.1:161", "192.168.17.1/161", "printsrv/161")
526    * - Port added to IPv6 address with '/' or using '[...]:'
527    *   ("::1/162", "[::1]/162", "[::1]:162")
528    *
529    * @param inaddr - Hostname or IP address
530    */
531   UdpAddress(const char *inaddr);
532
533   /**
534    * Construct an UDP address from another UDP address.
535    *
536    * @param udpaddr - address to copy
537    */
538   UdpAddress(const UdpAddress &udpaddr);
539
540   /**
541    * Construct an UDP address from a GenAddress.
542    *
543    * @param genaddr - address to copy
544    */
545   UdpAddress(const GenAddress &genaddr);
546
547   /**
548    * Construct an UDP address from a IP address.
549    * The port will be set to 0.
550    *
551    * @param ipaddr - address to copy
552    */
553   UdpAddress(const IpAddress &ipaddr);
554
555   /**
556    * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
557    */
558   ~UdpAddress() {};
559
560   /**
561    * Map other SnmpSyntax objects to UdpAddress.
562    */
563   SnmpSyntax& operator=(const SnmpSyntax &val);
564
565   /**
566    * Overloaded assignment operator for UdpAddress.
567    */
568   UdpAddress& operator=(const UdpAddress &udpaddr);
569
570   /**
571    * Overloaded assignment operator for IpAddress.
572    */
573   UdpAddress& operator=(const IpAddress &ipaddr);
574
575   /**
576    * Overloaded assignment operator for strings.
577    */
578   UdpAddress& operator=(const char *inaddr);
579
580   /**
581    * Return the syntax.
582    *
583    * @return This method always returns sNMP_SYNTAX_OCTETS.
584    */
585   SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
586
587   /**
588    * Return the space needed for serialization.
589    */
590   virtual int get_asn1_length() const
591     { return get_length() + 2; };
592
593   /**
594    * Clone this object.
595    *
596    * @return Pointer to the newly created object (allocated through new).
597    */
598   SnmpSyntax *clone() const { return (SnmpSyntax *) new UdpAddress(*this); };
599
600   /**
601    * Get a printable ASCII value of the address.
602    *
603    * @return String containing the numerical address
604    */
605   virtual const char *get_printable() const
606     { if (addr_changed) format_output(); return output_buffer; };
607
608   /**
609    * Overloaded operator for streaming output.
610    *
611    * @return String containing the numerical address
612    */
613   virtual operator const char *() const
614     { if (addr_changed) format_output(); return output_buffer; };
615
616   /**
617    * Set the port number.
618    *
619    * @note If the object is not valid(), the port may not be set.
620    */
621   void set_port(const unsigned short p);
622
623   /**
624    * Get the port number.
625    *
626    * @return The port number, or 0 is the object is not valid.
627    */
628   unsigned short get_port() const;
629
630   /**
631    * Get the length of the binary address (accessible through operator[]).
632    */
633   virtual int get_length() const
634     { return (ip_version == version_ipv4) ? UDPIPLEN : 
635              (have_ipv6_scope ? UDPIP6LEN_WITH_SCOPE : UDPIP6LEN_NO_SCOPE);};
636
637   /**
638    * Return the type of the address.
639    * @see Address::addr_type
640    * @return Always Address:type_udp
641    */
642   virtual addr_type get_type() const { return type_udp; };
643
644   /**
645    * Map a IPv4 UDP address to a IPv6 UDP address.
646    *
647    * @return - TRUE if no error occured.
648    */
649   virtual int map_to_ipv6();
650
651   /**
652    * Reset the object.
653    */
654   void clear()
655     { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
656
657   /**
658    * Set the IPv6 scope
659    */
660   virtual bool set_scope(const unsigned int scope);
661
662  protected:
663   SNMP_PP_MUTABLE char output_buffer[OUTBUFF];           // output buffer
664   char sep;                              // separator
665
666   // redefined parse address
667   // specific to IP addresses
668   virtual bool parse_address(const char *inaddr);
669
670   // redefined format output
671   // specific to IP addresses
672   virtual void format_output() const;
673 };
674
675 #ifdef _MAC_ADDRESS
676 //-------------------------------------------------------------------------
677 //---------[ 802.3 MAC Address Class ]-------------------------------------
678 //-------------------------------------------------------------------------
679 class DLLOPT MacAddress : public Address {
680
681 public:
682   // constructor, no arguments
683   MacAddress();
684
685   // constructor with a string argument
686   MacAddress(const char  *inaddr);
687
688   // constructor with another MAC object
689   MacAddress(const MacAddress  &macaddr);
690
691   // construct a MacAddress with a GenAddress
692   MacAddress(const GenAddress &genaddr);
693
694   // destructor
695   ~MacAddress() {};
696
697   /**
698    * Return the syntax.
699    *
700    * @return This method always returns sNMP_SYNTAX_OCTETS.
701    */
702   SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
703
704   /**
705    * Return the space needed for serialization.
706    */
707   virtual int get_asn1_length() const { return MACLEN + 2; };
708
709   /**
710    * Map other SnmpSyntax objects to MacAddress.
711    */
712   SnmpSyntax& operator=(const SnmpSyntax &val);
713
714   // assignment to another IpAddress object overloaded
715   MacAddress& operator=(const MacAddress &macaddress);
716
717   /**
718    * Clone this object.
719    *
720    * @return Pointer to the newly created object (allocated through new).
721    */
722   SnmpSyntax *clone() const { return (SnmpSyntax *) new MacAddress(*this); };
723
724   /**
725    * Get a printable ASCII value of the address.
726    *
727    * @return String containing the numerical address
728    */
729   virtual const char *get_printable() const
730     { if (addr_changed) format_output(); return output_buffer; };
731
732   /**
733    * Overloaded operator for streaming output.
734    *
735    * @return String containing the numerical address
736    */
737   virtual operator const char *() const
738     { if (addr_changed) format_output(); return output_buffer; };
739
740   /**
741    * Get the length of the binary address (accessible through operator[]).
742    */
743   virtual int get_length() const { return MACLEN; };
744
745   /**
746    * Return the type of the address.
747    * @see Address::addr_type
748    * @return Always Address:type_mac
749    */
750   virtual addr_type get_type() const { return type_mac; };
751
752   // return a hash key
753   unsigned int hashFunction() const;
754
755   /**
756    * Reset the object.
757    */
758   void clear()
759     { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
760
761  protected:
762   SNMP_PP_MUTABLE char output_buffer[OUTBUFF];           // output buffer
763
764   // redefined parse address for macs
765   virtual bool parse_address(const char *inaddr);
766
767   // redefined format output for MACs
768   virtual void format_output() const;
769 };
770 #endif // _MAC_ADDRESS
771
772 #ifdef _IPX_ADDRESS
773 //------------------------------------------------------------------------
774 //---------[ IPX Address Class ]------------------------------------------
775 //------------------------------------------------------------------------
776 class DLLOPT IpxAddress : public Address {
777
778 public:
779   // constructor no args
780   IpxAddress();
781
782   // constructor with a string arg
783   IpxAddress(const char  *inaddr);
784
785   // constructor with another ipx object
786   IpxAddress(const IpxAddress  &ipxaddr);
787
788   // construct with a GenAddress
789   IpxAddress(const GenAddress &genaddr);
790
791   // destructor
792   ~IpxAddress() {};
793
794   /**
795    * Return the syntax.
796    *
797    * @return This method always returns sNMP_SYNTAX_OCTETS.
798    */
799   virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
800
801   /**
802    * Return the space needed for serialization.
803    */
804   virtual int get_asn1_length() const  { return IPXLEN + 2; };
805
806   /**
807    * Map other SnmpSyntax objects to IpxAddress.
808    */
809   SnmpSyntax& operator=(const SnmpSyntax &val);
810
811   // assignment to another IpAddress object overloaded
812   IpxAddress& operator=(const IpxAddress &ipxaddress);
813
814 #ifdef _MAC_ADDRESS
815   // get the host id portion of an ipx address
816   int get_hostid(MacAddress& mac) const;
817 #endif
818
819   /**
820    * Clone this object.
821    *
822    * @return Pointer to the newly created object (allocated through new).
823    */
824   SnmpSyntax *clone() const { return (SnmpSyntax *) new IpxAddress(*this); };
825
826   /**
827    * Get a printable ASCII value of the address.
828    *
829    * @return String containing the numerical address
830    */
831   virtual const char *get_printable() const
832     { if (addr_changed) format_output(); return output_buffer; };
833
834   /**
835    * Overloaded operator for streaming output.
836    *
837    * @return String containing the numerical address
838    */
839   virtual operator const char *() const
840     { if (addr_changed) format_output(); return output_buffer; };
841
842   /**
843    * Get the length of the binary address (accessible through operator[]).
844    */
845   virtual int get_length() const { return IPXLEN; };
846
847   /**
848    * Return the type of the address.
849    * @see Address::addr_type
850    * @return Always Address:type_ipx
851    */
852   virtual addr_type get_type() const { return type_ipx; };
853
854   /**
855    * Reset the object.
856    */
857   void clear()
858     { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
859
860  protected:
861   // ipx format separator
862   char separator;
863   SNMP_PP_MUTABLE char output_buffer[OUTBUFF];           // output buffer
864
865   // redefined parse address for ipx strings
866   virtual bool parse_address(const char  *inaddr);
867
868   // redefined format output for ipx strings
869   // uses same separator as when constructed
870   virtual void format_output() const;
871
872 };
873
874
875
876 //------------------------------------------------------------------------
877 //---------[ IpxSock Address Class ]--------------------------------------
878 //------------------------------------------------------------------------
879 class DLLOPT IpxSockAddress : public IpxAddress {
880
881 public:
882   // constructor, no args
883   IpxSockAddress();
884
885   // constructor with a dotted string
886   IpxSockAddress(const char *inaddr);
887
888   // construct an Udp address with another Udp address
889   IpxSockAddress(const IpxSockAddress &ipxaddr);
890
891   //constructor with a GenAddress
892   IpxSockAddress(const GenAddress &genaddr);
893
894   //constructor with a IpxAddress
895   // default socket # is 0
896   IpxSockAddress(const IpxAddress &ipxaddr);
897
898   // destructor
899   ~IpxSockAddress() {};
900
901   // syntax type
902   //virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
903
904   /**
905    * Return the space needed for serialization.
906    */
907   virtual int get_asn1_length() const { return IPXSOCKLEN + 2; };
908
909   /**
910    * Map other SnmpSyntax objects to IpxSockAddress.
911    */
912   SnmpSyntax& operator=(const SnmpSyntax &val);
913
914   // assignment to another IpAddress object overloaded
915   IpxSockAddress& operator=(const IpxSockAddress &ipxaddr);
916
917   /**
918    * Clone this object.
919    *
920    * @return Pointer to the newly created object (allocated through new).
921    */
922   SnmpSyntax *clone() const { return (SnmpSyntax *)new IpxSockAddress(*this); };
923
924   // set the socket number
925   void set_socket(const unsigned short s);
926
927   // get the socket number
928   unsigned short get_socket() const;
929
930   /**
931    * Get a printable ASCII value of the address.
932    *
933    * @return String containing the numerical address
934    */
935   virtual const char *get_printable() const
936     { if (addr_changed) format_output(); return output_buffer; };
937
938   /**
939    * Overloaded operator for streaming output.
940    *
941    * @return String containing the numerical address
942    */
943   virtual operator const char *() const
944     { if (addr_changed) format_output(); return output_buffer; };
945
946   /**
947    * Get the length of the binary address (accessible through operator[]).
948    */
949   virtual int get_length() const { return IPXSOCKLEN; };
950
951   /**
952    * Return the type of the address.
953    * @see Address::addr_type
954    * @return Always Address:type_ipxsock
955    */
956   virtual addr_type get_type() const { return type_ipxsock; };
957
958   /**
959    * Reset the object.
960    */
961   void clear()
962     { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); };
963
964  protected:
965   SNMP_PP_MUTABLE char output_buffer[OUTBUFF];           // output buffer
966
967   // redefined parse address for ipx strings
968   virtual bool parse_address(const char  *inaddr);
969
970   // redefined format output
971   // specific to IP addresses
972   virtual void format_output() const;
973 };
974 #endif // _IPX_ADDRESS
975
976
977
978
979 //-------------------------------------------------------------------------
980 //--------[ Generic Address ]----------------------------------------------
981 //-------------------------------------------------------------------------
982 class DLLOPT GenAddress : public Address
983 {
984  public:
985   /**
986    * Construct an empty invalid generic address object.
987    */
988   GenAddress();
989
990   /**
991    * Construct a generic address from a string.
992    *
993    * To optimize the speed of the parsing method, use_type can be used
994    * to indicate that the address string is of the specified type.
995    *
996    * @param addr     - address string
997    * @param use_type - if this value is set, the input string is only
998    *                   parsed for the given type 
999    */
1000   GenAddress(const char *addr,
1001              const Address::addr_type use_type = Address::type_invalid);
1002
1003   /**
1004    * Construct a generic address from an Address object.
1005    *
1006    * @param addr - Any address object
1007    */
1008   GenAddress(const Address &addr);
1009
1010   /**
1011    * Construct a generic address from another generic address object.
1012    *
1013    * @param addr - Generic address object to copy
1014    */
1015   GenAddress(const GenAddress &addr);
1016
1017   /**
1018    * Destructor, free memory.
1019    */
1020   ~GenAddress() { if (address) delete address; };
1021
1022   /**
1023    * Return the syntax.
1024    *
1025    * @return This method returns sNMP_SYNTAX_IPADDR, sNMP_SYNTAX_OCTETS
1026    *         or sNMP_SYNTAX_NULL if the generic address does not have
1027    *         an address object.
1028    */
1029   SmiUINT32 get_syntax() const
1030     { return address ? address->get_syntax() : sNMP_SYNTAX_NULL; };
1031
1032   /**
1033    * Return the space needed for serialization.
1034    */
1035   virtual int get_asn1_length() const
1036     { return address ? address->get_asn1_length() : 2; };
1037
1038   /**
1039    * Clone this object.
1040    *
1041    * @return Pointer to the newly created object (allocated through new).
1042    */
1043   SnmpSyntax *clone() const { return (SnmpSyntax *)new GenAddress(*this); };
1044
1045   /**
1046    * Overloaded assignment operator for a GenAddress.
1047    */
1048   GenAddress& operator=(const GenAddress &addr);
1049
1050   /**
1051    * Overloaded assignment operator for a Address.
1052    */
1053   GenAddress& operator=(const Address &addr);
1054
1055   /**
1056    * Map other SnmpSyntax objects to GenAddress.
1057    */
1058   SnmpSyntax& operator=(const SnmpSyntax &val);
1059
1060   /**
1061    * Get a printable ASCII value of the address.
1062    *
1063    * @return String containing the numerical address
1064    */
1065   virtual const char *get_printable() const
1066     { return (address) ? address->get_printable() : output_buffer; };
1067
1068   /**
1069    * Overloaded operator for streaming output.
1070    *
1071    * @return String containing the numerical address
1072    */
1073   virtual operator const char *() const
1074     { return address ? (const char *)*address : output_buffer; };
1075
1076   /**
1077    * Get the length of the binary address (accessible through operator[]).
1078    */
1079   virtual int get_length() const
1080     { return (address) ? address->get_length() : 0; };
1081
1082   /**
1083    * Reset the object.
1084    */
1085   void clear() { if (address) address->clear(); };
1086
1087   /**
1088    * Return the type of the address.
1089    * @see Address::addr_type
1090    * @return Type of the contained address object or Address::type_invalid
1091    *         if it is not valid().
1092    */
1093   virtual addr_type get_type() const
1094     { return (valid()) ? address->get_type() : type_invalid; };
1095
1096   /**
1097    * Access the protected address.
1098    * The caller must make sure that this GenAddress object ist valid()
1099    * and is of the right type (get_type()).
1100    */
1101   const IpAddress  &cast_ipaddress()  const { return (IpAddress& )*address; };
1102
1103   /**
1104    * Access the protected address.
1105    * The caller must make sure that this GenAddress object ist valid()
1106    * and is of the right type (get_type()).
1107    */
1108   const UdpAddress &cast_udpaddress() const { return (UdpAddress&)*address; };
1109
1110 #ifdef _MAC_ADDRESS
1111   /**
1112    * Access the protected address.
1113    * The caller must make sure that this GenAddress object ist valid()
1114    * and is of the right type (get_type()).
1115    */
1116   const MacAddress &cast_macaddress() const { return (MacAddress&)*address; };
1117 #endif
1118
1119 #ifdef _IPX_ADDRESS
1120   /**
1121    * Access the protected address.
1122    * The caller must make sure that this GenAddress object ist valid()
1123    * and is of the right type (get_type()).
1124    */
1125   const IpxAddress &cast_ipxaddress() const { return (IpxAddress&)*address; };
1126
1127   /**
1128    * Access the protected address.
1129    * The caller must make sure that this GenAddress object ist valid()
1130    * and is of the right type (get_type()).
1131    */
1132   const IpxSockAddress &cast_ipxsockaddress() const
1133     { return (IpxSockAddress&)*address; };
1134 #endif
1135
1136 protected:
1137   // pointer to a concrete address
1138   Address *address;
1139   char output_buffer[1];           // output buffer
1140
1141   // redefined parse address for generic address
1142   virtual bool parse_address(const char *addr)
1143     { return parse_address(addr, Address::type_invalid); };
1144
1145   virtual bool parse_address(const char *addr,
1146                              const Address::addr_type use_type);
1147
1148   // format output for a generic address
1149   virtual void format_output() const {};
1150
1151   /**
1152    * Is this a GenAddress object.
1153    */
1154   virtual bool is_gen_address() const { return true; };
1155 };
1156
1157 // create AddressCollection type
1158 typedef SnmpCollection <GenAddress> AddressCollection;
1159 typedef SnmpCollection <UdpAddress> UdpAddressCollection;
1160
1161 #ifdef SNMP_PP_NAMESPACE
1162 } // end of namespace Snmp_pp
1163 #endif 
1164
1165 #endif  //_ADDRESS