diff --git a/java/jni/ZT_jniutils.cpp b/java/jni/ZT_jniutils.cpp index 24bca794e..e72771965 100644 --- a/java/jni/ZT_jniutils.cpp +++ b/java/jni/ZT_jniutils.cpp @@ -531,3 +531,28 @@ jbyteArray newByteArray(JNIEnv *env, size_t count) { return byteArrayObj; } + +bool isSocketAddressEmpty(const sockaddr_storage addr) { + + // + // was: + // struct sockaddr_storage nullAddress = {0}; + // + // but was getting this warning: + // warning: suggest braces around initialization of subobject + // + // when building ZeroTierOne + // + sockaddr_storage emptyAddress; //NOLINT + + // + // It is possible to assume knowledge about internals of sockaddr_storage and construct + // correct 0-initializer, but it is simpler to just treat sockaddr_storage as opaque and + // use memset here to fill with 0 + // + // This is also done in InetAddress.hpp for InetAddress + // + memset(&emptyAddress, 0, sizeof(sockaddr_storage)); + + return (memcmp(&addr, &emptyAddress, sizeof(sockaddr_storage)) == 0); //NOLINT +} diff --git a/java/jni/ZT_jniutils.h b/java/jni/ZT_jniutils.h index bad093218..e33dbea66 100644 --- a/java/jni/ZT_jniutils.h +++ b/java/jni/ZT_jniutils.h @@ -160,4 +160,6 @@ jbyteArray newByteArray(JNIEnv *env, const unsigned char *bytes, size_t count); jbyteArray newByteArray(JNIEnv *env, size_t count); +bool isSocketAddressEmpty(const sockaddr_storage addr); + #endif // ZT_jniutils_h_