INetAddressing.hh

Go to the documentation of this file.
00001 // $Id: INetAddressing.hh 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2006
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00027 #ifndef HH_SENF_Socket_Protocols_INet_INetAddressing_
00028 #define HH_SENF_Socket_Protocols_INet_INetAddressing_ 1
00029 
00030 // Custom includes
00031 #include <string>
00032 #include <netinet/in.h>
00033 #include <senf/Socket/Protocols/BSDAddressingPolicy.hh>
00034 #include <senf/Socket/Protocols/BSDSocketAddress.hh>
00035 #include "INet4Address.hh"
00036 #include "INet6Address.hh"
00037 
00038 //#include "INetAddressing.mpp"
00039 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00040 
00041 namespace senf {
00042 
00053     class INet4SocketAddress
00054         : public BSDSocketAddress
00055     {
00056     public:
00057         static short const addressFamily = AF_INET;
00058 
00059         //-////////////////////////////////////////////////////////////////////////
00061         //\{
00062 
00063         INet4SocketAddress();
00064         explicit INet4SocketAddress(std::string const & addr); 
00065 
00075         INet4SocketAddress(INet4Address const & addr, unsigned port);
00077 
00080         explicit INet4SocketAddress(unsigned port);
00082 
00084         INet4SocketAddress(const INet4SocketAddress& other);
00085         INet4SocketAddress& operator=(const INet4SocketAddress& other);
00086 
00087         //\}
00088         //-////////////////////////////////////////////////////////////////////////
00089 
00090         INet4Address address() const;   
00091         unsigned port() const;          
00092 
00093         void address(INet4Address const & addr); 
00094         void port(unsigned p);          
00095 
00096         using BSDSocketAddress::sockaddr_p;
00097         using BSDSocketAddress::socklen_p;
00098 
00099     private:
00100         struct ::sockaddr_in addr_;
00101     };
00102 
00107     std::ostream & operator<<(std::ostream & os, INet4SocketAddress const & addr);
00108     std::istream & operator>>(std::istream & is, INet4SocketAddress & addr);
00109 
00141     class INet6SocketAddress
00142         : public BSDSocketAddress
00143     {
00144     public:
00145         static short const addressFamily = AF_INET6;
00146 
00147         //-////////////////////////////////////////////////////////////////////////
00149         //\{
00150 
00151         INet6SocketAddress();           
00152         explicit INet6SocketAddress(std::string const & addr,
00153                                     INet6Address::Resolve_t resolve = INet6Address::ResolveINet6);
00155 
00163         INet6SocketAddress(INet6Address const & addr, unsigned port);
00165         INet6SocketAddress(INet6Address const & addr, unsigned port, std::string const & iface);
00167 
00169         explicit INet6SocketAddress(unsigned port);
00171 
00174         INet6SocketAddress(const INet6SocketAddress& other);
00175         INet6SocketAddress& operator=(const INet6SocketAddress& other);
00176 
00177         //\}
00178         //-////////////////////////////////////////////////////////////////////////
00179 
00180         INet6Address address() const;    
00181         void address(INet6Address const & addr); 
00182 
00183         unsigned port() const;          
00184         void port(unsigned port);       
00185 
00186         std::string iface() const;      
00187         void iface(std::string const & iface); 
00188 
00191         using BSDSocketAddress::sockaddr_p;
00192         using BSDSocketAddress::socklen_p;
00193 
00194     protected:
00195 
00196     private:
00197         void assignIface(std::string const & iface);
00198 
00199         struct sockaddr_in6 sockaddr_;
00200     };
00201 
00205     std::ostream & operator<<(std::ostream & os, INet6SocketAddress const & addr);
00206     std::istream & operator>>(std::istream & is, INet6SocketAddress & addr);
00207 
00209     //\{
00210 
00223     struct INet4AddressingPolicy
00224         : public BSDAddressingPolicy,
00225           private BSDAddressingPolicyMixin<INet4SocketAddress>
00226     {
00227         typedef INet4SocketAddress Address;
00228 
00229         using BSDAddressingPolicyMixin<INet4SocketAddress>::peer;
00230         using BSDAddressingPolicyMixin<INet4SocketAddress>::local;
00231         using BSDAddressingPolicyMixin<INet4SocketAddress>::connect;
00232         using BSDAddressingPolicyMixin<INet4SocketAddress>::bind;
00233     };
00234 
00247     struct INet6AddressingPolicy
00248         : public BSDAddressingPolicy,
00249           private BSDAddressingPolicyMixin<INet6SocketAddress>
00250     {
00251         typedef INet6SocketAddress Address;
00252 
00253         using BSDAddressingPolicyMixin<INet6SocketAddress>::peer;
00254         using BSDAddressingPolicyMixin<INet6SocketAddress>::local;
00255         using BSDAddressingPolicyMixin<INet6SocketAddress>::connect;
00256         using BSDAddressingPolicyMixin<INet6SocketAddress>::bind;
00257     };
00258 
00259     //\}
00260 
00261 }
00262 
00263 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00264 #include "INetAddressing.cci"
00265 //#include "INetAddressing.ct"
00266 //#include "INetAddressing.cti"
00267 //#include "INetAddressing.mpp"
00268 #endif
00269 
00270 
00271 // Local Variables:
00272 // mode: c++
00273 // fill-column: 100
00274 // c-file-style: "senf"
00275 // indent-tabs-mode: nil
00276 // ispell-local-dictionary: "american"
00277 // compile-command: "scons -u test"
00278 // comment-column: 40
00279 // End: