version 1.7, 2002/04/23 16:41:56
|
version 1.8, 2002/04/25 16:27:25
|
|
|
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/System.h> | #include <Pegasus/Common/System.h> |
|
#include <Pegasus/Common/Destroyer.h> |
#include <fcntl.h> | #include <fcntl.h> |
#include <unistd.h> | #include <unistd.h> |
#include <ctype.h> | #include <ctype.h> |
|
|
initialize(); | initialize(); |
| |
// TRAP OID: getting trapOid | // TRAP OID: getting trapOid |
char* _trapOid = trapOid.allocateCString(); |
ArrayDestroyer<char> _trapOid(trapOid.allocateCString()); |
_trapOid[strlen(_trapOid)-1] = '\0'; |
_trapOid.getPointer()[strlen(_trapOid.getPointer())-1] = '\0'; |
OID *sendtrapOid = MakeOIDFromDot(_trapOid); |
OID *sendtrapOid = MakeOIDFromDot(_trapOid.getPointer()); |
| |
// Destination : converting destination into Transport | // Destination : converting destination into Transport |
char* trap_dest = destination.allocateCString(); |
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); |
global_ti.t_ipAddr = inet_addr(trap_dest.getPointer()); |
global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort()); | global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort()); |
delete [] trap_dest; |
|
| |
// Community Name | // Community Name |
char* _community = community.allocateCString(); |
ArrayDestroyer<char> _community(community.allocateCString()); |
OctetString* community_name = MakeOctetStringFromText(_community); |
OctetString* community_name = MakeOctetStringFromText( |
delete [] _community; |
_community.getPointer()); |
| |
// getting IP address of the host | // getting IP address of the host |
char* hostname = System::getHostName().allocateCString(); |
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); |
hp=gethostbyname(hostname.getPointer()); |
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); |
delete [] hostname; |
|
| |
// formatting agent(host) address into OctetString format | // formatting agent(host) address into OctetString format |
OctetString* agent_addr; | OctetString* agent_addr; |
|
|
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]; |
| |
char* gtrap = ent.allocateCString(); |
ArrayDestroyer<char> gtrap(ent.allocateCString()); |
genTrap = atoi(gtrap) - 1; |
genTrap = atoi(gtrap.getPointer()) - 1; |
enterpriseOid = sendtrapOid; | enterpriseOid = sendtrapOid; |
delete [] gtrap; |
|
} | } |
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]; |
char* strap = oids[oids.size()-1].allocateCString(); |
ArrayDestroyer<char> strap(oids[oids.size()-1].allocateCString()); |
specTrap = atoi(strap); |
specTrap = atoi(strap.getPointer()); |
delete [] strap; |
|
| |
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]; |
| |
char* _ent = ent.allocateCString(); |
ArrayDestroyer<char> _ent(ent.allocateCString()); |
enterpriseOid = MakeOIDFromDot(_ent); |
enterpriseOid = MakeOIDFromDot(_ent.getPointer()); |
delete [] _ent; |
|
} | } |
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]; |
| |
char* _ent = ent.allocateCString(); |
ArrayDestroyer<char> _ent(ent.allocateCString()); |
enterpriseOid = MakeOIDFromDot(_ent); |
enterpriseOid = MakeOIDFromDot(_ent.getPointer()); |
delete [] _ent; |
|
} | } |
} | } |
| |
char* _vbOid; |
|
char* _vbValue; |
|
|
|
for(Uint32 i = 0; i < vbOids.size(); i++) | for(Uint32 i = 0; i < vbOids.size(); i++) |
{ | { |
_vbOid = vbOids[i].allocateCString(); |
ArrayDestroyer<char> _vbOid(vbOids[i].allocateCString()); |
_vbValue = vbValues[i].allocateCString(); |
ArrayDestroyer<char> _vbValue(vbValues[i].allocateCString()); |
| |
if ((object = MakeOIDFromDot(_vbOid)) == NULL) |
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)); |
newValue = CloneOctetString(MakeOctetStringFromText(_vbValue.getPointer())); |
if (newValue == NULL) | if (newValue == NULL) |
{ | { |
cout << "Invalid Value provided : " << vbValues[i] << endl; | cout << "Invalid Value provided : " << vbValues[i] << endl; |
|
|
} | } |
else | else |
{ | { |
int vbvalue = atoi(_vbValue); |
int vbvalue = atoi(_vbValue.getPointer()); |
void* value = &vbvalue; | void* value = &vbvalue; |
| |
if (newValue == NULL) | if (newValue == NULL) |
|
|
FreeOID(object); | FreeOID(object); |
} | } |
| |
delete [] _vbValue; |
|
delete [] _vbOid; |
|
|
|
vb3->next_var = NULL; | vb3->next_var = NULL; |
| |
// Now sending the trap | // Now sending the trap |
|
|
else | else |
{ | { |
cout << "Trap type not supported : " << trapType << endl; | cout << "Trap type not supported : " << trapType << endl; |
delete [] _trapOid; |
|
exit(2); | exit(2); |
} | } |
| |
FreeVarBindList(vb); | FreeVarBindList(vb); |
FreeVarBindList(vb2); | FreeVarBindList(vb2); |
FreeVarBindList(vb3); | FreeVarBindList(vb3); |
|
|
delete [] _trapOid; |
|
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |