Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "cxutils/networking/ip6address.h"
00041
00042 #include <string.h>
00043 #include <cstdio>
00044
00045 using namespace CxUtils;
00046
00052 IP6Address::IP6Address()
00053 {
00054 mString = "0.0.0.0.0.0";
00055 memset(mData, 0, sizeof(unsigned char)*6);
00056 }
00057
00058
00064 IP6Address::IP6Address(const char* ipAddress)
00065 {
00066 SetAddress(std::string(ipAddress));
00067 }
00068
00069
00075 IP6Address::IP6Address(const std::string& ipAddress)
00076 {
00077 SetAddress(ipAddress);
00078 }
00079
00080
00086 IP6Address::IP6Address(const IP6Address& ipAddress)
00087 {
00088 mString = ipAddress.mString;
00089 memcpy(mData, ipAddress.mData, sizeof(unsigned char)*6);
00090 }
00091
00092
00098 IP6Address::~IP6Address()
00099 {
00100 }
00101
00102
00113 bool IP6Address::SetAddress(const std::string& ipAddress)
00114 {
00115 int a, b, c, d, e, f;
00116 if(ipAddress.empty() == false &&
00117 sscanf(ipAddress.c_str(), "%d.%d.%d.%d.%d.%d", &a, &b, &c, &d, &e, &f) == 6)
00118 {
00119 mString = ipAddress;
00120 mData[0] = (unsigned char)a;
00121 mData[1] = (unsigned char)b;
00122 mData[2] = (unsigned char)c;
00123 mData[3] = (unsigned char)d;
00124 mData[4] = (unsigned char)e;
00125 mData[5] = (unsigned char)f;
00126 return true;
00127 }
00128 else
00129 {
00130 mString = "0.0.0.0.0.0";
00131 memset(mData, 0, sizeof(unsigned char)*6);
00132 }
00133 return false;
00134 }
00135
00136
00151 bool IP6Address::SetAddress(const unsigned char a,
00152 const unsigned char b,
00153 const unsigned char c,
00154 const unsigned char d,
00155 const unsigned char e,
00156 const unsigned char f)
00157 {
00158 mData[0] = a;
00159 mData[1] = b;
00160 mData[2] = c;
00161 mData[3] = d;
00162 mData[4] = e;
00163 mData[5] = f;
00164 char buffer[128];
00165 sprintf(buffer, "%d.%d.%d.%d.%d.%d", a, b, c, d, e, f);
00166 mString = buffer;
00167 return true;
00168 }
00169
00170
00176 IP6Address& IP6Address::operator=(const IP6Address& ipAddress)
00177 {
00178 mString = ipAddress.mString;
00179 memcpy(mData, ipAddress.mData, sizeof(unsigned char)*6);
00180 return *this;
00181 }
00182
00188 IP6Address& IP6Address::operator=(const std::string& ipAddress)
00189 {
00190 SetAddress(ipAddress);
00191 return *this;
00192 }
00193
00199 bool IP6Address::operator<(const IP6Address& ipAddress) const
00200 {
00201 return mString < ipAddress.mString;
00202 }
00203
00204
00210 bool IP6Address::operator<=(const IP6Address& ipAddress) const
00211 {
00212 return mString <= ipAddress.mString;
00213 }
00214
00215
00221 bool IP6Address::operator==(const IP6Address& ipAddress) const
00222 {
00223 if(memcmp(mData, ipAddress.mData, sizeof(unsigned char)*6) == 0)
00224 {
00225 return true;
00226 }
00227 return false;
00228 }
00229
00230
00236 bool IP6Address::operator!=(const IP6Address& ipAddress) const
00237 {
00238 if(memcmp(mData, ipAddress.mData, sizeof(unsigned char)*6) != 0)
00239 {
00240 return true;
00241 }
00242 return false;
00243 }
00244
00245
00246
00252 void IP6Address::Clear()
00253 {
00254 mString = "0.0.0.0.0.0";
00255 memset(mData, 0, sizeof(unsigned char)*6);
00256 }
00257
00258
00259