add isSocketAddressEmpty

This commit is contained in:
Brenton Bostick 2023-02-02 13:32:49 -05:00
parent 809022b273
commit 40d5f9b5d2
2 changed files with 27 additions and 0 deletions

View File

@ -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
}

View File

@ -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_