File: accept.c

package info (click to toggle)
systemtap 4.8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 39,000 kB
  • sloc: cpp: 78,785; ansic: 62,419; xml: 49,443; exp: 42,735; sh: 11,254; python: 3,062; perl: 2,252; tcl: 1,305; makefile: 1,072; lisp: 105; awk: 101; asm: 91; java: 56; sed: 16
file content (58 lines) | stat: -rw-r--r-- 1,595 bytes parent folder | download | duplicates (6)
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
/* COVERAGE: accept */

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <signal.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
    int s, fd_null;
    struct sockaddr_in sin1;
    socklen_t sinlen;

    /* On several platforms, glibc substitutes accept4() for
     * accept(). So, we'll just accept accept() or accept4(). */

    /* initialize sockaddr's */
    sin1.sin_family = AF_INET;
    sin1.sin_port = htons((getpid() % 32768) + 11000);
    sin1.sin_addr.s_addr = INADDR_ANY;
    sinlen = sizeof(sin1);

    fd_null = open("/dev/null", O_WRONLY);

    accept(-1, (struct sockaddr *)&sin1, &sinlen);
    //staptest// accept[4]? (-1, XXXX, XXXX[[[[, 0x0]]]]?) = -NNNN (EBADF)

    accept(fd_null, (struct sockaddr *)&sin1, &sinlen);
    //staptest// accept[4]? (NNNN, XXXX, XXXX[[[[, 0x0]]]]?) = -NNNN (ENOTSOCK)

    s = socket(PF_INET, SOCK_STREAM, 0);
    //staptest// socket (PF_INET, SOCK_STREAM, IPPROTO_IP) = NNNN

    bind(s, (struct sockaddr *)&sin1, sizeof(sin1));
    //staptest// bind (NNNN, {AF_INET, 0.0.0.0, NNNN}, 16) = NNNN

    accept(s, (struct sockaddr *)-1, &sinlen);
    //staptest// accept[4]? (NNNN, 0x[f]+, XXXX[[[[, 0x0]]]]?) = -NNNN (EINVAL)

    accept(s, (struct sockaddr *)&sin1, (socklen_t *)-1);
    //staptest// accept[4]? (NNNN, XXXX, 0x[f]+[[[[, 0x0]]]]?) = -NNNN (EINVAL)

    close(s);
    //staptest// close (NNNN) = 0

    close(fd_null);
    //staptest// close (NNNN) = 0

    return 0;
}