1  /* { dg-require-effective-target sockets } */
       2  /* { dg-skip-if "" { powerpc*-*-aix* } } */
       3  
       4  #include <sys/socket.h>
       5  #include <sys/un.h>
       6  #include <unistd.h>
       7  #include <errno.h>
       8  #include "analyzer-decls.h"
       9  
      10  int test_connect (int sockfd, const struct sockaddr *addr,
      11  		  socklen_t addrlen)
      12  {
      13    return connect (sockfd, addr, addrlen);
      14  }
      15  
      16  void test_null_connect (int fd)
      17  {
      18    errno = 0;
      19    int result = connect (fd, NULL, 0);
      20    __analyzer_eval (result == -1); /* { dg-warning "TRUE" } */
      21    __analyzer_eval (errno > 0); /* { dg-warning "TRUE" } */
      22  }
      23  
      24  int test_uninit_addr (int fd, const char *sockname)
      25  {
      26    struct sockaddr_un addr;
      27    return connect (fd, (struct sockaddr *)&addr, sizeof (addr));
      28    // TODO: complain about uninit addr.
      29  }
      30  
      31  void test_connect_after_bind (const char *sockname,
      32  			      const struct sockaddr *baddr, socklen_t baddrlen,
      33  			      const struct sockaddr *caddr, socklen_t caddrlen)
      34  {
      35    int fd = socket (AF_UNIX, SOCK_STREAM, 0); /* { dg-message "stream socket created here" } */
      36    if (fd == -1)
      37      return;
      38  
      39    if (bind (fd, baddr, baddrlen) == -1)
      40      {
      41        close (fd);
      42        return;
      43      }
      44  
      45    connect (fd, caddr, caddrlen); /* { dg-warning "'connect' on file descriptor 'fd' in wrong phase" "warning" } */
      46    /* { dg-message "'connect' expects a new socket file descriptor but 'fd' is bound" "final event" { target *-*-* } .-1 } */
      47  
      48    close (fd);      
      49  }
      50  
      51  int test_connect_on_constant ()
      52  {
      53    return connect (0, NULL, 0);
      54  }