|
Packit Service |
a2ae7a |
/* Test of inet_pton function.
|
|
Packit Service |
a2ae7a |
Copyright (C) 2009-2019 Free Software Foundation, Inc.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
a2ae7a |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
a2ae7a |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
a2ae7a |
(at your option) any later version.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
a2ae7a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a2ae7a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
a2ae7a |
GNU General Public License for more details.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
a2ae7a |
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Written by Bruno Haible <bruno@clisp.org>, 2009. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <config.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <arpa/inet.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include "signature.h"
|
|
Packit Service |
a2ae7a |
SIGNATURE_CHECK (inet_pton, int, (int, const char *, void *));
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <netinet/in.h>
|
|
Packit Service |
a2ae7a |
#include <sys/socket.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include "macros.h"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
int
|
|
Packit Service |
a2ae7a |
main (void)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
#if defined AF_INET /* HAVE_IPV4 */
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
/* This machine was for a long time known as
|
|
Packit Service |
a2ae7a |
ma2s2.mathematik.uni-karlsruhe.de. */
|
|
Packit Service |
a2ae7a |
const char printable[] = "129.13.115.2";
|
|
Packit Service |
a2ae7a |
struct in_addr internal;
|
|
Packit Service |
a2ae7a |
int ret;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
ret = inet_pton (AF_INET, printable, &internal);
|
|
Packit Service |
a2ae7a |
ASSERT (ret == 1);
|
|
Packit Service |
a2ae7a |
/* Verify that internal is filled in network byte order. */
|
|
Packit Service |
a2ae7a |
ASSERT (((unsigned char *) &internal)[0] == 0x81);
|
|
Packit Service |
a2ae7a |
ASSERT (((unsigned char *) &internal)[1] == 0x0D);
|
|
Packit Service |
a2ae7a |
ASSERT (((unsigned char *) &internal)[2] == 0x73);
|
|
Packit Service |
a2ae7a |
ASSERT (((unsigned char *) &internal)[3] == 0x02);
|
|
Packit Service |
a2ae7a |
# ifdef WORDS_BIGENDIAN
|
|
Packit Service |
a2ae7a |
ASSERT (internal.s_addr == 0x810D7302);
|
|
Packit Service |
a2ae7a |
# else
|
|
Packit Service |
a2ae7a |
ASSERT (internal.s_addr == 0x02730D81);
|
|
Packit Service |
a2ae7a |
# endif
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
return 0;
|
|
Packit Service |
a2ae7a |
}
|