Blame gl/tests/test-connect.c

Packit Service 4684c1
/* Test connecting a client socket.
Packit Service 4684c1
   Copyright (C) 2011-2020 Free Software Foundation, Inc.
Packit Service 4684c1
Packit Service 4684c1
   This program is free software: you can redistribute it and/or modify
Packit Service 4684c1
   it under the terms of the GNU General Public License as published by
Packit Service 4684c1
   the Free Software Foundation; either version 3 of the License, or
Packit Service 4684c1
   (at your option) any later version.
Packit Service 4684c1
Packit Service 4684c1
   This program is distributed in the hope that it will be useful,
Packit Service 4684c1
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 4684c1
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 4684c1
   GNU General Public License for more details.
Packit Service 4684c1
Packit Service 4684c1
   You should have received a copy of the GNU General Public License
Packit Service 4684c1
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit Service 4684c1
Packit Service 4684c1
#include <config.h>
Packit Service 4684c1
Packit Service 4684c1
#include <sys/socket.h>
Packit Service 4684c1
Packit Service 4684c1
#include "signature.h"
Packit Service 4684c1
SIGNATURE_CHECK (connect, int, (int, const struct sockaddr *, socklen_t));
Packit Service 4684c1
Packit Service 4684c1
#include <errno.h>
Packit Service 4684c1
#include <netinet/in.h>
Packit Service 4684c1
#include <arpa/inet.h>
Packit Service 4684c1
#include <unistd.h>
Packit Service 4684c1
Packit Service 4684c1
#include "sockets.h"
Packit Service 4684c1
#include "macros.h"
Packit Service 4684c1
Packit Service 4684c1
int
Packit Service 4684c1
main (void)
Packit Service 4684c1
{
Packit Service 4684c1
  (void) gl_sockets_startup (SOCKETS_1_1);
Packit Service 4684c1
Packit Service 4684c1
  /* Test behaviour for invalid file descriptors.  */
Packit Service 4684c1
  {
Packit Service 4684c1
    struct sockaddr_in addr;
Packit Service 4684c1
Packit Service 4684c1
    addr.sin_family = AF_INET;
Packit Service 4684c1
    inet_pton (AF_INET, "127.0.0.1", &addr.sin_addr);
Packit Service 4684c1
    addr.sin_port = htons (80);
Packit Service 4684c1
    {
Packit Service 4684c1
      errno = 0;
Packit Service 4684c1
      ASSERT (connect (-1, (const struct sockaddr *) &addr, sizeof (addr))
Packit Service 4684c1
              == -1);
Packit Service 4684c1
      ASSERT (errno == EBADF);
Packit Service 4684c1
    }
Packit Service 4684c1
    {
Packit Service 4684c1
      close (99);
Packit Service 4684c1
      errno = 0;
Packit Service 4684c1
      ASSERT (connect (99, (const struct sockaddr *) &addr, sizeof (addr))
Packit Service 4684c1
              == -1);
Packit Service 4684c1
      ASSERT (errno == EBADF);
Packit Service 4684c1
    }
Packit Service 4684c1
  }
Packit Service 4684c1
Packit Service 4684c1
  return 0;
Packit Service 4684c1
}