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

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