diff options
author | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
---|---|---|
committer | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
commit | e585187b248f48b3c6e9247b49fa07c6565d65e5 (patch) | |
tree | 637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /dep/include/sockets/Utility.h | |
parent | 26b5e033ffde3d161382fc9addbfa99738379641 (diff) |
*Backed out changeset 3be01fb200a5
--HG--
branch : trunk
Diffstat (limited to 'dep/include/sockets/Utility.h')
-rw-r--r-- | dep/include/sockets/Utility.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/dep/include/sockets/Utility.h b/dep/include/sockets/Utility.h index 8f1c15ab260..be0f6a05498 100644 --- a/dep/include/sockets/Utility.h +++ b/dep/include/sockets/Utility.h @@ -4,26 +4,32 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom + This library is made available under the terms of the GNU GPL. + If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_Utility_H #define _SOCKETS_Utility_H + #include "sockets-config.h" #include <ctype.h> #include <string.h> @@ -31,11 +37,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "socket_include.h" #include <map> #include <string> + #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif + #define TWIST_LEN 624 + class SocketAddress; + /** Conversion utilities. \ingroup util */ class Utility @@ -47,7 +57,9 @@ class Utility class Rng { public: Rng(unsigned long seed); + unsigned long Get(); + private: int m_value; unsigned long m_tmp[TWIST_LEN]; @@ -72,13 +84,16 @@ public: 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); + /** Checks whether a string is a valid ipv4/ipv6 ip number. */ static bool isipv4(const std::string&); /** Checks whether a string is a valid ipv4/ipv6 ip number. */ static bool isipv6(const std::string&); + /** Hostname to ip resolution ipv4, not asynchronous. */ static bool u2ip(const std::string&, ipaddr_t&); static bool u2ip(const std::string&, struct sockaddr_in& sa, int ai_flags = 0); + #ifdef ENABLE_IPV6 #ifdef IPPROTO_IPV6 /** Hostname to ip resolution ipv6, not asynchronous. */ @@ -86,10 +101,13 @@ public: static bool u2ip(const std::string&, struct sockaddr_in6& sa, int ai_flags = 0); #endif #endif + /** Reverse lookup of address to hostname */ static bool reverse(struct sockaddr *sa, socklen_t sa_len, std::string&, int flags = 0); 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); + /** Convert binary ip address to string: ipv4. */ static void l2ip(const ipaddr_t,std::string& ); static void l2ip(const in_addr&,std::string& ); @@ -97,6 +115,7 @@ public: #ifdef IPPROTO_IPV6 /** Convert binary ip address to string: ipv6. */ static void l2ip(const struct in6_addr&,std::string& ,bool mixed = false); + /** ipv6 address compare. */ static int in6_addr_compare(in6_addr,in6_addr); #endif @@ -129,15 +148,22 @@ public: /** Convert sockaddr struct to human readable string. \param sa Ptr to sockaddr struct */ static std::string Sa2String(struct sockaddr *sa); + /** Get current time in sec/microseconds. */ static void GetTime(struct timeval *); + static std::auto_ptr<SocketAddress> CreateAddress(struct sockaddr *,socklen_t); + static unsigned long ThreadID(); + static std::string ToLower(const std::string& str); static std::string ToUpper(const std::string& str); + static std::string ToString(double d); + /** Returns a random 32-bit integer */ static unsigned long Rnd(); + private: static std::string m_host; ///< local hostname static ipaddr_t m_ip; ///< local ip address @@ -151,8 +177,11 @@ private: static bool m_local_resolved; ///< ResolveLocal has been called if true }; + #ifdef SOCKETS_NAMESPACE } #endif + #endif // _SOCKETS_Utility_H + |