Home | History | Annotate | Download | only in socketcall
      1 /*
      2  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
      3  *    AUTHOR : sowmya adiga<sowmya.adiga (at) wipro.com>
      4  * Copyright (c) 2016 Cyril Hrubis <chrubis (at) suse.cz>
      5  *
      6  * This program is free software; you can redistribute it and/or modify it
      7  * under the terms of version 2 of the GNU General Public License as
      8  * published by the Free Software Foundation.
      9  *
     10  * This program is distributed in the hope that it would be useful, but
     11  * WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     13  *
     14  * You should have received a copy of the GNU General Public License along
     15  * with this program; if not, write the Free Software Foundation, Inc.,
     16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     17  *
     18  */
     19 /*
     20  * This is a basic test for the socketcall(2) system call.
     21  */
     22 #include <unistd.h>
     23 #include <errno.h>
     24 #include <sys/types.h>
     25 #include <sys/socket.h>
     26 #include <sys/syscall.h>
     27 #include <linux/net.h>
     28 #include <sys/un.h>
     29 #include <netinet/in.h>
     30 
     31 #include "tst_test.h"
     32 
     33 #ifdef __NR_socketcall
     34 
     35 #define socketcall(call, args) syscall(__NR_socketcall, call, args)
     36 
     37 struct test_case_t {
     38 	int call;
     39 	unsigned long args[3];
     40 	char *desc;
     41 } TC[] = {
     42 	{SYS_SOCKET, {PF_INET, SOCK_STREAM, 0}, "TCP stream"},
     43 	{SYS_SOCKET, {PF_UNIX, SOCK_DGRAM, 0}, "unix domain dgram"},
     44 	{SYS_SOCKET, {AF_INET, SOCK_RAW, 6}, "Raw socket"},
     45 	{SYS_SOCKET, {PF_INET, SOCK_DGRAM, 17}, "UDP dgram"}
     46 };
     47 
     48 void verify_socketcall(unsigned int i)
     49 {
     50 	TEST(socketcall(TC[i].call, TC[i].args));
     51 
     52 	if (TEST_RETURN < 0) {
     53 		tst_res(TFAIL | TTERRNO, "socketcall() for %s failed with %li",
     54 			TC[i].desc, TEST_RETURN);
     55 		return;
     56 	}
     57 
     58 	tst_res(TPASS, "socketcall() for %s", TC[i].desc);
     59 
     60 	SAFE_CLOSE(TEST_RETURN);
     61 }
     62 
     63 static struct tst_test test = {
     64 	.tid = "socketcall01",
     65 	.test = verify_socketcall,
     66 	.tcnt = ARRAY_SIZE(TC),
     67 	.needs_root = 1,
     68 };
     69 
     70 #else
     71 
     72 TST_TEST_TCONF("The socketcall() syscall is not supported");
     73 
     74 #endif
     75