sockaddr.h

Go to the documentation of this file.
00001 /*
00002     socklibpp library
00003     Copyright (C) 2005  Daniel K. O. <danielosmari at users.sf.net>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2.1 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00020 
00021 
00022 #ifndef SOCK_ADDR_H
00023 #define SOCK_ADDR_H
00024 
00025 
00031 #include <stdexcept>
00032 #include <iosfwd>
00033 #include <string>
00034 #include <inttypes.h>
00035 
00036 
00037 #include "sockcommon.h"
00038 
00039 namespace socklibpp {
00040 
00042 class addr {
00043 
00044         struct sockaddr *_M_data;
00045 
00046 protected:
00048         int _M_size;
00049 
00051         addr(struct sockaddr * _d, int _s) throw() :
00052                 _M_data(_d),
00053                 _M_size(_s)
00054         { }
00055         
00056         virtual
00057         ~addr() {}
00058 
00060         virtual void reset() throw() = 0;
00061 
00062         friend class sock;
00063 
00065         struct sockaddr *
00066         data() { return _M_data; }
00067 
00069         const struct sockaddr *
00070         data() const { return _M_data; }
00071 
00073         int
00074         size() const { return _M_size; }
00075         
00077         void
00078         size(int _size) { _M_size = _size; }
00079         
00080 public:
00081 
00083         enum family {
00084                 af_unspec       = AF_UNSPEC,    
00085                 af_unix         = AF_UNIX,      
00086                 af_inet         = AF_INET,      
00087                 af_inet6        = AF_INET6,     
00088                 af_max          = AF_MAX        
00089         };
00090 };
00091 
00092 
00093 
00098 class addr_in : public addr {
00099 
00100         struct sockaddr_in _M_addr;     // for IPv4
00101 
00102 protected:
00104         virtual void reset() throw();
00105 
00106 public:
00108         enum address {
00109                 addr_any        = INADDR_ANY,           
00110                 addr_loopback   = INADDR_LOOPBACK,      
00111                 addr_broadcast  = INADDR_BROADCAST,     
00112                 addr_none       = INADDR_NONE           
00113         };
00114 
00115 
00117         addr_in() throw();
00118 
00120         addr_in(address _addr, uint16_t _port) throw();
00121 
00123         addr_in(uint32_t _addr, uint16_t _port) throw();
00124 
00126         addr_in(const std::string&, uint16_t) throw (std::invalid_argument);
00127 
00129         addr_in(const std::string&) throw (std::invalid_argument);
00130         
00132         static bool validate_addr(const std::string&) throw();
00133         
00135         static bool validate_addr_port(const std::string&) throw();
00136         
00137         
00139         bool
00140         resolve(const std::string&) throw();
00141 
00143         bool
00144         resolve_port(const std::string&) throw();
00145         
00147         bool
00148         resolve_port(const std::string&, uint16_t) throw();
00149 
00151         bool
00152         resolve_port(const std::string&, const std::string&) throw();
00153 
00155         uint16_t        port() const throw ();
00156 
00158         void port(uint16_t _port) throw ();
00159         
00161         bool port(const std::string&, const std::string&) throw();
00162 
00164         bool port(const std::string&) throw();
00165 
00167         uint32_t ip() const throw();
00168         
00170         void ip(uint32_t _host) throw();
00171 
00173         bool
00174         ip(const std::string&) throw();
00175 
00176 
00178         bool
00179         ip_port(const std::string&, uint16_t) throw();
00180 
00182         bool
00183         ip_port(const std::string&) throw();
00184 
00186         bool
00187         ip_port(const std::string&, const std::string&) throw();
00188 
00189 
00191         std::string ip_str() const;
00192         
00193         
00194         
00195         
00196 
00197         friend
00198         std::ostream& operator<<(std::ostream&, const addr_in&);
00199         
00200         friend
00201         std::istream& operator>>(std::istream&, addr_in&);
00202 };
00203 
00205 std::ostream& operator<<(std::ostream&, const addr_in&);
00206 
00208 std::istream& operator>>(std::istream&, addr_in&);
00209 
00210 }
00211 
00212 
00213 #endif

Generated on Thu Jan 18 19:26:35 2007 for socklib++ by  doxygen 1.5.1