Provide an inline __cmsg_nxthdr.
This was defined as an inline in the legacy NDK headers. Keep that
here until we can get it into libandroid_support.
Test: make checkbuild
Bug: http://b/30465923
Change-Id: I62393b58e4fba3bc7337cc5ecf4ae1590b0e9917
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index 910fee1..03dc849 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -114,7 +114,22 @@
? (struct cmsghdr*) (msg)->msg_control : (struct cmsghdr*) NULL)
#define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) && (cmsg)->cmsg_len <= (unsigned long) ((mhdr)->msg_controllen - ((char*)(cmsg) - (char*)(mhdr)->msg_control)))
+#if __ANDROID_API__ >= 21
struct cmsghdr* __cmsg_nxthdr(struct msghdr*, struct cmsghdr*) __INTRODUCED_IN(21);
+#else
+/* TODO(danalbert): Move this into libandroid_support. */
+static inline struct cmsghdr* __cmsg_nxthdr(struct msghdr* msg, struct cmsghdr* cmsg) {
+ struct cmsghdr* ptr =
+ __BIONIC_CAST(reinterpret_cast, struct cmsghdr*,
+ (__BIONIC_CAST(reinterpret_cast, char*, cmsg) + CMSG_ALIGN(cmsg->cmsg_len)));
+ size_t len = __BIONIC_CAST(reinterpret_cast, char*, ptr + 1) -
+ __BIONIC_CAST(reinterpret_cast, char*, msg->msg_control);
+ if (len > msg->msg_controllen) {
+ return NULL;
+ }
+ return ptr;
+}
+#endif /* __ANDROID_API__ >= 21 */
#define SCM_RIGHTS 0x01
#define SCM_CREDENTIALS 0x02