Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

pnetdb.h

Go to the documentation of this file.
00001 /*
00002  *   P::Classes - Portable C++ Application Framework
00003  *   Copyright (C) 2000-2004  Christian Prochnow <cproch@seculogix.de>
00004  *
00005  *   This library is free software; you can redistribute it and/or
00006  *   modify it under the terms of the GNU Lesser General Public
00007  *   License as published by the Free Software Foundation; either
00008  *   version 2 of the License, or (at your option) any later version.
00009  *
00010  *   This library is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *   Lesser General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU Lesser General Public
00016  *   License along with this library; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef _pnetdb_h_
00021 #define _pnetdb_h_
00022 
00023 #include <pclasses/pexport.h>
00024 #include <pclasses/pexception.h>
00025 #include <pclasses/psocket.h>
00026 #include <string>
00027 #include <vector>
00028 
00029 struct hostent;
00030 struct servent;
00031 
00032 namespace P {
00033 
00035 
00039 class PNET_EXPORT NetDbError: public RuntimeError {
00040   public:
00041     inline NetDbError(int err, const char* _what, const SourceInfo& _si) throw()
00042       : RuntimeError(_what,_si), m_err(err) {}
00043 
00044     inline BaseError* clone() const
00045     { return new NetDbError(*this); }
00046 
00047     inline int error() const throw()
00048     { return m_err; }
00049 
00050     std::string text() const throw();
00051 
00052   private:
00053     int m_err;
00054 };
00055 
00057 
00061 class PNET_EXPORT NetDb {
00062   public:
00063 
00065 
00069     class PNET_EXPORT HostEntry {
00070       friend class NetDb;
00071 
00072       public:
00073         HostEntry();
00074         HostEntry(const HostEntry& h);
00075         HostEntry(const hostent* h);
00076         ~HostEntry();
00077 
00078         inline int domain() const
00079         { return m_domain; }
00080 
00081         inline const std::string& name() const
00082         { return m_name; }
00083 
00084         inline const std::string& alias(int num) const
00085         { return m_aliases[num]; }
00086 
00087         inline const NetworkAddress& addr(int num) const
00088         { return *m_addrs[num]; }
00089 
00090         inline int addrCount() const
00091         { return m_addrs.size(); }
00092 
00093         HostEntry& operator=(const HostEntry& h);
00094 
00095       private:
00096         int                          m_domain;
00097         std::string                  m_name;
00098         std::vector<std::string>     m_aliases;
00099         std::vector<NetworkAddress*> m_addrs;
00100     };
00101 
00103 
00107     class PNET_EXPORT ServiceEntry {
00108       friend class NetDb;
00109       
00110       public:
00111         ServiceEntry();
00112         ServiceEntry(const ServiceEntry& s);
00113         ServiceEntry(const servent* s);
00114         ~ServiceEntry();
00115         
00116         inline const std::string& name() const
00117         { return m_name; }
00118 
00119         inline const std::string& alias(int num) const
00120         { return m_aliases[num]; }
00121 
00122         inline port_t port() const
00123         { return m_port; }
00124 
00125         inline const std::string& protocol() const
00126         { return m_proto; }
00127 
00128         ServiceEntry& operator=(const ServiceEntry& s);
00129 
00130       private:
00131         std::string     m_name;
00132         std::vector<
00133           std::string>  m_aliases;
00134         port_t          m_port;
00135         std::string     m_proto;
00136     };
00137 
00138 
00140     static HostEntry hostByName(const std::string& name, int domain) throw(NetDbError);
00141 
00143     static HostEntry hostByAddress(const NetworkAddress& addr) throw(NetDbError);
00144 
00146     static ServiceEntry serviceByName(const std::string& name, const std::string& proto) throw(NetDbError);
00147 
00149     static ServiceEntry serviceByPort(port_t port, const std::string& proto) throw(NetDbError);
00150 
00151 };
00152 
00153 }
00154 
00155 #endif

Generated on Fri Mar 12 21:08:31 2004 for P::Classes by doxygen 1.3.3