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

  1 mike  1.2 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3 kumpf 1.10 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
  4            // The Open Group, Tivoli Systems
  5 mike  1.2  //
  6            // Permission is hereby granted, free of charge, to any person obtaining a copy
  7 kumpf 1.10 // of this software and associated documentation files (the "Software"), to
  8            // deal in the Software without restriction, including without limitation the
  9            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10 mike  1.2  // sell copies of the Software, and to permit persons to whom the Software is
 11            // furnished to do so, subject to the following conditions:
 12            // 
 13 kumpf 1.10 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14 mike  1.2  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16 kumpf 1.10 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 17            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 18            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 19 mike  1.2  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21            //
 22            //==============================================================================
 23            //
 24            // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
 25            //
 26 kumpf 1.12 // Modified By: Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
 27 mike  1.2  //
 28            //%/////////////////////////////////////////////////////////////////////////////
 29            
 30 kumpf 1.3  #include <Pegasus/Common/System.h>
 31 kumpf 1.12 #include <Pegasus/Common/ArrayInternal.h>
 32 kumpf 1.8  #include <Pegasus/Common/Destroyer.h>
 33 kumpf 1.12 #include <Pegasus/Common/InternalException.h>
 34 mike  1.2  #include "snmpDeliverTrap_emanate.h"
 35 kumpf 1.12 
 36 humberto 1.14 // l10n
 37               #include <Pegasus/Common/MessageLoader.h>
 38               
 39 kumpf    1.12 // EMANATE specific declarations and entry points - MUST be in begining
 40               // and outside NAMESPACE.
 41               
 42               // master agent needs these two declarations for communication with sub-agent.
 43               // Following two declarations must be in the CODE. 
 44               
 45               #include <prnt_lib.h>  // MUST be at the end in include list.
 46 mike     1.2  
 47 kumpf    1.3  static char *sr_filename = __FILE__;
 48               
 49               IPCFunctionP IPCfp;  /* IPC functions pointer  */
 50               
 51 kumpf    1.12 // This code would normally be generated by Emanate from defined MIB objects. 
 52               // Since we do not have MIB objects defined, just defined here to load 
 53               // subagent as library. OidList[] provides objects for entry point to master agent.
 54 kumpf    1.3  
 55               // The objects internal to the agent 
 56               ObjectInfo OidList[] = 
 57               {
 58               { { 0, NULL },
 59               #ifndef LIGHT
 60                   NULL,
 61               #endif /* LIGHT */
 62                   0, 0, 0, 0,
 63                   NULL, NULL }
 64               };
 65               
 66 kumpf    1.12 // This code would normally be generated by Emanate in k_* routine from defined MIB objects.
 67               // Since we do not have MIB objects defined, just define here to pass compile and
 68               // enable entry point for master agent to start communication with library.
 69 kumpf    1.3  
 70               // Called by the master agent during initialization */
 71               int k_initialize()
 72               {
 73                  return 1;
 74               }
 75 kumpf    1.9  
 76 kumpf    1.12 // END EMANATE specific declarations.
 77               
 78 kumpf    1.9  PEGASUS_NAMESPACE_BEGIN
 79               
 80               PEGASUS_USING_STD;
 81 kumpf    1.3  
 82               snmpDeliverTrap_emanate::snmpDeliverTrap_emanate()
 83               {
 84               
 85               }
 86               
 87               snmpDeliverTrap_emanate::~snmpDeliverTrap_emanate()
 88               {
 89               
 90               }
 91               
 92 kumpf    1.12 
 93               // initialize sub-agent
 94               
 95               // This also defines the communication protocol to be used between master
 96               // and sub-agent.
 97               
 98 kumpf    1.3  void snmpDeliverTrap_emanate::initialize()
 99               {
100               #ifndef SR_UDS_IPC
101                   InitIPCArrayTCP(&IPCfp);
102               #else /* SR_UDS_IPC */
103                   InitIPCArrayUDS(&IPCfp);
104               #endif /* SR_UDS_IPC */
105               
106                   if(InitSubagent() == -1) 
107                   {
108 humberto 1.14 
109                     // l10n
110               
111                     // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
112                     //   _MSG_INITSUBAGENT_FAILED);
113               
114                     throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
115               				    MessageLoaderParms(_MSG_INITSUBAGENT_FAILED_KEY,
116               						       _MSG_INITSUBAGENT_FAILED,
117               						       _MSG_INITSUBAGENT));
118               
119 kumpf    1.3      }
120               }
121               
122 humberto 1.14 
123 kumpf    1.3  void snmpDeliverTrap_emanate::deliverTrap(
124 kumpf    1.12         const String& trapOid,
125                       const String& securityName, 
126                       const String& targetHost, 
127                       const Uint16& targetHostFormat, 
128                       const String& otherTargetHostFormat, 
129                       const Uint32& portNumber,
130                       const Uint16& snmpVersion, 
131                       const String& engineID,
132                       Array<String>& vbOids,
133                       Array<String>& vbTypes,
134                       Array<String>& vbValues)
135 mike     1.2  {
136 kumpf    1.12     VarBind *vbhead = NULL;
137 kumpf    1.3      VarBind *vb = NULL;
138 kumpf    1.12     VarBind *vblast = NULL;
139 kumpf    1.3      
140                   OID	    *object = NULL;
141               
142 kumpf    1.12     // Initialize with Master agent
143               
144                   	initialize();
145               
146                   // Translate a string into an OID
147                   OID *sendtrapOid = MakeOIDFromDot(trapOid.getCString());
148               
149                   if (sendtrapOid == NULL)
150                   {
151 humberto 1.14 
152                     // l10n
153               
154                     // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
155                     // _MSG_INVALID_TRAPOID);
156               
157                     throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
158               				    MessageLoaderParms(_MSG_INVALID_KEY,
159               						       _MSG_INVALID_TRAPOID,
160               						       _MSG_TRAPOID));
161 kumpf    1.12     }
162               
163                   // Destination : convert targetHost into Transport
164 kumpf    1.5  
165 kumpf    1.12     CString trap_dest = targetHost.getCString();
166 kumpf    1.5  
167                   TransportInfo   global_ti;
168                   global_ti.type = SR_IP_TRANSPORT;
169               
170 kumpf    1.12     switch (targetHostFormat)
171                   {
172               	case _HOST_NAME:
173               	{
174               	    char * ipAddr = _getIPAddress(trap_dest); 
175               
176               	    if (ipAddr == NULL)
177               	    {
178 humberto 1.14 
179               	      // l10n
180               
181               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
182               	      //   _MSG_DESTINATION_NOT_FOUND);
183               
184               	      throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
185               					     MessageLoaderParms(_MSG_DESTINATION_NOT_FOUND_KEY,
186               								_MSG_DESTINATION_NOT_FOUND));
187               
188 kumpf    1.12  	    }
189                   	    global_ti.t_ipAddr = inet_addr(trap_dest);
190               	    break;	    
191               	}
192               	case _IPV4_ADDRESS:
193               	{
194                   	    global_ti.t_ipAddr = inet_addr(trap_dest);
195               	    break;	    
196               	}
197               	default:
198               	{
199 humberto 1.14 
200               	  // l10n
201               
202               	  // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
203               	  // _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED);
204               
205               	  throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_NOT_SUPPORTED,
206               					 MessageLoaderParms(_MSG_TARGETHOSTFORMAT_NOT_SUPPORTED_KEY,
207               							    _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED,
208               							    _MSG_HOSTNAME,
209               							    _MSG_IPV4,
210               							    _MSG_TARGETHOSTFORMAT));
211               
212 kumpf    1.12 	    break;	    
213               	}
214                   } 
215               
216                   global_ti.t_ipPort = htons((unsigned short)portNumber);
217               
218                   // Community Name, default is public
219                   CString _community;
220                   if (securityName.size() == 0)
221                   {
222               	String community;
223               	community.assign("public");
224               	_community = community.getCString();
225                   }
226                   else
227                   {
228               	_community = securityName.getCString();
229                   }
230               
231                   OctetString* community_name = MakeOctetStringFromText(_community);
232               
233 kumpf    1.12     if (community_name == NULL)
234                   {
235 humberto 1.14 
236                     // l10n
237               
238                     // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
239                     //   _MSG_INVALID_SECURITY_NAME);
240               
241                     throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
242               				    MessageLoaderParms(_MSG_INVALID_SECURITY_NAME_KEY,
243               						       _MSG_INVALID_SECURITY_NAME,
244               						       _MSG_SECURITY_NAME));
245               						       
246 kumpf    1.12     }
247 kumpf    1.5  
248 kumpf    1.3      // getting IP address of the host
249 kumpf    1.12 
250                   CString hostname = System::getHostName().getCString();
251                   char* IP_string = _getIPAddress(hostname);
252               
253 kumpf    1.3      // formatting agent(host) address into OctetString format
254 kumpf    1.12 
255 kumpf    1.3      OctetString* agent_addr;
256               
257                   SR_INT32 s1, s2, s3, s4;
258                   SR_UINT32 ipaddr;
259               
260                   // pull out each of the 4 octet values from IP address
261 kumpf    1.12 
262 kumpf    1.3      sscanf(IP_string,"%d.%d.%d.%d", &s1, &s2, &s3, &s4);
263                
264 kumpf    1.12     // validate the values for s1, s2, s3, and s4 to make sure values are
265 kumpf    1.3      // between 0 and 255
266 kumpf    1.12     if (!_isValidOctet(s1) || !_isValidOctet(s2) ||
267               	!_isValidOctet(s3) || !_isValidOctet(s4))
268                   {
269 humberto 1.14 
270                     // l10n
271               
272                     // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
273                     //   _MSG_INVALID_OCTET_VALUE);
274               
275                     throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
276               				  MessageLoaderParms(_MSG_INVALID_OCTET_VALUE_KEY,
277               						     _MSG_INVALID_OCTET_VALUE));
278 kumpf    1.12     }
279 kumpf    1.3   
280                   // create an empty 4 length OctetString
281 kumpf    1.12 
282 kumpf    1.3      agent_addr = MakeOctetString(NULL,4);
283 kumpf    1.12 
284                   if (agent_addr == NULL)
285                   {
286 humberto 1.14 
287                     // l10n
288               
289                     // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
290                     //   _MSG_CREATE_OCTET_FAILED);
291               
292                     throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
293               				    MessageLoaderParms(_MSG_CREATE_OCTET_FAILED_KEY,
294               						       _MSG_CREATE_OCTET_FAILED,
295               						       _MSG_OCTETSTRING));
296               
297 kumpf    1.12     }
298 kumpf    1.3   
299                   // fill in values for OctetString
300 kumpf    1.12 
301 kumpf    1.3      agent_addr->octet_ptr[0] = (unsigned char)s1;
302                   agent_addr->octet_ptr[1] = (unsigned char)s2;
303                   agent_addr->octet_ptr[2] = (unsigned char)s3;
304                   agent_addr->octet_ptr[3] = (unsigned char)s4;
305               
306 kumpf    1.4      // specTrap from trapOid. 
307 kumpf    1.12 
308 kumpf    1.5      SR_INT32 genTrap = 0;
309                   SR_INT32 specTrap = 0;
310 kumpf    1.3      
311 kumpf    1.5      OID* enterpriseOid ;
312               
313                   Array<String> standard_traps;
314               
315                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.1"));
316                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.2"));
317                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.3"));
318                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.4"));
319                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.5"));
320                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.6"));
321               
322                   Array<String> oids;
323                   String tmpoid = trapOid;
324               
325                   while(tmpoid.find(".") != PEG_NOT_FOUND)
326                   {
327                       oids.append(tmpoid.subString(0, tmpoid.find(".")));
328                       tmpoid = tmpoid.subString(tmpoid.find(".") + 1);
329                   }
330 kumpf    1.12 
331 kumpf    1.5      oids.append(tmpoid);
332               
333                   String ent;
334                   if (Contains(standard_traps, trapOid))
335                   {
336 kumpf    1.12     	//
337                   	// if the trapOid is one of the standard traps,
338                   	// then the SNMPV1 enterprise parameter must be set 
339                   	// to the value of the trapOid, the generic-trap
340                   	// parameter must be set to one of (0 - 5), and the 
341                   	// specific-trap parameter must be set to 0
342                   	//
343 kumpf    1.5  
344                       enterpriseOid = sendtrapOid;
345 kumpf    1.12 
346               	// the generic trap is last sub-identifier of the 
347               	// trapOid minus 1
348               	genTrap = atoi(oids[oids.size() - 1].getCString()) - 1;
349               	specTrap = 0;
350 kumpf    1.5      }
351                   else
352                   {
353 kumpf    1.12 	// 
354               	// if the trapOid is not one of the standard traps:
355               	// then 1) the generic-trap parameter must be set to 6, 
356               	// 2) if the next-to-last sub-identifier of the 
357               	// trapOid is zero, then the SNMPV1 enterprise 
358                	// parameter is the trapOid with the last 2 
359               	// sub-identifiers removed, otherwise, the 
360               	// SNMPV1 enterprise parameter is the trapOid 
361               	// with the last sub-identifier removed;
362               	// 3) the SNMPv1 specific-trap parameter is the last
363               	// sub-identifier of the trapOid;
364               	//
365               
366 kumpf    1.5  	genTrap = 6;
367 mike     1.2  
368 kumpf    1.11         specTrap = atoi(oids[oids.size()-1].getCString());
369 mike     1.2  
370 kumpf    1.12 	ent = oids[0];
371               	for (Uint8 i = 1; i < oids.size()-2; i++)
372               	{
373               	    ent = ent + "." + oids[i];
374               	}
375               
376               	if (oids[oids.size()-2] != "0")
377               	{
378               	    ent = ent + "." + oids[oids.size()-2];
379                  	}
380               
381               	enterpriseOid = MakeOIDFromDot(ent.getCString());
382               	
383               	if (enterpriseOid == NULL)
384               	{
385 humberto 1.14 
386               	  // l10n
387               
388               	  // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
389               	  //   _MSG_INVALID_ENTERPRISEOID);
390               
391               	  throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
392               					MessageLoaderParms(_MSG_INVALID_ENTERPRISEOID_KEY,
393               							   _MSG_INVALID_ENTERPRISEOID,
394               							   _MSG_ENTERPRISEOID));
395 kumpf    1.12 	}
396 kumpf    1.5      }
397               
398 kumpf    1.12     // creates VarBind
399 kumpf    1.4      for(Uint32 i = 0; i < vbOids.size(); i++)
400 mike     1.2      {
401 kumpf    1.12 	CString _vbOid = vbOids[i].getCString();
402               	CString _vbValue = vbValues[i].getCString();
403               
404               	if ((object = MakeOIDFromDot(_vbOid)) == NULL)
405 kumpf    1.3          {
406 humberto 1.14 
407               	  // l10n
408               	  
409               	  // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
410               	  //   _MSG_INVALID_PROPERTYOID);
411               
412               	  throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
413               					MessageLoaderParms(_MSG_INVALID_PROPERTYOID_KEY,
414               							   _MSG_INVALID_PROPERTYOID,
415               							   _MSG_OID,
416               							   _MSG_CIM));
417 kumpf    1.3          } 
418               
419 kumpf    1.12 	if (String::equalNoCase(vbTypes[i], "OctetString"))
420               	{
421                   	     OctetString*    value;
422               
423                            value = CloneOctetString(MakeOctetStringFromText(_vbValue));
424                            if (value == NULL)
425                            {
426 humberto 1.14 	       
427               	       // l10n
428               
429               	       // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
430               	       //   _MSG_INVALID_PROPERTYVALUE);
431               
432                      	         throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
433               					       MessageLoaderParms(_MSG_INVALID_PROPERTYVALUE_KEY,
434               								  _MSG_INVALID_PROPERTYVALUE,
435               								  _MSG_CIM));
436 kumpf    1.12              }
437               
438                            if ((vb = MakeVarBindWithValue(object, 
439               				  	(OID *) NULL, 
440               					OCTET_PRIM_TYPE, 
441               					value)) == NULL)
442                           {
443 humberto 1.14 
444               	      // l10n
445               
446               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
447               	      //    _MSG_MAKE_VARBIND_FAILED_FOR_OCTET_PRIM_TYPE);
448               
449               	      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
450               					    MessageLoaderParms(_MSG_MAKE_VARBIND_FAILED_KEY,
451               							       _MSG_MAKE_VARBIND_FAILED,
452               							       _MSG_VARBIND,
453               							       _MSG_OCTET_PRIM_TYPE));
454 kumpf    1.12             }
455                   	}
456               	else if (String::equalNoCase(vbTypes[i], "OID"))
457               	{
458                           void* value = MakeOIDFromDot(_vbValue);
459                           if (value == NULL)
460 kumpf    1.4              {
461 humberto 1.14 	      // l10n
462               
463               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
464               	      //    _MSG_INVALID_PROPERTYVALUE);
465               
466               	      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
467               					    MessageLoaderParms(_MSG_INVALID_PROPERTYVALUE_KEY,
468               							       _MSG_INVALID_PROPERTYVALUE,
469               							       _MSG_CIM));
470               							       
471 kumpf    1.4              }
472 kumpf    1.12 
473                           if ((vb = MakeVarBindWithValue(object, 
474               				  	(OID *) NULL, 
475               					OBJECT_ID_TYPE, 
476               					value)) == NULL)
477 kumpf    1.3              {
478 humberto 1.14 
479               	      // l10n
480               
481               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
482               	      //    _MSG_MAKE_VARBIND_FAILED_FOR_OBJECT_ID_TYPE);
483               
484               	      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
485               					    MessageLoaderParms(_MSG_MAKE_VARBIND_FAILED_KEY,
486               							       _MSG_MAKE_VARBIND_FAILED,
487               							       _MSG_VARBIND,
488               							       _MSG_OBJECT_ID_TYPE));
489 kumpf    1.3              }
490 kumpf    1.12 	}
491               	else
492               	{
493                           int vbvalue = atoi(_vbValue);
494 kumpf    1.6              void* value = &vbvalue;
495 kumpf    1.3  
496 kumpf    1.12             if (value == NULL)
497 kumpf    1.4              {
498 humberto 1.14 
499               	      // l10n
500               
501               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
502               	      //    _MSG_INVALID_PROPERTYVALUE);
503               
504               	      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
505               					    MessageLoaderParms(_MSG_INVALID_PROPERTYVALUE_KEY,
506               							       _MSG_INVALID_PROPERTYVALUE,
507               							       _MSG_CIM));
508 kumpf    1.4              }
509 kumpf    1.12 
510                           if ((vb = MakeVarBindWithValue(object, 
511               				  	(OID *) NULL, 
512               					INTEGER_TYPE, 
513               					value)) == NULL)
514 mike     1.2              {
515 humberto 1.14 
516               	      // l10n
517               
518               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
519               	      //    _MSG_MAKE_VARBIND_FAILED_FOR_INTEGER_TYPE);
520               
521               	      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
522               					    MessageLoaderParms(_MSG_MAKE_VARBIND_FAILED_KEY,
523               							       _MSG_MAKE_VARBIND_FAILED,
524               							       _MSG_VARBIND,
525               							       _MSG_INTEGER_TYPE));
526 mike     1.2              }
527 kumpf    1.12 	}
528               
529 kumpf    1.4          if (i == 0)
530                       {
531 kumpf    1.12             vbhead = vb;
532                           vblast = vb;
533 kumpf    1.4          }
534                       else
535                       {
536 kumpf    1.12             vblast->next_var = vb;
537                           vblast = vblast->next_var;
538 kumpf    1.4          }
539               
540 kumpf    1.3      }
541 kumpf    1.5  
542 kumpf    1.12     vblast->next_var = NULL;
543 kumpf    1.3  
544 kumpf    1.12     // Now send the trap
545                   switch (snmpVersion)
546 kumpf    1.3      {
547 kumpf    1.12 	case _SNMPv1_TRAP:
548               	{
549                           SendNotificationToDestSMIv1Params(
550               	    1,					// notifyType - TRAP
551 kumpf    1.5              genTrap,				// genTrap
552                           specTrap,				// specTrap
553 kumpf    1.3              enterpriseOid,			// enterprise
554                           agent_addr,				// agent_addr
555 kumpf    1.12             vbhead,				// vb
556 kumpf    1.3              NULL,				// contextName
557                           1,					// retryCount
558                           1,					// timeout
559 kumpf    1.5              community_name,			// securityName,
560 kumpf    1.3              SR_SECURITY_LEVEL_NOAUTH,		// securityLevel
561                           SR_SECURITY_MODEL_V1,		// securityModel
562                           &global_ti,				// Transport Info
563 kumpf    1.12             0);          			// cfg_chk
564               	    break;
565               	}
566               	case _SNMPv2C_TRAP:
567               	{
568                           SendNotificationToDestSMIv2Params(
569               	    (SR_INT32)SNMPv2_TRAP_TYPE,		// notifyType - NOTIFICATION
570 kumpf    1.3              sendtrapOid,			// snmpTrapOID
571                           agent_addr,				// agent_addr
572 kumpf    1.12             vbhead,				// vb
573 kumpf    1.3              NULL,				// contextName
574                           1,					// retryCount
575                           100,				// timeout
576 kumpf    1.5              community_name,			// securityName or community
577 kumpf    1.3              SR_SECURITY_LEVEL_NOAUTH,		// securityLevel
578 kumpf    1.12             SR_SECURITY_MODEL_V2C,		// securityModel
579 kumpf    1.3              &global_ti,				// TransportInfo
580                           0);					// cfg_chk
581 kumpf    1.12 	    break;
582               	}
583               	default:
584               	{
585 humberto 1.14 	  // l10n
586               
587               	  // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
588               	  // _MSG_VERSION_NOT_SUPPORTED);
589               
590               	  throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED,	  
591               					MessageLoaderParms(_MSG_VERSION_NOT_SUPPORTED_KEY,
592               							   _MSG_VERSION_NOT_SUPPORTED,
593               							   _MSG_SNMPv1,
594               							   _MSG_SNMPv2C,
595               							   _MSG_SNMPVersion));
596               
597               	  break;
598 kumpf    1.12 	}
599                   }
600               
601                   // Free OID built by calls MakeOIDFromDot()
602                   FreeOID(sendtrapOid);
603                   FreeOID(enterpriseOid);
604                   FreeOID(object);
605               
606                   // Free the data structures allocated and built by calls
607                   // MakeOctetString() and MakeOctetStringFrom Text()
608                   FreeOctetString(community_name);
609                   FreeOctetString(agent_addr);
610               
611                   // Free the VarBind data structures allocated and built 
612                   // by calls MakeVarBindWithValue()
613                   FreeVarBindList(vbhead);
614                   FreeVarBindList(vb);
615                   FreeVarBindList(vblast);
616               }
617               
618               // get the IP address of a host
619 kumpf    1.12 char * snmpDeliverTrap_emanate::_getIPAddress(const CString& hostName)
620               {
621                   struct hostent *targetHostInfo;
622                   struct in_addr in;
623               
624 keith.petley 1.13 #ifdef PEGASUS_OS_SOLARIS
625                   #define HOSTENT_BUFF_SIZE	8192
626                       char			buf[HOSTENT_BUFF_SIZE];
627                       struct hostent		h_result;
628                       int				h_errorp;
629                       targetHostInfo=gethostbyname_r(hostName, &h_result, buff,
630                   					HOSTENT_BUFF_SIZE, &h_errorp);
631                   #else
632 kumpf        1.12     targetHostInfo = gethostbyname(hostName);
633 keith.petley 1.13 #endif
634 kumpf        1.12 
635                       if (targetHostInfo == NULL)
636                       {
637                   	return(NULL);
638                       }
639                   	    
640                       char ** networkAddr;
641                       networkAddr = targetHostInfo->h_addr_list;
642                       (void)memcpy(&in.s_addr, *networkAddr, sizeof(in.s_addr));
643                       char * ipAddr = inet_ntoa(in);
644                       return(ipAddr);
645                   }
646                   
647                   // check the value of each part of an IP address which should be 
648                   // between 0 and 255
649                   Boolean snmpDeliverTrap_emanate::_isValidOctet(const Uint32& octetValue)
650                   {
651                       if (octetValue > 0 && octetValue < 255)
652                       {
653                   	return true;
654 kumpf        1.3      }
655                       else
656                       {
657 kumpf        1.12 	return false;
658 mike         1.2      }
659                   }
660                   
661                   PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2