nidas v1.2.3
Inet4Address.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2006, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26
27#ifndef NIDAS_UTIL_INET4ADDRESS
28#define NIDAS_UTIL_INET4ADDRESS
29
31#include "ThreadSupport.h"
32
33#include <arpa/inet.h>
34
35#include <string>
36#include <list>
37#include <map>
38
39namespace nidas { namespace util {
40
47public:
57 static std::list<Inet4Address> getAllByName(const std::string& hostname);
58
64 static Inet4Address getByName(const std::string& hostname);
65
74 static std::string getHostName(const Inet4Address& addr);
75
80
84 Inet4Address(const struct in_addr*);
85
89 Inet4Address(unsigned int addr);
90
94 std::string getHostAddress() const;
95
100 std::string getHostName() const throw();
101
105 const struct in_addr* getInAddrPtr() const { return &_inaddr; }
106
114 const struct in_addr getInAddr() const { return _inaddr; }
115
119 bool operator < (const Inet4Address& x) const {
120 return ntohl(_inaddr.s_addr) < ntohl(x._inaddr.s_addr);
121 }
122
126 bool operator == (const Inet4Address& x) const {
127 return _inaddr.s_addr == x._inaddr.s_addr;
128 }
129
133 bool operator != (const Inet4Address& x) const {
134 return _inaddr.s_addr != x._inaddr.s_addr;
135 }
136
142 bool isMultiCastAddress() const {
143 return (ntohl(_inaddr.s_addr) & 0xf0000000L) == 0xe0000000L;
144 }
145
149 int bitsMatch(const Inet4Address& x) const throw();
150
151protected:
152
156 struct in_addr _inaddr;
157
158};
159
160}} // namespace nidas namespace util
161
162#endif
Support for IP version 4 host address.
Definition Inet4Address.h:46
const struct in_addr getInAddr() const
Get the structure containing the 4 byte internet version 4 address.
Definition Inet4Address.h:114
static std::list< Inet4Address > getAllByName(const std::string &hostname)
Static method returning a list of addresses for a name.
Definition Inet4Address.cc:133
struct in_addr _inaddr
The IP address, in network byte order.
Definition Inet4Address.h:156
const struct in_addr * getInAddrPtr() const
Return const pointer to struct in_addr.
Definition Inet4Address.h:105
bool operator!=(const Inet4Address &x) const
Inequality operator for addresses.
Definition Inet4Address.h:133
bool operator==(const Inet4Address &x) const
Equality operator for addresses.
Definition Inet4Address.h:126
Inet4Address()
Default constructor.
Definition Inet4Address.cc:41
std::string getHostName() const
Return a hostname for this address.
Definition Inet4Address.cc:62
std::string getHostAddress() const
Return string containing address in dot notation: w.x.y.z.
Definition Inet4Address.cc:55
bool operator<(const Inet4Address &x) const
Comparator operator for addresses.
Definition Inet4Address.h:119
bool isMultiCastAddress() const
Is this address a multicast address? Multicast addresses are in the range 224.0.0....
Definition Inet4Address.h:142
int bitsMatch(const Inet4Address &x) const
How many leading bits match in the two addresses?
Definition Inet4Address.cc:187
static Inet4Address getByName(const std::string &hostname)
Return an address of a name, the first one found by getAllByName.
Definition Inet4Address.cc:175
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31