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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2