Blame gnulib-tests/test-inet_pton.c

Packit Service fdd496
/* Test of inet_pton function.
Packit Service fdd496
   Copyright (C) 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>, 2009.  */
Packit Service fdd496
Packit Service fdd496
#include <config.h>
Packit Service fdd496
Packit Service fdd496
#include <arpa/inet.h>
Packit Service fdd496
Packit Service fdd496
#include "signature.h"
Packit Service fdd496
SIGNATURE_CHECK (inet_pton, int, (int, const char *, void *));
Packit Service fdd496
Packit Service fdd496
#include <netinet/in.h>
Packit Service fdd496
#include <sys/socket.h>
Packit Service fdd496
Packit Service fdd496
#include "macros.h"
Packit Service fdd496
Packit Service fdd496
int
Packit Service fdd496
main (void)
Packit Service fdd496
{
Packit Service fdd496
#if defined AF_INET /* HAVE_IPV4 */
Packit Service fdd496
  {
Packit Service fdd496
    /* This machine was for a long time known as
Packit Service fdd496
       ma2s2.mathematik.uni-karlsruhe.de.  */
Packit Service fdd496
    const char printable[] = "129.13.115.2";
Packit Service fdd496
    struct in_addr internal;
Packit Service fdd496
    int ret;
Packit Service fdd496
Packit Service fdd496
    ret = inet_pton (AF_INET, printable, &internal);
Packit Service fdd496
    ASSERT (ret == 1);
Packit Service fdd496
    /* Verify that internal is filled in network byte order.  */
Packit Service fdd496
    ASSERT (((unsigned char *) &internal)[0] == 0x81);
Packit Service fdd496
    ASSERT (((unsigned char *) &internal)[1] == 0x0D);
Packit Service fdd496
    ASSERT (((unsigned char *) &internal)[2] == 0x73);
Packit Service fdd496
    ASSERT (((unsigned char *) &internal)[3] == 0x02);
Packit Service fdd496
# ifdef WORDS_BIGENDIAN
Packit Service fdd496
    ASSERT (internal.s_addr == 0x810D7302);
Packit Service fdd496
# else
Packit Service fdd496
    ASSERT (internal.s_addr == 0x02730D81);
Packit Service fdd496
# endif
Packit Service fdd496
  }
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
  return 0;
Packit Service fdd496
}