Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

ip_address.h

Go to the documentation of this file.
00001 
00002 #ifndef header_ip_address
00003 #define header_ip_address
00004 
00006 
00007 #include <string>
00008 
00009 class CL_IPAddress
00010 //: Socket name; container class for an IP address and port.
00011 {
00013 public:
00014         CL_IPAddress();
00015         // Constructs an IP address using INADDR_ANY and port 0.
00016 
00017         CL_IPAddress(unsigned int address, unsigned short port);
00018         // Constructs an IP address using the passed address and port.
00019 
00020         CL_IPAddress(const std::string &hostname, unsigned short port);
00021         // Construct an IP address using a hostname.
00022 
00023         CL_IPAddress(const CL_IPAddress &copy);
00024         // Copy constructor.
00025 
00027 public:
00028         unsigned int get_address() const { return ip; }
00029         // Returns the IP address in network byte order.
00030 
00031         unsigned short get_port() const { return port; }
00032         // Returns the IP port in host byte order.
00033 
00034         unsigned char &operator[](int i) { return ((unsigned char*) &ip)[i]; }
00035         // Returns the specified address field.
00036 
00037         const unsigned char &operator[](int i) const { return ((unsigned char*) &ip)[i]; }
00038         // Returns the specified address field.
00039 
00041 public:
00042         void set_address(unsigned int new_ip) { ip = new_ip; }
00043         // Set the IP address, in network byte order.
00044 
00045         void set_address(const std::string &hostname);
00046         // Set the IP address using a hostname.
00047 
00048         void set_port(unsigned short new_port) { port = new_port; }
00049         // Set the IP port.
00050 
00051         std::string dns_lookup() const;
00052         // Do a DNS lookup on the IP address.
00053 
00055 private:
00056         unsigned int ip;
00057         // IP address in network byte order.
00058 
00059         unsigned short port;
00060         // IP port in host byte order.
00061 };
00062 
00063 #endif

Generated at Wed Apr 4 19:54:01 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001