Debian Codegraph @

testsuite/systemtap.syscall/net1.c

raw
1 /* COVERAGE: socket fcntl fcntl64 bind listen accept */
2 #include <unistd.h>
3 #include <fcntl.h>
4 #include <sys/types.h>
5 #include <sys/socket.h>
6 #include <netinet/in.h>
7 #include <string.h>
8
9 int main()
10 {
11 struct sockaddr_in sa;
12 int flags, listenfd, cfd;
13
14
15 listenfd = socket(AF_INET, SOCK_STREAM, 0);
16 //staptest// socket (PF_INET, SOCK_STREAM, IPPROTO_IP) = NNNN
17
18 flags = fcntl(listenfd, F_GETFL, 0);
19 //staptest// fcntl[64]* (NNNN, F_GETFL, 0x[0]+) = NNNN
20
21 fcntl(listenfd, F_SETFL, flags | O_NONBLOCK);
22 //staptest// fcntl[64]* (NNNN, F_SETFL, XXXX) = 0
23
24 memset(&sa, 0, sizeof(sa));
25 sa.sin_family=AF_INET;
26 sa.sin_addr.s_addr = htonl(INADDR_ANY);
27 sa.sin_port = htons(8765);
28
29 bind(listenfd, (struct sockaddr *)&sa, sizeof(sa));
30 //staptest// bind (NNNN, {AF_INET, 0.0.0.0, 8765}, 16) = 0
31
32 listen (listenfd, 7);
33 //staptest// listen (NNNN, 7) = 0
34
35 cfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
36 //staptest// accept (NNNN, 0x0, 0x0) = -NNNN (EAGAIN)
37
38 close(cfd);
39
40 flags = fcntl(-1, F_GETFL, 0);
41 //staptest// fcntl[64]* (-1, F_GETFL, 0x[0]+) = -NNNN (EBADF)
42
43 flags = fcntl(listenfd, -1, 0);
44 //staptest// fcntl[64]* (NNNN, 0x[f]+, 0x[0]+) = -NNNN
45
46 flags = fcntl(listenfd, F_GETFL, -1);
47 //staptest// fcntl[64]* (NNNN, F_GETFL, 0x[f]+) = NNNN
48
49 close(listenfd);
50 return 0;
51 }