summaryrefslogtreecommitdiff
path: root/examples/network
diff options
context:
space:
mode:
authorShashank <shashank1.m@samsung.com>2014-08-06 09:40:20 +0200
committerKjell Ahlstedt <kjell.ahlstedt@bredband.net>2014-08-06 09:40:20 +0200
commit5d8d185025872b59ae4209a0531ae2bb107942e7 (patch)
treea62b2cd73b62f5e640f9294b045e2a1e28a5ad67 /examples/network
parente27ddd8adcf008933f937aca7b43bea3c33bc21a (diff)
downloadglibmm-5d8d185025872b59ae4209a0531ae2bb107942e7.tar.gz
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.
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/socket-client.cc12
-rw-r--r--examples/network/socket-server.cc21
2 files changed, 30 insertions, 3 deletions
diff --git a/examples/network/socket-client.cc b/examples/network/socket-client.cc
index 1276e37a..4fd02e1e 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 2bf9d2b9..c10cf7b3 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) {