diff --git a/src/libpsl-native/src/getfullyqualifiedname.cpp b/src/libpsl-native/src/getfullyqualifiedname.cpp index ef3605b4db..e88ab988e7 100644 --- a/src/libpsl-native/src/getfullyqualifiedname.cpp +++ b/src/libpsl-native/src/getfullyqualifiedname.cpp @@ -11,15 +11,7 @@ //! @brief GetFullyQualifiedName retrieves the fully qualified dns name of the host //! -//! @exception errno Passes these errors via errno to GetLastError: -//! - ERROR_INVALID_FUNCTION: getlogin_r() returned an unrecognized error code (from GetComputerName) -//! - ERROR_INVALID_ADDRESS: buffer is an invalid address (from GetComputerName) -//! - ERROR_GEN_FAILURE: buffer not large enough (from GetComputerName) -//! - ERROR_BAD_NET_NAME: Cannot determine network short name -//! //! @retval username as UTF-8 string, or null if unsuccessful -//! - char *GetFullyQualifiedName() { errno = 0; diff --git a/src/libpsl-native/test/test-getfullyqualifiedname.cpp b/src/libpsl-native/test/test-getfullyqualifiedname.cpp index 7e11d740fa..443ad23302 100644 --- a/src/libpsl-native/test/test-getfullyqualifiedname.cpp +++ b/src/libpsl-native/test/test-getfullyqualifiedname.cpp @@ -12,19 +12,30 @@ TEST(GetFullyQualifiedNameTest, ValidateLinuxGetFullyQualifiedDomainName) { - std::string actual(GetFullyQualifiedName()); - std::string hostname(GetComputerName()); + char *hostname = GetComputerName(); + ASSERT_STRNE(NULL, hostname); + + // this might be fail + errno = 0; + char *actual = GetFullyQualifiedName(); + int fqdnErrno = errno; struct addrinfo hints, *info; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_CANONNAME; - EXPECT_FALSE(getaddrinfo(hostname.c_str(), "http", &hints, &info)); + errno = 0; + if (getaddrinfo(hostname, "http", &hints, &info) != 0) + { + // test that getaddrinfo failed the same way + EXPECT_EQ(fqdnErrno, errno); + goto exit; + } // Compare canonical name to FQDN - EXPECT_STREQ(info->ai_canonname, actual.c_str()); - + EXPECT_STREQ(info->ai_canonname, actual); freeaddrinfo(info); - +exit: + free(hostname); }