summaryrefslogtreecommitdiff
path: root/ASNMP
diff options
context:
space:
mode:
authormrm <mrm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-07-16 01:26:47 +0000
committermrm <mrm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-07-16 01:26:47 +0000
commitbc5a2116887cd31c5e69d37485a0306597f6f677 (patch)
tree0bacee698f6881b14adc2305194b667e6a6ece1b /ASNMP
parentbacc583b6248b8ecea228d2028ea5addc9c4ef19 (diff)
downloadATCD-bc5a2116887cd31c5e69d37485a0306597f6f677.tar.gz
Hien Nguyen's fixes for purify errors in trap generation
Diffstat (limited to 'ASNMP')
-rw-r--r--ASNMP/asnmp/asn1.cpp18
-rw-r--r--ASNMP/asnmp/wpdu.cpp55
2 files changed, 44 insertions, 29 deletions
diff --git a/ASNMP/asnmp/asn1.cpp b/ASNMP/asnmp/asn1.cpp
index 46f821784d6..fa09b9a0251 100644
--- a/ASNMP/asnmp/asn1.cpp
+++ b/ASNMP/asnmp/asn1.cpp
@@ -1,8 +1,6 @@
-// $Id$
-
/* -*-C++-*- */
// ============================================================================
-//
+// $Id$
// = LIBRARY
// asnmp
//
@@ -1035,7 +1033,7 @@ void cmu_snmp::add_var(struct snmp_pdu *pdu,
vars->next_variable = NULL;
// hook in the Oid portion
- ACE_NEW(vars->name, oid[(name_length * sizeof(oid))]);
+ ACE_NEW(vars->name, oid[(name_length)]);
// fixed
ACE_OS::memcpy((char *)vars->name,(char *)name, name_length * sizeof(oid));
@@ -1355,8 +1353,10 @@ int cmu_snmp::build( struct snmp_pdu *pdu, u_char *packet,
// agent-addr
cp = asn1::build_string(cp,
- &length,
- (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR),
+ &length,
+ // HDN Fixed to use correct tag
+ (u_char)SMI_IPADDRESS,
+ //(u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR),
(u_char *)&pdu->agent_addr.sin_addr.s_addr,
sizeof(pdu->agent_addr.sin_addr.s_addr));
if (cp == NULL)
@@ -1383,7 +1383,9 @@ int cmu_snmp::build( struct snmp_pdu *pdu, u_char *packet,
// timestamp
cp = asn1::build_int(cp,
&length,
- (u_char )(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
+ // HDN Fixed to use correct tag
+ (u_char)SMI_TIMETICKS,
+ //(u_char )(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
(long *)&pdu->time,
sizeof(pdu->time));
if (cp == NULL)
@@ -1722,5 +1724,3 @@ int cmu_snmp::parse( struct snmp_pdu *pdu,
return 0;
}
-
-
diff --git a/ASNMP/asnmp/wpdu.cpp b/ASNMP/asnmp/wpdu.cpp
index 55d672c7c30..80538c11f7e 100644
--- a/ASNMP/asnmp/wpdu.cpp
+++ b/ASNMP/asnmp/wpdu.cpp
@@ -1,8 +1,6 @@
-// $Id$
-
/* -*-C++-*- */
// ============================================================================
-//
+// $Id$
// = LIBRARY
// asnmp
//
@@ -20,6 +18,7 @@
// ============================================================================
#include "asnmp/wpdu.h"
+#include <ace/Log_Msg.h>
#define DEFINE_TRAP_CONSTANTS_
#include "asnmp/enttraps.h"
@@ -72,6 +71,7 @@ wpdu::wpdu(const Pdu& pdu, const UdpTarget& target):
break;
case sNMP_PDU_V1TRAP:
+ target.get_read_community(comm_str);
if (set_trap_info(raw_pdu, pdu)) // will free raw_pdu
return;
break;
@@ -136,33 +136,50 @@ int wpdu::set_trap_info(snmp_pdu *raw_pdu, const Pdu& pdu) const
else if ( trapid == egpNeighborLoss)
raw_pdu->trap_type = V1_EGP_NEIGHBOR_LOSS; // egp neighbor loss
else {
- raw_pdu->trap_type = V1_ENT_SPECIFIC; // enterprise specific
+ raw_pdu->trap_type = V1_ENT_SPECIFIC; // enterprise specific
// last oid subid is the specific value
// if 2nd to last subid is "0", remove it
// enterprise is always the notify oid prefix
- raw_pdu->specific_type = (int) trapid[(int) (trapid.length() - 1)];
- trapid.trim(1);
- if ( trapid[(int)(trapid.length() - 1)] == 0 )
+ raw_pdu->specific_type = (int) trapid[(int) (trapid.length() - 1)];
+ trapid.trim(1);
+ if ( trapid[(int)(trapid.length() - 1)] == 0 )
trapid.trim(1);
- enterprise = trapid;
+ enterprise = trapid;
}
- if ( raw_pdu->trap_type != 6) // TODO: fix these magic numbers with defines
- pdu.get_notify_enterprise( enterprise);
+ if ( raw_pdu->trap_type != V1_ENT_SPECIFIC)
+ pdu.get_notify_enterprise( enterprise);
if ( enterprise.length() > 0) {
- // note!!
- // these are hooks into an SNMP++ oid
- // and therefor the raw_pdu enterprise
- // should not free them. null them out!!
- SmiLPOID rawOid;
- rawOid = enterprise.oidval();
- raw_pdu->enterprise = rawOid->ptr;
- raw_pdu->enterprise_length = (int) rawOid->len;
+ // note!! To the contrary, enterprise OID val is
+ // copied here and raw_pdu->enterprise is freed in free_pdu
+ // as it should be (HDN)
+ // these are hooks into an SNMP++ oid
+ // and therefor the raw_pdu enterprise
+ // should not free them. null them out!!
+ SmiLPOID rawOid;
+ rawOid = enterprise.oidval();
+ // HDN - enterprise is a local object, cannot simply assign pointer
+ //raw_pdu->enterprise = rawOid->ptr;
+ raw_pdu->enterprise_length = (int) rawOid->len;
+ ACE_NEW_RETURN(raw_pdu->enterprise,
+ oid[raw_pdu->enterprise_length],-1);
+ ACE_OS::memcpy((char *)raw_pdu->enterprise,(char *)rawOid->ptr,
+ raw_pdu->enterprise_length * sizeof(oid));
}
TimeTicks timestamp;
pdu.get_notify_timestamp( timestamp);
raw_pdu->time = ( unsigned long) timestamp;
+
+ // HDN - set agent addr using the local hostname if possible
+ char localHostName[MAXHOSTNAMELEN];
+ if (ACE_OS::hostname(localHostName, sizeof(localHostName)) != -1) {
+ struct hostent* hostInfo;
+ if (hostInfo = ACE_OS::gethostbyname(localHostName)) {
+ ACE_OS::memcpy(&(raw_pdu->agent_addr.sin_addr), hostInfo->h_addr, hostInfo->h_length);
+ }
+ }
+
return 0;
}
@@ -497,5 +514,3 @@ const unsigned char *wpdu::get_community() const
return community_name;
}
-
-