Logo
~Sockets~
~Examples~
~Contact~


Utility Class Reference
[Utilities]

Conversion utilities. More...

#include <Utility.h>

List of all members.


Static Public Member Functions

static std::string base64 (const std::string &str_in)
static std::string base64d (const std::string &str_in)
static std::string l2string (long l)
static std::string bigint2string (uint64_t l)
static uint64_t atoi64 (const std::string &str)
static unsigned int hex2unsigned (const std::string &str)
static std::string rfc1738_encode (const std::string &src)
static std::string rfc1738_decode (const std::string &src)
static bool isipv4 (const std::string &)
 Checks whether a string is a valid ipv4/ipv6 ip number.
static bool isipv6 (const std::string &)
 Checks whether a string is a valid ipv4/ipv6 ip number.
static bool u2ip (const std::string &, ipaddr_t &)
 Hostname to ip resolution ipv4, not asynchronous.
static bool u2ip (const std::string &, struct sockaddr_in &sa, int ai_flags=0)
static bool reverse (struct sockaddr *sa, socklen_t sa_len, std::string &, int flags=0)
 Reverse lookup of address to hostname.
static bool reverse (struct sockaddr *sa, socklen_t sa_len, std::string &hostname, std::string &service, int flags=0)
static bool u2service (const std::string &name, int &service, int ai_flags=0)
static void l2ip (const ipaddr_t, std::string &)
 Convert binary ip address to string: ipv4.
static void l2ip (const in_addr &, std::string &)
static void ResolveLocal ()
 ResolveLocal (hostname) - call once before calling any GetLocal method.
static const std::string & GetLocalHostname ()
 Returns local hostname, ResolveLocal must be called once before using.
static ipaddr_t GetLocalIP ()
 Returns local ip, ResolveLocal must be called once before using.
static const std::string & GetLocalAddress ()
 Returns local ip number as string.
static void SetEnv (const std::string &var, const std::string &value)
 Set environment variable.
static std::string Sa2String (struct sockaddr *sa)
 Convert sockaddr struct to human readable string.
static void GetTime (struct timeval *)
 Get current time in sec/microseconds.
static std::auto_ptr< SocketAddressCreateAddress (struct sockaddr *, socklen_t)
static unsigned long ThreadID ()

Static Private Attributes

static std::string m_host
 local hostname
static ipaddr_t m_ip = 0
 local ip address
static std::string m_addr
 local ip address in string format
static bool m_local_resolved = false
 ResolveLocal has been called if true.

Detailed Description

Conversion utilities.

Definition at line 57 of file Utility.h.


Member Function Documentation

std::string Utility::base64 ( const std::string &  str_in  )  [static]

Definition at line 61 of file Utility.cpp.

Referenced by MinionSocket::OnVerifiedLine(), and MinderSocket::SendHello().

00062 {
00063         std::string str;
00064         Base64 m_b;
00065         m_b.encode(str_in, str, false); // , false == do not add cr/lf
00066         return str;
00067 }

std::string Utility::base64d ( const std::string &  str_in  )  [static]

Definition at line 70 of file Utility.cpp.

References Base64::decode().

Referenced by MinderSocket::OnLine(), and MinionSocket::OnVerifiedLine().

00071 {
00072         std::string str;
00073         Base64 m_b;
00074         m_b.decode(str_in, str);
00075         return str;
00076 }

std::string Utility::l2string ( long  l  )  [static]

std::string Utility::bigint2string ( uint64_t  l  )  [static]

Definition at line 89 of file Utility.cpp.

00090 {
00091         std::string str;
00092         uint64_t tmp = l;
00093         while (tmp)
00094         {
00095                 uint64_t a = tmp % 10;
00096                 str = (char)(a + 48) + str;
00097                 tmp /= 10;
00098         }
00099         if (!str.size())
00100         {
00101                 str = "0";
00102         }
00103         return str;
00104 }

uint64_t Utility::atoi64 ( const std::string &  str  )  [static]

Definition at line 107 of file Utility.cpp.

00108 {
00109         uint64_t l = 0;
00110         for (size_t i = 0; i < str.size(); i++)
00111         {
00112                 l = l * 10 + str[i] - 48;
00113         }
00114         return l;
00115 }

unsigned int Utility::hex2unsigned ( const std::string &  str  )  [static]

Definition at line 118 of file Utility.cpp.

00119 {
00120         unsigned int r = 0;
00121         for (size_t i = 0; i < str.size(); i++)
00122         {
00123                 r = r * 16 + str[i] - 48 - ((str[i] >= 'A') ? 7 : 0) - ((str[i] >= 'a') ? 32 : 0);
00124         }
00125         return r;
00126 }

std::string Utility::rfc1738_encode ( const std::string &  src  )  [static]

Definition at line 133 of file Utility.cpp.

Referenced by HttpPostSocket::OnConnect().

00134 {
00135 static  char hex[] = "0123456789ABCDEF";
00136         std::string dst;
00137         for (size_t i = 0; i < src.size(); i++)
00138         {
00139                 if (isalnum(src[i]))
00140                 {
00141                         dst += src[i];
00142                 }
00143                 else
00144                 if (src[i] == ' ')
00145                 {
00146                         dst += '+';
00147                 }
00148                 else
00149                 {
00150                         unsigned char c = static_cast<unsigned char>(src[i]);
00151                         dst += '%';
00152                         dst += hex[c / 16];
00153                         dst += hex[c % 16];
00154                 }
00155         }
00156         return dst;
00157 } // rfc1738_encode

std::string Utility::rfc1738_decode ( const std::string &  src  )  [static]

Definition at line 164 of file Utility.cpp.

00165 {
00166         std::string dst;
00167         for (size_t i = 0; i < src.size(); i++)
00168         {
00169                 if (src[i] == '%' && isxdigit(src[i + 1]) && isxdigit(src[i + 2]))
00170                 {
00171                         char c1 = src[++i];
00172                         char c2 = src[++i];
00173                         c1 = c1 - 48 - ((c1 >= 'A') ? 7 : 0) - ((c1 >= 'a') ? 32 : 0);
00174                         c2 = c2 - 48 - ((c2 >= 'A') ? 7 : 0) - ((c2 >= 'a') ? 32 : 0);
00175                         dst += (char)(c1 * 16 + c2);
00176                 }
00177                 else
00178                 if (src[i] == '+')
00179                 {
00180                         dst += ' ';
00181                 }
00182                 else
00183                 {
00184                         dst += src[i];
00185                 }
00186         }
00187         return dst;
00188 } // rfc1738_decode

bool Utility::isipv4 ( const std::string &   )  [static]

Checks whether a string is a valid ipv4/ipv6 ip number.

Definition at line 191 of file Utility.cpp.

Referenced by ResolvSocket::OnDetached(), TcpSocket::Open(), Ipv4Address::Resolve(), and u2ip().

00192 {
00193         int dots = 0;
00194         // %! ignore :port?
00195         for (size_t i = 0; i < str.size(); i++)
00196         {
00197                 if (str[i] == '.')
00198                         dots++;
00199                 else
00200                 if (!isdigit(str[i]))
00201                         return false;
00202         }
00203         if (dots != 3)
00204                 return false;
00205         return true;
00206 }

bool Utility::isipv6 ( const std::string &   )  [static]

Checks whether a string is a valid ipv4/ipv6 ip number.

Definition at line 209 of file Utility.cpp.

References Parse::getword().

Referenced by ResolvSocket::OnDetached().

00210 {
00211         size_t qc = 0;
00212         size_t qd = 0;
00213         for (size_t i = 0; i < str.size(); i++)
00214         {
00215                 qc += (str[i] == ':') ? 1 : 0;
00216                 qd += (str[i] == '.') ? 1 : 0;
00217         }
00218         if (qc > 7)
00219         {
00220                 return false;
00221         }
00222         if (qd && qd != 3)
00223         {
00224                 return false;
00225         }
00226         Parse pa(str,":.");
00227         std::string tmp = pa.getword();
00228         while (tmp.size())
00229         {
00230                 if (tmp.size() > 4)
00231                 {
00232                         return false;
00233                 }
00234                 for (size_t i = 0; i < tmp.size(); i++)
00235                 {
00236                         if (tmp[i] < '0' || (tmp[i] > '9' && tmp[i] < 'A') ||
00237                                 (tmp[i] > 'F' && tmp[i] < 'a') || tmp[i] > 'f')
00238                         {
00239                                 return false;
00240                         }
00241                 }
00242                 //
00243                 tmp = pa.getword();
00244         }
00245         return true;
00246 }

bool Utility::u2ip ( const std::string &  ,
ipaddr_t  
) [static]

Hostname to ip resolution ipv4, not asynchronous.

Definition at line 249 of file Utility.cpp.

Referenced by UdpSocket::AddMulticastMembership(), UdpSocket::DropMulticastMembership(), Ipv4Address::Ipv4Address(), ResolvSocket::OnDetached(), ResolvSocket::OnLine(), MinionSocket::OnLine(), MinderSocket::OnLine(), TcpSocket::Open(), SocketHandler::Resolve(), Ipv4Address::Resolve(), ResolveLocal(), SocketHandler::SetSocks4Host(), and Socket::SetSocks4Host().

00250 {
00251         struct sockaddr_in sa;
00252         bool r = Utility::u2ip(str, sa);
00253         memcpy(&l, &sa.sin_addr, sizeof(l));
00254         return r;
00255 }

bool Utility::u2ip ( const std::string &  ,
struct sockaddr_in &  sa,
int  ai_flags = 0 
) [static]

Definition at line 531 of file Utility.cpp.

References isipv4(), and RandomNumber::next().

00532 {
00533         memset(&sa, 0, sizeof(sa));
00534         sa.sin_family = AF_INET;
00535 #ifdef NO_GETADDRINFO
00536         if ((ai_flags & AI_NUMERICHOST) != 0 || isipv4(host))
00537         {
00538                 Parse pa((char *)host.c_str(), ".");
00539                 union {
00540                         struct {
00541                                 unsigned char b1;
00542                                 unsigned char b2;
00543                                 unsigned char b3;
00544                                 unsigned char b4;
00545                         } a;
00546                         ipaddr_t l;
00547                 } u;
00548                 u.a.b1 = static_cast<unsigned char>(pa.getvalue());
00549                 u.a.b2 = static_cast<unsigned char>(pa.getvalue());
00550                 u.a.b3 = static_cast<unsigned char>(pa.getvalue());
00551                 u.a.b4 = static_cast<unsigned char>(pa.getvalue());
00552                 memcpy(&sa.sin_addr, &u.l, sizeof(sa.sin_addr));
00553                 return true;
00554         }
00555 #ifndef LINUX
00556         struct hostent *he = gethostbyname( host.c_str() );
00557         if (!he)
00558         {
00559                 return false;
00560         }
00561         memcpy(&sa.sin_addr, he -> h_addr, sizeof(sa.sin_addr));
00562 #else
00563         struct hostent he;
00564         struct hostent *result;
00565         int myerrno;
00566         char buf[2000];
00567         int n = gethostbyname_r(host.c_str(), &he, buf, sizeof(buf), &result, &myerrno);
00568         if (n)
00569         {
00570                 return false;
00571         }
00572         memcpy(&sa.sin_addr, he.h_addr, 4);
00573 #endif
00574         return true;
00575 #else
00576         struct addrinfo hints;
00577         memset(&hints, 0, sizeof(hints));
00578         // AI_NUMERICHOST
00579         // AI_CANONNAME
00580         // AI_PASSIVE - server
00581         // AI_ADDRCONFIG
00582         // AI_V4MAPPED
00583         // AI_ALL
00584         // AI_NUMERICSERV
00585         hints.ai_flags = ai_flags;
00586         hints.ai_family = AF_INET;
00587         hints.ai_socktype = 0;
00588         hints.ai_protocol = 0;
00589         struct addrinfo *res;
00590         if (Utility::isipv4(host))
00591                 hints.ai_flags |= AI_NUMERICHOST;
00592         int n = getaddrinfo(host.c_str(), NULL, &hints, &res);
00593         if (!n)
00594         {
00595                 RandomNumber prng( true );
00596                 std::vector<struct addrinfo *> vec;
00597                 struct addrinfo *ai = res;
00598                 while (ai)
00599                 {
00600                         if (ai -> ai_addrlen == sizeof(sa))
00601                                 vec.push_back( ai );
00602                         prng.next();
00603                         //
00604                         ai = ai -> ai_next;
00605                 }
00606                 if (!vec.size())
00607                         return false;
00608                 ai = vec[prng.next() % vec.size()];
00609                 {
00610                         memcpy(&sa, ai -> ai_addr, ai -> ai_addrlen);
00611                 }
00612                 freeaddrinfo(res);
00613                 return true;
00614         }
00615         std::string error = "Error: ";
00616 #ifndef __CYGWIN__
00617         error += gai_strerror(n);
00618 #endif
00619         return false;
00620 #endif // NO_GETADDRINFO
00621 }

bool Utility::reverse ( struct sockaddr *  sa,
socklen_t  sa_len,
std::string &  ,
int  flags = 0 
) [static]

Reverse lookup of address to hostname.

Definition at line 743 of file Utility.cpp.

Referenced by Ipv4Address::Convert(), l2ip(), ResolvSocket::OnDetached(), and Ipv4Address::Reverse().

00744 {
00745         std::string service;
00746         return Utility::reverse(sa, sa_len, hostname, service, flags);
00747 }

bool Utility::reverse ( struct sockaddr *  sa,
socklen_t  sa_len,
std::string &  hostname,
std::string &  service,
int  flags = 0 
) [static]

Definition at line 750 of file Utility.cpp.

00751 {
00752         hostname = "";
00753         service = "";
00754 #ifdef NO_GETADDRINFO
00755         switch (sa -> sa_family)
00756         {
00757         case AF_INET:
00758                 if (flags & NI_NUMERICHOST)
00759                 {
00760                         union {
00761                                 struct {
00762                                         unsigned char b1;
00763                                         unsigned char b2;
00764                                         unsigned char b3;
00765                                         unsigned char b4;
00766                                 } a;
00767                                 ipaddr_t l;
00768                         } u;
00769                         struct sockaddr_in *sa_in = (struct sockaddr_in *)sa;
00770                         memcpy(&u.l, &sa_in -> sin_addr, sizeof(u.l));
00771                         char tmp[100];
00772                         sprintf(tmp, "%u.%u.%u.%u", u.a.b1, u.a.b2, u.a.b3, u.a.b4);
00773                         hostname = tmp;
00774                         return true;
00775                 }
00776                 else
00777                 {
00778                         struct sockaddr_in *sa_in = (struct sockaddr_in *)sa;
00779                         struct hostent *h = gethostbyaddr( (const char *)&sa_in -> sin_addr, sizeof(sa_in -> sin_addr), AF_INET);
00780                         if (h)
00781                         {
00782                                 hostname = h -> h_name;
00783                                 return true;
00784                         }
00785                 }
00786                 break;
00787 #ifdef ENABLE_IPV6
00788         case AF_INET6:
00789                 if (flags & NI_NUMERICHOST)
00790                 {
00791                         char slask[100]; // l2ip temporary
00792                         *slask = 0;
00793                         unsigned int prev = 0;
00794                         bool skipped = false;
00795                         bool ok_to_skip = true;
00796                         {
00797                                 unsigned short addr16[8];
00798                                 struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)sa;
00799                                 memcpy(addr16, &sa_in6 -> sin6_addr, sizeof(addr16));
00800                                 for (size_t i = 0; i < 8; i++)
00801                                 {
00802                                         unsigned short x = ntohs(addr16[i]);
00803                                         if (*slask && (x || !ok_to_skip || prev))
00804                                                 strcat(slask,":");
00805                                         if (x || !ok_to_skip)
00806                                         {
00807                                                 sprintf(slask + strlen(slask),"%x", x);
00808                                                 if (x && skipped)
00809                                                         ok_to_skip = false;
00810                                         }
00811                                         else
00812                                         {
00813                                                 skipped = true;
00814                                         }
00815                                         prev = x;
00816                                 }
00817                         }
00818                         if (!*slask)
00819                                 strcpy(slask, "::");
00820                         hostname = slask;
00821                         return true;
00822                 }
00823                 else
00824                 {
00825                         // %! TODO: ipv6 reverse lookup
00826                         struct sockaddr_in6 *sa_in = (struct sockaddr_in6 *)sa;
00827                         struct hostent *h = gethostbyaddr( (const char *)&sa_in -> sin6_addr, sizeof(sa_in -> sin6_addr), AF_INET6);
00828                         if (h)
00829                         {
00830                                 hostname = h -> h_name;
00831                                 return true;
00832                         }
00833                 }
00834                 break;
00835 #endif
00836         }
00837         return false;
00838 #else
00839         char host[NI_MAXHOST];
00840         char serv[NI_MAXSERV];
00841         // NI_NOFQDN
00842         // NI_NUMERICHOST
00843         // NI_NAMEREQD
00844         // NI_NUMERICSERV
00845         // NI_DGRAM
00846         int n = getnameinfo(sa, sa_len, host, sizeof(host), serv, sizeof(serv), flags);
00847         if (n)
00848         {
00849                 // EAI_AGAIN
00850                 // EAI_BADFLAGS
00851                 // EAI_FAIL
00852                 // EAI_FAMILY
00853                 // EAI_MEMORY
00854                 // EAI_NONAME
00855                 // EAI_OVERFLOW
00856                 // EAI_SYSTEM
00857                 return false;
00858         }
00859         hostname = host;
00860         service = serv;
00861         return true;
00862 #endif // NO_GETADDRINFO
00863 }

bool Utility::u2service ( const std::string &  name,
int &  service,
int  ai_flags = 0 
) [static]

Definition at line 866 of file Utility.cpp.

00867 {
00868 #ifdef NO_GETADDRINFO
00869         // %!
00870         return false;
00871 #else
00872         struct addrinfo hints;
00873         service = 0;
00874         memset(&hints, 0, sizeof(hints));
00875         // AI_NUMERICHOST
00876         // AI_CANONNAME
00877         // AI_PASSIVE - server
00878         // AI_ADDRCONFIG
00879         // AI_V4MAPPED
00880         // AI_ALL
00881         // AI_NUMERICSERV
00882         hints.ai_flags = ai_flags;
00883         hints.ai_family = AF_UNSPEC;
00884         hints.ai_socktype = 0;
00885         hints.ai_protocol = 0;
00886         struct addrinfo *res;
00887         int n = getaddrinfo(NULL, name.c_str(), &hints, &res);
00888         if (!n)
00889         {
00890                 service = res -> ai_protocol;
00891                 freeaddrinfo(res);
00892                 return true;
00893         }
00894         return false;
00895 #endif // NO_GETADDRINFO
00896 }

void Utility::l2ip ( const   ipaddr_t,
std::string &   
) [static]

Convert binary ip address to string: ipv4.

Definition at line 271 of file Utility.cpp.

References reverse().

Referenced by MinionSocket::MinionSocket(), ResolvSocket::OnConnect(), ResolvSocket::OnDetached(), TcpSocket::Open(), ResolveLocal(), Sa2String(), and MinionSocket::SendHello().

00272 {
00273         struct sockaddr_in sa;
00274         memset(&sa, 0, sizeof(sa));
00275         sa.sin_family = AF_INET;
00276         memcpy(&sa.sin_addr, &ip, sizeof(sa.sin_addr));
00277         Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), str, NI_NUMERICHOST);
00278 }

void Utility::l2ip ( const in_addr &  ,
std::string &   
) [static]

Definition at line 281 of file Utility.cpp.

References reverse().

00282 {
00283         struct sockaddr_in sa;
00284         memset(&sa, 0, sizeof(sa));
00285         sa.sin_family = AF_INET;
00286         sa.sin_addr = ip;
00287         Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), str, NI_NUMERICHOST);
00288 }

void Utility::ResolveLocal (  )  [static]

ResolveLocal (hostname) - call once before calling any GetLocal method.

Definition at line 355 of file Utility.cpp.

References l2ip(), m_addr, m_host, m_ip, m_local_resolved, and u2ip().

Referenced by GetLocalAddress(), GetLocalHostname(), and GetLocalIP().

00356 {
00357         char h[256];
00358 
00359         // get local hostname and translate into ip-address
00360         *h = 0;
00361         gethostname(h,255);
00362         {
00363                 if (Utility::u2ip(h, m_ip))
00364                 {
00365                         Utility::l2ip(m_ip, m_addr);
00366                 }
00367         }
00368 #ifdef ENABLE_IPV6
00369 #ifdef IPPROTO_IPV6
00370         memset(&m_local_ip6, 0, sizeof(m_local_ip6));
00371         {
00372                 if (Utility::u2ip(h, m_local_ip6))
00373                 {
00374                         Utility::l2ip(m_local_ip6, m_local_addr6);
00375                 }
00376         }
00377 #endif
00378 #endif
00379         m_host = h;
00380         m_local_resolved = true;
00381 }

const std::string & Utility::GetLocalHostname (  )  [static]

Returns local hostname, ResolveLocal must be called once before using.

See also:
ResolveLocal

Definition at line 384 of file Utility.cpp.

References m_host, m_local_resolved, and ResolveLocal().

00385 {
00386         if (!m_local_resolved)
00387         {
00388                 ResolveLocal();
00389         }
00390         return m_host;
00391 }

ipaddr_t Utility::GetLocalIP (  )  [static]

Returns local ip, ResolveLocal must be called once before using.

See also:
ResolveLocal

Definition at line 394 of file Utility.cpp.

References m_ip, m_local_resolved, and ResolveLocal().

00395 {
00396         if (!m_local_resolved)
00397         {
00398                 ResolveLocal();
00399         }
00400         return m_ip;
00401 }

const std::string & Utility::GetLocalAddress (  )  [static]

Returns local ip number as string.

See also:
ResolveLocal

Definition at line 404 of file Utility.cpp.

References m_addr, m_local_resolved, and ResolveLocal().

00405 {
00406         if (!m_local_resolved)
00407         {
00408                 ResolveLocal();
00409         }
00410         return m_addr;
00411 }

void Utility::SetEnv ( const std::string &  var,
const std::string &  value 
) [static]

Set environment variable.

Parameters:
var Name of variable to set
value Value

Definition at line 438 of file Utility.cpp.

Referenced by HttpdSocket::OnHeaderComplete(), and SSLInitializer::SSLInitializer().

00439 {
00440 #if (defined(SOLARIS8) || defined(SOLARIS))
00441         {
00442                 static std::map<std::string, char *> vmap;
00443                 if (vmap.find(var) != vmap.end())
00444                 {
00445                         delete[] vmap[var];
00446                 }
00447                 vmap[var] = new char[var.size() + 1 + value.size() + 1];
00448                 sprintf(vmap[var], "%s=%s", var.c_str(), value.c_str());
00449                 putenv( vmap[var] );
00450         }
00451 #elif defined _WIN32
00452         {
00453                 std::string slask = var + "=" + value;
00454                 _putenv( (char *)slask.c_str());
00455         }
00456 #else
00457         setenv(var.c_str(), value.c_str(), 1);
00458 #endif
00459 }

std::string Utility::Sa2String ( struct sockaddr *  sa  )  [static]

Convert sockaddr struct to human readable string.

Parameters:
sa Ptr to sockaddr struct

Definition at line 462 of file Utility.cpp.

References l2ip(), and l2string().

Referenced by SctpSocket::getladdrs(), and SctpSocket::getpaddrs().

00463 {
00464 #ifdef ENABLE_IPV6
00465 #ifdef IPPROTO_IPV6
00466         if (sa -> sa_family == AF_INET6)
00467         {
00468                 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
00469                 std::string tmp;
00470                 Utility::l2ip(sa6 -> sin6_addr, tmp);
00471                 return tmp + ":" + Utility::l2string(ntohs(sa6 -> sin6_port));
00472         }
00473 #endif
00474 #endif
00475         if (sa -> sa_family == AF_INET)
00476         {
00477                 struct sockaddr_in *sa4 = (struct sockaddr_in *)sa;
00478                 ipaddr_t a;
00479                 memcpy(&a, &sa4 -> sin_addr, 4);
00480                 std::string tmp;
00481                 Utility::l2ip(a, tmp);
00482                 return tmp + ":" + Utility::l2string(ntohs(sa4 -> sin_port));
00483         }
00484         return "";
00485 }

void Utility::GetTime ( struct timeval *   )  [static]

Get current time in sec/microseconds.

Definition at line 488 of file Utility.cpp.

00489 {
00490 #ifdef _WIN32
00491         FILETIME ft; // Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
00492         GetSystemTimeAsFileTime(&ft);
00493         uint64_t tt;
00494         memcpy(&tt, &ft, sizeof(tt));
00495         tt /= 10; // make it usecs
00496         p->tv_sec = (long)tt / 1000000;
00497         p->tv_usec = (long)tt % 1000000;
00498 #else
00499         gettimeofday(p, NULL);
00500 #endif
00501 }

std::auto_ptr< SocketAddress > Utility::CreateAddress ( struct sockaddr *  ,
socklen_t   
) [static]

Definition at line 504 of file Utility.cpp.

00505 {
00506         switch (sa -> sa_family)
00507         {
00508         case AF_INET:
00509                 if (sa_len == sizeof(struct sockaddr_in))
00510                 {
00511                         struct sockaddr_in *p = (struct sockaddr_in *)sa;
00512                         return std::auto_ptr<SocketAddress>(new Ipv4Address(*p));
00513                 }
00514                 break;
00515 #ifdef ENABLE_IPV6
00516 #ifdef IPPROTO_IPV6
00517         case AF_INET6:
00518                 if (sa_len == sizeof(struct sockaddr_in6))
00519                 {
00520                         struct sockaddr_in6 *p = (struct sockaddr_in6 *)sa;
00521                         return std::auto_ptr<SocketAddress>(new Ipv6Address(*p));
00522                 }
00523                 break;
00524 #endif
00525 #endif
00526         }
00527         return std::auto_ptr<SocketAddress>(NULL);
00528 }

unsigned long Utility::ThreadID (  )  [static]

Definition at line 899 of file Utility.cpp.

Referenced by SSLInitializer::SSL_id_function().

00900 {
00901 #ifdef _WIN32
00902         return GetCurrentThreadId();
00903 #else
00904         return pthread_self();
00905 #endif
00906 }


Member Data Documentation

std::string Utility::m_host [static, private]

local hostname

Definition at line 141 of file Utility.h.

Referenced by GetLocalHostname(), and ResolveLocal().

ipaddr_t Utility::m_ip = 0 [static, private]

local ip address

Definition at line 142 of file Utility.h.

Referenced by GetLocalIP(), and ResolveLocal().

std::string Utility::m_addr [static, private]

local ip address in string format

Definition at line 143 of file Utility.h.

Referenced by GetLocalAddress(), and ResolveLocal().

bool Utility::m_local_resolved = false [static, private]

ResolveLocal has been called if true.

Definition at line 150 of file Utility.h.

Referenced by GetLocalAddress(), GetLocalHostname(), GetLocalIP(), and ResolveLocal().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4