"Fossies" - the Fresh Open Source Software Archive

Member "npadmin-0.14/session.h" (19 Apr 2001, 2689 Bytes) of package /linux/misc/old/npadmin-0.14.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (c) 2000 Ben Woodard
    2  * All rights reserved.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public Licence
    6  * as published by the Free Software Foundation; either version 2
    7  * of the Licence, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRENTY; without even the implied warrenty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   12  * GNU General Public Licence in the COPYING file for more
   13  * details.
   14  *
   15  * You should have received a copy of the GNU Library General 
   16  * Public License along with the GNU C Library; see the file 
   17  * COPYING.LIB.  If not, write to the Free Software Foundation, 
   18  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
   19  */
   20 
   21 #ifndef __SESSION_H_
   22 #define __SESSION_H_
   23 
   24 #include <netdb.h>
   25 #include <pthread.h>
   26 
   27 #include "ber.h"
   28 #include "oidseq.h"
   29 #include "snmpsock.h" 
   30 
   31 #define SESSION_DEBUGSNMP_FLAG 0x1ul
   32 #define SESSION_DISABLED_FLAG  0x2ul
   33 
   34 #define NEEDNL_ENTRY 1
   35 #define NEEDNL_LINE 0
   36 
   37 enum SNMP_error_unrecoverable {SNMPERR_NoResponse, SNMPERR_SocketErr};
   38 
   39 class SNMP_error_oid{
   40   char *oidstr;
   41 public:
   42   SNMP_error_oid(const char* str);
   43   ~SNMP_error_oid();
   44   int operator==(const char* otherstr);
   45 };
   46 
   47 class SNMP_session {
   48   static char need_newline; 
   49   static SNMP_session *lastprint;
   50   static pthread_mutex_t lastprint_m;
   51 
   52   SNMP_socket *sock;
   53 
   54   char *community;
   55   hostent *he;
   56   int ipidx;
   57   char *hostname;
   58 
   59   OidSeq *do_req(Tags tag, OidSeq *oids);
   60 
   61   unsigned int flags;
   62   int debugfile;
   63 public:
   64   static void end();
   65 
   66   SNMP_session *next;
   67 
   68   SNMP_session(SNMP_socket *sockp, char *host, const char *community=NULL);
   69   ~SNMP_session();
   70 
   71   /* these take one oid sequence and then return a new oidseq with
   72      the values filled in. The oidseq passed in will not be 
   73      touched and the oidseq that is returned will need to be 
   74      freed. There are two reasons for not filling in the original 
   75      oidseq. 1) it is more work. 2) that way you can use the
   76      same sequence to ask multiple hosts the same questions. */
   77   OidSeq *get(OidSeq *oids){return do_req(GET_REQ_TAG,oids);}
   78   OidSeq *get_next(OidSeq *oids){return do_req(GET_NEXT_TAG,oids);}
   79   inline OidSeq *set(OidSeq *oids){return do_req(SET_REQ_TAG,oids);}
   80   inline char *ConnHost(){return he->h_addr_list[ipidx];}
   81   inline char *Hostname(){return hostname;}
   82 
   83   void setDebug();
   84   void write_debug(CONST char *dirstr, BerSequence *packet);
   85   void write_debug_bin(unsigned char *data, unsigned len);
   86 
   87   void printstr(unsigned long *argflags,char need_newline,
   88         const char *str);
   89 };
   90 
   91 #endif