Blame gnulib-tests/test-sys_socket.c

Packit Service fdd496
/* Test of <sys/socket.h> substitute.
Packit Service fdd496
   Copyright (C) 2007, 2009-2017 Free Software Foundation, Inc.
Packit Service fdd496
Packit Service fdd496
   This program is free software: you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3 of the License, or
Packit Service fdd496
   (at your option) any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
Packit Service fdd496
Packit Service fdd496
#include <config.h>
Packit Service fdd496
Packit Service fdd496
#include <sys/socket.h>
Packit Service fdd496
Packit Service fdd496
#include <errno.h>
Packit Service fdd496
Packit Service fdd496
#if HAVE_SHUTDOWN
Packit Service fdd496
/* Check some integer constant expressions.  */
Packit Service fdd496
int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
/* Check that the 'socklen_t' type is defined.  */
Packit Service fdd496
socklen_t t1;
Packit Service fdd496
Packit Service fdd496
/* Check that the 'size_t' and 'ssize_t' types are defined.  */
Packit Service fdd496
size_t t2;
Packit Service fdd496
ssize_t t3;
Packit Service fdd496
Packit Service fdd496
/* Check that 'struct iovec' is defined.  */
Packit Service fdd496
struct iovec io;
Packit Service fdd496
Packit Service fdd496
/* Check that a minimal set of 'struct msghdr' is defined.  */
Packit Service fdd496
struct msghdr msg;
Packit Service fdd496
Packit Service fdd496
int
Packit Service fdd496
main (void)
Packit Service fdd496
{
Packit Service fdd496
  struct sockaddr_storage x;
Packit Service fdd496
  sa_family_t i;
Packit Service fdd496
Packit Service fdd496
  /* Check some errno values.  */
Packit Service fdd496
  switch (ENOTSOCK)
Packit Service fdd496
    {
Packit Service fdd496
    case ENOTSOCK:
Packit Service fdd496
    case EADDRINUSE:
Packit Service fdd496
    case ENETRESET:
Packit Service fdd496
    case ECONNABORTED:
Packit Service fdd496
    case ECONNRESET:
Packit Service fdd496
    case ENOTCONN:
Packit Service fdd496
    case ESHUTDOWN:
Packit Service fdd496
      break;
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  x.ss_family = 42;
Packit Service fdd496
  i = 42;
Packit Service fdd496
  msg.msg_iov = &io;
Packit Service fdd496
Packit Service fdd496
  return (x.ss_family - i + msg.msg_namelen + msg.msg_iov->iov_len
Packit Service fdd496
          + msg.msg_iovlen);
Packit Service fdd496
}