(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.4 and 1.6

version 1.4, 2002/03/21 23:00:08 version 1.6, 2002/04/17 22:46:33
Line 103 
Line 103 
     Array<String>& vbTypes,     Array<String>& vbTypes,
     Array<String>& vbValues)     Array<String>& vbValues)
 { {
     initialize();  
   
     //void*   newValue;  
     OctetString*   newValue;     OctetString*   newValue;
     char*   entV2Trap;  
     int     vb_link_flag = 0;  
  
     VarBind *vb = NULL;     VarBind *vb = NULL;
     VarBind *vb2 = NULL;     VarBind *vb2 = NULL;
Line 116 
Line 111 
  
     OID     *object = NULL;     OID     *object = NULL;
  
       // Initializing with Master agent
       initialize();
   
       // TRAP OID: getting trapOid
       char* _trapOid = trapOid.allocateCString();
       _trapOid[strlen(_trapOid)-1] = '\0';
       OID *sendtrapOid = MakeOIDFromDot(_trapOid);
   
       // Destination : converting destination into Transport
       char* trap_dest = destination.allocateCString();
       TransportInfo   global_ti;
       global_ti.type = SR_IP_TRANSPORT;
       global_ti.t_ipAddr = inet_addr(trap_dest);
       global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort());
       delete [] trap_dest;
   
       // Community Name
       char* _community = community.allocateCString();
       OctetString* community_name = MakeOctetStringFromText(_community);
       delete [] _community;
   
     // getting IP address of the host     // getting IP address of the host
     char* hostname = System::getHostName().allocateCString();     char* hostname = System::getHostName().allocateCString();
     char **p;     char **p;
Line 125 
Line 141 
     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);
       delete [] hostname;
     // 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 159 
Line 168 
     // ATTN-NU-20020312 : Write code to get enterprise, genTrap and     // ATTN-NU-20020312 : Write code to get enterprise, genTrap and
     // specTrap from trapOid.     // specTrap from trapOid.
  
     String enterprise;      //NU_SNMP
   
       SR_INT32 genTrap = 0;
       SR_INT32 specTrap = 0;
  
     OID* enterpriseOid = MakeOIDFromDot(enterprise.allocateCString());      OID* enterpriseOid ;
  
     // getting trap data for do_trap()      Array<String> standard_traps;
     entV2Trap = trapOid.allocateCString();  
  
     // getting trapOid      standard_traps.append(String("1.3.6.1.6.3.1.1.5.1"));
     OID *sendtrapOid = MakeOIDFromDot(trapOid.allocateCString());      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];
   
           char* gtrap = ent.allocateCString();
           genTrap = atoi(gtrap) - 1;
           enterpriseOid = sendtrapOid;
           delete [] gtrap;
       }
       else
       {
           genTrap = 6;
   
           ent = oids[0];
           for (Uint8 i = 1; i < oids.size()-1; i++)
               ent = ent + "." + oids[i];
           char* strap = oids[oids.size()-1].allocateCString();
           specTrap = atoi(strap);
           delete [] strap;
   
           if (oids[oids.size()-2] == "0")
           {
               ent = oids[0];
               for (Uint8 i = 1; i < oids.size()-2; i++)
                   ent = ent + "." + oids[i];
   
               char* _ent = ent.allocateCString();
               enterpriseOid = MakeOIDFromDot(_ent);
               delete [] _ent;
           }
           else
           {
               ent = oids[0];
               for (Uint8 i = 1; i < oids.size()-1; i++)
                   ent = ent + "." + oids[i];
   
               char* _ent = ent.allocateCString();
               enterpriseOid = MakeOIDFromDot(_ent);
               delete [] _ent;
           }
       }
   
       char* _vbOid;
       char* _vbValue;
  
     for(Uint32 i = 0; i < vbOids.size(); i++)     for(Uint32 i = 0; i < vbOids.size(); i++)
     {     {
         if ((object = MakeOIDFromDot(vbOids[i].allocateCString())) == NULL)          _vbOid = vbOids[i].allocateCString();
           _vbValue = vbValues[i].allocateCString();
   
           if ((object = MakeOIDFromDot(_vbOid)) == 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              newValue = CloneOctetString(MakeOctetStringFromText(_vbValue));
                            (vbValues[i].allocateCString()));  
             if (newValue == NULL)             if (newValue == NULL)
             {             {
                 cout << "Invalid Value provided : " << vbValues[i] << endl;                 cout << "Invalid Value provided : " << vbValues[i] << endl;
Line 197 
Line 279 
         }         }
         else         else
         {         {
             newValue = CloneOctetString(MakeOctetString(              int vbvalue = atoi(_vbValue);
                 (unsigned char *) vbValues[i].allocateCString(),              void* value = &vbvalue;
                 strlen(vbValues[i].allocateCString())));  
  
             if (newValue == NULL)             if (newValue == NULL)
             {             {
Line 209 
Line 290 
             if ((vb2 = MakeVarBindWithValue(object,             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;
Line 229 
Line 310 
         FreeOID(object);         FreeOID(object);
     }     }
  
       delete [] _vbValue;
       delete [] _vbOid;
   
     vb3->next_var = NULL;     vb3->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"))  
     {  
         cout << "Sending SNMPv1 Trap : " << trapOid << endl;  
         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"))
     {     {
         cout << "Sending SNMPv2 Trap : " << trapOid << endl;  
         SendNotificationToDestSMIv2Params(         SendNotificationToDestSMIv2Params(
             1,                                  // notifyType              1,                                  // notifyType - NOTIFICATION
             sendtrapOid,                        // snmpTrapOID             sendtrapOid,                        // snmpTrapOID
             agent_addr,                         // agent_addr             agent_addr,                         // agent_addr
             //vb2,                              // vb  
             vb,                         // 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 283 
Line 355 
     else     else
     {     {
         cout << "Trap type not supported : " << trapType << endl;         cout << "Trap type not supported : " << trapType << endl;
           delete [] _trapOid;
         exit(2);         exit(2);
     }     }
   
       FreeVarBindList(vb);
       FreeVarBindList(vb2);
       FreeVarBindList(vb3);
   
       delete [] _trapOid;
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.4  
changed lines
  Added in v.1.6

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2