1 #ifndef __SESSION_H_ 2 #define __SESSION_H_ 3 4 #include <netdb.h> 5 #include <pthread.h> 6 7 #include "ber.h" 8 #include "oidseq.h" 9 #include "snmpsock.h" 10 11 #define SESSION_DEBUGSNMP_FLAG 0x1ul 12 #define SESSION_DISABLED_FLAG 0x2ul 13 14 #define NEEDNL_ENTRY 1 15 #define NEEDNL_LINE 0 16 17 enum SNMP_error_unrecoverable {SNMPERR_NoResponse, SNMPERR_SocketErr}; 18 19 class SNMP_error_oid{ 20 char *oidstr; 21 public: 22 SNMP_error_oid(const char* str); 23 ~SNMP_error_oid(); 24 int operator==(const char* otherstr); 25 }; 26 27 class SNMP_session { 28 static char need_newline; 29 static SNMP_session *lastprint; 30 static pthread_mutex_t lastprint_m; 31 32 SNMP_socket *sock; 33 34 char *community; 35 hostent *he; 36 int ipidx; 37 char *hostname; 38 39 OidSeq *do_req(Tags tag, OidSeq *oids); 40 41 unsigned int flags; 42 int debugfile; 43 public: 44 static void end(); 45 46 SNMP_session *next; 47 48 SNMP_session(SNMP_socket *sockp, char *host, const char *community=NULL); 49 ~SNMP_session(); 50 51 /* these take one oid sequence and then return a new oidseq with 52 the values filled in. The oidseq passed in will not be 53 touched and the oidseq that is returned will need to be 54 freed. There are two reasons for not filling in the original 55 oidseq. 1) it is more work. 2) that way you can use the 56 same sequence to ask multiple hosts the same questions. */ get(OidSeq * oids)57 OidSeq *get(OidSeq *oids){return do_req(GET_REQ_TAG,oids);} get_next(OidSeq * oids)58 OidSeq *get_next(OidSeq *oids){return do_req(GET_NEXT_TAG,oids);} set(OidSeq * oids)59 inline OidSeq *set(OidSeq *oids){return do_req(SET_REQ_TAG,oids);} ConnHost()60 inline char *ConnHost(){return he->h_addr_list[ipidx];} Hostname()61 inline char *Hostname(){return hostname;} 62 63 void setDebug(); 64 void write_debug(CONST char *dirstr, BerSequence *packet); 65 void write_debug_bin(unsigned char *data, unsigned len); 66 67 void printstr(unsigned long *argflags,char need_newline,char *str); 68 }; 69 70 #endif 71