Home | History | Annotate | Line # | Download | only in sys
t_bind.c revision 1.1
      1 /*	$NetBSD: t_bind.c,v 1.1 2015/04/05 06:36:52 martin Exp $	*/
      2 /*
      3  * Copyright (c) 2015 The NetBSD Foundation, Inc.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
     16  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     17  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
     20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     22  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
     24  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <errno.h>
     30 #include <stdlib.h>
     31 #include <string.h>
     32 
     33 #include <unistd.h>
     34 
     35 #include <sys/socket.h>
     36 #include <arpa/inet.h>
     37 #include <netinet/in.h>
     38 
     39 #include <atf-c.h>
     40 
     41 ATF_TC(bind_foreign_family);
     42 
     43 ATF_TC_HEAD(bind_foreign_family, tc)
     44 {
     45 	atf_tc_set_md_var(tc, "descr", "Checks that bindinging a socket "
     46 	    "with a different address family fails");
     47 }
     48 
     49 ATF_TC_BODY(bind_foreign_family, tc)
     50 {
     51 	struct sockaddr_in addr;
     52 
     53 	memset(&addr, 0, sizeof(addr));
     54 	/* use a sin_family != the socket type */
     55 	addr.sin_port = htons(8000);
     56 	addr.sin_addr.s_addr = INADDR_ANY;
     57 
     58 	int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
     59 	ATF_REQUIRE(sock != -1);
     60 
     61 	/* should fail but currently doesn't */
     62 	ATF_REQUIRE(-1 == bind(sock, (struct sockaddr *)&addr, sizeof(addr)));
     63 	ATF_REQUIRE(EINVAL == errno);
     64 
     65 	close(sock);
     66 }
     67 
     68 ATF_TP_ADD_TCS(tp)
     69 {
     70 
     71 	ATF_TP_ADD_TC(tp, bind_foreign_family);
     72 
     73 	return atf_no_error();
     74 }
     75