You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by qi...@apache.org on 2017/11/28 12:50:56 UTC
[2/4] mesos git commit: Made `mesos-tcp-connect` support IPv6.
Made `mesos-tcp-connect` support IPv6.
Review: https://reviews.apache.org/r/63795
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f9cb1891
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f9cb1891
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f9cb1891
Branch: refs/heads/master
Commit: f9cb1891a95466b20f9cb88b2a5887b4b99adaae
Parents: cd60edf
Author: Qian Zhang <zh...@gmail.com>
Authored: Tue Nov 14 16:28:09 2017 +0800
Committer: Qian Zhang <zh...@gmail.com>
Committed: Tue Nov 28 18:28:58 2017 +0800
----------------------------------------------------------------------
src/checks/tcp_connect.cpp | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/f9cb1891/src/checks/tcp_connect.cpp
----------------------------------------------------------------------
diff --git a/src/checks/tcp_connect.cpp b/src/checks/tcp_connect.cpp
index 2514f4a..17d7abf 100644
--- a/src/checks/tcp_connect.cpp
+++ b/src/checks/tcp_connect.cpp
@@ -30,6 +30,9 @@
#include <iostream>
#include <string>
+#include <process/address.hpp>
+#include <process/network.hpp>
+
#include <stout/flags.hpp>
#include <stout/option.hpp>
#include <stout/path.hpp>
@@ -49,8 +52,6 @@ using std::string;
//
// TODO(alexr): Add support for Windows, see MESOS-6117.
//
-// TODO(alexr): Support IPv6, see MESOS-6120.
-//
// NOTE: Consider using stout network abstractions instead of raw system
// sockets. Once stout supports IPv6 migrating to it will buy us implicit
// Windows and IPv6 compatibilities.
@@ -63,7 +64,7 @@ public:
{
add(&Flags::ip,
"ip",
- "IP of the target host. Only IPv4 is supported.");
+ "IP of the target host.");
add(&Flags::port,
"port",
@@ -79,18 +80,14 @@ public:
// If the TCP handshake is successful, returns `EXIT_SUCCESS`.
int testTCPConnect(const string& ip, int port)
{
- // Set up destination address.
- struct sockaddr_in to;
- memset(&to, 0, sizeof(to));
- to.sin_family = AF_INET;
- to.sin_port = htons(port);
- if (inet_pton(AF_INET, ip.c_str(), &to.sin_addr) != 1) {
+ Try<net::IP> parse = net::IP::parse(ip);
+ if (parse.isError()){
cerr << "Cannot convert '" << ip << "' into a network address" << endl;
return EXIT_FAILURE;
}
// Create a TCP socket.
- int socket = ::socket(AF_INET, SOCK_STREAM, 0);
+ int socket = ::socket(parse->family(), SOCK_STREAM, 0);
if (socket < 0) {
cerr << "Failed to create socket: " << strerror(errno) << endl;
return EXIT_FAILURE;
@@ -99,8 +96,12 @@ int testTCPConnect(const string& ip, int port)
// Try to connect to socket. If the connection succeeds,
// zero is returned, indicating the remote port is open.
cout << "Connecting to " << ip << ":" << port << endl;
- if (connect(socket, reinterpret_cast<sockaddr*>(&to), sizeof(to)) < 0) {
- cerr << "Connection failed: " << strerror(errno) << endl;
+ Try<Nothing, SocketError> connect = process::network::connect(
+ socket,
+ process::network::inet::Address(parse.get(), port));
+
+ if (connect.isError()) {
+ cerr << connect.error().message << endl;
close(socket);
return EXIT_FAILURE;
}