diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-07-14 13:32:36 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-07-14 13:32:36 +0000 |
commit | d5301d5a589816c6ba377dff4f5cc16804d905b2 (patch) | |
tree | f61fe0365b2ebf0351cfa90ba20fecb39814a434 | |
parent | 3a22f22cbe1bc71fde2aba11223cf473d5bf2553 (diff) | |
download | ATCD-d5301d5a589816c6ba377dff4f5cc16804d905b2.tar.gz |
ChangeLogTag: Wed Jul 14 08:26:42 1999 Brian Raven <brianr@mrpotatohead.liffe.com>
-rw-r--r-- | ASNMP/ChangeLog | 21 | ||||
-rw-r--r-- | ASNMP/asnmp/snmp.cpp | 34 | ||||
-rw-r--r-- | ASNMP/asnmp/snmp.h | 9 | ||||
-rw-r--r-- | ASNMP/asnmp/wpdu.cpp | 13 |
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; |