source: web/old/remctl-2.14/tests/portable/inet_ntop-t.c @ f6f3e91

web
Last change on this file since f6f3e91 was f6f3e91, checked in by Jessica B. Hamrick <jhamrick@…>, 15 years ago

Preserve directory hierarchy (not sure what happened to it)

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 * inet_ntop test suite.
3 *
4 * Written by Russ Allbery <rra@stanford.edu>
5 * Copyright 2009 Board of Trustees, Leland Stanford Jr. University
6 * Copyright (c) 2004, 2005, 2006
7 *     by Internet Systems Consortium, Inc. ("ISC")
8 * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
9 *     2002, 2003 by The Internet Software Consortium and Rich Salz
10 *
11 * See LICENSE for licensing terms.
12 */
13
14#include <config.h>
15#include <portable/system.h>
16#include <portable/socket.h>
17
18#include <errno.h>
19
20#include <tests/tap/basic.h>
21
22/* Some systems too old to have inet_ntop don't have EAFNOSUPPORT. */
23#ifndef EAFNOSUPPORT
24# define EAFNOSUPPORT EDOM
25#endif
26
27const char *test_inet_ntop(int, const void *, char *, socklen_t);
28
29
30static void
31test_addr(const char *expected, unsigned long addr)
32{
33    struct in_addr in;
34    char result[INET_ADDRSTRLEN];
35
36    in.s_addr = htonl(addr);
37    if (test_inet_ntop(AF_INET, &in, result, sizeof(result)) == NULL) {
38        printf("# cannot convert %lu: %s", addr, strerror(errno));
39        ok(0, "converting %s", expected);
40    } else
41        ok(1, "converting %s", expected);
42    is_string(expected, result, "...with correct result");
43}
44
45
46int
47main(void)
48{
49    plan(6 + 5 * 2);
50
51    ok(test_inet_ntop(AF_UNIX, NULL, NULL, 0) == NULL, "AF_UNIX failure");
52    is_int(EAFNOSUPPORT, errno, "...with right errno");
53    ok(test_inet_ntop(AF_INET, NULL, NULL, 0) == NULL, "empty buffer");
54    is_int(ENOSPC, errno, "...with right errno");
55    ok(test_inet_ntop(AF_INET, NULL, NULL, 11) == NULL, "NULL buffer");
56    is_int(ENOSPC, errno, "...with right errno");
57
58    test_addr(        "0.0.0.0", 0x0);
59    test_addr(      "127.0.0.0", 0x7f000000UL);
60    test_addr("255.255.255.255", 0xffffffffUL);
61    test_addr("172.200.232.199", 0xacc8e8c7UL);
62    test_addr(        "1.2.3.4", 0x01020304UL);
63
64    return 0;
65}
Note: See TracBrowser for help on using the repository browser.