Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/sys - ATF_REQUIRE(EINVAL == errno);



details:   https://anonhg.NetBSD.org/src/rev/324d9e2db61f
branches:  trunk
changeset: 337184:324d9e2db61f
user:      rtr <rtr%NetBSD.org@localhost>
date:      Sun Apr 05 23:15:54 2015 +0000

description:
-       ATF_REQUIRE(EINVAL == errno);
+       ATF_REQUIRE(EAFNOSUPPORT == errno);

as per http://pubs.opengroup.org/onlinepubs/009695399/functions/bind.html

while here remove some unnecessary initialization of port and addr members
and replace with a comment explaining why.

diffstat:

 tests/lib/libc/sys/t_bind.c |  14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diffs (35 lines):

diff -r fb0ca90402c2 -r 324d9e2db61f tests/lib/libc/sys/t_bind.c
--- a/tests/lib/libc/sys/t_bind.c       Sun Apr 05 22:36:36 2015 +0000
+++ b/tests/lib/libc/sys/t_bind.c       Sun Apr 05 23:15:54 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_bind.c,v 1.1 2015/04/05 06:36:52 martin Exp $        */
+/*     $NetBSD: t_bind.c,v 1.2 2015/04/05 23:15:54 rtr Exp $   */
 /*
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -50,17 +50,21 @@
 {
        struct sockaddr_in addr;
 
+       /* addr.sin_family = AF_UNSPEC = 0 */
        memset(&addr, 0, sizeof(addr));
-       /* use a sin_family != the socket type */
-       addr.sin_port = htons(8000);
-       addr.sin_addr.s_addr = INADDR_ANY;
+
+       /*
+        * it is not necessary to initialize sin_{addr,port} since
+        * those structure members shall not be accessed if bind
+        * fails correctly.
+        */
 
        int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
        ATF_REQUIRE(sock != -1);
 
        /* should fail but currently doesn't */
        ATF_REQUIRE(-1 == bind(sock, (struct sockaddr *)&addr, sizeof(addr)));
-       ATF_REQUIRE(EINVAL == errno);
+       ATF_REQUIRE(EAFNOSUPPORT == errno);
 
        close(sock);
 }



Home | Main Index | Thread Index | Old Index