Common.h

Go to the documentation of this file.
00001 
00002 //written by Luke Lenhart, 2007-2008
00003 //See /docs/License.txt for details on how this code may be used.
00004 
00005 #pragma once
00006 
00007 #include "../base/Types.h"
00008 #include <string>
00009 
00011 namespace NET
00012 {
00014     class Address
00015     {
00016     public:
00018         inline Address()
00019         {
00020             ZeroOut();
00021         }
00022 
00024         inline Address(const std::string &addressColonPort)
00025         {
00026             ZeroOut();
00027             SetAddress(addressColonPort);
00028         }
00029 
00031         inline Address(const std::string &addressString, uint16 portNumber)
00032         {
00033             ZeroOut();
00034             SetAddress(addressString);
00035             port=portNumber;
00036         }
00037 
00039         std::string GetIPString() const;
00040 
00042         inline uint GetIP() const
00043         {
00044             return ip;
00045         }
00046 
00048         std::string GetIPPortString() const;
00049 
00051         std::string GetNameString() const;
00052 
00054         std::string GetNamePortString() const;
00055 
00057         inline uint16 GetPort() const
00058         {
00059             return port;
00060         }
00061 
00063         void SetAddress(const std::string &addressString);
00064 
00066         inline void SetIP(uint32 ipValue)
00067         {
00068             ip=ipValue;
00069             name.clear();
00070         }
00071 
00073         inline void SetPort(uint16 portNumber)
00074         {
00075             port=portNumber;
00076         }
00077 
00079         inline bool operator==(const Address &o) const
00080         {
00081             return port==o.port && ip==o.ip;
00082         }
00083 
00084     private:
00085         uint32 ip;
00086         uint16 port;
00087         mutable std::string name; //cached dns name
00088 
00089         //resets all members to 0
00090         inline void ZeroOut()
00091         {
00092             ip=0;
00093             name="0.0.0.0";
00094             port=0;
00095         }
00096 
00097         //performs dns lookups
00098         static uint32 DnsNameToIP(const std::string &sourceName);
00099         static std::string DnsIpToName(uint32 sourceIP);
00100 
00101         //ip string to uint32
00102         static uint32 ParseIPString(const std::string &ipstr);
00103     };
00104 
00105     // -- common utility information
00106 
00107     //TODO: handle the case of multiple network adapters
00108 
00110     std::string GetLocalIP();
00111 
00113     std::string GetNetworkBroadcastIP();
00114 
00116     std::string GetDirectBroadcastIP();
00117 }

Generated on Sat Aug 9 15:05:05 2008 for MPMA Framework by  doxygen 1.5.6