(file) Return to snmpDeliverTrap_emanate.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Handler / snmpIndicationHandler

Diff for /pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpDeliverTrap_emanate.cpp between version 1.3 and 1.8

version 1.3, 2002/03/14 00:07:48 version 1.8, 2002/04/25 16:27:25
Line 29 
Line 29 
  
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
 #include <Pegasus/Common/System.h> #include <Pegasus/Common/System.h>
   #include <Pegasus/Common/Destroyer.h>
 #include <fcntl.h> #include <fcntl.h>
 #include <unistd.h> #include <unistd.h>
 #include <ctype.h> #include <ctype.h>
 #include <sys/stat.h> #include <sys/stat.h>
 #include "snmpDeliverTrap_emanate.h" #include "snmpDeliverTrap_emanate.h"
   #include "prnt_lib.h"
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
Line 102 
Line 104 
     Array<String>& vbTypes,     Array<String>& vbTypes,
     Array<String>& vbValues)     Array<String>& vbValues)
 { {
     initialize();      OctetString*    newValue;
   
     void*   newValue;  
     char*   entV2Trap;  
     int     vb_link_flag = 0;  
  
     VarBind *vb = NULL;     VarBind *vb = NULL;
     VarBind *vb2 = NULL;     VarBind *vb2 = NULL;
       VarBind *vb3 = NULL;
  
     OID     *object = NULL;     OID     *object = NULL;
  
       // Initializing with Master agent
       initialize();
   
       // TRAP OID: getting trapOid
       ArrayDestroyer<char> _trapOid(trapOid.allocateCString());
       _trapOid.getPointer()[strlen(_trapOid.getPointer())-1] = '\0';
       OID *sendtrapOid = MakeOIDFromDot(_trapOid.getPointer());
   
       // Destination : converting destination into Transport
       ArrayDestroyer<char> trap_dest(destination.allocateCString());
       TransportInfo   global_ti;
       global_ti.type = SR_IP_TRANSPORT;
       global_ti.t_ipAddr = inet_addr(trap_dest.getPointer());
       global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort());
   
       // Community Name
       ArrayDestroyer<char> _community(community.allocateCString());
       OctetString* community_name = MakeOctetStringFromText(
                                         _community.getPointer());
   
     // getting IP address of the host     // getting IP address of the host
     char* hostname = System::getHostName().allocateCString();      ArrayDestroyer<char> hostname(System::getHostName().allocateCString());
     char **p;     char **p;
     struct hostent *hp;     struct hostent *hp;
     struct in_addr in;     struct in_addr in;
     hp=gethostbyname(hostname);      hp=gethostbyname(hostname.getPointer());
     p = hp->h_addr_list;     p = hp->h_addr_list;
     (void)memcpy(&in.s_addr, *p, sizeof(in.s_addr));     (void)memcpy(&in.s_addr, *p, sizeof(in.s_addr));
     char* IP_string = inet_ntoa(in);     char* IP_string = inet_ntoa(in);
  
     // converting destination into Transport  
     TransportInfo   global_ti;  
     global_ti.type = SR_IP_TRANSPORT;  
     // address to which to send trap  
     global_ti.t_ipAddr = inet_addr(destination.allocateCString());  
     // port to which to send trap  
     global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort());  
   
     // formatting agent(host) address into OctetString format     // formatting agent(host) address into OctetString format
     OctetString* agent_addr;     OctetString* agent_addr;
  
Line 153 
Line 164 
     agent_addr->octet_ptr[2] = (unsigned char)s3;     agent_addr->octet_ptr[2] = (unsigned char)s3;
     agent_addr->octet_ptr[3] = (unsigned char)s4;     agent_addr->octet_ptr[3] = (unsigned char)s4;
  
     // ATTN : Write code to get enterprise, genTrap and specTrap      // specTrap from trapOid.
     // from trapOid.      SR_INT32 genTrap = 0;
       SR_INT32 specTrap = 0;
  
     // << 03-12-2002 : NU (HP)      OID* enterpriseOid ;
  
     String enterprise;      Array<String> standard_traps;
   
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.1"));
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.2"));
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.3"));
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.4"));
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.5"));
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.6"));
   
       Array<String> oids;
       String tmpoid = trapOid;
   
       while(tmpoid.find(".") != PEG_NOT_FOUND)
       {
           oids.append(tmpoid.subString(0, tmpoid.find(".")));
           tmpoid = tmpoid.subString(tmpoid.find(".") + 1);
       }
       oids.append(tmpoid);
   
       String ent;
       if (oids[oids.size()-2] == "0")
       {
           ent = oids[0];
           for (Uint8 i = 1; i < oids.size()-2; i++)
               ent = ent + "." + oids[i];
       }
   
       if (Contains(standard_traps, trapOid))
       {
           ent = oids[0];
           for (Uint8 i = 1; i < oids.size()-1; i++)
               ent = ent + "." + oids[i];
   
           ArrayDestroyer<char> gtrap(ent.allocateCString());
           genTrap = atoi(gtrap.getPointer()) - 1;
           enterpriseOid = sendtrapOid;
       }
       else
       {
           genTrap = 6;
  
     OID* enterpriseOid = MakeOIDFromDot(enterprise.allocateCString());          ent = oids[0];
           for (Uint8 i = 1; i < oids.size()-1; i++)
               ent = ent + "." + oids[i];
           ArrayDestroyer<char> strap(oids[oids.size()-1].allocateCString());
           specTrap = atoi(strap.getPointer());
   
           if (oids[oids.size()-2] == "0")
           {
               ent = oids[0];
               for (Uint8 i = 1; i < oids.size()-2; i++)
                   ent = ent + "." + oids[i];
  
     // getting trap data for do_trap()              ArrayDestroyer<char> _ent(ent.allocateCString());
     entV2Trap = trapOid.allocateCString();              enterpriseOid = MakeOIDFromDot(_ent.getPointer());
           }
           else
           {
               ent = oids[0];
               for (Uint8 i = 1; i < oids.size()-1; i++)
                   ent = ent + "." + oids[i];
  
     // getting trapOid              ArrayDestroyer<char> _ent(ent.allocateCString());
     OID *sendtrapOid = MakeOIDFromDot(trapOid.allocateCString());              enterpriseOid = MakeOIDFromDot(_ent.getPointer());
           }
       }
  
     for(Uint8 i = 0; i < vbOids.size(); i++)      for(Uint32 i = 0; i < vbOids.size(); i++)
     {     {
         if ((object = MakeOIDFromDot(vbOids[i].allocateCString())) == NULL)          ArrayDestroyer<char> _vbOid(vbOids[i].allocateCString());
           ArrayDestroyer<char> _vbValue(vbValues[i].allocateCString());
   
           if ((object = MakeOIDFromDot(_vbOid.getPointer())) == NULL)
         {         {
             cout << "Invalid OID received: " << vbOids[i] << endl;             cout << "Invalid OID received: " << vbOids[i] << endl;
             return;             return;
         }         }
  
         if (strcmp(vbTypes[i].allocateCString(),"OctetString") == 0)          if (vbTypes[i] == String("OctetString"))
           {
               newValue = CloneOctetString(MakeOctetStringFromText(_vbValue.getPointer()));
               if (newValue == NULL)
         {         {
             newValue = MakeOctetStringFromText(vbValues[i].allocateCString());                  cout << "Invalid Value provided : " << vbValues[i] << endl;
             if ((vb = MakeVarBindWithValue(object,                  return;
               }
               if ((vb2 = MakeVarBindWithValue(object,
                 (OID *) NULL,                 (OID *) NULL,
                 OCTET_PRIM_TYPE,                 OCTET_PRIM_TYPE,
                 newValue)) == NULL)                 newValue)) == NULL)
Line 190 
Line 267 
         }         }
         else         else
         {         {
             newValue = MakeOctetString(              int vbvalue = atoi(_vbValue.getPointer());
                 (unsigned char *) vbValues[i].allocateCString(),              void* value = &vbvalue;
                 strlen(vbValues[i].allocateCString()));  
  
             if ((vb = MakeVarBindWithValue(object,              if (newValue == NULL)
               {
                   cout << "Invalid Value provided : " << vbValues[i] << endl;
                   return;
               }
               if ((vb2 = MakeVarBindWithValue(object,
                 (OID *) NULL,                 (OID *) NULL,
                 INTEGER_TYPE,                 INTEGER_TYPE,
                 newValue)) == NULL)                  value)) == NULL)
             {             {
                 cout << "Invalid Integer Value: " << vbValues[i] << endl;                 cout << "Invalid Integer Value: " << vbValues[i] << endl;
                 return;                 return;
             }             }
         }         }
           if (i == 0)
         if (!vb_link_flag)  
         {         {
             vb_link_flag = 1;              vb = vb2;
             vb2 = vb;              vb3 = vb2;
             FreeOID(object);  
         }         }
         else         else
         {         {
             vb2->next_var = vb;              vb3->next_var = vb2;
             vb2 = vb;              vb3 = vb3->next_var;
             FreeOID(object);  
         }         }
   
           FreeOID(object);
     }     }
  
     vb_link_flag = 0;      vb3->next_var = NULL;
     vb2->next_var = NULL;  
     vb->next_var = NULL;  
  
     // Now sending the trap     // Now sending the trap
     if (trapType == String("SNMPGeneric"))      if (trapType == String("SNMPv1"))
     {  
         do_trap(6, 4, vb2, enterpriseOid, entV2Trap);  
         FreeVarBindList(vb);  
         FreeVarBindList(vb2);  
     }  
     else if (trapType == String("SNMPv1"))  
     {     {
         SendNotificationToDestSMIv1Params(         SendNotificationToDestSMIv1Params(
             1,                                  // notifyType              1,                                  // notifyType - TRAP
             6,                                  // genTrap              genTrap,                            // genTrap
             1,                                  // specTrap              specTrap,                           // specTrap
             enterpriseOid,                      // enterprise             enterpriseOid,                      // enterprise
             agent_addr,                         // agent_addr             agent_addr,                         // agent_addr
             vb2,                                // vb              vb,                                 // vb
             NULL,                               // contextName             NULL,                               // contextName
             1,                                  // retryCount             1,                                  // retryCount
             1,                                  // timeout             1,                                  // timeout
             MakeOctetStringFromText(community.allocateCString()),       // securityName,              community_name,                     // securityName,
             SR_SECURITY_LEVEL_NOAUTH,           // securityLevel             SR_SECURITY_LEVEL_NOAUTH,           // securityLevel
             SR_SECURITY_MODEL_V1,               // securityModel             SR_SECURITY_MODEL_V1,               // securityModel
             &global_ti,                         // Transport Info             &global_ti,                         // Transport Info
             0);                                 // cfg_chk             0);                                 // cfg_chk
   
         FreeVarBindList(vb);  
         FreeVarBindList(vb2);  
     }     }
     else if (trapType == String("SNMPv2"))     else if (trapType == String("SNMPv2"))
     {     {
         SendNotificationToDestSMIv2Params(         SendNotificationToDestSMIv2Params(
             1,                                  // notifyType              1,                                  // notifyType - NOTIFICATION
             sendtrapOid,                        // snmpTrapOID             sendtrapOid,                        // snmpTrapOID
             agent_addr,                         // agent_addr             agent_addr,                         // agent_addr
             vb2,                                // vb              vb,                                 // vb
             NULL,                               // contextName             NULL,                               // contextName
             1,                                  // retryCount             1,                                  // retryCount
             100,                                // timeout             100,                                // timeout
             MakeOctetStringFromText(community.allocateCString()),       // securityName or community              community_name,                     // securityName or community
             SR_SECURITY_LEVEL_NOAUTH,           // securityLevel             SR_SECURITY_LEVEL_NOAUTH,           // securityLevel
             SR_SECURITY_MODEL_V1,               // securityModel             SR_SECURITY_MODEL_V1,               // securityModel
             &global_ti,                         // TransportInfo             &global_ti,                         // TransportInfo
Line 273 
Line 342 
         cout << "Trap type not supported : " << trapType << endl;         cout << "Trap type not supported : " << trapType << endl;
         exit(2);         exit(2);
     }     }
   
       FreeVarBindList(vb);
       FreeVarBindList(vb2);
       FreeVarBindList(vb3);
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.3  
changed lines
  Added in v.1.8

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2