[svn] commit: r3159 - in /branches/vorner-sockcreator/src/bin/sockcreator: sockcreator.cc tests/sockcreator_tests.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Sun Oct 10 08:01:33 UTC 2010


Author: vorner
Date: Sun Oct 10 08:01:33 2010
New Revision: 3159

Log:
Implemented get_sock

And fixed a test. It seems underlaying bind does not like passing NULL
pointer as address and kills program with sigterm.

Modified:
    branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.cc
    branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc

Modified: branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.cc
==============================================================================
--- branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.cc (original)
+++ branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.cc Sun Oct 10 08:01:33 2010
@@ -23,7 +23,14 @@
 int
 get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len)
 {
-    // TODO Implement
+    int sock(socket(bind_addr->sa_family, type, 0));
+    if(sock == -1) {
+        return -1;
+    }
+    if(bind(sock, bind_addr, addr_len) == -1) {
+        return -2;
+    }
+    return sock;
 }
 
 int

Modified: branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc
==============================================================================
--- branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc (original)
+++ branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc Sun Oct 10 08:01:33 2010
@@ -109,7 +109,9 @@
  * is able to report error.
  */
 TEST(get_sock, fail_with_nonsense) {
-    ASSERT_LT(get_sock(0, NULL, 0), 0);
+    struct sockaddr addr;
+    memset(&addr, 0, sizeof addr);
+    ASSERT_LT(get_sock(0, &addr, sizeof addr), 0);
 }
 
 /*




More information about the bind10-changes mailing list