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 | 6377bd53ffdc519e675edf7908a37658844ee75f (patch) | |
tree | f61fe0365b2ebf0351cfa90ba20fecb39814a434 /ASNMP/asnmp | |
parent | 87ef0701eae02da285c119724516a3c90eeb2efe (diff) | |
download | ATCD-6377bd53ffdc519e675edf7908a37658844ee75f.tar.gz |
ChangeLogTag: Wed Jul 14 08:26:42 1999 Brian Raven <brianr@mrpotatohead.liffe.com>
Diffstat (limited to 'ASNMP/asnmp')
-rw-r--r-- | ASNMP/asnmp/snmp.cpp | 34 | ||||
-rw-r--r-- | ASNMP/asnmp/snmp.h | 9 | ||||
-rw-r--r-- | ASNMP/asnmp/wpdu.cpp | 13 |
3 files changed, 50 insertions, 6 deletions
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; |