conexus logo

ipv6_address.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the conexus library.                             *
00006  *                                                                         *
00007  *   The conexus library is free software; you can redistribute it and/or  *
00008  *   modify it under the terms of the GNU General Public License           *
00009  *   version 3 as published by the Free Software Foundation.               *
00010  *                                                                         *
00011  *   The conexus library is distributed in the hope that it will be        *
00012  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
00013  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014  *   General Public License for more details.                              *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
00018  ***************************************************************************/
00019 #ifndef CONEXUS_IPV6ADDRESS_H
00020 #define CONEXUS_IPV6ADDRESS_H
00021 
00022 #include <string>
00023 
00024 #include <sys/socket.h>
00025 #include <netinet/in.h>
00026 #include <arpa/inet.h>
00027 
00028 #include <conexus/address.h>
00029 #include <conexus/ipaddress_interface.h>
00030 #include <conexus/except.h>
00031 
00032 namespace Conexus
00033   {
00034 
00035     namespace IPv4 {
00036       class Address;
00037     }
00038 
00045   namespace IPv6
00046     {
00047 
00049       typedef enum IPV4_EMBEDDED_TYPE { IPV4_COMPATIBLE, IPV4_MAPPED } IPV4_EMBEDDED_TYPE;
00050 
00052       struct in6_addr operator&( const struct in6_addr& first, const struct in6_addr& second );
00053 
00055       struct in6_addr operator|( const struct in6_addr& first, const struct in6_addr& second );
00056 
00058       struct in6_addr operator^( const struct in6_addr& first, const struct in6_addr& second );
00059 
00061       struct in6_addr operator~( const struct in6_addr& addr );
00062 
00064       struct in6_addr& operator&=( struct in6_addr& first, const struct in6_addr& second );
00065 
00067       struct in6_addr& operator|=( struct in6_addr& first, const struct in6_addr& second );
00068 
00070       struct in6_addr& operator^=( struct in6_addr& first, const struct in6_addr& second );
00071 
00073       bool operator==( const struct in6_addr&, const struct in6_addr& );
00074 
00076       bool operator<( const struct in6_addr&, const struct in6_addr& );
00077 
00079       bool operator!=( const struct in6_addr&, const struct in6_addr& );
00080 
00095       class Address: public Conexus::Address, public virtual IPAddressInterface
00096       {
00097       public:
00098 
00100         static const struct in6_addr LOOPBACK;
00101 
00103         static const struct in6_addr IPV4_COMPATIBLE_PREFIX;
00104 
00106         static const struct in6_addr IPV4_MAPPED_PREFIX;
00107 
00109         typedef ConexusPointer<Address> pointer;
00110 
00118         Address(const struct in6_addr& host = in6addr_any, uint16_t port = 0);
00119 
00120         Address(uint32_t host, uint16_t port=0);
00121 
00122         Address(const std::string& host, uint16_t port=0);
00123 
00125         Address(const struct sockaddr_in6& addr);
00126 
00128         Address(const struct sockaddr_storage& addr);
00129 
00131         Address(const IPv4::Address& ipv4addr, IPV4_EMBEDDED_TYPE ipv4type = IPV4_MAPPED);
00132 
00134         static pointer create(const struct in6_addr& host = in6addr_any, uint16_t port = 0);
00135 
00136         static pointer create( uint32_t host, uint16_t port );
00137 
00138         static pointer create( const std::string& host, uint16_t port );
00139 
00141         static pointer create(const struct sockaddr_in6& addr);
00142 
00144         static pointer create(const struct sockaddr_storage& addr);
00145 
00147         static pointer create(const IPv4::Address& ipv4addr, IPV4_EMBEDDED_TYPE ipv4type = IPV4_MAPPED);
00148 
00150         virtual ~Address();
00151 
00153         struct in6_addr host() const;
00154 
00156         std::string host_string() const;
00157 
00159         struct in6_addr subnet_mask() const;
00160 
00162         std::string subnet_mask_string() const;
00163 
00165         unsigned prefix_length() const;
00166 
00168         std::string prefix_length_string() const;
00169 
00171         std::string host_subnet_mask_string() const;
00172 
00174         std::string cidr_host_string() const;
00175 
00177         struct in6_addr prefix() const;
00178 
00180         std::string prefix_string() const;
00181 
00183         struct in6_addr local_address() const;
00184 
00186         std::string local_address_string() const;
00187 
00189         uint16_t port() const;
00190 
00192         std::string port_string() const;
00193 
00195         void set_host(const struct in6_addr& host);
00196 
00210         void set_host(const std::string& host);
00211 
00213         virtual void set_host(const std::string& host, uint16_t port);
00214 
00216         void set_host(uint32_t host, IPV4_EMBEDDED_TYPE type=IPV4_MAPPED);
00217 
00219         void set_host_prefix_length(uint32_t host, unsigned prefix_length, IPV4_EMBEDDED_TYPE type=IPV4_MAPPED);
00220 
00222         void set_prefix_length(unsigned prefix_length);
00223 
00225         void set_prefix_length(const std::string& prefix_length);
00226 
00228         void set_port(uint16_t port);
00229 
00231         void set_port(const std::string& port);
00232 
00233         uint32_t flowinfo();
00234 
00235         void set_flowinfo( uint32_t f );
00236 
00237         uint32_t scope_id();
00238 
00239         void set_scope_id( uint32_t sid );
00240 
00242         std::string hostname() const;
00243 
00245         std::string servicename() const;
00246 
00248         bool is_reserved() const;
00249 
00251         bool is_nsap() const;
00252 
00254         bool is_ipx() const;
00255 
00257         bool is_aggregatable_global() const;
00258 
00260         bool is_link_local() const;
00261 
00263         bool is_site_local() const;
00264 
00266         bool is_multicast() const;
00267 
00274         bool is_multicast_interface_local() const;
00275 
00282         bool is_multicast_link_local() const;
00283 
00289         bool is_multicast_site_local() const;
00290 
00297         bool is_multicast_organization_local() const;
00298 
00300         bool is_multicast_global() const;
00301 
00303         bool is_any() const;
00304 
00306         bool is_loopback() const;
00307 
00309         bool is_ipv4() const;
00310 
00312         bool is_ipv4_compatible() const;
00313 
00315         bool is_ipv4_mapped() const;
00316 
00318         socklen_t sockaddr_size() const;
00319 
00321         struct sockaddr_in6& sockaddr_in();
00322 
00324         struct sockaddr_in6* sockaddr_in_ptr();
00325 
00326         operator struct sockaddr_in6*();
00327 
00329         Address& operator=(const Address& other);
00330 
00331         Address& operator=( const Conexus::Address& other );
00332 
00334         bool operator==(const Address& other);
00335 
00337         virtual bool is_ipv4() { return this->is_ipv4_compatible(); }
00338 
00340         virtual bool is_ipv6() { return true; }
00341 
00342         virtual sigc::signal<void>& signal_changed( );
00343 
00344         virtual sigc::signal<void>& signal_host_changed( );
00345 
00346         virtual sigc::signal<void>& signal_port_changed( );
00347 
00348         virtual sigc::signal<void>& signal_flowinfo_changed( );
00349 
00350         virtual sigc::signal<void>& signal_scope_id_changed( );
00351 
00352         virtual sigc::signal<void>& signal_prefix_changed( );
00353 
00354         protected:
00355           struct in6_addr m_host;
00356 
00357           uint16_t m_port;
00358 
00359           uint32_t m_flowinfo;
00360 
00361           uint32_t m_scope_id;
00362 
00364           unsigned m_prefix_length;
00365 
00366           sigc::signal<void> m_signal_changed;
00367 
00368           sigc::signal<void> m_signal_host_changed;
00369 
00370           sigc::signal<void> m_signal_port_changed;
00371 
00372           sigc::signal<void> m_signal_flowinfo_changed;
00373 
00374           sigc::signal<void> m_signal_scope_id_changed;
00375 
00376           sigc::signal<void> m_signal_prefix_changed;
00377       };
00378 
00384       std::string host_to_string(const struct in6_addr&);
00385 
00391       struct in6_addr string_to_host(const std::string&);
00392 
00397       void string_to_host_prefix(const std::string&, struct in6_addr& host, int& prefix);
00398 
00404       bool is_valid_hostname(const std::string&);
00405 
00415       std::string host_to_hostname( const struct in6_addr& host ) throw (address_exception);
00416 
00422       std::string service_to_servicename( uint16_t service ) throw (address_exception);
00423 
00430       struct in6_addr hostname_to_host( const std::string& hostname ) throw (address_exception);
00431 
00437       uint16_t servicename_to_service( const std::string& servicename ) throw (address_exception);
00438 
00443       bool validate_subnet_mask( const struct in6_addr& subnet_mask ) throw();
00444 
00449       struct in6_addr create_subnet_mask(unsigned prefix_length);
00450 
00451   }
00452 
00453 }
00454 
00455 #endif

Generated on Wed Jul 8 15:50:07 2009 for conexus by doxygen 1.5.8