version 1.8, 2002/04/25 16:27:25
|
version 1.11, 2002/08/29 00:27:52
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001 BMC Software, Hewlett Packard, IBM, The Open Group, |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
// Tivoli Systems |
// The Open Group, Tivoli Systems |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
#include "snmpDeliverTrap_emanate.h" | #include "snmpDeliverTrap_emanate.h" |
#include "prnt_lib.h" | #include "prnt_lib.h" |
| |
PEGASUS_NAMESPACE_BEGIN |
|
|
|
PEGASUS_USING_STD; |
|
|
|
static char *sr_filename = __FILE__; | static char *sr_filename = __FILE__; |
| |
IPCFunctionP IPCfp; /* IPC functions pointer */ | IPCFunctionP IPCfp; /* IPC functions pointer */ |
|
|
return 1; | return 1; |
} | } |
| |
|
PEGASUS_NAMESPACE_BEGIN |
|
|
|
PEGASUS_USING_STD; |
|
|
snmpDeliverTrap_emanate::snmpDeliverTrap_emanate() | snmpDeliverTrap_emanate::snmpDeliverTrap_emanate() |
{ | { |
| |
|
|
initialize(); | initialize(); |
| |
// TRAP OID: getting trapOid | // TRAP OID: getting trapOid |
ArrayDestroyer<char> _trapOid(trapOid.allocateCString()); |
CString _trapOid = trapOid.getCString(); |
_trapOid.getPointer()[strlen(_trapOid.getPointer())-1] = '\0'; |
_trapOid[strlen(_trapOid)-1] = '\0'; |
OID *sendtrapOid = MakeOIDFromDot(_trapOid.getPointer()); |
OID *sendtrapOid = MakeOIDFromDot(_trapOid); |
| |
// Destination : converting destination into Transport | // Destination : converting destination into Transport |
ArrayDestroyer<char> trap_dest(destination.allocateCString()); |
|
TransportInfo global_ti; | TransportInfo global_ti; |
global_ti.type = SR_IP_TRANSPORT; | global_ti.type = SR_IP_TRANSPORT; |
global_ti.t_ipAddr = inet_addr(trap_dest.getPointer()); |
global_ti.t_ipAddr = inet_addr(destination.getCString()); |
global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort()); | global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort()); |
| |
// Community Name | // Community Name |
ArrayDestroyer<char> _community(community.allocateCString()); |
|
OctetString* community_name = MakeOctetStringFromText( | OctetString* community_name = MakeOctetStringFromText( |
_community.getPointer()); |
community.getCString()); |
| |
// getting IP address of the host | // getting IP address of the host |
ArrayDestroyer<char> hostname(System::getHostName().allocateCString()); |
|
char **p; | char **p; |
struct hostent *hp; | struct hostent *hp; |
struct in_addr in; | struct in_addr in; |
hp=gethostbyname(hostname.getPointer()); |
hp=gethostbyname(System::getHostName().getCString()); |
p = hp->h_addr_list; | p = hp->h_addr_list; |
(void)memcpy(&in.s_addr, *p, sizeof(in.s_addr)); | (void)memcpy(&in.s_addr, *p, sizeof(in.s_addr)); |
char* IP_string = inet_ntoa(in); | char* IP_string = inet_ntoa(in); |
|
|
for (Uint8 i = 1; i < oids.size()-1; i++) | for (Uint8 i = 1; i < oids.size()-1; i++) |
ent = ent + "." + oids[i]; | ent = ent + "." + oids[i]; |
| |
ArrayDestroyer<char> gtrap(ent.allocateCString()); |
genTrap = atoi(ent.getCString()) - 1; |
genTrap = atoi(gtrap.getPointer()) - 1; |
|
enterpriseOid = sendtrapOid; | enterpriseOid = sendtrapOid; |
} | } |
else | else |
|
|
ent = oids[0]; | ent = oids[0]; |
for (Uint8 i = 1; i < oids.size()-1; i++) | for (Uint8 i = 1; i < oids.size()-1; i++) |
ent = ent + "." + oids[i]; | ent = ent + "." + oids[i]; |
ArrayDestroyer<char> strap(oids[oids.size()-1].allocateCString()); |
specTrap = atoi(oids[oids.size()-1].getCString()); |
specTrap = atoi(strap.getPointer()); |
|
| |
if (oids[oids.size()-2] == "0") | if (oids[oids.size()-2] == "0") |
{ | { |
|
|
for (Uint8 i = 1; i < oids.size()-2; i++) | for (Uint8 i = 1; i < oids.size()-2; i++) |
ent = ent + "." + oids[i]; | ent = ent + "." + oids[i]; |
| |
ArrayDestroyer<char> _ent(ent.allocateCString()); |
enterpriseOid = MakeOIDFromDot(ent.getCString()); |
enterpriseOid = MakeOIDFromDot(_ent.getPointer()); |
|
} | } |
else | else |
{ | { |
|
|
for (Uint8 i = 1; i < oids.size()-1; i++) | for (Uint8 i = 1; i < oids.size()-1; i++) |
ent = ent + "." + oids[i]; | ent = ent + "." + oids[i]; |
| |
ArrayDestroyer<char> _ent(ent.allocateCString()); |
enterpriseOid = MakeOIDFromDot(ent.getCString()); |
enterpriseOid = MakeOIDFromDot(_ent.getPointer()); |
|
} | } |
} | } |
| |
for(Uint32 i = 0; i < vbOids.size(); i++) | for(Uint32 i = 0; i < vbOids.size(); i++) |
{ | { |
ArrayDestroyer<char> _vbOid(vbOids[i].allocateCString()); |
if ((object = MakeOIDFromDot(vbOids[i].getCString())) == NULL) |
ArrayDestroyer<char> _vbValue(vbValues[i].allocateCString()); |
|
|
|
if ((object = MakeOIDFromDot(_vbOid.getPointer())) == NULL) |
|
{ | { |
cout << "Invalid OID received: " << vbOids[i] << endl; | cout << "Invalid OID received: " << vbOids[i] << endl; |
return; | return; |
|
|
| |
if (vbTypes[i] == String("OctetString")) | if (vbTypes[i] == String("OctetString")) |
{ | { |
newValue = CloneOctetString(MakeOctetStringFromText(_vbValue.getPointer())); |
newValue = CloneOctetString(MakeOctetStringFromText(vbValues[i].getCString())); |
if (newValue == NULL) | if (newValue == NULL) |
{ | { |
cout << "Invalid Value provided : " << vbValues[i] << endl; | cout << "Invalid Value provided : " << vbValues[i] << endl; |