summaryrefslogtreecommitdiff
path: root/ASNMP/asnmp/snmp.h
blob: d57a97113241d70a1333fd7e713a5c0b42fffaec (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
/* -*-C++-*- */
// $Id$
#ifndef SNMP_CLS_
#define SNMP_CLS_
// ============================================================================
//
// = LIBRARY
//    asnmp
//
// = FILENAME
//    snmp.h
//
// = DESCRIPTION
//   SNMP class defintion. 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, 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"

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

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

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

    int get_next( 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 set( 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 trap( Pdu &pdu, UdpTarget &target);
    // send an SNMPv1 trap (unreliable) to a remote system (def port 162)

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

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

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

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

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

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

 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&);

  ACE_SOCK_Dgram iv_snmp_session_;
  // io object

  int construct_status_;
  // status of construction

  int last_transaction_status_;
  // result code from last transaction

  unsigned req_id_;
  // transaction request id

  static char host_name_[MAXHOSTNAMELEN];
};

#endif //SNMP_CLS_