Commit 7efd76dd authored by Xavier Claessens's avatar Xavier Claessens

struct ip_mreq_source definition is broken on Android NDK <= r16

This fix the build on Android r16 and older, see:
https://issuetracker.google.com/issues/36987220

https://bugzilla.gnome.org/show_bug.cgi?id=740791
parent 63435556
Pipeline #9636 passed with stage
in 9 minutes and 26 seconds
......@@ -15,6 +15,9 @@
/* poll doesn't work on devices */
#mesondefine BROKEN_POLL
/* struct ip_mreq_source definition is broken on Android NDK <= r16 */
#mesondefine BROKEN_IP_MREQ_SOURCE_STRUCT
/* Whether we're building a DLL and hence need symbols exported for a DLL */
#mesondefine DLL_EXPORT
......
......@@ -961,6 +961,21 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
AC_MSG_RESULT(no)
])
AC_MSG_CHECKING([if ip_mreq_source.imr_interface has s_addr member])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[
#include <netinet/in.h>
]],
[[
struct ip_mreq_source mc_req_src;
mc_req_src.imr_interface.s_addr = 0;
]])], [
AC_MSG_RESULT(yes)
], [
AC_MSG_RESULT(no)
AC_DEFINE(BROKEN_IP_MREQ_SOURCE_STRUCT, 1, [struct ip_mreq_source definition is broken on Android NDK <= r16])
])
AS_IF([test $glib_native_win32 = yes], [
# <wspiapi.h> in the Windows SDK and in mingw-w64 has wrappers for
# inline workarounds for getaddrinfo, getnameinfo and freeaddrinfo if
......
......@@ -2380,6 +2380,13 @@ g_socket_multicast_group_operation_ssm (GSocket *socket,
case G_SOCKET_FAMILY_IPV4:
{
#ifdef IP_ADD_SOURCE_MEMBERSHIP
#ifdef BROKEN_IP_MREQ_SOURCE_STRUCT
#define S_ADDR_FIELD(src) src.imr_interface
#else
#define S_ADDR_FIELD(src) src.imr_interface.s_addr
#endif
gint optname;
struct ip_mreq_source mc_req_src;
......@@ -2397,7 +2404,7 @@ g_socket_multicast_group_operation_ssm (GSocket *socket,
memset (&mc_req_src, 0, sizeof (mc_req_src));
/* By default use the default IPv4 multicast interface. */
mc_req_src.imr_interface.s_addr = g_htonl (INADDR_ANY);
S_ADDR_FIELD(mc_req_src) = g_htonl (INADDR_ANY);
  • On mingw64 x64 I got this error:

    gsocket.c: In function 'g_socket_multicast_group_operation_ssm': gsocket.c:2407:34: error: incompatible types when assigning to type 'struct in_addr' from type 'unsigned int' S_ADDR_FIELD(mc_req_src) = g_htonl (INADDR_ANY); ^ make[4]: *** [Makefile:3432: libgio_2_0_la-gsocket.lo] Error 1 make[4]: *** Waiting for unfinished jobs.... make[4]: Leaving directory '/home/user/gimp_libs/glib/gio' make[3]: *** [Makefile:4722: all-recursive] Error 1 make[3]: Leaving directory '/home/user/gimp_libs/glib/gio' make[2]: *** [Makefile:2281: all] Error 2 make[2]: Leaving directory '/home/user/gimp_libs/glib/gio' make[1]: *** [Makefile:1271: all-recursive] Error 1 make[1]: Leaving directory '/home/user/gimp_libs/glib' make: *** [Makefile:898: all] Error 2

    Edited by Cupidazul
Please register or sign in to reply
if (iface)
{
......@@ -2412,7 +2419,7 @@ g_socket_multicast_group_operation_ssm (GSocket *socket,
return FALSE;
}
/* (0.0.0.iface_index) only works on Windows. */
mc_req_src.imr_interface.s_addr = g_htonl (iface_index);
S_ADDR_FIELD(mc_req_src) = g_htonl (iface_index);
#elif defined (HAVE_SIOCGIFADDR)
int ret;
struct ifreq ifr;
......@@ -2442,7 +2449,7 @@ g_socket_multicast_group_operation_ssm (GSocket *socket,
}
iface_addr = (struct sockaddr_in *) &ifr.ifr_addr;
mc_req_src.imr_interface.s_addr = iface_addr->sin_addr.s_addr;
S_ADDR_FIELD(mc_req_src) = iface_addr->sin_addr.s_addr;
#endif /* defined(G_OS_WIN32) && defined (HAVE_IF_NAMETOINDEX) */
}
memcpy (&mc_req_src.imr_multiaddr, g_inet_address_to_bytes (group),
......@@ -2455,6 +2462,9 @@ g_socket_multicast_group_operation_ssm (GSocket *socket,
join_group ? IP_ADD_SOURCE_MEMBERSHIP : IP_DROP_SOURCE_MEMBERSHIP;
result = setsockopt (socket->priv->fd, IPPROTO_IP, optname,
&mc_req_src, sizeof (mc_req_src));
#undef S_ADDR_FIELD
#else
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
join_group ?
......
......@@ -152,6 +152,16 @@ if host_system != 'windows'
glib_conf.set('HAVE_SIOCGIFADDR', '/**/')
endif
if not cc.compiles('''#include <netinet/in.h>
int main(int argc, char ** argv) {
struct ip_mreq_source mc_req_src;
mc_req_src.imr_interface.s_addr = 0;
return 0;
}''',
name : 'ip_mreq_source.imr_interface has s_addr member')
glib_conf.set('BROKEN_IP_MREQ_SOURCE_STRUCT', 1)
endif
endif
network_args_string = ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment