libzmq master
The Intelligent Transport Layer

tcp_address.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2009-2011 250bpm s.r.o.
00003     Copyright (c) 2007-2009 iMatix Corporation
00004     Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
00005 
00006     This file is part of 0MQ.
00007 
00008     0MQ is free software; you can redistribute it and/or modify it under
00009     the terms of the GNU Lesser General Public License as published by
00010     the Free Software Foundation; either version 3 of the License, or
00011     (at your option) any later version.
00012 
00013     0MQ is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public License
00019     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #ifndef __ZMQ_TCP_ADDRESS_HPP_INCLUDED__
00023 #define __ZMQ_TCP_ADDRESS_HPP_INCLUDED__
00024 
00025 #include "platform.hpp"
00026 
00027 #if defined ZMQ_HAVE_WINDOWS
00028 #include "windows.hpp"
00029 #else
00030 #include <sys/socket.h>
00031 #include <netinet/in.h>
00032 #endif
00033 
00034 namespace zmq
00035 {
00036 
00037     class tcp_address_t
00038     {
00039     public:
00040 
00041         tcp_address_t ();
00042         ~tcp_address_t ();
00043 
00044         //  This function translates textual TCP address into an address
00045         //  strcuture. If 'local' is true, names are resolved as local interface
00046         //  names. If it is false, names are resolved as remote hostnames.
00047         //  If 'ipv4only' is true, the name will never resolve to IPv6 address.
00048         int resolve (const char* name_, bool local_, bool ipv4only_);
00049 
00050 #if defined ZMQ_HAVE_WINDOWS
00051         unsigned short family ();
00052 #else
00053         sa_family_t family ();
00054 #endif
00055         sockaddr *addr ();
00056         socklen_t addrlen ();
00057 
00058     private:
00059 
00060         int resolve_nic_name (const char *nic_, bool ipv4only_);
00061         int resolve_interface (const char *interface_, bool ipv4only_);
00062         int resolve_hostname (const char *hostname_, bool ipv4only_);
00063 
00064         union {
00065             sockaddr generic;
00066             sockaddr_in ipv4;
00067             sockaddr_in6 ipv6;
00068         } address;
00069 
00070         tcp_address_t (const tcp_address_t&);
00071         const tcp_address_t &operator = (const tcp_address_t&);
00072     };
00073     
00074 }
00075 
00076 #endif
00077 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines