libassa  3.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Address.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //------------------------------------------------------------------------------
3 // Address.h
4 //------------------------------------------------------------------------------
5 // Copyright (C) 1997 Vladislav Grinchenko
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //------------------------------------------------------------------------------
12 #ifndef ADDRESS_H
13 #define ADDRESS_H
14 
15 #if !defined (WIN32)
16 # include <netinet/in.h>
17 # include <netdb.h>
18 # include <sys/types.h>
19 # include <sys/socket.h>
20 # include <netinet/in.h>
21 # include <arpa/inet.h> // addresses handling
22 # include <sys/un.h>
23 #endif
24 
25 #include <string.h>
26 #include <errno.h>
27 
28 #include "assa/Logger.h"
29 #include "assa/Assure.h"
30 
31 namespace ASSA {
32 
33 typedef struct sockaddr SA; // stolen from R.Stevens
34 typedef struct sockaddr_in SA_IN;
35 
36 #if defined (WIN32)
37 struct sockaddr_un
38 {
39  short sun_family; /* AF_UNIX */
40  char sun_path [108]; /* Path name */
41 };
42 #endif
43 
44 typedef struct sockaddr_un SA_UN;
45 
51 class Address {
52 public:
54  enum addr_state_t {
55  goodbit=0,
56  badbit=1
57  };
58  typedef int addrstate;
59 
60 private:
61  unsigned char m_state;
62 
63 public:
65  Address () : m_state (Address::goodbit) { trace("Address::Address"); }
66 
68  virtual ~Address() {}
69 
73  bool good() const { return m_state == 0; }
74 
80  bool bad() const { return m_state & Address::badbit; }
81 
86  operator void* () const { return (void*) good (); }
87 
91  bool operator! () const { return bad (); }
92 
94 
95  virtual const int getLength() const = 0;
96 
98  virtual SA* getAddress() const = 0;
99 
101  virtual void dump ()
102  {
103  trace("Address");
104  DL((TRACE,"state - %s\n", good () ? "good" : "bad"));
105  }
106 
107 protected:
111  void setstate (addrstate flag_) { m_state |= flag_; }
112 };
113 
114 } // end namespace ASSA
115 
116 #endif /* ADDRESS_H */