summaryrefslogtreecommitdiff
path: root/ASNMP
diff options
context:
space:
mode:
authorlevine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-07-14 13:32:36 +0000
committerlevine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-07-14 13:32:36 +0000
commit6377bd53ffdc519e675edf7908a37658844ee75f (patch)
treef61fe0365b2ebf0351cfa90ba20fecb39814a434 /ASNMP
parent87ef0701eae02da285c119724516a3c90eeb2efe (diff)
downloadATCD-6377bd53ffdc519e675edf7908a37658844ee75f.tar.gz
ChangeLogTag: Wed Jul 14 08:26:42 1999 Brian Raven <brianr@mrpotatohead.liffe.com>
Diffstat (limited to 'ASNMP')
-rw-r--r--ASNMP/ChangeLog21
-rw-r--r--ASNMP/asnmp/snmp.cpp34
-rw-r--r--ASNMP/asnmp/snmp.h9
-rw-r--r--ASNMP/asnmp/wpdu.cpp13
4 files changed, 71 insertions, 6 deletions
diff --git a/ASNMP/ChangeLog b/ASNMP/ChangeLog
index 046975f76fc..399fd6e16e4 100644
--- a/ASNMP/ChangeLog
+++ b/ASNMP/ChangeLog
@@ -1,3 +1,24 @@
+Wed Jul 14 08:26:42 1999 Brian Raven <brianr@mrpotatohead.liffe.com>
+
+ * asnmp/snmp.{h,cpp},wpdu.cpp:
+ SYNOPSIS:
+ 1) The agent IP address in traps originating from logical
+ domains on an Enterprise 10000 is that of the physical domain.
+
+ 2) The code that gets the IP address uses gethostbyname
+ which is unsafe in a MT environment (according to the man page).
+
+ DESCRIPTION:
+ 1) The problem seems to be caused by hostname only returning
+ the physical domain name.
+
+ SAMPLE FIX/WORKAROUND:
+ 1) To get around this problem I added the capability to
+ override the local host name.
+
+ 2) I would suggest using the GenAddress class to obtain the
+ IP address.
+
Tue Jun 22 13:34:54 1999 David L. Levine <levine@cs.wustl.edu>
* agent/Makefile: replaced rm -f with $(RM).
diff --git a/ASNMP/asnmp/snmp.cpp b/ASNMP/asnmp/snmp.cpp
index f14d07bcccb..f6ad69fb25a 100644
--- a/ASNMP/asnmp/snmp.cpp
+++ b/ASNMP/asnmp/snmp.cpp
@@ -54,6 +54,8 @@ const authenticationFailureOid authenticationFailure;
const egpNeighborLossOid egpNeighborLoss;
const snmpTrapEnterpriseOid snmpTrapEnterprise;
+char Snmp::host_name_[MAXHOSTNAMELEN] = "";
+
Snmp::Snmp(unsigned short port): result_(0), construct_status_(SNMP_CLASS_ERROR), last_transaction_status_(0)
{
ACE_TRACE("Snmp::Snmp");
@@ -246,4 +248,36 @@ int Snmp::trap( Pdu &pdu, UdpTarget &target)
return -1;
}
+// Allow host name to be overriden. Supplying a null pointer or zero
+// length string removes the override.
+void Snmp::override_host_name(const char* name)
+{
+ if (name)
+ {
+ ACE_OS::strncpy(host_name_, name, MAXHOSTNAMELEN);
+ host_name_[MAXHOSTNAMELEN-1] = 0;
+ }
+ else {
+ host_name_[0] = 0;
+ }
+}
+
+// Returns the current host name in the supplied string.
+void Snmp::get_host_name(char* name, int len)
+{
+ if (name)
+ {
+ if (ACE_OS::strlen(host_name_) > 0)
+ {
+ ACE_OS::strncpy(name, host_name_, len);
+ name[len-1] = 0;
+ }
+ else
+ {
+ if (ACE_OS::hostname(name, len-1) == -1)
+ name[0] = 0;
+ }
+ }
+}
+
Snmp_Result::~Snmp_Result() {}
diff --git a/ASNMP/asnmp/snmp.h b/ASNMP/asnmp/snmp.h
index 65a7700721b..d57a9711324 100644
--- a/ASNMP/asnmp/snmp.h
+++ b/ASNMP/asnmp/snmp.h
@@ -102,6 +102,12 @@ class ACE_Export Snmp : public transaction_result
void result(transaction * t, int rc);
// for async transaction results
+ static void override_host_name(const char* name);
+ // allow the host name to be overriden
+
+ static void get_host_name(char* name, int len);
+ // returns the overriden host name
+
protected:
void check_default_port(UdpTarget& target,unsigned short port=DEF_AGENT_PORT);
int run_transaction(Pdu& pdu, UdpTarget& target);
@@ -121,7 +127,8 @@ class ACE_Export Snmp : public transaction_result
unsigned req_id_;
// transaction request id
+
+ static char host_name_[MAXHOSTNAMELEN];
};
#endif //SNMP_CLS_
-
diff --git a/ASNMP/asnmp/wpdu.cpp b/ASNMP/asnmp/wpdu.cpp
index 973d8fe430f..43c38d9a5e6 100644
--- a/ASNMP/asnmp/wpdu.cpp
+++ b/ASNMP/asnmp/wpdu.cpp
@@ -175,11 +175,14 @@ int wpdu::set_trap_info(snmp_pdu *raw_pdu, const Pdu& pdu) const
// 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);
- }
+ Snmp::get_host_name(localHostName, MAXHOSTNAMELEN);
+ if (ACE_OS::strlen(localHostName) > 0) {
+ GenAddress addr(localHostName);
+ OctetStr octet;
+ addr.to_octet(octet);
+ ACE_OS::memcpy(&(raw_pdu->agent_addr.sin_addr),
+ octet.data(),
+ octet.length());
}
return 0;