testsuite: Skip analyzer tests on AIX.
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / fd-glibc-byte-stream-socket.c
blobd9666f99edd5cf8ea82b08b584fa68b31864be5b
1 /* Example from glibc manual (16.9.6). */
2 /* { dg-require-effective-target sockets } */
3 /* { dg-skip-if "" { powerpc*-*-aix* } } */
5 #include <stdio.h>
6 #include <string.h>
7 #include <errno.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <sys/types.h>
11 #include <sys/socket.h>
12 #include <netinet/in.h>
13 #include <netdb.h>
15 #define PORT 5555
16 #define MESSAGE "Yow!!! Are we having fun yet?!?"
17 #define SERVERHOST "www.gnu.org"
19 void
20 write_to_server (int filedes)
22 int nbytes;
24 nbytes = write (filedes, MESSAGE, strlen (MESSAGE) + 1);
25 if (nbytes < 0)
27 perror ("write");
28 exit (EXIT_FAILURE);
33 int
34 main (void)
36 extern void init_sockaddr (struct sockaddr_in *name,
37 const char *hostname,
38 uint16_t port);
39 int sock;
40 struct sockaddr_in servername;
42 /* Create the socket. */
43 sock = socket (PF_INET, SOCK_STREAM, 0);
44 if (sock < 0)
46 perror ("socket (client)");
47 exit (EXIT_FAILURE);
50 /* Connect to the server. */
51 init_sockaddr (&servername, SERVERHOST, PORT);
52 if (0 > connect (sock,
53 (struct sockaddr *) &servername,
54 sizeof (servername)))
56 perror ("connect (client)");
57 exit (EXIT_FAILURE);
60 /* Send data to the server. */
61 write_to_server (sock);
62 close (sock);
63 exit (EXIT_SUCCESS);