diff options
| author | jsing <> | 2014-06-22 16:57:34 +0000 |
|---|---|---|
| committer | jsing <> | 2014-06-22 16:57:34 +0000 |
| commit | cb803576289954e210dc3fc384c71ceaad77666e (patch) | |
| tree | eef4d9675811ce987c2636769042c4e9d1eb94a3 /src | |
| parent | 9faf7302e7627f58abc36860fb88d748b321e041 (diff) | |
| download | openbsd-cb803576289954e210dc3fc384c71ceaad77666e.tar.gz openbsd-cb803576289954e210dc3fc384c71ceaad77666e.tar.bz2 openbsd-cb803576289954e210dc3fc384c71ceaad77666e.zip | |
Add regress tests for BIO_get_host_ip().
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libcrypto/bio/biotest.c | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/src/regress/lib/libcrypto/bio/biotest.c b/src/regress/lib/libcrypto/bio/biotest.c index 3639cb1f36..c6d38eb5b1 100644 --- a/src/regress/lib/libcrypto/bio/biotest.c +++ b/src/regress/lib/libcrypto/bio/biotest.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: biotest.c,v 1.1 2014/06/22 14:30:52 jsing Exp $ */ | 1 | /* $OpenBSD: biotest.c,v 1.2 2014/06/22 16:57:34 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -15,11 +15,42 @@ | |||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #include <sys/types.h> | ||
| 19 | |||
| 18 | #include <stdlib.h> | 20 | #include <stdlib.h> |
| 21 | #include <strings.h> | ||
| 22 | |||
| 23 | #include <netinet/in.h> | ||
| 19 | 24 | ||
| 20 | #include <openssl/bio.h> | 25 | #include <openssl/bio.h> |
| 21 | #include <openssl/err.h> | 26 | #include <openssl/err.h> |
| 22 | 27 | ||
| 28 | struct bio_get_host_ip_test { | ||
| 29 | char *input; | ||
| 30 | u_int32_t ip; | ||
| 31 | int ret; | ||
| 32 | }; | ||
| 33 | |||
| 34 | struct bio_get_host_ip_test bio_get_host_ip_tests[] = { | ||
| 35 | {"", 0, 0}, | ||
| 36 | {".", 0, 0}, | ||
| 37 | {"1", 0, 0}, | ||
| 38 | {"1.2", 0, 0}, | ||
| 39 | {"1.2.3", 0, 0}, | ||
| 40 | {"1.2.3.", 0, 0}, | ||
| 41 | {"1.2.3.4", 0x01020304, 1}, | ||
| 42 | {"1.2.3.256", 0, 0}, | ||
| 43 | {"1:2:3::4", 0, 0}, | ||
| 44 | {"0.0.0.0", INADDR_ANY, 1}, | ||
| 45 | {"127.0.0.1", INADDR_LOOPBACK, 1}, | ||
| 46 | {"localhost", INADDR_LOOPBACK, 1}, | ||
| 47 | {"255.255.255.255", INADDR_BROADCAST, 1}, | ||
| 48 | {"0xff.0xff.0xff.0xff", 0, 0}, | ||
| 49 | }; | ||
| 50 | |||
| 51 | #define N_BIO_GET_IP_TESTS \ | ||
| 52 | (sizeof(bio_get_host_ip_tests) / sizeof(*bio_get_host_ip_tests)) | ||
| 53 | |||
| 23 | struct bio_get_port_test { | 54 | struct bio_get_port_test { |
| 24 | char *input; | 55 | char *input; |
| 25 | unsigned short port; | 56 | unsigned short port; |
| @@ -46,6 +77,38 @@ struct bio_get_port_test bio_get_port_tests[] = { | |||
| 46 | (sizeof(bio_get_port_tests) / sizeof(*bio_get_port_tests)) | 77 | (sizeof(bio_get_port_tests) / sizeof(*bio_get_port_tests)) |
| 47 | 78 | ||
| 48 | static int | 79 | static int |
| 80 | do_bio_get_host_ip_tests(void) | ||
| 81 | { | ||
| 82 | struct bio_get_host_ip_test *bgit; | ||
| 83 | unsigned char ip[4]; | ||
| 84 | int failed = 0; | ||
| 85 | size_t i; | ||
| 86 | int ret; | ||
| 87 | |||
| 88 | for (i = 0; i < N_BIO_GET_IP_TESTS; i++) { | ||
| 89 | bgit = &bio_get_host_ip_tests[i]; | ||
| 90 | memset(ip, 0, sizeof(*ip)); | ||
| 91 | |||
| 92 | ret = BIO_get_host_ip(bgit->input, ip); | ||
| 93 | if (ret != bgit->ret) { | ||
| 94 | fprintf(stderr, "FAIL: test %zi (\"%s\") %s, want %s\n", | ||
| 95 | i, bgit->input, ret ? "success" : "failure", | ||
| 96 | bgit->ret ? "success" : "failure"); | ||
| 97 | failed = 1; | ||
| 98 | continue; | ||
| 99 | } | ||
| 100 | if (ret && ntohl(*((u_int32_t *)ip)) != bgit->ip) { | ||
| 101 | fprintf(stderr, "FAIL: test %zi (\"%s\") returned ip " | ||
| 102 | "%x != %x\n", i, bgit->input, | ||
| 103 | ntohl(*((u_int32_t *)ip)), bgit->ip); | ||
| 104 | failed = 1; | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | return failed; | ||
| 109 | } | ||
| 110 | |||
| 111 | static int | ||
| 49 | do_bio_get_port_tests(void) | 112 | do_bio_get_port_tests(void) |
| 50 | { | 113 | { |
| 51 | struct bio_get_port_test *bgpt; | 114 | struct bio_get_port_test *bgpt; |
| @@ -79,5 +142,10 @@ do_bio_get_port_tests(void) | |||
| 79 | int | 142 | int |
| 80 | main(int argc, char **argv) | 143 | main(int argc, char **argv) |
| 81 | { | 144 | { |
| 82 | return do_bio_get_port_tests(); | 145 | int ret = 0; |
| 146 | |||
| 147 | ret |= do_bio_get_host_ip_tests(); | ||
| 148 | ret |= do_bio_get_port_tests(); | ||
| 149 | |||
| 150 | return (ret); | ||
| 83 | } | 151 | } |
