Project import generated by Copybara. GitOrigin-RevId: 7f0284f66b5c113e0e0c1fec8f9f130c10c8fd34
diff --git a/avahi-core/domain-util.c b/avahi-core/domain-util.c index 936bc07..65aea80 100644 --- a/avahi-core/domain-util.c +++ b/avahi-core/domain-util.c
@@ -28,6 +28,7 @@ #include <ctype.h> #include <sys/utsname.h> #include <stdio.h> +#include <inttypes.h> #include <avahi-common/malloc.h> @@ -84,14 +85,20 @@ } #endif -uint32_t random_host_id() { - static uint32_t random_id = 0; +// Returns a randomized MAC address. +uint64_t random_host_id() { + const uint64_t kMacAddressMask = 0xFFFFFFFFFFFF; + const uint64_t kMacMulticastBit = 0x010000000000; + const uint64_t kMacLocalBit = 0x020000000000; + static uint64_t random_id = 0; + if (!random_id) { // The random seed has been initialized in avahi-daemon/main.c - random_id = (uint32_t) rand(); + random_id = (((uint64_t) rand()) << 32) | (uint64_t) rand(); if (!random_id) { random_id = 1; } + random_id = (random_id | kMacLocalBit) & (kMacAddressMask & ~kMacMulticastBit); } return random_id; } @@ -100,55 +107,8 @@ assert(ret_s); assert(size > 0); - if (gethostname(ret_s, size) >= 0) { - ret_s[size-1] = 0; - strip_bad_chars(ret_s); - } else - *ret_s = 0; - - if (strcmp(ret_s, "localhost") == 0 || strncmp(ret_s, "localhost.", 10) == 0) { - *ret_s = 0; - avahi_log_warn("System host name is set to 'localhost'. This is not a suitable mDNS host name, looking for alternatives."); - } - - if (*ret_s == 0) { - /* No hostname was set, so let's take the OS name */ - -#ifdef __linux__ - - /* Try LSB distribution name first */ - if (load_lsb_distrib_id(ret_s, size) >= 0) { - strip_bad_chars(ret_s); - avahi_strdown(ret_s); - } - - if (*ret_s == 0) -#endif - - { - /* Try uname() second */ - struct utsname utsname; - - if (uname(&utsname) >= 0) { - snprintf(ret_s, size, "%s", utsname.sysname); - strip_bad_chars(ret_s); - avahi_strdown(ret_s); - } - - /* Give up */ - if (*ret_s == 0) - snprintf(ret_s, size, "unnamed"); - } - } - - /* Append random host ID */ - { - size_t len; - len = strlen(ret_s); - if (size > len) { - snprintf(ret_s + len, size - len, "-%x", random_host_id()); - } - } + // For Matter spec compliance, we use a host name in the form of a MAC address. + snprintf(ret_s, size, "%012" PRIX64 , random_host_id()); if (size >= AVAHI_LABEL_MAX) ret_s[AVAHI_LABEL_MAX-1] = 0;
diff --git a/avahi-glib/Android.mk b/avahi-glib/Android.mk new file mode 100644 index 0000000..eb26e48 --- /dev/null +++ b/avahi-glib/Android.mk
@@ -0,0 +1,55 @@ +LOCAL_PATH:=$(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE:=libavahi-glib + +LOCAL_SRC_FILES := \ + glib-watch.c \ + glib-malloc.c + +LOCAL_SHARED_LIBRARIES:=\ + libavahi-common \ + libglib + +LOCAL_CFLAGS := \ + -DHAVE_CONFIG_H \ + -g \ + -O2 \ + -fstack-protector \ + -std=c99 \ + -Wall \ + -W \ + -Wextra \ + -pedantic \ + -pipe \ + -Wformat \ + -Wold-style-definition \ + -Wdeclaration-after-statement \ + -Wfloat-equal \ + -Wmissing-declarations \ + -Wmissing-prototypes \ + -Wstrict-prototypes \ + -Wredundant-decls \ + -Wmissing-noreturn \ + -Wshadow \ + -Wendif-labels \ + -Wpointer-arith \ + -Wbad-function-cast \ + -Wcast-qual \ + -Wcast-align \ + -Wwrite-strings \ + -fdiagnostics-show-option \ + -Wno-cast-qual \ + -fno-strict-aliasing \ + -DDEBUG_TRAP=__asm__\(\"int\ $3\"\) + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH) \ + external/avahi \ + /usr/include/glib + +LOCAL_PRELINK_MODULE := false + +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/.. + +include $(BUILD_SHARED_LIBRARY)
diff --git a/avahi-glib/NOTICE b/avahi-glib/NOTICE new file mode 120000 index 0000000..7e1b82f --- /dev/null +++ b/avahi-glib/NOTICE
@@ -0,0 +1 @@ +../NOTICE \ No newline at end of file