Merge "Include ping6 in userdebug builds."
diff --git a/Android.mk b/Android.mk
index 0991eeb..d20d1c1 100644
--- a/Android.mk
+++ b/Android.mk
@@ -3,5 +3,5 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= ping6.c
LOCAL_MODULE := ping6
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := debug
include $(BUILD_EXECUTABLE)
diff --git a/ping6.c b/ping6.c
index ccf9c4c..fc1eb84 100644
--- a/ping6.c
+++ b/ping6.c
@@ -131,6 +131,8 @@
#include <unistd.h>
#include <poll.h>
+#include <private/android_filesystem_config.h>
+
#ifdef IPSEC
#include <netinet6/ah.h>
#include <netinet6/ipsec.h>
@@ -298,6 +300,23 @@
void usage(void);
int
+isInSupplementaryGroup(gid_t group)
+{
+ int numgroups, i;
+ gid_t groups[sysconf(_SC_NGROUPS_MAX) + 1];
+ numgroups = getgroups(sizeof(groups) / sizeof(groups[0]), groups);
+ if (numgroups < 0) {
+ perror("getgroups");
+ return 0;
+ }
+ for (i = 0; i < numgroups; i++) {
+ if (group == groups[i])
+ return 1;
+ }
+ return 0;
+}
+
+int
main(int argc, char *argv[])
{
struct itimerval itimer;
@@ -331,6 +350,11 @@
int mflag = 0;
#endif
+ if (getuid() != 0 && !isInSupplementaryGroup(AID_INET)) {
+ fprintf(stderr, "%s: not root or in group AID_INET\n", argv[0]);
+ exit(3);
+ }
+
/* just to be sure */
memset(&smsghdr, 0, sizeof(smsghdr));
memset(&smsgiov, 0, sizeof(smsgiov));