mcproxy/mcproxy/include/utils/addr_storage.hpp
Go to the documentation of this file.00001 /* 00002 * This file is part of mcproxy. 00003 * 00004 * mcproxy is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as published by 00006 * the Free Software Foundation; either version 3 of the License, or (at your 00007 * option) any later version. 00008 * 00009 * mcproxy is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00011 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00012 * License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with mcproxy; see the file COPYING.LESSER. 00016 * 00017 * written by Sebastian Woelke, in cooperation with: 00018 * INET group, Hamburg University of Applied Sciences, 00019 * Website: http://mcproxy.realmv6.org/ 00020 */ 00021 00022 00023 #ifndef ADDR_STORAGE_HPP 00024 #define ADDR_STORAGE_HPP 00025 00026 #include <iostream> 00027 #include <sys/socket.h> 00028 #include <string> 00029 #include <netinet/in.h> 00030 00034 #define INIT_ADDR_FAMILY -1 00035 00039 class addr_storage 00040 { 00041 private: 00042 struct sockaddr_storage m_addr; 00043 public: 00047 addr_storage(); 00048 00052 addr_storage(int addr_family); 00053 00057 addr_storage(const std::string& m_addr); 00058 00062 addr_storage(const struct sockaddr_storage& m_addr); 00063 00067 addr_storage(const addr_storage& m_addr); 00068 00072 addr_storage(const struct in_addr& m_addr); 00073 00077 addr_storage(const struct in6_addr& m_addr); 00078 00082 addr_storage(const struct sockaddr& m_addr); 00083 00084 //----------------------------------------------------------- 00085 00089 addr_storage& operator=(const addr_storage& s); 00090 00094 addr_storage& operator=(const struct sockaddr_storage& s); 00095 00099 addr_storage& operator=(const std::string& s); 00100 00104 addr_storage& operator=(const struct in_addr& s); 00105 00109 addr_storage& operator=(const struct in6_addr& s); 00110 00114 addr_storage& operator=(const struct sockaddr& s); 00115 00119 bool operator==(const addr_storage& addr) const; 00120 00124 bool operator!=(addr_storage& addr) const; 00125 00129 struct sockaddr_storage get_sockaddr_storage(); 00130 00134 int get_addr_family() const; 00135 00139 std::string to_string() const; 00140 00144 addr_storage& mask(const addr_storage& s); 00145 00149 static void test_addr_storage(); 00150 00154 friend bool operator< (const addr_storage& addr1, const addr_storage& addr2); 00155 00159 friend std::ostream& operator <<(std::ostream& s, const addr_storage a); 00160 00164 friend struct sockaddr_storage& operator<<=(struct sockaddr_storage& l,const addr_storage& r); 00165 00169 friend struct in_addr& operator<<=(struct in_addr& l,const addr_storage& r); 00170 00174 friend struct in6_addr& operator<<=(struct in6_addr& l,const addr_storage& r); 00175 }; 00176 00177 00178 00179 #endif // ADDR_STORAGE_HPP 00180