00001 // LICENSE: (Please see the file COPYING for details) 00002 // 00003 // NUS - Nemesis Utilities System: A C++ application development framework 00004 // Copyright (C) 2006, 2008 Otavio Rodolfo Piske 00005 // 00006 // This file is part of NUS 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Lesser General Public 00010 // License as published by the Free Software Foundation version 2.1 00011 // of the License. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Lesser General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Lesser General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 // 00022 #ifndef NHOSTADDRESS_H 00023 #define NHOSTADDRESS_H 00024 00032 #include "ndefs.h" 00033 #include "nobject.h" 00034 #include "nstring.h" 00035 #include "nlist.h" 00036 #include "nbaseexceptions.h" 00037 #include "nnetworkexception.h" 00038 00039 #include <netdb.h> 00040 #include <sys/socket.h> 00041 #include <netinet/in.h> 00042 #include <arpa/inet.h> 00043 #include <climits> 00044 00048 class NHostAddress: public NObject { 00049 public: 00053 NHostAddress(void); 00054 00059 NHostAddress(const NString &addr); 00060 00066 NHostAddress(const NHostAddress &addr); 00067 00072 NHostAddress(const sockaddr *addr); 00073 00077 void clear(void); 00078 00085 void setAddress(nuint32 ip); 00086 00092 void setAddress(const NString &addr); 00093 00100 void setAddress(const sockaddr *sock); 00101 00112 nuint32 resolve(void) const; 00113 00118 NString toString(void) const; 00119 00125 static NString toString(nuint32 ip); 00126 00131 NString address(void) const; 00132 00137 NList<NString> aliases(void); 00138 00145 NList<nuint32> addresses(void); 00146 00151 bool isNull(void) const; 00152 00157 bool isLocalhost(void) const; 00158 00164 NHostAddress &operator=(const NHostAddress &rhs); 00165 00171 NHostAddress &operator=(const NString &rhs); 00172 00173 private: 00174 NString m_addr; 00175 mutable struct hostent m_host; 00176 00177 void throwErrorByCode(int herr) const; 00178 00179 }; 00180 00181 #endif // NHOSTADDRESS_H