Blame gl/tests/test-connect.c

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