After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 678660 - Use the new multicast functions in GLib-2.32
Use the new multicast functions in GLib-2.32
Status: RESOLVED FIXED
Product: gssdp
Classification: Other
Component: General
unspecified
Other Linux
: Normal minor
: ---
Assigned To: GUPnP Maintainers
GUPnP Maintainers
Depends on:
Blocks:
 
 
Reported: 2012-06-23 07:55 UTC by Riko Yamada
Modified: 2019-02-22 09:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Use the glib-2.32 multicast features. make check passed. (6.37 KB, patch)
2012-06-23 07:56 UTC, Riko Yamada
needs-work Details | Review
Use the code in GSSDPClient to obtain the name of network interface (9.29 KB, patch)
2012-06-27 02:49 UTC, Riko Yamada
needs-work Details | Review
This is the third attempt to use glib-2.32 multicast functions (22.62 KB, patch)
2012-08-19 06:15 UTC, Riko Yamada
none Details | Review
The fourth attempt to use the multicast socket in glib-2.32 (16.20 KB, patch)
2012-08-19 20:10 UTC, Riko Yamada
committed Details | Review

Description Riko Yamada 2012-06-23 07:55:35 UTC
Glib-2.32 has introduced a bunch of multicast functions which can replace the in-house similar functions defined in gssdp-socket-function.c. A benefit of using GLib-2.32 functions is that they support ipv6.

The attached patch will use #ifdef #else to make a try to use the 2.32 functions meanwhile keep the old functionality.
Comment 1 Riko Yamada 2012-06-23 07:56:57 UTC
Created attachment 217060 [details] [review]
Use the glib-2.32 multicast features. make check passed.
Comment 2 Zeeshan Ali 2012-06-23 13:29:27 UTC
(In reply to comment #0)
> Glib-2.32 has introduced a bunch of multicast functions which can replace the
> in-house similar functions defined in gssdp-socket-function.c. A benefit of
> using GLib-2.32 functions is that they support ipv6.
> 
> The attached patch will use #ifdef #else to make a try to use the 2.32
> functions meanwhile keep the old functionality.

Haven't yet looked at the patches but lots of respect points for initiating this effort. I would rather want to not use #ifdefs here at all and just bump our glib dependency. People who use old glib are free to keep using old gupnp. I must point out that 2.32 is a stable release that is already in latest releases of distros so not the same as requring latest unstable release or git master..
Comment 3 Zeeshan Ali 2012-06-23 14:01:47 UTC
So just to be clear, once you have removed the #ifdefs, I'll review the patch.
Comment 4 Jens Georg 2012-06-24 07:01:00 UTC
Review of attachment 217060 [details] [review]:

Nice work, I agree on the #ifdefs with Zeeshan, though.

::: libgssdp/gssdp-resource-browser.c
@@ -468,3 +468,3 @@
                                   version + 1,
-                                  G_REGEX_MATCH_ANCHORED,
-                                  0)) {
+                                  G_REGEX_ANCHORED,
+                                  G_REGEX_MATCH_ANCHORED)) {

This is a separate bug, can you extract this patch please? Good catch.

::: libgssdp/gssdp-socket-source.c
@@ +301,3 @@
+                /* Subscribe to multicast channel */
+#ifdef GLIB_VERSION_2_32
+                struct ifaddrs *addrs, *iap; 

I don't really like this unix-specific stuff here, and it's redundant work as we already have the interface's name in GSSDPClient. This is internal API, so you freely change the functions and pass the name instead of the address.
Comment 5 Riko Yamada 2012-06-25 18:31:08 UTC
Just want to make it clear. As to your last paragraph, did you mean the function 'get_host_ip'? Did you suggest changing this function or write another based on this one?
Comment 6 Jens Georg 2012-06-26 07:08:01 UTC
No, what I mean is that the ifa->ifa_name is available in GSSDPClient->priv->iface after init_network_info has been called, which is before any of the socket sources is created.

So you can either pass it to gssdp_socket_source_new instead of gssdp_client_get_host_ip or in addition to it if you still need the IP.
Comment 7 Riko Yamada 2012-06-27 02:49:25 UTC
Created attachment 217340 [details] [review]
Use the code in GSSDPClient to obtain the name of network interface

This patch is based on Jens suggestion.
Comment 8 Jens Georg 2012-06-27 07:09:54 UTC
Review of attachment 217340 [details] [review]:

I think gssdp-socket-functions.[ch] are useless now so the two files can go away.

I'll need to try the patches on Windows and OpenBSD and see if it's still working there.

::: libgssdp/gssdp-socket-source.c
@@ +32,3 @@
+#include <net/if.h>
+#include <ifaddrs.h>
+#endif

I think those includes aren't necessary anymore

@@ +43,1 @@
 static void

Same here. Do you need them?

@@ +273,3 @@
         if (self->priv->type == GSSDP_SOCKET_SOURCE_TYPE_MULTICAST) {
+                /* The 4th argument 'iface_name' can't be NULL even though Glib API doc says you 
+                 * can. 'NULL' will fail the test.

Yes. We simulate that functionality in GSSDPClient by semi-arbitrarily choosing an interface  so you're correct that here the function always has to use the interface provided by it.
Comment 9 Jens Georg 2012-06-27 10:40:37 UTC
The patch has trailing whitespace, btw.
Comment 10 Riko Yamada 2012-06-27 15:05:37 UTC
(In reply to comment #8)
> Review of attachment 217340 [details] [review]:
> 
> I think gssdp-socket-functions.[ch] are useless now so the two files can go
> away.
There are still functions called by gssdp-socket-source.c

Do we still need to call gssdp_socket_mcast_interface_set() in gssdp-socket-source.c: around line 215? I removed this call temporarily and the test seemed OK.

> 
> I'll need to try the patches on Windows and OpenBSD and see if it's still
> working there.
> 
> ::: libgssdp/gssdp-socket-source.c
> @@ +32,3 @@
> +#include <net/if.h>
> +#include <ifaddrs.h>
> +#endif
> 
> I think those includes aren't necessary anymore
No. They should be removed.

> 
> @@ +43,1 @@
>  static void
> 
> Same here. Do you need them?
I have no idea.

> 
> @@ +273,3 @@
>          if (self->priv->type == GSSDP_SOCKET_SOURCE_TYPE_MULTICAST) {
> +                /* The 4th argument 'iface_name' can't be NULL even though
> Glib API doc says you 
> +                 * can. 'NULL' will fail the test.
> 
> Yes. We simulate that functionality in GSSDPClient by semi-arbitrarily choosing
> an interface  so you're correct that here the function always has to use the
> interface provided by it.
Comment 11 Jens Georg 2012-06-29 21:33:44 UTC
Seems to work under Windows. OpenBSD still to check.
Comment 12 Riko Yamada 2012-08-19 06:15:53 UTC
Created attachment 221733 [details] [review]
This is the third attempt to use glib-2.32 multicast functions

Merged with the HEAD of master.


The biggest difference compared to the previous attempted patches:
I removed the files gssdp-socket-function.[ch]. It worked on my Ubuntu Linux. For the function gssdp_socket_reuse_address (), it seems that glib/gio has already taken care of the difference between Windows and Linux (see the function body of g_socket_bind () in gio/gsocket.c). Therefore I deleted it. I have no idea if it will work in OpenBSD.
Comment 13 Jens Georg 2012-08-19 12:35:45 UTC
I am not sure we can skip the SO_REUSEADDR. gsocket.c says "You don't want to do this on windows". Yes, it does mean something else on windows, but we need it there since the multicast address + port are definitely taken by its SSDP system service.

And I think we need gssdp_socket_mcast_interface_set as it sets the correct source interface instead of using the default mcast interface, which is necessary in multi-home scenarios. I missed that question before, sorry.
Comment 14 Riko Yamada 2012-08-19 20:10:28 UTC
Created attachment 221758 [details] [review]
The fourth attempt to use the multicast socket in glib-2.32 

Per Jens' request, add back gssdp_socket_mcast_interface_set () and gssdp_socket_reuse_address ()
Comment 15 Jens Georg 2014-03-15 09:02:08 UTC
Committed with minor changes due to changed upstream code