nidas v1.2.3
Inet4SocketAddress.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_INETSOCKETADDRESS
28#define NIDAS_UTIL_INETSOCKETADDRESS
29
30#include "SocketAddress.h"
31#include "Inet4Address.h"
32
33namespace nidas { namespace util {
34
42public:
43
48
53
55
56 Inet4SocketAddress(const struct sockaddr_in* _sockaddr);
57
62
67
72
76 int getFamily() const { return _sockaddr.sin_family; }
77
81 int getPort() const { return ntohs(_sockaddr.sin_port); }
82
86 void setPort(int val) { _sockaddr.sin_port = htons((short)val); }
87
92 return Inet4Address(&_sockaddr.sin_addr);
93 }
94
101 struct sockaddr* getSockAddrPtr() { return (struct sockaddr*) &_sockaddr; }
102
106 const struct sockaddr* getConstSockAddrPtr() const
107 {
108 return (const struct sockaddr*) &_sockaddr;
109 }
110
111 socklen_t getSockAddrLen() const { return sizeof(_sockaddr); }
112
116 std::string toString() const;
117
121 std::string toAddressString() const;
122
127 bool operator < (const Inet4SocketAddress& x) const;
128
132 bool operator == (const Inet4SocketAddress& x) const;
133
134protected:
135 struct sockaddr_in _sockaddr;
136};
137
138}} // namespace nidas namespace util
139
140#endif
Support for IP version 4 host address.
Definition Inet4Address.h:46
A IP version 4 socket address, containing a host address, and a port number.
Definition Inet4SocketAddress.h:41
std::string toString() const
Java style toString: returns "inet:hostname:port".
Definition Inet4SocketAddress.cc:84
bool operator==(const Inet4SocketAddress &x) const
Equality operator for addresses.
Definition Inet4SocketAddress.cc:115
struct sockaddr * getSockAddrPtr()
Provide non-const pointer to struct sockaddr_in.
Definition Inet4SocketAddress.h:101
socklen_t getSockAddrLen() const
Return the length of the struct sockaddr_XX for this address family.
Definition Inet4SocketAddress.h:111
Inet4SocketAddress()
Default constructor, address of 0.0.0.0 (INADDR_ANY), port 0.
Definition Inet4SocketAddress.cc:35
bool operator<(const Inet4SocketAddress &x) const
Comparator operator for addresses.
Definition Inet4SocketAddress.cc:104
Inet4Address getInet4Address() const
Return the IP address portion.
Definition Inet4SocketAddress.h:91
Inet4SocketAddress & operator=(const Inet4SocketAddress &x)
Assignment operator.
Definition Inet4SocketAddress.cc:69
Inet4SocketAddress * clone() const
Virtual constructor.
Definition Inet4SocketAddress.cc:79
int getPort() const
Return the port number.
Definition Inet4SocketAddress.h:81
void setPort(int val)
Set the port number.
Definition Inet4SocketAddress.h:86
const struct sockaddr * getConstSockAddrPtr() const
Provide const pointer to struct sockaddr_in.
Definition Inet4SocketAddress.h:106
int getFamily() const
Return the address family, AF_INET.
Definition Inet4SocketAddress.h:76
struct sockaddr_in _sockaddr
Definition Inet4SocketAddress.h:135
std::string toAddressString() const
Java style toString, but no DNS lookup: returns "inet:w.x.y.z:port".
Definition Inet4SocketAddress.cc:92
An interface for a socket address.
Definition SocketAddress.h:36
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
static n_u::SerialPort port
Definition sing.cc:68