1e7c06510178c9167b948a417f28159c317735687robbiew/*
2e7c06510178c9167b948a417f28159c317735687robbiew * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
36b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis *    AUTHOR : sowmya adiga<sowmya.adiga@wipro.com>
46b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
5e7c06510178c9167b948a417f28159c317735687robbiew *
6e7c06510178c9167b948a417f28159c317735687robbiew * This program is free software; you can redistribute it and/or modify it
7e7c06510178c9167b948a417f28159c317735687robbiew * under the terms of version 2 of the GNU General Public License as
8e7c06510178c9167b948a417f28159c317735687robbiew * published by the Free Software Foundation.
9e7c06510178c9167b948a417f28159c317735687robbiew *
10e7c06510178c9167b948a417f28159c317735687robbiew * This program is distributed in the hope that it would be useful, but
11e7c06510178c9167b948a417f28159c317735687robbiew * WITHOUT ANY WARRANTY; without even the implied warranty of
12e7c06510178c9167b948a417f28159c317735687robbiew * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13e7c06510178c9167b948a417f28159c317735687robbiew *
14e7c06510178c9167b948a417f28159c317735687robbiew * You should have received a copy of the GNU General Public License along
15fed9641096e27f79a0f2d9adfe9839dd8d11dc0fWanlong Gao * with this program; if not, write the Free Software Foundation, Inc.,
16fed9641096e27f79a0f2d9adfe9839dd8d11dc0fWanlong Gao * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17e7c06510178c9167b948a417f28159c317735687robbiew *
18e7c06510178c9167b948a417f28159c317735687robbiew */
196b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis/*
206b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis * This is a basic test for the socketcall(2) system call.
216b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis */
22e0ccc7dab8bb803c2df7de525d214d84a6387a88vapier#include <unistd.h>
236b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis#include <errno.h>
24e7c06510178c9167b948a417f28159c317735687robbiew#include <sys/types.h>
25e7c06510178c9167b948a417f28159c317735687robbiew#include <sys/socket.h>
266b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis#include <sys/syscall.h>
27e7c06510178c9167b948a417f28159c317735687robbiew#include <linux/net.h>
28e0ccc7dab8bb803c2df7de525d214d84a6387a88vapier#include <sys/un.h>
29e0ccc7dab8bb803c2df7de525d214d84a6387a88vapier#include <netinet/in.h>
30afd4843765a549fedf06fbf402fe4a07bf84a953robbiew
316b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis#include "tst_test.h"
32e0ccc7dab8bb803c2df7de525d214d84a6387a88vapier
33322602838a2da51eef286301972d7277454646abrobbiew#ifdef __NR_socketcall
34322602838a2da51eef286301972d7277454646abrobbiew
35e0ccc7dab8bb803c2df7de525d214d84a6387a88vapier#define socketcall(call, args) syscall(__NR_socketcall, call, args)
36e7c06510178c9167b948a417f28159c317735687robbiew
37e7c06510178c9167b948a417f28159c317735687robbiewstruct test_case_t {
38e7c06510178c9167b948a417f28159c317735687robbiew	int call;
39e7c06510178c9167b948a417f28159c317735687robbiew	unsigned long args[3];
40e7c06510178c9167b948a417f28159c317735687robbiew	char *desc;
4156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak} TC[] = {
426b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis	{SYS_SOCKET, {PF_INET, SOCK_STREAM, 0}, "TCP stream"},
436b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis	{SYS_SOCKET, {PF_UNIX, SOCK_DGRAM, 0}, "unix domain dgram"},
446b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis	{SYS_SOCKET, {AF_INET, SOCK_RAW, 6}, "Raw socket"},
456b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis	{SYS_SOCKET, {PF_INET, SOCK_DGRAM, 17}, "UDP dgram"}
46e7c06510178c9167b948a417f28159c317735687robbiew};
47e7c06510178c9167b948a417f28159c317735687robbiew
486b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubisvoid verify_socketcall(unsigned int i)
49e7c06510178c9167b948a417f28159c317735687robbiew{
506b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis	TEST(socketcall(TC[i].call, TC[i].args));
51e7c06510178c9167b948a417f28159c317735687robbiew
526b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis	if (TEST_RETURN < 0) {
536b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis		tst_res(TFAIL | TTERRNO, "socketcall() for %s failed with %li",
546b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis			TC[i].desc, TEST_RETURN);
556b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis		return;
56e7c06510178c9167b948a417f28159c317735687robbiew	}
5756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak
586b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis	tst_res(TPASS, "socketcall() for %s", TC[i].desc);
59e7c06510178c9167b948a417f28159c317735687robbiew
606b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis	SAFE_CLOSE(TEST_RETURN);
61e7c06510178c9167b948a417f28159c317735687robbiew}
62e7c06510178c9167b948a417f28159c317735687robbiew
636b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubisstatic struct tst_test test = {
646b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis	.test = verify_socketcall,
656b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis	.tcnt = ARRAY_SIZE(TC),
666b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis	.needs_root = 1,
676b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril Hrubis};
68322602838a2da51eef286301972d7277454646abrobbiew
69322602838a2da51eef286301972d7277454646abrobbiew#else
70322602838a2da51eef286301972d7277454646abrobbiew
716b37c6f648fea4be733cd930b2fa570be1a97cf9Cyril HrubisTST_TEST_TCONF("The socketcall() syscall is not supported");
72322602838a2da51eef286301972d7277454646abrobbiew
73ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman#endif
74