File: s2n_rfc5952_test.c

package info (click to toggle)
aws-crt-python 0.24.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 75,932 kB
  • sloc: ansic: 418,984; python: 23,626; makefile: 6,035; sh: 4,075; ruby: 208; java: 82; perl: 73; cpp: 25; xml: 11
file content (91 lines) | stat: -rw-r--r-- 3,382 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

#include <arpa/inet.h>

#include "s2n_test.h"

#if defined(__FreeBSD__) || defined(__OpenBSD__)
    #include <netinet/in.h>
    #include <sys/socket.h>
    #include <sys/types.h>
#endif

#include "utils/s2n_rfc5952.h"

int main(int argc, char **argv)
{
    BEGIN_TEST();
    EXPECT_SUCCESS(s2n_disable_tls13_in_test());

    uint8_t ipv4[4];
    uint8_t ipv6[16];

    uint8_t ipv4_buf[sizeof("255.255.255.255")];
    uint8_t ipv6_buf[sizeof("1111:2222:3333:4444:5555:6666:7777:8888")];

    struct s2n_blob ipv4_blob = { 0 };
    EXPECT_SUCCESS(s2n_blob_init(&ipv4_blob, ipv4_buf, sizeof(ipv4_buf)));
    struct s2n_blob ipv6_blob = { 0 };
    EXPECT_SUCCESS(s2n_blob_init(&ipv6_blob, ipv6_buf, sizeof(ipv6_buf)));

    EXPECT_SUCCESS(inet_pton(AF_INET, "111.222.111.111", ipv4));
    EXPECT_OK(s2n_inet_ntop(AF_INET, ipv4, &ipv4_blob));
    EXPECT_EQUAL(strcmp("111.222.111.111", (char *) ipv4_buf), 0);

    EXPECT_SUCCESS(inet_pton(AF_INET, "0.0.0.0", ipv4));
    EXPECT_OK(s2n_inet_ntop(AF_INET, ipv4, &ipv4_blob));
    EXPECT_EQUAL(strcmp("0.0.0.0", (char *) ipv4_buf), 0);

    EXPECT_SUCCESS(inet_pton(AF_INET, "100.104.123.1", ipv4));
    EXPECT_OK(s2n_inet_ntop(AF_INET, ipv4, &ipv4_blob));
    EXPECT_EQUAL(strcmp("100.104.123.1", (char *) ipv4_buf), 0);

    EXPECT_SUCCESS(inet_pton(AF_INET, "255.255.255.255", ipv4));
    EXPECT_OK(s2n_inet_ntop(AF_INET, ipv4, &ipv4_blob));
    EXPECT_EQUAL(strcmp("255.255.255.255", (char *) ipv4_buf), 0);

    EXPECT_SUCCESS(inet_pton(AF_INET6, "2001:db8:0:0:0:0:2:1", ipv6));
    EXPECT_OK(s2n_inet_ntop(AF_INET6, ipv6, &ipv6_blob));
    EXPECT_EQUAL(strcmp("2001:db8::2:1", (char *) ipv6_buf), 0);

    EXPECT_SUCCESS(inet_pton(AF_INET6, "2001:db8::1", ipv6));
    EXPECT_OK(s2n_inet_ntop(AF_INET6, ipv6, &ipv6_blob));
    EXPECT_EQUAL(strcmp("2001:db8::1", (char *) ipv6_buf), 0);

    EXPECT_SUCCESS(inet_pton(AF_INET6, "2001:db8:0:1:1:1:1:1", ipv6));
    EXPECT_OK(s2n_inet_ntop(AF_INET6, ipv6, &ipv6_blob));
    EXPECT_EQUAL(strcmp("2001:db8:0:1:1:1:1:1", (char *) ipv6_buf), 0);

    EXPECT_SUCCESS(inet_pton(AF_INET6, "2001:db8::1:0:0:1", ipv6));
    EXPECT_OK(s2n_inet_ntop(AF_INET6, ipv6, &ipv6_blob));
    EXPECT_EQUAL(strcmp("2001:db8::1:0:0:1", (char *) ipv6_buf), 0);

    EXPECT_SUCCESS(inet_pton(AF_INET6, "0:0:0:0:0:0:0:1", ipv6));
    EXPECT_OK(s2n_inet_ntop(AF_INET6, ipv6, &ipv6_blob));
    EXPECT_EQUAL(strcmp("::1", (char *) ipv6_buf), 0);

    EXPECT_SUCCESS(inet_pton(AF_INET6, "0:0:0:0:0:0:0:0", ipv6));
    EXPECT_OK(s2n_inet_ntop(AF_INET6, ipv6, &ipv6_blob));
    EXPECT_EQUAL(strcmp("::", (char *) ipv6_buf), 0);

/* Prevents build failure on Mac */
#ifndef AF_BLUETOOTH
    #define AF_BLUETOOTH 31
#endif

    EXPECT_ERROR_WITH_ERRNO(s2n_inet_ntop(AF_BLUETOOTH, ipv6, &ipv6_blob), S2N_ERR_INVALID_ARGUMENT);
    END_TEST();
}