[glibmm] Network example: Add --use-ipv6 command line option
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Network example: Add --use-ipv6 command line option
- Date: Wed, 6 Aug 2014 07:53:05 +0000 (UTC)
commit 5d8d185025872b59ae4209a0531ae2bb107942e7
Author: Shashank <shashank1 m samsung com>
Date: Wed Aug 6 09:40:20 2014 +0200
Network example: Add --use-ipv6 command line option
* examples/network/socket-client.cc:
* examples/network/socket-server.cc: Add --use-ipv6 command line option.
Bug #734094.
examples/network/socket-client.cc | 12 +++++++++++-
examples/network/socket-server.cc | 21 +++++++++++++++++++--
2 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/examples/network/socket-client.cc b/examples/network/socket-client.cc
index 1276e37..4fd02e1 100644
--- a/examples/network/socket-client.cc
+++ b/examples/network/socket-client.cc
@@ -9,6 +9,7 @@ gboolean verbose = FALSE;
gboolean non_blocking = FALSE;
gboolean use_udp = FALSE;
gboolean use_source = FALSE;
+gboolean use_ipv6 = FALSE;
int cancel_timeout = 0;
static GOptionEntry cmd_entries[] = {
@@ -22,6 +23,8 @@ static GOptionEntry cmd_entries[] = {
"Enable non-blocking i/o", NULL},
{"use-source", 's', 0, G_OPTION_ARG_NONE, &use_source,
"Use GSource to wait for non-blocking i/o", NULL},
+ {"use-ipv6", 'i', 0, G_OPTION_ARG_NONE, &use_ipv6,
+ "Use ipv6 address family", NULL},
{0, 0, 0, G_OPTION_ARG_NONE, 0, 0, 0}
};
@@ -134,7 +137,14 @@ main (int argc,
try {
// FIXME: enum.pl has a problem generating the SocketFamily enum
// correctly, so I'm using the C enum directly for now as a workaround.
- socket = Gio::Socket::create ((Gio::SocketFamily)G_SOCKET_FAMILY_IPV4, socket_type,
Gio::SOCKET_PROTOCOL_DEFAULT);
+ if (use_ipv6)
+ {
+ socket = Gio::Socket::create ((Gio::SocketFamily)G_SOCKET_FAMILY_IPV6, socket_type,
Gio::SOCKET_PROTOCOL_DEFAULT);
+ }
+ else
+ {
+ socket = Gio::Socket::create ((Gio::SocketFamily)G_SOCKET_FAMILY_IPV4, socket_type,
Gio::SOCKET_PROTOCOL_DEFAULT);
+ }
} catch (const Gio::Error& error)
{
std::cerr << Glib::ustring::compose ("%1: %2\n", argv[0], error.what ());
diff --git a/examples/network/socket-server.cc b/examples/network/socket-server.cc
index 2bf9d2b..c10cf7b 100644
--- a/examples/network/socket-server.cc
+++ b/examples/network/socket-server.cc
@@ -10,6 +10,7 @@ gboolean dont_reuse_address = FALSE;
gboolean non_blocking = FALSE;
gboolean use_udp = FALSE;
gboolean use_source = FALSE;
+gboolean use_ipv6 = FALSE;
int cancel_timeout = 0;
static GOptionEntry cmd_entries[] = {
@@ -27,6 +28,8 @@ static GOptionEntry cmd_entries[] = {
"Enable non-blocking i/o", NULL},
{"use-source", 's', 0, G_OPTION_ARG_NONE, &use_source,
"Use GSource to wait for non-blocking i/o", NULL},
+ {"use-ipv6", 'i', 0, G_OPTION_ARG_NONE, &use_ipv6,
+ "Use ipv6 address family", NULL},
{0, 0, 0, G_OPTION_ARG_NONE, 0, 0, 0}
};
@@ -126,7 +129,14 @@ main (int argc,
socket_type = Gio::SOCKET_TYPE_STREAM;
try {
- socket = Gio::Socket::create ((Gio::SocketFamily)G_SOCKET_FAMILY_IPV4, socket_type,
Gio::SOCKET_PROTOCOL_DEFAULT);
+ if (use_ipv6)
+ {
+ socket = Gio::Socket::create ((Gio::SocketFamily)G_SOCKET_FAMILY_IPV6, socket_type,
Gio::SOCKET_PROTOCOL_DEFAULT);
+ }
+ else
+ {
+ socket = Gio::Socket::create ((Gio::SocketFamily)G_SOCKET_FAMILY_IPV4, socket_type,
Gio::SOCKET_PROTOCOL_DEFAULT);
+ }
} catch (const Gio::Error& error)
{
std::cerr << Glib::ustring::compose ("%1: %2\n", argv[0], error.what ());
@@ -136,7 +146,14 @@ main (int argc,
if (non_blocking)
socket->set_blocking (false);
- src_address = Gio::InetSocketAddress::create (Gio::InetAddress::create_any ((Gio::SocketFamily)
G_SOCKET_FAMILY_IPV4), port);
+ if (use_ipv6)
+ {
+ src_address = Gio::InetSocketAddress::create (Gio::InetAddress::create_any ((Gio::SocketFamily)
G_SOCKET_FAMILY_IPV6), port);
+ }
+ else
+ {
+ src_address = Gio::InetSocketAddress::create (Gio::InetAddress::create_any ((Gio::SocketFamily)
G_SOCKET_FAMILY_IPV4), port);
+ }
try {
socket->bind (src_address, !dont_reuse_address);
} catch (const Gio::Error& error) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]