📄 address.h
字号:
* @return the friendly name or a zero length string (no null pointer) */ char *friendly_name(int &status); /** * Get a printable ASCII value of the address. * * @return String containing the numerical address */ virtual const char *get_printable() const { if (addr_changed) format_output(); return output_buffer; }; /** * Overloaded operator for streaming output. * * @return String containing the numerical address */ virtual operator const char *() const { if (addr_changed) format_output(); return output_buffer; }; /** * Logically AND the address with the param. * * @param ipaddr - address to use as mask */ void mask(const IpAddress &ipaddr); /** * Get the count of matching bits from the left. * * @param match_ip - address to match with */ int get_match_bits(const IpAddress match_ip) const; /** * Get the length of the binary address (accessible through operator[]). */ virtual int get_length() const { return (ip_version == version_ipv4) ? IPLEN : IP6LEN; }; /** * Return the type of the address. * @see Address::addr_type * @return Always Address:type_ip */ virtual addr_type get_type() const { return type_ip; }; /** * Return the syntax. * * @return This method always returns sNMP_SYNTAX_IPADDR. */ virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_IPADDR; }; /** * Return the space needed for serialization. */ virtual int get_asn1_length() const { return (ip_version == version_ipv4) ? (IPLEN + 2) : (IP6LEN + 2); }; /** * Return the IP version of the address. * * @return one of Address::version_type */ virtual version_type get_ip_version() const { return ip_version; }; /** * Map a IPv4 address to a IPv6 address. * * @return - TRUE if no error occured. */ virtual int map_to_ipv6(); /** * Reset the object. */ void clear(); protected: SNMP_PP_MUTABLE char output_buffer[OUTBUFF]; // output buffer // friendly name storage char iv_friendly_name[MAX_FRIENDLY_NAME]; int iv_friendly_name_status; // redefined parse address // specific to IP addresses virtual bool parse_address(const char *inaddr); // redefined format output // specific to IP addresses virtual void format_output() const; // parse a dotted string int parse_dotted_ipstring(const char *inaddr); // parse a coloned string int parse_coloned_ipstring(const char *inaddr); // using the currently defined address, do a DNS // and try to fill up the name int addr_to_friendly(); // support both ipv4 and ipv6 addresses version_type ip_version;};//------------------------------------------------------------------------//---------[ UDP Address Class ]------------------------------------------//------------------------------------------------------------------------class DLLOPT UdpAddress : public IpAddress{ public: /** * Construct an empty invalid UDP address. */ UdpAddress(); /** * Construct an UDP address from a string. * * The following formats can be used additional to those recognized by * IpAdress: * - Port added to IPv4 address with '/' or ':' * ("192.168.17.1:161", "192.168.17.1/161", "printsrv/161") * - Port added to IPv6 address with '/' or using '[...]:' * ("::1/162", "[::1]/162", "[::1]:162") * * @param inaddr - Hostname or IP address */ UdpAddress(const char *inaddr); /** * Construct an UDP address from another UDP address. * * @param udpaddr - address to copy */ UdpAddress(const UdpAddress &udpaddr); /** * Construct an UDP address from a GenAddress. * * @param genaddr - address to copy */ UdpAddress(const GenAddress &genaddr); /** * Construct an UDP address from a IP address. * The port will be set to 0. * * @param ipaddr - address to copy */ UdpAddress(const IpAddress &ipaddr); /** * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden). */ ~UdpAddress() {}; /** * Map other SnmpSyntax objects to UdpAddress. */ SnmpSyntax& operator=(const SnmpSyntax &val); /** * Overloaded assignment operator for UdpAddress. */ UdpAddress& operator=(const UdpAddress &udpaddr); /** * Overloaded assignment operator for IpAddress. */ UdpAddress& operator=(const IpAddress &ipaddr); /** * Overloaded assignment operator for strings. */ UdpAddress& operator=(const char *inaddr); /** * Return the syntax. * * @return This method always returns sNMP_SYNTAX_OCTETS. */ SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; }; /** * Return the space needed for serialization. */ virtual int get_asn1_length() const { return (ip_version == version_ipv4) ? (UDPIPLEN + 2) : (UDPIP6LEN + 2);}; /** * Clone this object. * * @return Pointer to the newly created object (allocated through new). */ SnmpSyntax *clone() const { return (SnmpSyntax *) new UdpAddress(*this); }; /** * Get a printable ASCII value of the address. * * @return String containing the numerical address */ virtual const char *get_printable() const { if (addr_changed) format_output(); return output_buffer; }; /** * Overloaded operator for streaming output. * * @return String containing the numerical address */ virtual operator const char *() const { if (addr_changed) format_output(); return output_buffer; }; /** * Set the port number. * * @note If the object is not valid(), the port may not be set. */ void set_port(const unsigned short p); /** * Get the port number. * * @return The port number, or 0 is the object is not valid. */ unsigned short get_port() const; /** * Get the length of the binary address (accessible through operator[]). */ virtual int get_length() const { return (ip_version == version_ipv4) ? UDPIPLEN : UDPIP6LEN; }; /** * Return the type of the address. * @see Address::addr_type * @return Always Address:type_udp */ virtual addr_type get_type() const { return type_udp; }; /** * Map a IPv4 UDP address to a IPv6 UDP address. * * @return - TRUE if no error occured. */ virtual int map_to_ipv6(); /** * Reset the object. */ void clear() { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); }; protected: SNMP_PP_MUTABLE char output_buffer[OUTBUFF]; // output buffer char sep; // separator // redefined parse address // specific to IP addresses virtual bool parse_address(const char *inaddr); // redefined format output // specific to IP addresses virtual void format_output() const;};#ifdef _MAC_ADDRESS//-------------------------------------------------------------------------//---------[ 802.3 MAC Address Class ]-------------------------------------//-------------------------------------------------------------------------class DLLOPT MacAddress : public Address {public: // constructor, no arguments MacAddress(); // constructor with a string argument MacAddress(const char *inaddr); // constructor with another MAC object MacAddress(const MacAddress &macaddr); // construct a MacAddress with a GenAddress MacAddress(const GenAddress &genaddr); // destructor ~MacAddress() {}; /** * Return the syntax. * * @return This method always returns sNMP_SYNTAX_OCTETS. */ SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; }; /** * Return the space needed for serialization. */ virtual int get_asn1_length() const { return MACLEN + 2; }; /** * Map other SnmpSyntax objects to MacAddress. */ SnmpSyntax& operator=(const SnmpSyntax &val); // assignment to another IpAddress object overloaded MacAddress& operator=(const MacAddress &macaddress); /** * Clone this object. * * @return Pointer to the newly created object (allocated through new). */ SnmpSyntax *clone() const { return (SnmpSyntax *) new MacAddress(*this); }; /** * Get a printable ASCII value of the address. * * @return String containing the numerical address */ virtual const char *get_printable() const { if (addr_changed) format_output(); return output_buffer; }; /** * Overloaded operator for streaming output. * * @return String containing the numerical address */ virtual operator const char *() const { if (addr_changed) format_output(); return output_buffer; }; /** * Get the length of the binary address (accessible through operator[]). */ virtual int get_length() const { return MACLEN; }; /** * Return the type of the address. * @see Address::addr_type * @return Always Address:type_mac */ virtual addr_type get_type() const { return type_mac; }; // return a hash key unsigned int hashFunction() const; /** * Reset the object. */ void clear() { Address::clear(); memset(output_buffer, 0, sizeof(output_buffer)); }; protected: SNMP_PP_MUTABLE char output_buffer[OUTBUFF]; // output buffer // redefined parse address for macs virtual bool parse_address(const char *inaddr); // redefined format output for MACs virtual void format_output() const;};#endif // _MAC_ADDRESS#ifdef _IPX_ADDRESS//------------------------------------------------------------------------//---------[ IPX Address Class ]------------------------------------------//------------------------------------------------------------------------class DLLOPT IpxAddress : public Address {public: // constructor no args IpxAddress(); // constructor with a string arg IpxAddress(const char *inaddr); // constructor with another ipx object IpxAddress(const IpxAddress &ipxaddr); // construct with a GenAddress
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -