00001 // -*- C++ -*- 00002 // Represents a bidirectional connection to a socket. This is an abstract 00003 // class; you must instantiate an appropriate subclass (currently UDSConn 00004 // or TCPConn). 00005 // 00006 // ***** BEGIN LICENSE BLOCK ***** 00007 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 00008 // 00009 // The contents of this file are subject to the Mozilla Public License 00010 // Version 1.1 (the "License"); you may not use this file except in 00011 // compliance with the License. You may obtain a copy of the License at 00012 // http://www.mozilla.org/MPL/ 00013 // 00014 // Software distributed under the License is distributed on an "AS IS" 00015 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00016 // the License for the specific language governing rights and limitations 00017 // under the License. 00018 // 00019 // The Original Code is the consmgr network/serial-line monitoring package. 00020 // 00021 // The Initial Developer of the Original Code is Chris P. Ross. 00022 // Portions created by the Initial Developer are Copyright (C) 2000-2008 00023 // the Initial Developer. All Rights Reserved. 00024 // 00025 // Contributor(s): 00026 // Geoff Adams 00027 // 00028 // Alternatively, the contents of this file may be used under the terms of 00029 // either the GNU General Public License Version 2 or later (the "GPL"), or 00030 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 00031 // in which case the provisions of the GPL or the LGPL are applicable instead 00032 // of those above. If you wish to allow use of your version of this file only 00033 // under the terms of either the GPL or the LGPL, and not to allow others to 00034 // use your version of this file under the terms of the MPL, indicate your 00035 // decision by deleting the provisions above and replace them with the notice 00036 // and other provisions required by the GPL or the LGPL. If you do not delete 00037 // the provisions above, a recipient may use your version of this file under 00038 // the terms of any one of the MPL, the GPL or the LGPL. 00039 // 00040 // ***** END LICENSE BLOCK ***** 00041 00042 #ifndef __SOCKADDR_H 00043 #define __SOCKADDR_H 00044 00045 extern "C" { 00046 #include <sys/types.h> 00047 #include <netdb.h> 00048 #include <sys/socket.h> 00049 } 00050 00051 #include <loki/SmartPtr.h> 00052 00069 class SocketAddress { 00070 // Only our subclasses should be allowed to use our constructor(s). 00071 protected: 00072 SocketAddress(); 00073 SocketAddress(const struct sockaddr*); 00074 00075 public: 00076 virtual ~SocketAddress(); 00077 00081 const struct sockaddr *get_addr() const; 00082 00083 socklen_t length() const; 00084 int family() const; 00085 00086 // Generate an ID string to indicate what we're connected to... 00087 virtual std::string get_id() const = 0; 00088 00089 protected: 00091 void set_addr(const struct sockaddr*); 00092 00094 struct sockaddr_storage addr; 00095 00099 socklen_t sock_addrlen; 00100 }; 00101 00105 typedef Loki::SmartPtr<SocketAddress, 00106 Loki::RefCountedMTAdj<Loki::ObjectLevelLockable>::RefCountedMT> 00107 SocketAddressP; 00108 00111 #endif /* __SOCKADDR_H */