1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_diameter_codec_basetypes_Address_hpp
10 #define anna_diameter_codec_basetypes_Address_hpp
14 #include <anna/diameter/codec/basetypes/OctetString.hpp>
16 #include <anna/config/defines.hpp>
30 * Diameter Address container
32 * Diameter address includes 2 bytes with ip version and 4/16 more for IPv4 and IPv6 respectively
35 * IPv6 ADDRESS FORMAT CONSIDERATIONS
37 * IPv6 addresses have two logical parts: a 64-bit network prefix, and a 64-bit host address part.
38 * The host address is often automatically generated from the interface MAC address.
39 * An IPv6 address is represented by 8 groups of 16-bit hexadecimal values separated by colons (:) shown as follows:
41 * A typical example of an IPv6 address is
43 * 2001:0db8:85a3:0000:0000:8a2e:0370:7334.
45 * The hexadecimal digits are case-insensitive.
47 * The 128-bit IPv6 address can be abbreviated with the following rules:
49 * * Rule one: Leading zeroes within a 16-bit value may be omitted. For example, the address fe80:0000:0000:0000:0202:b3ff:fe1e:8329
50 * may be written as fe80:0:0:0:202:b3ff:fe1e:8329
52 * * Rule two: A single occurrence of consecutive groups of zeroes within an address may be replaced by a double colon.
53 * For example, fe80:0:0:0:202:b3ff:fe1e:8329 becomes fe80::202:b3ff:fe1e:8329
56 * RULE ONE IS AUTOMATICALLY APPLIED BY sscanf and %X parsing
57 * RULE TWO IS NOT APPLIED OVER THIS CLASS METHODS
60 * In environments of dual-stack hosts that support both IPv4 and IPv6, an IPv4 address is expressed as an IPv6 address in an IPv6-mapped address.
61 * For example, the IPv4-mapped IPv6 address ::ffff:c000:280 is usually written as ::ffff:192.0.2.128, thus expressing clearly the original IPv4
62 * address that was mapped to IPv6.
64 * The address ::ffff:1.2.3.4 is IPv4-mapped, different than address ::1.2.3.4 which is IPV4-compatible.
67 class Address : OctetString {
69 iana_address_t a_address;
70 bool a_abbreviatePresentation; // specially for IPv6 address type
73 // Only for derived diameter type:
74 void updateBasic() throw(anna::RuntimeException);
76 void setPrintableString(const char * printableString) throw(anna::RuntimeException);
84 Address() : a_abbreviatePresentation(true) {};
87 * Presentation mode: abbreviate (i.e. two standard rules applied for IPv6) or expanded (i.e. groups of zeroes on IP address)
89 * @param abb Abbreviate mode boolean indicator
91 void setAbbreviatePresentation(bool abb) throw() { a_abbreviatePresentation = abb; };
95 // Class-specific ////////////////////////////////////////////////////////////////////////////////////
98 * Gets the IANA address
100 * @return IANA address
102 const iana_address_t& getIANAAddress() const throw() { return a_address; }
105 * Sets the IANA address
107 * @param address IANA address
109 void setIANAAddress(const iana_address_t& address) throw(anna::RuntimeException) { a_address = address; updateBasic(); }
111 //////////////////////////////////////////////////////////////////////////////////////////////////////
116 std::string getFormatName() const throw() { return "Address"; }
122 * Gets the natural/smart string representation for IANA address
123 * Launch exception when data is not printable: only IPv4 and IPv6 are printable-supported
125 * @return Natural/smart string representation for IANA address (only IPv4 and IPv6 are printable-supported)
127 std::string asPrintableString() throw(anna::RuntimeException);
130 std::string asString() throw(anna::RuntimeException) { return a_address.asString(); }
135 void decode(const char* buffer, const int size) throw(anna::RuntimeException);
138 // exports /////////////////////////////
139 using AvpData::getSize;
141 //using OctetString::asPrintableString;
142 using AvpData::asDataBlockString;
143 using OctetString::asString;
144 using AvpData::asHexString;
145 //using OctetString::decode;
146 using AvpData::fromPrintableString;
147 using AvpData::fromHexString;