debian/libconexus-dev/usr/include/conexus-0.5/conexus/ipv4_address.h

00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation version 2.1.                *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this library; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018  ***************************************************************************/
00019 #ifndef CONEXUS_IPV4ADDRESS_H
00020 #define CONEXUS_IPV4ADDRESS_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/ipaddress.h>
00029 #include <conexus/except.h>
00030 
00031 namespace Conexus
00032   {
00033 
00034     namespace IPv6 {
00035       class Address;
00036     }
00037 
00044   namespace IPv4
00045     {
00046 
00061       class Address: public IPAddress
00062       {
00063       public:
00064 
00066         typedef ConexusPointer<Address> pointer;
00067 
00077         Address(uint32_t address=INADDR_ANY, uint16_t port=0);
00078 
00080         Address(const struct sockaddr_in& addr);
00081 
00083         Address(const struct sockaddr_storage& addr);
00084 
00086         Address(const struct sockaddr& addr);
00087 
00089         Address(const IPv6::Address& addr);
00090 
00092         static Address::pointer create( uint32_t address=INADDR_ANY, uint16_t port=0 );
00093 
00095         static Address::pointer create(const struct sockaddr_in& addr);
00096 
00098         static Address::pointer create(const struct sockaddr_storage& addr);
00099 
00101         static Address::pointer create(const struct sockaddr& addr);
00102 
00104         static Address::pointer create(const IPv6::Address& ipv6addr);
00105 
00107         virtual ~Address();
00108 
00110         uint32_t address() const;
00111 
00113         std::string address_string() const;
00114 
00116         uint32_t subnet_mask() const;
00117 
00119         std::string subnet_mask_string() const;
00120 
00122         unsigned prefix_length() const;
00123 
00125         std::string prefix_length_string() const;
00126 
00128         std::string address_subnet_mask_string() const;
00129 
00131         std::string cidr_address_string() const;
00132 
00134         uint32_t prefix() const;
00135 
00137         std::string prefix_string() const;
00138 
00140         uint32_t broadcast_address() const;
00141 
00143         std::string broadcast_address_string() const;
00144 
00146         uint32_t local_address() const;
00147 
00149         std::string local_address_string() const;
00150 
00152         uint16_t port() const;
00153 
00155         std::string port_string() const;
00156 
00158         void set_address(uint32_t address);
00159 
00174         void set_address(std::string address);
00175 
00177         virtual void set_address(std::string address, uint16_t port);
00178 
00180         void set_address_subnet_mask(uint32_t address, uint32_t subnet_mask);
00181 
00183         void set_address_prefix_length(uint32_t address, unsigned prefix_length);
00184 
00186         void set_subnet_mask(uint32_t subnet_mask);
00187 
00189         void set_subnet_mask(std::string subnet_mask);
00190 
00192         void set_prefix_length(unsigned prefix_length);
00193 
00195         void set_prefix_length(std::string prefix_length);
00196 
00198         void set_port(uint16_t port);
00199 
00201         void set_port(std::string port);
00202 
00207         bool is_valid_hostname(const std::string) const;
00208 
00210         std::string hostname() const;
00211 
00213         std::string servicename() const;
00214 
00223         bool is_private() const;
00224 
00226         bool is_reserved() const;
00227 
00229         bool is_loopback() const;
00230 
00232         bool is_broadcast() const;
00233 
00235         bool is_multicast() const;
00236 
00238         bool is_any() const;
00239 
00241         socklen_t sockaddr_size() const;
00242 
00244         struct sockaddr_in& sockaddr_in();
00245 
00247         struct sockaddr_in* sockaddr_in_ptr();
00248 
00249         operator struct sockaddr_in*();
00250 
00251         Address& operator=(const Address& other);
00252 
00254         bool operator==(const Address& other) const;
00255 
00257         virtual const std::string& object_type() { static std::string s("Conexus::IPv4::Address"); return s; }
00258 
00260         virtual bool is_ipv4() { return true; }
00261 
00263         virtual bool is_ipv6() { return false; }
00264 
00265         protected:
00270         struct sockaddr_in* m_psockaddr_in;
00271 
00273         unsigned m_prefix_length;
00274 
00275       };
00276 
00278       std::string address_to_string(uint32_t);
00279 
00281       uint32_t string_to_address(std::string);
00282 
00284       void string_to_address_prefix(const std::string&, uint32_t& address, int& prefix);
00285 
00290       bool is_valid_hostname(const std::string);
00291 
00293       std::string address_to_hostname( uint32_t address ) throw (address_exception);
00294 
00296       std::string service_to_servicename( uint16_t service ) throw (address_exception);
00297 
00299       uint32_t hostname_to_address( std::string hostname ) throw (address_exception);
00300 
00302       uint16_t servicename_to_service( std::string servicename ) throw (address_exception);
00303 
00305       bool validate_subnet_mask( uint32_t subnet_mask ) throw();
00306 
00308       uint32_t create_subnet_mask(unsigned prefix_length);
00309 
00311       unsigned subnet_mask_length( uint32_t subnet_mask ) throw();
00312 
00313   }
00314 
00315 }
00316 
00317 #endif

Generated on Tue Mar 13 19:54:43 2007 by  doxygen 1.5.1