All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Static Public Member Functions
GpCoreTools::Address Class Reference

Brief description of class still missing. More...

#include <Address.h>

List of all members.

Public Member Functions

 Address ()
 Address (in_addr_t a)
 Address (int index, const Address &subnet)
 Address (const Address &o)
void fromString (const char *a)
int index () const
bool isValid () const
bool operator!= (const Address &o) const
Address operator& (const Address &o) const
bool operator< (const Address &o) const
Address operator= (const Address &o)
bool operator== (const Address &o) const
bool operator> (const Address &o) const
Address subnet () const
std::string toString () const
in_addr_t value () const

Static Public Member Functions

static void identifyMe (const char *interface)
static const Addressmask ()
static int maskSize ()
static const Addressme ()
static void setMaskSize (int m)

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

{_value=0;}
GpCoreTools::Address::Address ( in_addr_t  a) [inline]
{_value=a;}
GpCoreTools::Address::Address ( int  index,
const Address subnet 
)

Description of constructor still missing

{
  _value=(index << _maskSize) | (subnet & _mask)._value;
}
GpCoreTools::Address::Address ( const Address o) [inline]
{_value=o._value;}

Member Function Documentation

void GpCoreTools::Address::fromString ( const char *  a) [inline]

Referenced by TimeRequest::exec(), identifyMe(), and main().

{_value=inet_addr(a);}
void GpCoreTools::Address::identifyMe ( const char *  interface) [static]

References fromString(), isValid(), toString(), and GpCoreTools::Log::write().

{
  _me._value=0;
  struct ifaddrs *ifaddr, *ifa;
  char host[NI_MAXHOST];
  if(getifaddrs(&ifaddr)==-1) {
    Log::write(2, "error getifaddrs: %s\n", strerror(errno));
  } else {
    // Walk through linked list, maintaining head pointer so we can free list later
    for(ifa=ifaddr; ifa!=NULL; ifa=ifa->ifa_next) {
      if(ifa->ifa_addr && ifa->ifa_addr->sa_family==AF_INET && strcmp(ifa->ifa_name, interface)==0) {
        if(getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)!=0) {
          Log::write(2, "error getnameinfo: %s\n", strerror(errno));
          break;
        }
        _me.fromString(host);
        break;
      }
    }
    freeifaddrs(ifaddr);
  }
  if(_me.isValid()) {
    Log::write(0, "running on host %s\n", _me.toString().data());
  }
}
bool GpCoreTools::Address::isValid ( ) const [inline]
static const Address& GpCoreTools::Address::mask ( ) [inline, static]
{return _mask;}
static int GpCoreTools::Address::maskSize ( ) [inline, static]
{return _maskSize;}
static const Address& GpCoreTools::Address::me ( ) [inline, static]

Referenced by GpCoreTools::UdpServerStream::send().

{return _me;}
bool GpCoreTools::Address::operator!= ( const Address o) const [inline]
{return _value!=o._value;}
Address GpCoreTools::Address::operator& ( const Address o) const [inline]

Referenced by subnet().

{return _value & o._value;}
bool GpCoreTools::Address::operator< ( const Address o) const [inline]
{return _value<o._value;}
Address GpCoreTools::Address::operator= ( const Address o) [inline]
{_value=o._value; return *this;}
bool GpCoreTools::Address::operator== ( const Address o) const [inline]
{return _value==o._value;}
bool GpCoreTools::Address::operator> ( const Address o) const [inline]
{return _value>o._value;}
void GpCoreTools::Address::setMaskSize ( int  m) [static]
{
  _mask=(0xFFFFFFFF) >> (32-m);
  _maskSize=m;
}

References operator&().

Referenced by GpCoreTools::UdpServerStream::send().

{return operator&(_mask);}
std::string GpCoreTools::Address::toString ( ) const [inline]
in_addr_t GpCoreTools::Address::value ( ) const [inline]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines