File: session.h

package info (click to toggle)
npadmin 0.8-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 524 kB
  • ctags: 792
  • sloc: cpp: 3,514; ansic: 1,176; sh: 327; makefile: 52
file content (69 lines) | stat: -rw-r--r-- 1,830 bytes parent folder | download
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
#ifndef __SESSION_H_
#define __SESSION_H_

#include <netdb.h>
#include <pthread.h>

#include "ber.h"
#include "oidseq.h"
#include "snmpsock.h" 

#define SESSION_DEBUGSNMP_FLAG 0x1ul
#define SESSION_DISABLED_FLAG  0x2ul

#define NEEDNL_ENTRY 1
#define NEEDNL_LINE 0

enum SNMP_error_unrecoverable {SNMPERR_NoResponse, SNMPERR_SocketErr};

class SNMP_error_oid{
  char *oidstr;
public:
  SNMP_error_oid(char* str);
  ~SNMP_error_oid();
  int operator==(CONST char* otherstr);
};

class SNMP_session {
  static char need_newline; 
  static SNMP_session *lastprint;
  static pthread_mutex_t lastprint_m;

  SNMP_socket *sock;

  char *community;
  hostent *he;
  int ipidx;
  char *hostname;

  OidSeq *do_req(Tags tag, OidSeq *oids);

  unsigned int flags;
  int debugfile;
public:
  static void end();

  SNMP_session *next;

  SNMP_session(SNMP_socket *sockp, char *host, const char *community=NULL);
  ~SNMP_session();

  // these take one oid sequence and then return a new oidseq with the values 
  // filled in. The oidseq passed in will not be touched and the oidseq that 
  // is returned will need to be freed. There are two reasons for not filling
  // in the original oidseq. 1) it is more work. 2) that way you can use the
  // same sequence to ask multiple hosts the same questions.
  inline OidSeq *get(OidSeq *oids){return do_req(GET_REQ_TAG,oids);}
  inline OidSeq *get_next(OidSeq *oids){return do_req(GET_NEXT_TAG,oids);}
  inline OidSeq *set(OidSeq *oids){return do_req(SET_REQ_TAG,oids);}
  inline char *ConnHost(){return he->h_addr_list[ipidx];}
  inline char *Hostname(){return hostname;}

  void setDebug();
  void write_debug(CONST char *dirstr, BerSequence *packet);
  void write_debug_bin(unsigned char *data, unsigned len);

  void printstr(unsigned long *argflags,char need_newline,char *str);
};

#endif