00001 // -*- c++ -*- 00002 //------------------------------------------------------------------------------ 00003 // Address.h 00004 //------------------------------------------------------------------------------ 00005 // Copyright (C) 1997 Vladislav Grinchenko 00006 // 00007 // This library is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU Library General Public 00009 // License as published by the Free Software Foundation; either 00010 // version 2 of the License, or (at your option) any later version. 00011 //------------------------------------------------------------------------------ 00012 #ifndef ADDRESS_H 00013 #define ADDRESS_H 00014 00015 #include <netinet/in.h> 00016 #include <netdb.h> 00017 #include <sys/types.h> 00018 #include <sys/socket.h> 00019 #include <netinet/in.h> 00020 #include <arpa/inet.h> // addresses handling 00021 #include <sys/un.h> 00022 #include <string.h> 00023 #include <errno.h> 00024 00025 #include "assa/Logger.h" 00026 #include "assa/Assure.h" 00027 00028 namespace ASSA { 00029 00030 typedef struct sockaddr SA; // stolen from R.Stevens 00031 typedef struct sockaddr_in SA_IN; 00032 typedef struct sockaddr_un SA_UN; 00033 00039 class Address { 00040 public: 00042 enum addr_state_t { 00043 goodbit=0, 00044 badbit=1 00045 }; 00046 typedef int addrstate; 00047 00048 private: 00049 unsigned char m_state; 00050 00051 public: 00053 Address () : m_state (Address::goodbit) { trace("Address::Address"); } 00054 00056 virtual ~Address() {} 00057 00061 bool good() const { return m_state == 0; } 00062 00068 bool bad() const { return m_state & Address::badbit; } 00069 00074 operator void* () const { return (void*) good (); } 00075 00079 bool operator! () const { return bad (); } 00080 00082 00083 virtual const int getLength() const = 0; 00084 00086 virtual SA* getAddress() const = 0; 00087 00089 virtual void dump () 00090 { 00091 trace("Address"); 00092 DL((TRACE,"state - %s\n", good () ? "good" : "bad")); 00093 } 00094 00095 protected: 00099 void setstate (addrstate flag_) { m_state |= flag_; } 00100 }; 00101 00102 } // end namespace ASSA 00103 00104 #endif /* ADDRESS_H */