ENUt

ipv6address.h

Go to the documentation of this file.
00001 /*
00002     
00003   This file is a part of ENUt, a library containing network
00004   programming utilities.
00005   
00006   Copyright (C) 2006-2008  Hasselt University - Expertise Centre for
00007                       Digital Media (EDM) (http://www.edm.uhasselt.be)
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00022   USA
00023 
00024 */
00025 
00030 #ifndef NUT_IPV6ADDRESS_H
00031 
00032 #define NUT_IPV6ADDRESS_H
00033 
00034 #include "nutconfig.h"
00035 
00036 #ifdef NUTCONFIG_SUPPORT_IPV6
00037 
00038 #include "networklayeraddress.h"
00039 #if ! (defined(WIN32) || defined(_WIN32_WCE))
00040         #include <netinet/in.h>
00041 #endif
00042 
00043 namespace nut
00044 {
00045 
00047 class ENUT_IMPORTEXPORT IPv6Address : public NetworkLayerAddress
00048 {
00049 public:
00050         IPv6Address() : NetworkLayerAddress(IPv6)                                               { for (int i = 0 ; i < 16 ; i++) m_ip.s6_addr[i] = 0; }
00051 
00053         IPv6Address(in6_addr ip) : NetworkLayerAddress(IPv6)                                    { ip = m_ip; }
00054 
00056         IPv6Address(const uint8_t ip[16]) : NetworkLayerAddress(IPv6)                           { for (int i = 0 ; i < 16 ; i++) m_ip.s6_addr[i] = ip[i]; }
00057         ~IPv6Address()                                                                          { }     
00058 
00060         in6_addr getAddress() const                                                             { return m_ip; }
00061 
00062         NetworkLayerAddress *createCopy() const                                                 { return new IPv6Address(m_ip); }
00063         bool isSameAddress(const NetworkLayerAddress &address) const;
00064         std::string getAddressString() const;
00065 private:
00066         in6_addr m_ip;
00067 };
00068 
00069 inline bool IPv6Address::isSameAddress(const NetworkLayerAddress &address) const
00070 {
00071         if (address.getProtocol() != IPv6)
00072                 return false;
00073         
00074         const IPv6Address &addr = (const IPv6Address &)address;
00075 
00076         for (int i = 0 ; i < 16 ; i++)
00077         {
00078                 if (m_ip.s6_addr[i] != addr.m_ip.s6_addr[i])
00079                         return false;
00080         }
00081         return true;
00082 }
00083 
00084 } // end namespace
00085 
00086 #endif // NUTCONFIG_SUPPORT_IPV6
00087 
00088 #endif // NUT_IPV6ADDRESS_H
00089