Commit 34d65e22 authored by Martin Sustrik's avatar Martin Sustrik

Tero Marttila's Ipv6 patch - part I.

parent 6edec4fe
...@@ -127,7 +127,6 @@ zmq::fd_signaler_t::fd_signaler_t () ...@@ -127,7 +127,6 @@ zmq::fd_signaler_t::fd_signaler_t ()
memset (&addr, 0, sizeof (addr)); memset (&addr, 0, sizeof (addr));
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
//resolve_ip_hostname (&addr, "127.0.0.1:0");
addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
addr.sin_port = 0; addr.sin_port = 0;
......
...@@ -245,8 +245,10 @@ static int resolve_nic_name (in_addr* addr_, char const *interface_) ...@@ -245,8 +245,10 @@ static int resolve_nic_name (in_addr* addr_, char const *interface_)
#endif #endif
int zmq::resolve_ip_interface (sockaddr_in* addr_, char const *interface_) int zmq::resolve_ip_interface (sockaddr_storage* addr_, char const *interface_)
{ {
sockaddr_in *addr = (sockaddr_in*) addr_;
// Find the ':' that separates NIC name from port. // Find the ':' that separates NIC name from port.
const char *delimiter = strchr (interface_, ':'); const char *delimiter = strchr (interface_, ':');
if (!delimiter) { if (!delimiter) {
...@@ -255,17 +257,17 @@ int zmq::resolve_ip_interface (sockaddr_in* addr_, char const *interface_) ...@@ -255,17 +257,17 @@ int zmq::resolve_ip_interface (sockaddr_in* addr_, char const *interface_)
} }
// Clean the structure and fill in protocol family. // Clean the structure and fill in protocol family.
memset (addr_, 0, sizeof (sockaddr_in)); memset (addr, 0, sizeof (sockaddr_in));
addr_->sin_family = AF_INET; addr->sin_family = AF_INET;
// Resolve the name of the NIC. // Resolve the name of the NIC.
std::string nic_name (interface_, delimiter - interface_); std::string nic_name (interface_, delimiter - interface_);
if (resolve_nic_name (&addr_->sin_addr, nic_name.c_str ()) != 0) if (resolve_nic_name (&addr->sin_addr, nic_name.c_str ()) != 0)
return -1; return -1;
// Resolve the port. // Resolve the port.
addr_->sin_port = htons ((uint16_t) atoi (delimiter + 1)); addr->sin_port = htons ((uint16_t) atoi (delimiter + 1));
if (!addr_->sin_port) { if (!addr->sin_port) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
...@@ -273,8 +275,10 @@ int zmq::resolve_ip_interface (sockaddr_in* addr_, char const *interface_) ...@@ -273,8 +275,10 @@ int zmq::resolve_ip_interface (sockaddr_in* addr_, char const *interface_)
return 0; return 0;
} }
int zmq::resolve_ip_hostname (sockaddr_in *addr_, const char *hostname_) int zmq::resolve_ip_hostname (sockaddr_storage *addr_, const char *hostname_)
{ {
sockaddr_in *addr = (sockaddr_in*) addr_;
// Find the ':' that separates hostname name from port. // Find the ':' that separates hostname name from port.
const char *delimiter = strchr (hostname_, ':'); const char *delimiter = strchr (hostname_, ':');
if (!delimiter) { if (!delimiter) {
...@@ -297,12 +301,12 @@ int zmq::resolve_ip_hostname (sockaddr_in *addr_, const char *hostname_) ...@@ -297,12 +301,12 @@ int zmq::resolve_ip_hostname (sockaddr_in *addr_, const char *hostname_)
return -1; return -1;
} }
zmq_assert (res->ai_addr->sa_family == AF_INET); zmq_assert (res->ai_addr->sa_family == AF_INET);
memcpy (addr_, res->ai_addr, sizeof (sockaddr_in)); memcpy (addr, res->ai_addr, sizeof (sockaddr_in));
freeaddrinfo (res); freeaddrinfo (res);
// Fill in the port number. // Fill in the port number.
addr_->sin_port = htons ((uint16_t) atoi (delimiter + 1)); addr->sin_port = htons ((uint16_t) atoi (delimiter + 1));
if (!addr_->sin_port) { if (!addr->sin_port) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
......
...@@ -41,15 +41,15 @@ namespace zmq ...@@ -41,15 +41,15 @@ namespace zmq
// Resolves network interface name in <nic-name>:<port> format. Symbol "*" // Resolves network interface name in <nic-name>:<port> format. Symbol "*"
// (asterisk) resolves to INADDR_ANY (all network interfaces). // (asterisk) resolves to INADDR_ANY (all network interfaces).
int resolve_ip_interface (sockaddr_in* addr_, char const *interface_); int resolve_ip_interface (sockaddr_storage *addr_, char const *interface_);
// This function resolves a string in <hostname>:<port-number> format. // This function resolves a string in <hostname>:<port-number> format.
// Hostname can be either the name of the host or its IP address. // Hostname can be either the name of the host or its IP address.
int resolve_ip_hostname (sockaddr_in *addr_, const char *hostname_); int resolve_ip_hostname (sockaddr_storage *addr_, const char *hostname_);
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
// This function sets up the sockaddr_un structure with the pathname_ // This function sets up the sockaddr_un structure with the pathname_
int resolve_local_path( sockaddr_un * addr_, const char* pathname_); int resolve_local_path (sockaddr_un *addr_, const char* pathname_);
#endif #endif
} }
......
...@@ -45,7 +45,7 @@ zmq::tcp_connecter_t::~tcp_connecter_t () ...@@ -45,7 +45,7 @@ zmq::tcp_connecter_t::~tcp_connecter_t ()
int zmq::tcp_connecter_t::set_address (const char *protocol_, const char *addr_) int zmq::tcp_connecter_t::set_address (const char *protocol_, const char *addr_)
{ {
if (strcmp (protocol_, "tcp") == 0) if (strcmp (protocol_, "tcp") == 0)
return resolve_ip_hostname ((sockaddr_in*) &addr, addr_); return resolve_ip_hostname (&addr, addr_);
errno = EPROTONOSUPPORT; errno = EPROTONOSUPPORT;
return -1; return -1;
...@@ -56,7 +56,7 @@ int zmq::tcp_connecter_t::open () ...@@ -56,7 +56,7 @@ int zmq::tcp_connecter_t::open ()
zmq_assert (s == retired_fd); zmq_assert (s == retired_fd);
// Create the socket. // Create the socket.
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); s = socket (addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
if (s == INVALID_SOCKET) { if (s == INVALID_SOCKET) {
wsa_error_to_errno (); wsa_error_to_errno ();
return -1; return -1;
...@@ -74,7 +74,7 @@ int zmq::tcp_connecter_t::open () ...@@ -74,7 +74,7 @@ int zmq::tcp_connecter_t::open ()
wsa_assert (rc != SOCKET_ERROR); wsa_assert (rc != SOCKET_ERROR);
// Connect to the remote peer. // Connect to the remote peer.
rc = ::connect (s, (sockaddr*) &addr, sizeof (sockaddr_in)); rc = ::connect (s, (sockaddr*) &addr, sizeof (addr));
// Connect was successfull immediately. // Connect was successfull immediately.
if (rc == 0) if (rc == 0)
...@@ -153,7 +153,7 @@ zmq::tcp_connecter_t::~tcp_connecter_t () ...@@ -153,7 +153,7 @@ zmq::tcp_connecter_t::~tcp_connecter_t ()
int zmq::tcp_connecter_t::set_address (const char *protocol_, const char *addr_) int zmq::tcp_connecter_t::set_address (const char *protocol_, const char *addr_)
{ {
if (strcmp (protocol_, "tcp") == 0) if (strcmp (protocol_, "tcp") == 0)
return resolve_ip_hostname ((struct sockaddr_in*)&addr, addr_); return resolve_ip_hostname (&addr, addr_);
else if (strcmp (protocol_, "ipc") == 0) else if (strcmp (protocol_, "ipc") == 0)
return resolve_local_path (( struct sockaddr_un*)&addr, addr_); return resolve_local_path (( struct sockaddr_un*)&addr, addr_);
...@@ -166,10 +166,10 @@ int zmq::tcp_connecter_t::open () ...@@ -166,10 +166,10 @@ int zmq::tcp_connecter_t::open ()
zmq_assert (s == retired_fd); zmq_assert (s == retired_fd);
struct sockaddr *sa = (struct sockaddr*) &addr; struct sockaddr *sa = (struct sockaddr*) &addr;
if (AF_INET == sa->sa_family) { if (AF_UNIX != sa->sa_family) {
// Create the socket. // Create the socket.
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); s = socket (sa->sa_family, SOCK_STREAM, IPPROTO_TCP);
if (s == -1) if (s == -1)
return -1; return -1;
...@@ -193,7 +193,7 @@ int zmq::tcp_connecter_t::open () ...@@ -193,7 +193,7 @@ int zmq::tcp_connecter_t::open ()
#endif #endif
// Connect to the remote peer. // Connect to the remote peer.
rc = ::connect (s, (struct sockaddr*) &addr, sizeof (sockaddr_in)); rc = ::connect (s, (struct sockaddr*) &addr, sizeof (addr));
// Connect was successfull immediately. // Connect was successfull immediately.
if (rc == 0) if (rc == 0)
...@@ -211,9 +211,10 @@ int zmq::tcp_connecter_t::open () ...@@ -211,9 +211,10 @@ int zmq::tcp_connecter_t::open ()
errno = err; errno = err;
return -1; return -1;
} }
else if (AF_UNIX == sa->sa_family) { else {
// Create the socket. // Create the socket.
zmq_assert (AF_UNIX == sa->sa_family);
s = socket (AF_UNIX, SOCK_STREAM, 0); s = socket (AF_UNIX, SOCK_STREAM, 0);
if (s == -1) if (s == -1)
return -1; return -1;
......
...@@ -58,7 +58,7 @@ namespace zmq ...@@ -58,7 +58,7 @@ namespace zmq
private: private:
// Address to connect to. // Address to connect to.
sockaddr_in addr; sockaddr_storage addr;
// Underlying socket. // Underlying socket.
fd_t s; fd_t s;
......
...@@ -50,12 +50,12 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_) ...@@ -50,12 +50,12 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_)
} }
// Convert the interface into sockaddr_in structure. // Convert the interface into sockaddr_in structure.
int rc = resolve_ip_interface ((sockaddr_in*) &addr, addr_); int rc = resolve_ip_interface (&addr, addr_);
if (rc != 0) if (rc != 0)
return rc; return rc;
// Create a listening socket. // Create a listening socket.
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); s = socket (addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
if (s == INVALID_SOCKET) { if (s == INVALID_SOCKET) {
wsa_error_to_errno (); wsa_error_to_errno ();
return -1; return -1;
...@@ -73,7 +73,7 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_) ...@@ -73,7 +73,7 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_)
wsa_assert (rc != SOCKET_ERROR); wsa_assert (rc != SOCKET_ERROR);
// Bind the socket to the network interface and port. // Bind the socket to the network interface and port.
rc = bind (s, (struct sockaddr*) &addr, sizeof (sockaddr_in)); rc = bind (s, (struct sockaddr*) &addr, sizeof (addr));
if (rc == SOCKET_ERROR) { if (rc == SOCKET_ERROR) {
wsa_error_to_errno (); wsa_error_to_errno ();
return -1; return -1;
...@@ -157,13 +157,13 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_) ...@@ -157,13 +157,13 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_)
{ {
if (strcmp (protocol_, "tcp") == 0 ) { if (strcmp (protocol_, "tcp") == 0 ) {
// Convert the interface into sockaddr_in structure. // Resolve the sockaddr to bind to.
int rc = resolve_ip_interface ((struct sockaddr_in*) &addr, addr_); int rc = resolve_ip_interface (&addr, addr_);
if (rc != 0) if (rc != 0)
return -1; return -1;
// Create a listening socket. // Create a listening socket.
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); s = socket (addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
if (s == -1) if (s == -1)
return -1; return -1;
...@@ -180,7 +180,7 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_) ...@@ -180,7 +180,7 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_)
errno_assert (rc != -1); errno_assert (rc != -1);
// Bind the socket to the network interface and port. // Bind the socket to the network interface and port.
rc = bind (s, (struct sockaddr*) &addr, sizeof (sockaddr_in)); rc = bind (s, (struct sockaddr*) &addr, sizeof (addr));
if (rc != 0) { if (rc != 0) {
close (); close ();
return -1; return -1;
...@@ -305,7 +305,7 @@ zmq::fd_t zmq::tcp_listener_t::accept () ...@@ -305,7 +305,7 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
errno_assert (rc != -1); errno_assert (rc != -1);
struct sockaddr *sa = (struct sockaddr*) &addr; struct sockaddr *sa = (struct sockaddr*) &addr;
if (AF_INET == sa->sa_family) { if (AF_UNIX != sa->sa_family) {
// Disable Nagle's algorithm. // Disable Nagle's algorithm.
int flag = 1; int flag = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment