/home/vlg/develop/libASSA/libassa/assa/Address.h

Go to the documentation of this file.
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 #if !defined (WIN32)
00016 #  include <netinet/in.h>
00017 #  include <netdb.h>
00018 #  include <sys/types.h>
00019 #  include <sys/socket.h>
00020 #  include <netinet/in.h>
00021 #  include <arpa/inet.h>        // addresses handling
00022 #  include <sys/un.h>
00023 #endif
00024 
00025 #include <string.h>
00026 #include <errno.h>
00027 
00028 #include "assa/Logger.h"
00029 #include "assa/Assure.h"
00030 
00031 namespace ASSA {
00032 
00033 typedef struct sockaddr SA;           // stolen from R.Stevens
00034 typedef struct sockaddr_in SA_IN;
00035 
00036 #if defined (WIN32)
00037 struct sockaddr_un 
00038 {
00039     short sun_family;                 /* AF_UNIX   */
00040     char  sun_path [108];             /* Path name */
00041 };
00042 #endif
00043 
00044 typedef struct sockaddr_un SA_UN;   
00045 
00051 class Address {
00052 public:
00054     enum addr_state_t { 
00055         goodbit=0,              
00056         badbit=1                
00057     };
00058     typedef int addrstate;
00059 
00060 private:
00061     unsigned char m_state;
00062 
00063 public:
00065     Address () : m_state (Address::goodbit) { trace("Address::Address");    }
00066 
00068     virtual ~Address() {}
00069 
00073     bool good() const { return m_state == 0; }
00074 
00080     bool bad() const { return m_state & Address::badbit; }
00081 
00086     operator void* () const { return (void*) good (); }
00087 
00091     bool operator! () const { return bad (); }
00092     
00094 
00095     virtual const int getLength() const = 0;
00096 
00098     virtual SA* getAddress() const = 0;
00099     
00101     virtual void dump () 
00102         {   
00103             trace("Address");
00104             DL((TRACE,"state   - %s\n", good () ? "good" : "bad"));
00105         }
00106 
00107 protected:
00111     void setstate (addrstate flag_) { m_state |= flag_; }
00112 };
00113 
00114 } // end namespace ASSA
00115 
00116 #endif /* ADDRESS_H */

Generated on Sun Aug 13 15:08:00 2006 for libassa by  doxygen 1.4.6