• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
4  * Copyright (c) 2020 Yang Xu <xuyang2018.jy@cn.fujitsu.com>
5  * Author: Sowmya Adiga <sowmya.adiga@wipro.com>
6  *
7  * This is a basic test for the socketcall(2) for bind(2) and listen(2).
8  */
9 #include <unistd.h>
10 #include <errno.h>
11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #include <linux/net.h>
14 #include <sys/un.h>
15 #include <netinet/in.h>
16 
17 #include "tst_test.h"
18 #include "lapi/syscalls.h"
19 
20 static struct sockaddr_in si;
21 
verify_socketcall(void)22 static void verify_socketcall(void)
23 {
24 	unsigned long args[3];
25 	int s = -1;
26 
27 	s = SAFE_SOCKET(AF_INET, SOCK_STREAM, 6);
28 	args[0] = s;
29 	args[1] = (unsigned long)&si;
30 	args[2] = sizeof(si);
31 
32 	TEST(tst_syscall(__NR_socketcall, SYS_BIND, args));
33 	if (TST_RET < 0)
34 		tst_res(TFAIL | TTERRNO, "socketcall() for bind call failed with %ld", TST_RET);
35 	else
36 		tst_res(TPASS, "socketcall() for bind call passed, returned %ld", TST_RET);
37 
38 	args[1] = 1;
39 	args[2] = 0;
40 
41 	TEST(tst_syscall(__NR_socketcall, SYS_LISTEN, args));
42 	if (TST_RET < 0)
43 		tst_res(TFAIL | TTERRNO, "socketcall() for listen call failed with %ld", TST_RET);
44 	else
45 		tst_res(TPASS, "socketcall() for listen call passed, returned %ld", TST_RET);
46 
47 	SAFE_CLOSE(s);
48 }
49 
setup(void)50 static void setup(void)
51 {
52 	si.sin_family = AF_INET;
53 	si.sin_addr.s_addr = htons(INADDR_ANY);
54 	si.sin_port = 0;
55 }
56 
57 static struct tst_test test = {
58 	.setup = setup,
59 	.test_all = verify_socketcall,
60 };
61