summaryrefslogtreecommitdiff
path: root/ACE/ASNMP/asnmp/snmp.h
blob: 14dd2a61d871213e6df90b20108b64b38349d036 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* -*-C++-*- */
#ifndef SNMP_CLS_
#define SNMP_CLS_
//=============================================================================
/**
 *  @file    snmp.h
 *
 * SNMP class definition. The Snmp class provides an object oriented
 * approach to SNMP. The SNMP class is an encapsulation of SNMP
 * sessions, gets, sets, etc. The class manages all SNMP
 * resources and provides complete retry and timeout capability.
 *
 *  @author Peter E Mellquist  design
 *  @author first implementation Michael R. MacFaden port to ACE / use Reactor pattern
 */
//=============================================================================

/*===================================================================
   Copyright (c) 1996
   Hewlett-Packard Company

  ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  Permission to use, copy, modify, distribute and/or sell this software
  and/or its documentation is hereby granted without fee. User agrees
  to display the above copyright notice and this license notice in all
  copies of the software and any documentation of the software. User
  agrees to assume all liability for the use of the software; Hewlett-Packard
  makes no representations about the suitability of this software for any
  purpose. It is provided "AS-IS without warranty of any kind,either express
  or implied. User hereby grants a royalty-free license to any and all
  derivatives based upon this software code base.
=====================================================================*/

#include "ace/Reactor.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/SOCK_Dgram.h"

#include "asnmp/oid.h"                // snmp++ oid class
#include "asnmp/vb.h"                 // snbmp++ vb class
#include "asnmp/target.h"             // snmp++ target class
#include "asnmp/pdu.h"                // snmp++ pdu class
#include "asnmp/snmperrs.h"           // error macros and strings
#include "asnmp/address.h"            // snmp++ address class defs
#include "asnmp/transaction_result.h"
#include "asnmp/ASNMP_Export.h"

class Snmp;
class ASNMP_Export Snmp_Result
{
  public:
    Snmp_Result ();
    virtual ~Snmp_Result();
    virtual void result(Snmp *snmp, int result) = 0;
};

// Snmp session class - supports Version 1 operations in blocking mode
/**
 * @class Snmp
 *
 * @brief Concrete class Snmp defined the session and interface to
 * communicate with another SNMP Version 1 agent
 */
class ASNMP_Export Snmp : public transaction_result
{
  Snmp_Result * result_;
  Pdu * pdu_;
  unsigned hold_req_id_;
public:
  Snmp(unsigned short port = INADDR_ANY);
  virtual ~Snmp();

  /// retrieve data from a peer agent for a given list of oid values
  /// default port 161
  int get( Pdu &pdu, UdpTarget &target, Snmp_Result * cb = 0);

  /**
   * retrieve data lexically adjacent to the oids specified in the pdu
   * from the peer agent
   * default port 161
   */
  int get_next( Pdu &pdu, UdpTarget &target, Snmp_Result * cb = 0);

  /// set data in the agent from the list of oids in the pdu
  /// default port 161
  int set( Pdu &pdu, UdpTarget &target, Snmp_Result * cb = 0);

  /// send an SNMPv1 trap (unreliable) to a remote system (def port 162)
  int trap( Pdu &pdu, UdpTarget &target);

  /// status of object after construction
  int valid() const;

  /// given error code, return string reason
  static const char * error_string(int code);

  /// retrieve a reason string if any of the above commands fail
  const char * error_string();

  /// for async transaction results
  void result(transaction * t, int rc);

  /// allow the host name to be overriden
  static void override_host_name(const char* name);

  /// returns the overriden host name
  static void get_host_name(char* name, int len);

protected:
  void check_default_port(UdpTarget& target,unsigned short port=DEF_AGENT_PORT);
  int run_transaction(Pdu& pdu, UdpTarget& target);
  int run_transaction(Pdu& pdu, UdpTarget& target, Snmp_Result * cb);
  int validate_args(const Pdu& pdu, const UdpTarget& target) const;

  Snmp(const Snmp&);

  /// io object
  ACE_SOCK_Dgram iv_snmp_session_;

  /// status of construction
  int construct_status_;

  /// result code from last transaction
  int last_transaction_status_;

  /// transaction request id
  unsigned req_id_;

  static char host_name_[MAXHOSTNAMELEN];
};

#endif //SNMP_CLS_