00001
00014
00015
00016 #ifndef IPADDRESS_H_
00017 #define IPADDRESS_H_
00018
00019 #ifdef _MSC_VER
00020 #pragma once
00021 #endif // MSVC
00022
00023 #include <iosfwd>
00024 #include <string>
00025 #include <memory>
00026
00027
00028 #include "SocketIncludes.h"
00029
00030
00032
00033
00034 class IpAddress
00035 {
00036 public:
00037
00038 IpAddress( unsigned long code = INADDR_ANY );
00039 IpAddress( const std::string& address );
00040 IpAddress( const in_addr& address );
00041 IpAddress( const IpAddress& address );
00042
00043
00044 ~IpAddress();
00045
00046
00047 IpAddress& operator=( const in_addr& address );
00048 IpAddress& operator=( const IpAddress& address );
00049
00050
00051 bool operator==( const IpAddress& address ) const;
00052 bool operator<( const IpAddress& address ) const;
00053
00054
00055 std::ostream& operator<<( std::ostream& stream) const;
00056
00057
00058 operator in_addr() const;
00059
00060
00061 unsigned long toLong() const throw();
00062
00063
00064 void set( const std::string& string );
00065 void set( unsigned long code ) throw();
00066 void setHostName( const std::string& hostName );
00067
00068
00069 bool isLocal() const;
00070
00071
00072 bool isDefined() const;
00073
00074
00075 static const IpAddress& getLocalIpAddress();
00076
00077 private:
00078
00079 struct in_addr ipAddress;
00080
00081
00082 static std::auto_ptr<IpAddress> localIpAddress;
00083 };
00084
00085
00086 #endif // IPADDRESS_H_
00087