Browse Source

[2587] Fix for unit test; set sa_len if available

On NetBSD4, getnameinfo() used in a test does a strict check on the sa_len field, which isn't set by asio. So this fix sets it if the field is there.
Jelte Jansen 12 years ago
parent
commit
4b9b3bdcb7
1 changed files with 11 additions and 2 deletions
  1. 11 2
      src/bin/auth/tests/auth_srv_unittest.cc

+ 11 - 2
src/bin/auth/tests/auth_srv_unittest.cc

@@ -1716,9 +1716,18 @@ void
 checkAddrPort(const struct sockaddr& actual_sa,
               const string& expected_addr, uint16_t expected_port)
 {
+    // ASIO does not set as_len, which is not a problem on most
+    // systems, but it will make getnameinfo() fail on NetBSD 4
+    // So we make a copy and if the field is available, we set it
+    const socklen_t sa_len = getSALength(actual_sa);
+    struct sockaddr sa;
+    memcpy(&sa, &actual_sa, sa_len);
+#ifdef HAVE_SA_LEN
+    sa.sa_len = sa_len;
+#endif
     char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
-    const int error = getnameinfo(&actual_sa, getSALength(actual_sa), hbuf,
-                                  sizeof(hbuf), sbuf, sizeof(sbuf),
+    const int error = getnameinfo(&sa, sa_len, hbuf, sizeof(hbuf),
+                                  sbuf, sizeof(sbuf),
                                   NI_NUMERICHOST | NI_NUMERICSERV);
     if (error != 0) {
         isc_throw(isc::Unexpected, "getnameinfo failed: " <<