Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
6.6 KiB

  1. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  2. /*-----------------------------------------------------------------
  3. Filename: address.hpp
  4. Written By: B.Rajeev
  5. Purpose:
  6. Provides an abstract class SnmpTransportAddress for manipulating
  7. SNMP transport address information. The class SnmpTransportIpAddress
  8. provides an implementation of the abstract class for IP addresses
  9. -----------------------------------------------------------------*/
  10. #ifndef __ADDRESS__
  11. #define __ADDRESS__
  12. // an IP address is specified using these many UCHAR fields
  13. #define SNMP_IP_ADDR_LEN 4
  14. #define SNMP_IPX_ADDR_LEN 10
  15. #define SNMP_IPX_NETWORK_LEN 4
  16. #define SNMP_IPX_STATION_LEN 6
  17. // behaviour of ip address resolution
  18. #define SNMP_ADDRESS_RESOLVE_VALUE 1
  19. #define SNMP_ADDRESS_RESOLVE_NAME 2
  20. // The SNMP transport information is defined by this abstract class
  21. // since this class may not be instantiated, the copy constructor
  22. // and the "=" operators have been made private and give null definitions
  23. class DllImportExport SnmpTransportAddress
  24. {
  25. private:
  26. // should not be called - returns itself
  27. SnmpTransportAddress & operator= ( IN const SnmpTransportAddress &address )
  28. {
  29. return *this;
  30. }
  31. // private copy constructor
  32. SnmpTransportAddress(IN const SnmpTransportAddress &address) {}
  33. protected:
  34. // protected constructor
  35. SnmpTransportAddress () {}
  36. public:
  37. virtual ~SnmpTransportAddress () {}
  38. virtual BOOL IsValid () const = 0;
  39. virtual SnmpTransportAddress *Copy () const = 0;
  40. // enables indexing a particular UCHAR field of the address
  41. virtual UCHAR operator [] ( IN const USHORT index ) const = 0;
  42. // copies the UCHAR fields describing the address onto the OUT UCHAR *
  43. // parameter. atmost the specified USHORT fields are copied and the
  44. // number of copied fields is returned
  45. virtual USHORT GetAddress ( OUT UCHAR * , IN const USHORT ) const = 0;
  46. // returns the number of UCHAR fields currently describing the address
  47. virtual USHORT GetAddressLength () const = 0;
  48. // returns a character string representation of the address
  49. virtual char *GetAddress () = 0;
  50. virtual operator void *() const = 0;
  51. virtual void *operator()(void) const = 0;
  52. } ;
  53. // provides an implementation of the SnmpTransportAddress for IP addresses
  54. class DllImportExport SnmpTransportIpAddress : public SnmpTransportAddress
  55. {
  56. private:
  57. BOOL is_valid;
  58. UCHAR field[SNMP_IP_ADDR_LEN];
  59. // the dotted notation character string representation of the address
  60. // is constructed on demand and stored in the field 'dotted_notation'
  61. // the field 'allocated' is flagged 'dotted_notation' points to
  62. // allocated memory
  63. BOOL allocated;
  64. char *dotted_notation;
  65. BOOL GetIpAddress ( IN const char *address ) ;
  66. public:
  67. SnmpTransportIpAddress ( IN const UCHAR *address, IN const USHORT address_length );
  68. SnmpTransportIpAddress ( IN const char *address, IN const ULONG addressResolution = SNMP_ADDRESS_RESOLVE_VALUE );
  69. // the input parameter 'address' contains a single value (32bits) to
  70. // be stored internally in SNMP_IP_ADDR_LEN UCHAR fields
  71. SnmpTransportIpAddress ( IN const ULONG address );
  72. SnmpTransportIpAddress ( IN const SnmpTransportIpAddress &address )
  73. {
  74. allocated = FALSE;
  75. *this = address;
  76. }
  77. SnmpTransportIpAddress ()
  78. {
  79. is_valid = FALSE;
  80. allocated = FALSE;
  81. }
  82. ~SnmpTransportIpAddress();
  83. USHORT GetAddress ( OUT UCHAR *address , IN const USHORT length ) const ;
  84. USHORT GetAddressLength () const
  85. {
  86. return ((is_valid)?SNMP_IP_ADDR_LEN:0);
  87. }
  88. // memory for the decimal notation string is allocated only when
  89. // the char *GetAddress method is called (and the address is valid)
  90. // this memory must be freed if required
  91. char *GetAddress ();
  92. BOOL IsValid () const
  93. {
  94. return is_valid;
  95. }
  96. SnmpTransportAddress *Copy () const ;
  97. BOOL operator== ( IN const SnmpTransportIpAddress & address ) const ;
  98. BOOL operator!= ( IN const SnmpTransportIpAddress & address ) const
  99. {
  100. return !(*this==address);
  101. }
  102. SnmpTransportIpAddress & operator= ( IN const UCHAR *ipAddr ) ;
  103. SnmpTransportIpAddress & operator= ( IN const SnmpTransportIpAddress &address );
  104. UCHAR operator [] ( IN const USHORT index ) const ;
  105. void * operator()(void) const
  106. {
  107. return ( (is_valid==TRUE)?(void *)this:NULL );
  108. }
  109. operator void *() const
  110. {
  111. return SnmpTransportIpAddress::operator()();
  112. }
  113. static BOOL ValidateAddress ( IN const char *address , IN const ULONG addressResolution = SNMP_ADDRESS_RESOLVE_VALUE ) ;
  114. };
  115. // provides an implementation of the SnmpTransportAddress for IP addresses
  116. class DllImportExport SnmpTransportIpxAddress : public SnmpTransportAddress
  117. {
  118. private:
  119. BOOL is_valid;
  120. UCHAR field[SNMP_IPX_ADDR_LEN];
  121. // the dotted notation character string representation of the address
  122. // is constructed on demand and stored in the field 'dotted_notation'
  123. // the field 'allocated' is flagged 'dotted_notation' points to
  124. // allocated memory
  125. BOOL allocated;
  126. char *dotted_notation;
  127. BOOL GetIpxAddress ( IN const char *address ) ;
  128. public:
  129. SnmpTransportIpxAddress ( IN const UCHAR *address, IN const USHORT address_length );
  130. SnmpTransportIpxAddress ( IN const char *address );
  131. SnmpTransportIpxAddress ( IN const SnmpTransportIpxAddress &address )
  132. {
  133. allocated = FALSE;
  134. *this = address;
  135. }
  136. SnmpTransportIpxAddress ()
  137. {
  138. is_valid = FALSE;
  139. allocated = FALSE;
  140. }
  141. ~SnmpTransportIpxAddress();
  142. USHORT GetAddress ( OUT UCHAR *address , IN const USHORT length ) const ;
  143. USHORT GetAddressLength () const
  144. {
  145. return ((is_valid)?SNMP_IPX_ADDR_LEN:0);
  146. }
  147. // memory for the decimal notation string is allocated only when
  148. // the char *GetAddress method is called (and the address is valid)
  149. // this memory must be freed if required
  150. char *GetAddress ();
  151. BOOL IsValid () const
  152. {
  153. return is_valid;
  154. }
  155. SnmpTransportAddress *Copy () const ;
  156. BOOL operator== ( IN const SnmpTransportIpxAddress & address ) const ;
  157. BOOL operator!= ( IN const SnmpTransportIpxAddress & address ) const
  158. {
  159. return !(*this==address);
  160. }
  161. SnmpTransportIpxAddress & operator= ( IN const UCHAR *ipxAddr ) ;
  162. SnmpTransportIpxAddress & operator= ( IN const SnmpTransportIpxAddress &address );
  163. UCHAR operator [] ( IN const USHORT index ) const ;
  164. void * operator()(void) const
  165. {
  166. return ( (is_valid==TRUE)?(void *)this:NULL );
  167. }
  168. operator void *() const
  169. {
  170. return SnmpTransportIpxAddress::operator()();
  171. }
  172. static BOOL ValidateAddress ( IN const char *address ) ;
  173. };
  174. #endif // __ADDRESS__