00001 // -*- c++ -*- 00002 //------------------------------------------------------------------------------ 00003 // INETAddress.h 00004 //------------------------------------------------------------------------------ 00005 // Copyright (c) 1999 by 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 INET_ADDRESS_H 00013 #define INET_ADDRESS_H 00014 00015 #include <vector> 00016 using std::vector; 00017 00018 #include "assa/Address.h" 00019 00020 namespace ASSA { 00021 00027 class INETAddress : public Address { 00028 public: 00030 enum Protocol { 00031 TCP, 00032 UDP 00033 }; 00034 00035 public: 00037 INETAddress (); 00038 00045 INETAddress (struct in_addr * haddr_, int port_); 00046 00053 INETAddress(const char* host_, int port_); 00054 00063 INETAddress (const char* host_, const char* service_, 00064 Protocol protocol_ = TCP); 00065 00071 INETAddress (int port_); 00072 00093 INETAddress (const char* address_, Protocol protocol_ = TCP); 00094 00096 INETAddress (SA_IN* address_); 00097 00099 INETAddress (SA* address_); 00100 00102 ~INETAddress () { 00103 // trace_with_mask("INETAddress::~INETAddress",SOCKTRACE); 00104 } 00105 00107 const int getLength () const { return sizeof (m_address); } 00108 00110 SA* getAddress () const { return (SA*) &m_address; } 00111 00113 string getHostName (); 00114 00116 int getPort () const { return ntohs (m_address.sin_port); } 00117 00119 void dump (); 00120 00128 static string 00129 get_fully_qualified_domain_name (vector<string>& aliases_); 00130 00131 private: 00148 void createHostPort (const char* host_, int port_); 00149 00160 int getServiceByName (string serv_, Protocol prot_ = TCP); 00161 00164 void init (); 00165 00166 private: 00168 static string m_fqdn_cache; 00169 00170 private: 00172 SA_IN m_address; 00173 }; 00174 00175 00176 } // end namespace ASSA 00177 00178 #endif /* INET_ADDRESS_H */