libassa  3.5.1
INETAddress.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //------------------------------------------------------------------------------
3 // INETAddress.h
4 //------------------------------------------------------------------------------
5 // Copyright (c) 1999 by 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 INET_ADDRESS_H
13 #define INET_ADDRESS_H
14 
15 #include <vector>
16 using std::vector;
17 
18 #include "assa/Address.h"
19 
20 namespace ASSA {
21 
27 class INETAddress : public Address {
28 public:
30  enum Protocol {
31  TCP,
32  UDP
33  };
34 
35 public:
37  INETAddress ();
38 
45  INETAddress (struct in_addr * haddr_, int port_);
46 
53  INETAddress(const char* host_, int port_);
54 
63  INETAddress (const char* host_, const char* service_,
64  Protocol protocol_ = TCP);
65 
71  INETAddress (int port_);
72 
93  INETAddress (const char* address_, Protocol protocol_ = TCP);
94 
96  INETAddress (SA_IN* address_);
97 
99  INETAddress (SA* address_);
100 
103 // trace_with_mask("INETAddress::~INETAddress",SOCKTRACE);
104  }
105 
107  const int getLength () const { return sizeof (m_address); }
108 
110  SA* getAddress () const { return (SA*) &m_address; }
111 
113  string getHostName ();
114 
116  int getPort () const { return ntohs (m_address.sin_port); }
117 
119  void dump ();
120 
128  static string
129  get_fully_qualified_domain_name (vector<string>& aliases_);
130 
131 private:
148  void createHostPort (const char* host_, int port_);
149 
160  int getServiceByName (string serv_, Protocol prot_ = TCP);
161 
164  void init ();
165 
166 private:
168  static string m_fqdn_cache;
169 
170 private:
173 };
174 
175 
176 } // end namespace ASSA
177 
178 #endif /* INET_ADDRESS_H */
Address is an abstraction for INET or UNIX-domain address data type.
void init()
Perform initialization common to all ctors.
Definition: INETAddress.cpp:33
string getHostName()
Return host name.
void dump()
Dump the address content to log file.
static string get_fully_qualified_domain_name(vector< string > &aliases_)
Return fully-qualified host name.
SA * getAddress() const
Get hold of address structure.
Definition: INETAddress.h:110
~INETAddress()
Destructor.
Definition: INETAddress.h:102
INETAddress()
Default constructor.
Definition: INETAddress.cpp:39
int getServiceByName(string serv_, Protocol prot_=TCP)
Lookup port by its service name found in /etc/services.
int getPort() const
Return port.
Definition: INETAddress.h:116
void createHostPort(const char *host_, int port_)
Makes socket address out of host name and port.
@ UDP
UDP protocol.
Definition: INETAddress.h:32
@ TCP
TCP protocol.
Definition: INETAddress.h:31
SA_IN m_address
Internet address structure sockaddr_in.
Definition: INETAddress.h:172
static string m_fqdn_cache
Cached fully-qualified domain name.
Definition: INETAddress.h:168
const int getLength() const
Return address length.
Definition: INETAddress.h:107
Definition: Acceptor.h:40
struct sockaddr_in SA_IN
Definition: Address.h:34
struct sockaddr SA
Definition: Address.h:33