(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 humberto 1.15 						       _MSG_INITSUBAGENT_FAILED));
117 humberto 1.14 
118 kumpf    1.3      }
119               }
120               
121 humberto 1.14 
122 kumpf    1.3  void snmpDeliverTrap_emanate::deliverTrap(
123 kumpf    1.12         const String& trapOid,
124                       const String& securityName, 
125                       const String& targetHost, 
126                       const Uint16& targetHostFormat, 
127                       const String& otherTargetHostFormat, 
128                       const Uint32& portNumber,
129                       const Uint16& snmpVersion, 
130                       const String& engineID,
131                       Array<String>& vbOids,
132                       Array<String>& vbTypes,
133                       Array<String>& vbValues)
134 mike     1.2  {
135 kumpf    1.12     VarBind *vbhead = NULL;
136 kumpf    1.3      VarBind *vb = NULL;
137 kumpf    1.12     VarBind *vblast = NULL;
138 kumpf    1.3      
139                   OID	    *object = NULL;
140               
141 kumpf    1.12     // Initialize with Master agent
142               
143                   	initialize();
144               
145                   // Translate a string into an OID
146                   OID *sendtrapOid = MakeOIDFromDot(trapOid.getCString());
147               
148                   if (sendtrapOid == NULL)
149                   {
150 humberto 1.14 
151                     // l10n
152               
153                     // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
154                     // _MSG_INVALID_TRAPOID);
155               
156                     throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
157               				    MessageLoaderParms(_MSG_INVALID_KEY,
158 humberto 1.15 						       _MSG_INVALID_TRAPOID));
159 kumpf    1.12     }
160               
161                   // Destination : convert targetHost into Transport
162 kumpf    1.5  
163 kumpf    1.12     CString trap_dest = targetHost.getCString();
164 kumpf    1.5  
165                   TransportInfo   global_ti;
166                   global_ti.type = SR_IP_TRANSPORT;
167               
168 kumpf    1.12     switch (targetHostFormat)
169                   {
170               	case _HOST_NAME:
171               	{
172               	    char * ipAddr = _getIPAddress(trap_dest); 
173               
174               	    if (ipAddr == NULL)
175               	    {
176 humberto 1.14 
177               	      // l10n
178               
179               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
180               	      //   _MSG_DESTINATION_NOT_FOUND);
181               
182               	      throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
183               					     MessageLoaderParms(_MSG_DESTINATION_NOT_FOUND_KEY,
184               								_MSG_DESTINATION_NOT_FOUND));
185               
186 kumpf    1.12  	    }
187                   	    global_ti.t_ipAddr = inet_addr(trap_dest);
188               	    break;	    
189               	}
190               	case _IPV4_ADDRESS:
191               	{
192                   	    global_ti.t_ipAddr = inet_addr(trap_dest);
193               	    break;	    
194               	}
195               	default:
196               	{
197 humberto 1.14 
198               	  // l10n
199               
200               	  // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
201               	  // _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED);
202               
203               	  throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_NOT_SUPPORTED,
204               					 MessageLoaderParms(_MSG_TARGETHOSTFORMAT_NOT_SUPPORTED_KEY,
205 humberto 1.15 							    _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED));
206 humberto 1.14 
207 kumpf    1.12 	    break;	    
208               	}
209                   } 
210               
211                   global_ti.t_ipPort = htons((unsigned short)portNumber);
212               
213                   // Community Name, default is public
214                   CString _community;
215                   if (securityName.size() == 0)
216                   {
217               	String community;
218               	community.assign("public");
219               	_community = community.getCString();
220                   }
221                   else
222                   {
223               	_community = securityName.getCString();
224                   }
225               
226                   OctetString* community_name = MakeOctetStringFromText(_community);
227               
228 kumpf    1.12     if (community_name == NULL)
229                   {
230 humberto 1.14 
231                     // l10n
232               
233                     // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
234                     //   _MSG_INVALID_SECURITY_NAME);
235               
236                     throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
237               				    MessageLoaderParms(_MSG_INVALID_SECURITY_NAME_KEY,
238 humberto 1.15 						       _MSG_INVALID_SECURITY_NAME));
239 humberto 1.14 						       
240 kumpf    1.12     }
241 kumpf    1.5  
242 kumpf    1.3      // getting IP address of the host
243 kumpf    1.12 
244                   CString hostname = System::getHostName().getCString();
245                   char* IP_string = _getIPAddress(hostname);
246               
247 kumpf    1.3      // formatting agent(host) address into OctetString format
248 kumpf    1.12 
249 kumpf    1.3      OctetString* agent_addr;
250               
251                   SR_INT32 s1, s2, s3, s4;
252                   SR_UINT32 ipaddr;
253               
254                   // pull out each of the 4 octet values from IP address
255 kumpf    1.12 
256 kumpf    1.3      sscanf(IP_string,"%d.%d.%d.%d", &s1, &s2, &s3, &s4);
257                
258 kumpf    1.12     // validate the values for s1, s2, s3, and s4 to make sure values are
259 kumpf    1.3      // between 0 and 255
260 kumpf    1.12     if (!_isValidOctet(s1) || !_isValidOctet(s2) ||
261               	!_isValidOctet(s3) || !_isValidOctet(s4))
262                   {
263 humberto 1.14 
264                     // l10n
265               
266                     // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
267                     //   _MSG_INVALID_OCTET_VALUE);
268               
269                     throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
270               				  MessageLoaderParms(_MSG_INVALID_OCTET_VALUE_KEY,
271               						     _MSG_INVALID_OCTET_VALUE));
272 kumpf    1.12     }
273 kumpf    1.3   
274                   // create an empty 4 length OctetString
275 kumpf    1.12 
276 kumpf    1.3      agent_addr = MakeOctetString(NULL,4);
277 kumpf    1.12 
278                   if (agent_addr == NULL)
279                   {
280 humberto 1.14 
281                     // l10n
282               
283                     // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
284                     //   _MSG_CREATE_OCTET_FAILED);
285               
286                     throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
287               				    MessageLoaderParms(_MSG_CREATE_OCTET_FAILED_KEY,
288 humberto 1.15 						       _MSG_CREATE_OCTET_FAILED));
289 humberto 1.14 
290 kumpf    1.12     }
291 kumpf    1.3   
292                   // fill in values for OctetString
293 kumpf    1.12 
294 kumpf    1.3      agent_addr->octet_ptr[0] = (unsigned char)s1;
295                   agent_addr->octet_ptr[1] = (unsigned char)s2;
296                   agent_addr->octet_ptr[2] = (unsigned char)s3;
297                   agent_addr->octet_ptr[3] = (unsigned char)s4;
298               
299 kumpf    1.4      // specTrap from trapOid. 
300 kumpf    1.12 
301 kumpf    1.5      SR_INT32 genTrap = 0;
302                   SR_INT32 specTrap = 0;
303 kumpf    1.3      
304 kumpf    1.5      OID* enterpriseOid ;
305               
306                   Array<String> standard_traps;
307               
308                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.1"));
309                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.2"));
310                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.3"));
311                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.4"));
312                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.5"));
313                   standard_traps.append(String("1.3.6.1.6.3.1.1.5.6"));
314               
315                   Array<String> oids;
316                   String tmpoid = trapOid;
317               
318                   while(tmpoid.find(".") != PEG_NOT_FOUND)
319                   {
320                       oids.append(tmpoid.subString(0, tmpoid.find(".")));
321                       tmpoid = tmpoid.subString(tmpoid.find(".") + 1);
322                   }
323 kumpf    1.12 
324 kumpf    1.5      oids.append(tmpoid);
325               
326                   String ent;
327                   if (Contains(standard_traps, trapOid))
328                   {
329 kumpf    1.12     	//
330                   	// if the trapOid is one of the standard traps,
331                   	// then the SNMPV1 enterprise parameter must be set 
332                   	// to the value of the trapOid, the generic-trap
333                   	// parameter must be set to one of (0 - 5), and the 
334                   	// specific-trap parameter must be set to 0
335                   	//
336 kumpf    1.5  
337                       enterpriseOid = sendtrapOid;
338 kumpf    1.12 
339               	// the generic trap is last sub-identifier of the 
340               	// trapOid minus 1
341               	genTrap = atoi(oids[oids.size() - 1].getCString()) - 1;
342               	specTrap = 0;
343 kumpf    1.5      }
344                   else
345                   {
346 kumpf    1.12 	// 
347               	// if the trapOid is not one of the standard traps:
348               	// then 1) the generic-trap parameter must be set to 6, 
349               	// 2) if the next-to-last sub-identifier of the 
350               	// trapOid is zero, then the SNMPV1 enterprise 
351                	// parameter is the trapOid with the last 2 
352               	// sub-identifiers removed, otherwise, the 
353               	// SNMPV1 enterprise parameter is the trapOid 
354               	// with the last sub-identifier removed;
355               	// 3) the SNMPv1 specific-trap parameter is the last
356               	// sub-identifier of the trapOid;
357               	//
358               
359 kumpf    1.5  	genTrap = 6;
360 mike     1.2  
361 kumpf    1.11         specTrap = atoi(oids[oids.size()-1].getCString());
362 mike     1.2  
363 kumpf    1.12 	ent = oids[0];
364               	for (Uint8 i = 1; i < oids.size()-2; i++)
365               	{
366               	    ent = ent + "." + oids[i];
367               	}
368               
369               	if (oids[oids.size()-2] != "0")
370               	{
371               	    ent = ent + "." + oids[oids.size()-2];
372                  	}
373               
374               	enterpriseOid = MakeOIDFromDot(ent.getCString());
375               	
376               	if (enterpriseOid == NULL)
377               	{
378 humberto 1.14 
379               	  // l10n
380               
381               	  // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
382               	  //   _MSG_INVALID_ENTERPRISEOID);
383               
384               	  throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
385               					MessageLoaderParms(_MSG_INVALID_ENTERPRISEOID_KEY,
386 humberto 1.15 							   _MSG_INVALID_ENTERPRISEOID));
387 kumpf    1.12 	}
388 kumpf    1.5      }
389               
390 kumpf    1.12     // creates VarBind
391 kumpf    1.4      for(Uint32 i = 0; i < vbOids.size(); i++)
392 mike     1.2      {
393 kumpf    1.12 	CString _vbOid = vbOids[i].getCString();
394               	CString _vbValue = vbValues[i].getCString();
395               
396               	if ((object = MakeOIDFromDot(_vbOid)) == NULL)
397 kumpf    1.3          {
398 humberto 1.14 
399               	  // l10n
400               	  
401               	  // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
402               	  //   _MSG_INVALID_PROPERTYOID);
403               
404               	  throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
405               					MessageLoaderParms(_MSG_INVALID_PROPERTYOID_KEY,
406 humberto 1.15 							   _MSG_INVALID_PROPERTYOID));
407 kumpf    1.3          } 
408               
409 kumpf    1.12 	if (String::equalNoCase(vbTypes[i], "OctetString"))
410               	{
411                   	     OctetString*    value;
412               
413                            value = CloneOctetString(MakeOctetStringFromText(_vbValue));
414                            if (value == NULL)
415                            {
416 humberto 1.14 	       
417               	       // l10n
418               
419               	       // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
420               	       //   _MSG_INVALID_PROPERTYVALUE);
421               
422                      	         throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
423               					       MessageLoaderParms(_MSG_INVALID_PROPERTYVALUE_KEY,
424 humberto 1.15 								  _MSG_INVALID_PROPERTYVALUE));
425 kumpf    1.12              }
426               
427                            if ((vb = MakeVarBindWithValue(object, 
428               				  	(OID *) NULL, 
429               					OCTET_PRIM_TYPE, 
430               					value)) == NULL)
431                           {
432 humberto 1.14 
433               	      // l10n
434               
435               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
436               	      //    _MSG_MAKE_VARBIND_FAILED_FOR_OCTET_PRIM_TYPE);
437               
438               	      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
439 humberto 1.15 					    MessageLoaderParms(_MSG_MAKE_VARBIND_FAILED_FOR_OCTET_PRIM_TYPE_KEY,
440               							       _MSG_MAKE_VARBIND_FAILED_FOR_OCTET_PRIM_TYPE));
441 kumpf    1.12             }
442                   	}
443               	else if (String::equalNoCase(vbTypes[i], "OID"))
444               	{
445                           void* value = MakeOIDFromDot(_vbValue);
446                           if (value == NULL)
447 kumpf    1.4              {
448 humberto 1.14 	      // l10n
449               
450               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
451               	      //    _MSG_INVALID_PROPERTYVALUE);
452               
453               	      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
454               					    MessageLoaderParms(_MSG_INVALID_PROPERTYVALUE_KEY,
455 humberto 1.15 							       _MSG_INVALID_PROPERTYVALUE));
456 humberto 1.14 							       
457 kumpf    1.4              }
458 kumpf    1.12 
459                           if ((vb = MakeVarBindWithValue(object, 
460               				  	(OID *) NULL, 
461               					OBJECT_ID_TYPE, 
462               					value)) == NULL)
463 kumpf    1.3              {
464 humberto 1.14 
465               	      // l10n
466               
467               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
468               	      //    _MSG_MAKE_VARBIND_FAILED_FOR_OBJECT_ID_TYPE);
469               
470               	      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
471 humberto 1.15 					    MessageLoaderParms(_MSG_MAKE_VARBIND_FAILED_FOR_OBJECT_ID_TYPE_KEY,
472               							       _MSG_MAKE_VARBIND_FAILED_FOR_OBJECT_ID_TYPE));
473 kumpf    1.3              }
474 kumpf    1.12 	}
475               	else
476               	{
477                           int vbvalue = atoi(_vbValue);
478 kumpf    1.6              void* value = &vbvalue;
479 kumpf    1.3  
480 kumpf    1.12             if (value == NULL)
481 kumpf    1.4              {
482 humberto 1.14 
483               	      // l10n
484               
485               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
486               	      //    _MSG_INVALID_PROPERTYVALUE);
487               
488               	      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
489               					    MessageLoaderParms(_MSG_INVALID_PROPERTYVALUE_KEY,
490 humberto 1.15 							       _MSG_INVALID_PROPERTYVALUE));
491 kumpf    1.4              }
492 kumpf    1.12 
493                           if ((vb = MakeVarBindWithValue(object, 
494               				  	(OID *) NULL, 
495               					INTEGER_TYPE, 
496               					value)) == NULL)
497 mike     1.2              {
498 humberto 1.14 
499               	      // l10n
500               
501               	      // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
502               	      //    _MSG_MAKE_VARBIND_FAILED_FOR_INTEGER_TYPE);
503               
504               	      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
505 humberto 1.15 					    MessageLoaderParms(_MSG_MAKE_VARBIND_FAILED_FOR_INTEGER_TYPE_KEY,
506               							       _MSG_MAKE_VARBIND_FAILED_FOR_INTEGER_TYPE));
507 mike     1.2              }
508 kumpf    1.12 	}
509               
510 kumpf    1.4          if (i == 0)
511                       {
512 kumpf    1.12             vbhead = vb;
513                           vblast = vb;
514 kumpf    1.4          }
515                       else
516                       {
517 kumpf    1.12             vblast->next_var = vb;
518                           vblast = vblast->next_var;
519 kumpf    1.4          }
520               
521 kumpf    1.3      }
522 kumpf    1.5  
523 kumpf    1.12     vblast->next_var = NULL;
524 kumpf    1.3  
525 kumpf    1.12     // Now send the trap
526                   switch (snmpVersion)
527 kumpf    1.3      {
528 kumpf    1.12 	case _SNMPv1_TRAP:
529               	{
530                           SendNotificationToDestSMIv1Params(
531               	    1,					// notifyType - TRAP
532 kumpf    1.5              genTrap,				// genTrap
533                           specTrap,				// specTrap
534 kumpf    1.3              enterpriseOid,			// enterprise
535                           agent_addr,				// agent_addr
536 kumpf    1.12             vbhead,				// vb
537 kumpf    1.3              NULL,				// contextName
538                           1,					// retryCount
539                           1,					// timeout
540 kumpf    1.5              community_name,			// securityName,
541 kumpf    1.3              SR_SECURITY_LEVEL_NOAUTH,		// securityLevel
542                           SR_SECURITY_MODEL_V1,		// securityModel
543                           &global_ti,				// Transport Info
544 kumpf    1.12             0);          			// cfg_chk
545               	    break;
546               	}
547               	case _SNMPv2C_TRAP:
548               	{
549                           SendNotificationToDestSMIv2Params(
550               	    (SR_INT32)SNMPv2_TRAP_TYPE,		// notifyType - NOTIFICATION
551 kumpf    1.3              sendtrapOid,			// snmpTrapOID
552                           agent_addr,				// agent_addr
553 kumpf    1.12             vbhead,				// vb
554 kumpf    1.3              NULL,				// contextName
555                           1,					// retryCount
556                           100,				// timeout
557 kumpf    1.5              community_name,			// securityName or community
558 kumpf    1.3              SR_SECURITY_LEVEL_NOAUTH,		// securityLevel
559 kumpf    1.12             SR_SECURITY_MODEL_V2C,		// securityModel
560 kumpf    1.3              &global_ti,				// TransportInfo
561                           0);					// cfg_chk
562 kumpf    1.12 	    break;
563               	}
564               	default:
565               	{
566 humberto 1.14 	  // l10n
567               
568               	  // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
569               	  // _MSG_VERSION_NOT_SUPPORTED);
570               
571               	  throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED,	  
572               					MessageLoaderParms(_MSG_VERSION_NOT_SUPPORTED_KEY,
573 humberto 1.15 							   _MSG_VERSION_NOT_SUPPORTED));
574 humberto 1.14 
575               	  break;
576 kumpf    1.12 	}
577                   }
578               
579                   // Free OID built by calls MakeOIDFromDot()
580                   FreeOID(sendtrapOid);
581                   FreeOID(enterpriseOid);
582                   FreeOID(object);
583               
584                   // Free the data structures allocated and built by calls
585                   // MakeOctetString() and MakeOctetStringFrom Text()
586                   FreeOctetString(community_name);
587                   FreeOctetString(agent_addr);
588               
589                   // Free the VarBind data structures allocated and built 
590                   // by calls MakeVarBindWithValue()
591                   FreeVarBindList(vbhead);
592                   FreeVarBindList(vb);
593                   FreeVarBindList(vblast);
594               }
595               
596               // get the IP address of a host
597 kumpf    1.12 char * snmpDeliverTrap_emanate::_getIPAddress(const CString& hostName)
598               {
599                   struct hostent *targetHostInfo;
600                   struct in_addr in;
601               
602 keith.petley 1.13 #ifdef PEGASUS_OS_SOLARIS
603                   #define HOSTENT_BUFF_SIZE	8192
604                       char			buf[HOSTENT_BUFF_SIZE];
605                       struct hostent		h_result;
606                       int				h_errorp;
607                       targetHostInfo=gethostbyname_r(hostName, &h_result, buff,
608                   					HOSTENT_BUFF_SIZE, &h_errorp);
609                   #else
610 kumpf        1.12     targetHostInfo = gethostbyname(hostName);
611 keith.petley 1.13 #endif
612 kumpf        1.12 
613                       if (targetHostInfo == NULL)
614                       {
615                   	return(NULL);
616                       }
617                   	    
618                       char ** networkAddr;
619                       networkAddr = targetHostInfo->h_addr_list;
620                       (void)memcpy(&in.s_addr, *networkAddr, sizeof(in.s_addr));
621                       char * ipAddr = inet_ntoa(in);
622                       return(ipAddr);
623                   }
624                   
625                   // check the value of each part of an IP address which should be 
626                   // between 0 and 255
627                   Boolean snmpDeliverTrap_emanate::_isValidOctet(const Uint32& octetValue)
628                   {
629                       if (octetValue > 0 && octetValue < 255)
630                       {
631                   	return true;
632 kumpf        1.3      }
633                       else
634                       {
635 kumpf        1.12 	return false;
636 mike         1.2      }
637                   }
638                   
639                   PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2