android: c_compat: add __cmsg_nxthd() for Android KitKat 4.4
authorHauke Mehrtens <hauke.mehrtens@lantiq.com>
Thu, 15 Oct 2015 11:59:13 +0000 (13:59 +0200)
committerJon A. Cruz <jonc@osg.samsung.com>
Wed, 13 Jan 2016 07:38:01 +0000 (07:38 +0000)
The function __cmsg_nxthd() is missing in Android 4.4, but the Android NDK
header files in the version we are using are referencing it and we use it in
our code, this functions was added in version 5.0. To make IoTivity
dynamically loadable on Android KitKat 4.4 add this functions
as a weak symbol, so it will be used if the c lib does not provide it, like
on Android < 5.0 This code was taken from these two resources:
https://raw.githubusercontent.com/android/platform_bionic/master/libc/bionic/__cmsg_nxthdr.cpp
https://github.com/android/platform_bionic/commit/ff64831b0965c16c95c9f81a148f30a6ef3a6c64

Change-Id: I02ef763cf3f82c73b1e0169230dd8c7e9d6d379b
Signed-off-by: Hauke Mehrtens <hauke.mehrtens@lantiq.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3895
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
build_common/android/compatibility/c_compat.c

index b76c739..1a36575 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdlib.h>
+#include <sys/socket.h>
 
 /* from stdlib.h */
 float strtof(const char *nptr, char **endptr)
@@ -45,3 +46,25 @@ void srandom(unsigned int __s)
 {
     srand48(__s);
 }
+
+/* from __cmsg_nxthdr.cpp */
+/*
+ * The function __cmsg_nxthd() is missing in Android 4.4, but the Android NDK
+ * header files in the version we are using are referencing it and we use it in
+ * our code, this functions was added in version 5.0. To make IoTivity
+ * dynamically loadable at load time on Android KitKat 4.4 add this functions
+ * as a weak symbol, so it will be used if the c lib does not provide it, like
+ * on Android < 5.0 This code was taken from these two resources:
+ * https://raw.githubusercontent.com/android/platform_bionic/master/libc/bionic/__cmsg_nxthdr.cpp
+ * https://github.com/android/platform_bionic/commit/ff64831b0965c16c95c9f81a148f30a6ef3a6c64
+ */
+struct cmsghdr* __attribute__((weak)) __cmsg_nxthdr(struct msghdr* msg, struct cmsghdr* cmsg)
+{
+    struct cmsghdr* ptr;
+    ptr = (struct cmsghdr*)(((unsigned char*) cmsg) + CMSG_ALIGN(cmsg->cmsg_len));
+    size_t len = (unsigned long)((char*)(ptr+1) - (char*) msg->msg_control);
+    if (len > msg->msg_controllen) {
+        return NULL;
+    }
+    return ptr;
+}