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 697185 - GSocket – Allow specifying the multicast interface from an IPv4 address
GSocket – Allow specifying the multicast interface from an IPv4 address
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: network
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-04-03 15:38 UTC by Sebastian Dröge (slomo)
Modified: 2013-08-19 16:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0001-GSocket-Allow-specifying-the-multicast-interface-fro.patch (2.92 KB, patch)
2013-04-03 15:38 UTC, Sebastian Dröge (slomo)
needs-work Details | Review
0001-GSocket-Implement-multicast-interface-selection-on-W.patch (2.84 KB, patch)
2013-07-31 12:13 UTC, Sebastian Dröge (slomo)
reviewed Details | Review
0002-GSocket-Implement-multicast-interface-selection-on-W.patch (3.44 KB, patch)
2013-08-07 11:47 UTC, Sebastian Dröge (slomo)
none Details | Review
0002-GSocket-Implement-multicast-interface-selection-on-W.patch (3.47 KB, patch)
2013-08-07 12:02 UTC, Sebastian Dröge (slomo)
committed Details | Review

Description Sebastian Dröge (slomo) 2013-04-03 15:38:57 UTC
Created attachment 240492 [details] [review]
0001-GSocket-Allow-specifying-the-multicast-interface-fro.patch

Hi,

the attached patch allows specifying the multicast interface from an IPv4 address

This is the only way to specify an interface on Windows before XP.
If the passed string is not a valid IPv4 address it will be handled
as an interface name instead.
Comment 1 Dan Winship 2013-04-16 18:05:15 UTC
Comment on attachment 240492 [details] [review]
0001-GSocket-Allow-specifying-the-multicast-interface-fro.patch

>This is the only way to specify an interface on Windows before XP.

Don't we require at least Windows XP now? From configure.ac:

    AC_DEFINE([_WIN32_WINNT], [0x0501], [Target the Windows XP API])

I forget the specifics, but I'm pretty sure we non-conditionally depend on certain functions that only exist in XP now...


But anyway (in case that's not true), I don't like this change, because the point of having glib-level APIs is to abstract around stuff like this; we don't want people to have to use the API differently if they want to support old Winodws.

Can't glib just translate the interface name to an IP address itself in this case? It looks like you ought to be able to do that by using GetAdaptersInfo() (http://msdn.microsoft.com/en-us/library/windows/desktop/aa365917%28v=vs.85%29.aspx). (There might be a simpler method in there somewhere too; I didn't look that hard.)
Comment 2 Sebastian Dröge (slomo) 2013-04-16 20:01:24 UTC
(In reply to comment #1)
> (From update of attachment 240492 [details] [review])
> >This is the only way to specify an interface on Windows before XP.
> 
> Don't we require at least Windows XP now? From configure.ac:
> 
>     AC_DEFINE([_WIN32_WINNT], [0x0501], [Target the Windows XP API])
> 
> I forget the specifics, but I'm pretty sure we non-conditionally depend on
> certain functions that only exist in XP now...

Erm, typo. That's for Windows XP and earlier versions, so effectively Windows XP only :)

> But anyway (in case that's not true), I don't like this change, because the
> point of having glib-level APIs is to abstract around stuff like this; we don't
> want people to have to use the API differently if they want to support old
> Winodws.
> 
> Can't glib just translate the interface name to an IP address itself in this
> case? It looks like you ought to be able to do that by using GetAdaptersInfo()
> (http://msdn.microsoft.com/en-us/library/windows/desktop/aa365917%28v=vs.85%29.aspx).
> (There might be a simpler method in there somewhere too; I didn't look that
> hard.)

Ah, I missed that function... everything I looked up was only available after Windows XP. So yes, makes sense to change it to that instead.

How would you handle the case where an interface has multiple addresses assigned? Join the multicast group for all of these addresses?
Comment 3 Dan Winship 2013-04-16 20:32:24 UTC
(In reply to comment #2)
> How would you handle the case where an interface has multiple addresses
> assigned? Join the multicast group for all of these addresses?

Oh, hey, the documentation for struct ip_mreq (http://msdn.microsoft.com/en-us/library/windows/desktop/ms738695%28v=vs.85%29.aspx) says that you can actually put an ifindex (in network byte order) in the imr_interface field instead of an address. So I guess basically you'll just be using GetAdaptersInfo() to implement if_nametoindex().
Comment 4 Sebastian Dröge (slomo) 2013-07-04 08:50:16 UTC
Ah, that indeed looks like the best option for this. Thanks :) I hope I'll have some time to implement this soon
Comment 5 Sebastian Dröge (slomo) 2013-07-31 12:13:57 UTC
Created attachment 250542 [details] [review]
0001-GSocket-Implement-multicast-interface-selection-on-W.patch

Untested patch that implements this. It compiles at least. Please review, I'll test it later
Comment 6 Dan Winship 2013-07-31 12:35:06 UTC
Comment on attachment 250542 [details] [review]
0001-GSocket-Implement-multicast-interface-selection-on-W.patch

basically looks good


>+#ifdef G_OS_WIN32
>+# include <iphlpapi.h>
>+#endif

put that with the other networking includes in gnetworking.h.in

>+  gulong addresses_len = 15*1024;

the docs say you can just pass a NULL addresses pointer to GetAdaptersAddresses() to get back the right addresses_len. So you don't need to initialize the buffer to a random size.

>+      addresses = g_realloc (addresses, addresses_len);
>+
>+      if (!addresses)
>+        return 0;

g_realloc() cannot fail

>+      res = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, addresses, &addresses_len);

space before "("

>+  if (i == 4 || res != NO_ERROR)
>+    {
>+      g_free (addresses);
>+      return 0;
>+    }

although not needed in any of the places where if_nametoindex() is *currently* used in gsocket.c, you should probably set errno on error anyway.
Comment 7 Sebastian Dröge (slomo) 2013-08-07 11:47:27 UTC
Created attachment 251057 [details] [review]
0002-GSocket-Implement-multicast-interface-selection-on-W.patch
Comment 8 Sebastian Dröge (slomo) 2013-08-07 12:02:52 UTC
Created attachment 251061 [details] [review]
0002-GSocket-Implement-multicast-interface-selection-on-W.patch
Comment 9 Dan Winship 2013-08-19 16:29:37 UTC
pushed