# address.h

Go to the documentation of this file.

    00001 /* $Id: address.h 15163 2009-01-20 11:28:18Z rubidium $ */
    00002
    00005 #ifndef NETWORK_ADDRESS_H
    00006 #define NETWORK_ADDRESS_H
    00007
    00008 #ifdef ENABLE_NETWORK
    00009
    00010 #include "os_abstraction.h"
    00011
    00017 class NetworkAddress {
    00018 private:
    00019   bool resolved;
    00020   char *hostname;
    00021   uint32 ip;
    00022   uint16 port;
    00023
    00024 public:
    00030   NetworkAddress(in_addr_t ip, uint16 port) :
    00031     resolved(true),
    00032     hostname(NULL),
    00033     ip(ip),
    00034     port(port)
    00035   {
    00036   }
    00037
    00043   NetworkAddress(const char *hostname, uint16 port) :
    00044     resolved(false),
    00045     hostname(strdup(hostname)),
    00046     ip(0),
    00047     port(port)
    00048   {
    00049   }
    00050
    00055   NetworkAddress(const NetworkAddress &address) :
    00056     resolved(address.resolved),
    00057     hostname(address.hostname == NULL ? NULL : strdup(address.hostname)),
    00058     ip(address.ip),
    00059     port(address.port)
    00060   {
    00061   }
    00062
    00064   ~NetworkAddress()
    00065   {
    00066     free(hostname);
    00067   }
    00068
    00074   const char *GetHostname() const;
    00075
    00081   uint32 GetIP();
    00082
    00087   uint16 GetPort() const
    00088   {
    00089     return this->port;
    00090   }
    00091
    00096   bool IsResolved() const
    00097   {
    00098     return this->resolved;
    00099   }
    00100 };
    00101
    00102 #endif /* ENABLE_NETWORK */
    00103 #endif /* NETWORK_ADDRESS_H */