aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools/syscall_test.c
blob: 47c27978bf188a342137f629c916d5c19512457f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <net/ethernet.h>

int main(int argc, char **argv) {
	if (argc != 2) {
		printf("Usage: test [sleep|socket|mkdir]\n");
		return 1;
	}

	if (strcmp(argv[1], "sleep") == 0) {
		printf("before sleep\n");
		sleep(1);
		printf("after sleep\n");
	}
	else if (strcmp(argv[1], "socket") == 0) {
		int sock;

		printf("testing socket AF_INET\n");
		if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
			perror("socket");
		}
		else
			close(sock);

		printf("testing socket AF_INET6\n");
		if ((sock = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
			perror("socket");
		}
		else
			close(sock);

		printf("testing socket AF_NETLINK\n");
		if ((sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) {
			perror("socket");
		}
		else
			close(sock);
			
		printf("testing socket AF_UNIX\n");
		if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
			perror("socket");
		}
		else
			close(sock);
			
		// root needed to be able to handle this
		printf("testing socket AF_PACKETX\n");
		if ((sock = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_ARP))) < 0) {
			perror("socket");
		}
		else
			close(sock);
		printf("after socket\n");
	}
	else if (strcmp(argv[1], "mkdir") == 0) {
		printf("before mkdir\n");
		mkdir("tmp", 0777);
		printf("after mkdir\n");
	}
	else {
		fprintf(stderr, "Error: invalid argument\n");
		return 1;
	}
	return 0;
}