2011-08-18 17:40:42 +02:00
|
|
|
/*
|
2015-01-22 10:32:06 +01:00
|
|
|
Copyright (c) 2007-2015 Contributors as noted in the AUTHORS file
|
2011-08-18 17:40:42 +02:00
|
|
|
|
|
|
|
This file is part of 0MQ.
|
|
|
|
|
|
|
|
0MQ is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
0MQ is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ZMQ_TCP_ADDRESS_HPP_INCLUDED__
|
|
|
|
#define __ZMQ_TCP_ADDRESS_HPP_INCLUDED__
|
|
|
|
|
|
|
|
#include "platform.hpp"
|
|
|
|
|
2011-08-18 17:58:46 +02:00
|
|
|
#if defined ZMQ_HAVE_WINDOWS
|
|
|
|
#include "windows.hpp"
|
|
|
|
#else
|
2011-08-18 17:40:42 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
2011-08-18 17:58:46 +02:00
|
|
|
#endif
|
2011-08-18 17:40:42 +02:00
|
|
|
|
|
|
|
namespace zmq
|
|
|
|
{
|
|
|
|
|
|
|
|
class tcp_address_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
tcp_address_t ();
|
2012-04-18 21:42:11 +02:00
|
|
|
tcp_address_t (const sockaddr *sa, socklen_t sa_len);
|
2012-04-20 17:16:26 +02:00
|
|
|
virtual ~tcp_address_t ();
|
2011-08-18 17:40:42 +02:00
|
|
|
|
|
|
|
// This function translates textual TCP address into an address
|
|
|
|
// strcuture. If 'local' is true, names are resolved as local interface
|
|
|
|
// names. If it is false, names are resolved as remote hostnames.
|
2013-01-31 20:47:45 +01:00
|
|
|
// If 'ipv6' is true, the name may resolve to IPv6 address.
|
2014-04-30 14:43:37 +02:00
|
|
|
int resolve (const char *name_, bool local_, bool ipv6_, bool is_src_ = false);
|
2011-08-18 17:40:42 +02:00
|
|
|
|
2012-04-18 21:42:11 +02:00
|
|
|
// The opposite to resolve()
|
|
|
|
virtual int to_string (std::string &addr_);
|
|
|
|
|
2011-08-18 17:58:46 +02:00
|
|
|
#if defined ZMQ_HAVE_WINDOWS
|
2012-02-02 14:56:51 +01:00
|
|
|
unsigned short family () const;
|
2011-08-18 17:58:46 +02:00
|
|
|
#else
|
2012-02-02 14:56:51 +01:00
|
|
|
sa_family_t family () const;
|
2011-08-18 17:58:46 +02:00
|
|
|
#endif
|
2012-02-02 14:56:51 +01:00
|
|
|
const sockaddr *addr () const;
|
|
|
|
socklen_t addrlen () const;
|
2011-08-18 17:40:42 +02:00
|
|
|
|
2014-04-30 14:43:37 +02:00
|
|
|
const sockaddr *src_addr () const;
|
|
|
|
socklen_t src_addrlen () const;
|
|
|
|
bool has_src_addr () const;
|
|
|
|
|
2012-04-12 16:37:14 +02:00
|
|
|
protected:
|
2014-04-30 14:43:37 +02:00
|
|
|
int resolve_nic_name (const char *nic_, bool ipv6_, bool is_src_ = false);
|
|
|
|
int resolve_interface (const char *interface_, bool ipv6_, bool is_src_ = false);
|
|
|
|
int resolve_hostname (const char *hostname_, bool ipv6_, bool is_src_ = false);
|
2011-08-18 17:40:42 +02:00
|
|
|
|
|
|
|
union {
|
|
|
|
sockaddr generic;
|
|
|
|
sockaddr_in ipv4;
|
|
|
|
sockaddr_in6 ipv6;
|
|
|
|
} address;
|
2014-04-30 14:43:37 +02:00
|
|
|
|
|
|
|
union {
|
|
|
|
sockaddr generic;
|
|
|
|
sockaddr_in ipv4;
|
|
|
|
sockaddr_in6 ipv6;
|
|
|
|
} source_address;
|
|
|
|
bool _has_src_addr;
|
2012-04-12 16:37:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class tcp_address_mask_t : public tcp_address_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
tcp_address_mask_t ();
|
|
|
|
|
|
|
|
// This function enhances tcp_address_t::resolve() with ability to parse
|
|
|
|
// additional cidr-like(/xx) mask value at the end of the name string.
|
|
|
|
// Works only with remote hostnames.
|
2013-01-31 20:47:45 +01:00
|
|
|
int resolve (const char *name_, bool ipv6_);
|
2011-08-18 17:40:42 +02:00
|
|
|
|
2012-04-18 21:42:11 +02:00
|
|
|
// The opposite to resolve()
|
|
|
|
int to_string (std::string &addr_);
|
|
|
|
|
2012-08-28 01:05:51 +02:00
|
|
|
int mask () const;
|
2012-04-12 16:37:14 +02:00
|
|
|
|
2012-08-28 01:05:51 +02:00
|
|
|
bool match_address (const struct sockaddr *ss, const socklen_t ss_len) const;
|
2012-04-12 16:37:14 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
int address_mask;
|
2011-08-18 17:40:42 +02:00
|
|
|
};
|
2012-04-12 16:37:14 +02:00
|
|
|
|
2011-08-18 17:40:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|