Debian Codegraph @

testsuite/systemtap.syscall/accept4.c

raw
1 /* COVERAGE: accept4 */
2
3 #define _GNU_SOURCE
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include <sys/un.h>
10 #include <netinet/in.h>
11 #include <signal.h>
12 #include <errno.h>
13 #include <stdlib.h>
14 #include <sys/stat.h>
15 #include <fcntl.h>
16 #include <sys/syscall.h>
17
18 // Note we can't test for __NR_accept4 here and avoid compilation if
19 // it isn't set, since on some platforms accept4() gets implemented
20 // via socketcall(). But, accept4 support was added to glibc in
21 // version 2.10.
22
23 int main()
24 {
25 #if __GLIBC_PREREQ(2, 10)
26 int s, fd_null;
27 struct sockaddr_in sin1;
28 socklen_t sinlen;
29
30 /* initialize sockaddr's */
31 sin1.sin_family = AF_INET;
32 sin1.sin_port = htons((getpid() % 32768) + 11000);
33 sin1.sin_addr.s_addr = INADDR_ANY;
34
35 fd_null = open("/dev/null", O_WRONLY);
36
37 accept4(-1, NULL, NULL, 0);
38 //staptest// accept4 (-1, 0x0, 0x0, 0x0) = -NNNN (EBADF)
39
40 accept4(fd_null, (struct sockaddr *)&sin1, &sinlen, 0);
41 //staptest// accept4 (NNNN, XXXX, XXXX, 0x0) = -NNNN (ENOTSOCK)
42
43 s = socket(PF_INET, SOCK_STREAM, 0);
44 //staptest// socket (PF_INET, SOCK_STREAM, IPPROTO_IP) = NNNN
45
46 bind(s, (struct sockaddr *)&sin1, sizeof(sin1));
47 //staptest// bind (NNNN, {AF_INET, 0.0.0.0, NNNN}, 16) = 0
48
49 accept4(s, (struct sockaddr *)-1, &sinlen, 0);
50 //staptest// accept4 (NNNN, 0x[f]+, XXXX, 0x0) = -NNNN (EINVAL)
51
52 accept4(s, (struct sockaddr *)&sin1, (socklen_t *)-1, 0);
53 //staptest// accept4 (NNNN, XXXX, 0x[f]+, 0x0) = -NNNN (EINVAL)
54
55 #ifndef SOCK_CLOEXEC
56 #define SOCK_CLOEXEC 02000000
57 #endif
58 accept4(s, (struct sockaddr *)&sin1, (socklen_t *)&sinlen, SOCK_CLOEXEC);
59 //staptest// accept4 (NNNN, XXXX, XXXX, SOCK_CLOEXEC) = -NNNN (EINVAL)
60
61 accept4(s, (struct sockaddr *)&sin1, (socklen_t *)&sinlen, -1);
62 //staptest// accept4 (NNNN, XXXX, XXXX, SOCK_CLOEXEC|SOCK_NONBLOCK|0xfff7f7ff) = -NNNN (EINVAL)
63
64 close(s);
65 //staptest// close (NNNN) = 0
66
67 close(fd_null);
68 //staptest// close (NNNN) = 0
69 #endif
70
71 return 0;
72 }