1 /* { dg-require-effective-target sockets } */
2 /* { dg-skip-if "" { powerpc*-*-aix* } } */
5 #include <sys/socket.h>
9 #include "analyzer-decls.h"
11 int test_listen (int fd
, int backlog
)
13 return listen (fd
, backlog
);
16 /* Some systems seem to allow repeated calls to listen. */
18 void test_double_listen (int fd
, int backlog
)
24 void test_listen_before_bind (int fd
, const char *sockname
)
26 if (listen (fd
, 5) == -1) /* { dg-message "stream socket marked as passive here via 'listen'" } */
29 struct sockaddr_un addr
;
30 memset (&addr
, 0, sizeof (addr
));
31 addr
.sun_family
= AF_UNIX
;
32 strncpy (addr
.sun_path
, sockname
, sizeof(addr
.sun_path
) - 1);
33 bind (fd
, (struct sockaddr
*)&addr
, sizeof (addr
)); /* { dg-warning "'bind' on file descriptor 'fd' in wrong phase" "warning" } */
34 /* { dg-message "'bind' expects a new socket file descriptor but 'fd' is already listening" "final event" { target *-*-* } .-1 } */
37 void test_listen_on_unchecked_bind (int fd
, const char *sockname
)
39 struct sockaddr_un addr
;
40 memset (&addr
, 0, sizeof (addr
));
41 addr
.sun_family
= AF_UNIX
;
42 strncpy (addr
.sun_path
, sockname
, sizeof(addr
.sun_path
) - 1);
43 bind (fd
, (struct sockaddr
*)&addr
, sizeof (addr
)); /* { dg-message "when 'bind' fails" } */
44 listen (fd
, 5); /* { dg-warning "'listen' on file descriptor 'fd' in wrong phase" "warning" } */
45 /* { dg-message "'listen' expects a bound stream socket file descriptor but 'fd' has not yet been bound" "final event" { target *-*-* } .-1 } */
49 void test_listen_on_new_datagram_socket (void)
51 int fd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
54 listen (fd
, 5); /* { dg-message "'listen' on datagram socket file descriptor 'fd' \\\[-Wanalyzer-fd-type-mismatch\\\]" "warning" } */
55 /* { dg-message "'listen' expects a stream socket file descriptor but 'fd' is a datagram socket" "final event" { target *-*-* } .-1 } */
59 void test_listen_on_connected_socket (int fd
)
61 int afd
= accept (fd
, NULL
, 0);
64 listen (afd
, 5); /* { dg-warning "'listen' on file descriptor 'afd' in wrong phase" "warning" } */
65 /* { dg-message "'listen' expects a bound stream socket file descriptor but 'afd' is connected" "final event" { target *-*-* } .-1 } */
69 int test_listen_on_constant ()
71 return listen (0, 10);