Go to the documentation of this file.00001
00002
00003
00004
00005 #pragma once
00006
00007 #include "../base/Setup.h"
00008
00009 #ifdef MPMA_COMPILE_NET
00010
00011 #include "../base/Types.h"
00012
00013 #include <string>
00014
00016 namespace NET
00017 {
00019 class Address
00020 {
00021 public:
00023 inline Address()
00024 {
00025 ZeroOut();
00026 }
00027
00029 inline Address(const std::string &addressColonPort)
00030 {
00031 ZeroOut();
00032 SetAddress(addressColonPort);
00033 }
00034
00036 inline Address(const std::string &addressString, uint16 portNumber)
00037 {
00038 ZeroOut();
00039 SetAddress(addressString);
00040 port=portNumber;
00041 }
00042
00044 std::string GetIPString() const;
00045
00047 inline nuint GetIP() const
00048 {
00049 return ip;
00050 }
00051
00053 std::string GetIPPortString() const;
00054
00056 std::string GetNameString() const;
00057
00059 std::string GetNamePortString() const;
00060
00062 inline uint16 GetPort() const
00063 {
00064 return port;
00065 }
00066
00068 void SetAddress(const std::string &addressString);
00069
00071 inline void SetIP(uint32 ipValue)
00072 {
00073 ip=ipValue;
00074 name.clear();
00075 }
00076
00078 inline void SetPort(uint16 portNumber)
00079 {
00080 port=portNumber;
00081 }
00082
00084 inline bool operator==(const Address &o) const
00085 {
00086 return port==o.port && ip==o.ip;
00087 }
00088
00089 private:
00090 uint32 ip;
00091 uint16 port;
00092 mutable std::string name;
00093
00094
00095 inline void ZeroOut()
00096 {
00097 ip=0;
00098 name="0.0.0.0";
00099 port=0;
00100 }
00101
00102
00103 static uint32 DnsNameToIP(const std::string &sourceName);
00104 static std::string DnsIpToName(uint32 sourceIP);
00105
00106
00107 static uint32 ParseIPString(const std::string &ipstr);
00108 };
00109
00110
00111
00112
00113
00115 std::string GetLocalIP();
00116
00118 std::string GetNetworkBroadcastIP();
00119
00121 std::string GetDirectBroadcastIP();
00122 }
00123
00124 #endif //#ifdef MPMA_COMPILE_NET