[gssdp] socket-source: Request either PKTINFO or PKTINFO6
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gssdp] socket-source: Request either PKTINFO or PKTINFO6
- Date: Thu, 24 Jan 2019 10:33:36 +0000 (UTC)
commit ced9e81b121168f04d5019113580b0ff7df8b804
Author: Jens Georg <mail jensge org>
Date: Thu Jan 24 11:25:58 2019 +0100
socket-source: Request either PKTINFO or PKTINFO6
Depending on the socket's family. Also fixes a memory leak with error
if we fail to enable PKTINFO6 on a socket and an abort if both fail.
Fixes #2
libgssdp/gssdp-socket-functions.c | 31 +++++++++++++++++++------------
libgssdp/gssdp-socket-functions.h | 1 +
libgssdp/gssdp-socket-source.c | 1 +
3 files changed, 21 insertions(+), 12 deletions(-)
---
diff --git a/libgssdp/gssdp-socket-functions.c b/libgssdp/gssdp-socket-functions.c
index 48cce65..042736f 100644
--- a/libgssdp/gssdp-socket-functions.c
+++ b/libgssdp/gssdp-socket-functions.c
@@ -155,6 +155,7 @@ gssdp_socket_reuse_address (GSocket *socket,
gboolean
gssdp_socket_enable_info (GSocket *socket,
+ GSocketFamily family,
gboolean enable,
GError **error)
{
@@ -164,19 +165,25 @@ gssdp_socket_enable_info (GSocket *socket,
g_object_unref (g_object_new (GSSDP_TYPE_PKTINFO_MESSAGE, NULL));
g_object_unref (g_object_new (GSSDP_TYPE_PKTINFO6_MESSAGE, NULL));
- gssdp_socket_option_set (socket,
- IPPROTO_IPV6,
- IPV6_RECVPKTINFO,
- (char *)&enable,
- sizeof (enable),
- error);
+ if (family == G_SOCKET_FAMILY_IPV6) {
+ return gssdp_socket_option_set (socket,
+ IPPROTO_IPV6,
+ IPV6_RECVPKTINFO,
+ (char *)&enable,
+ sizeof (enable),
+ error);
+ } else if (family == G_SOCKET_FAMILY_IPV4) {
+ return gssdp_socket_option_set (socket,
+ IPPROTO_IP,
+ IP_PKTINFO,
+ (char *) &enable,
+ sizeof (enable),
+ error);
+ } else {
+ g_warning ("Invalid socket family: %d", family);
- return gssdp_socket_option_set (socket,
- IPPROTO_IP,
- IP_PKTINFO,
- (char *) &enable,
- sizeof (enable),
- error);
+ return FALSE;
+ }
#else
__GSSDP_UNUSED (socket);
__GSSDP_UNUSED (enable);
diff --git a/libgssdp/gssdp-socket-functions.h b/libgssdp/gssdp-socket-functions.h
index 7be7a46..bd266a7 100644
--- a/libgssdp/gssdp-socket-functions.h
+++ b/libgssdp/gssdp-socket-functions.h
@@ -36,6 +36,7 @@ gssdp_socket_reuse_address (GSocket *socket,
G_GNUC_INTERNAL gboolean
gssdp_socket_enable_info (GSocket *socket,
+ GSocketFamily family,
gboolean enable,
GError **error);
diff --git a/libgssdp/gssdp-socket-source.c b/libgssdp/gssdp-socket-source.c
index 6ad895d..87f8b7a 100644
--- a/libgssdp/gssdp-socket-source.c
+++ b/libgssdp/gssdp-socket-source.c
@@ -229,6 +229,7 @@ gssdp_socket_source_do_init (GInitable *initable,
g_socket_set_broadcast (priv->socket, TRUE);
if (!gssdp_socket_enable_info (priv->socket,
+ family,
TRUE,
&inner_error)) {
g_propagate_prefixed_error (error,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]