summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2014-06-22 16:57:35 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2014-06-22 16:57:35 +0000
commitd29169e6ebac267122cd8580bf0b6a33afd1e9bf (patch)
tree52ee69180d83da443069f987ae4622f005293f4a /regress
parent173a913f33c770d023f5ebaca8b198b1f2f471e3 (diff)
Add regress tests for BIO_get_host_ip().
Diffstat (limited to 'regress')
-rw-r--r--regress/lib/libcrypto/bio/biotest.c72
1 files changed, 70 insertions, 2 deletions
diff --git a/regress/lib/libcrypto/bio/biotest.c b/regress/lib/libcrypto/bio/biotest.c
index 3639cb1f369..c6d38eb5b1d 100644
--- a/regress/lib/libcrypto/bio/biotest.c
+++ b/regress/lib/libcrypto/bio/biotest.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: biotest.c,v 1.1 2014/06/22 14:30:52 jsing Exp $ */
+/* $OpenBSD: biotest.c,v 1.2 2014/06/22 16:57:34 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@@ -15,11 +15,42 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
+
#include <stdlib.h>
+#include <strings.h>
+
+#include <netinet/in.h>
#include <openssl/bio.h>
#include <openssl/err.h>
+struct bio_get_host_ip_test {
+ char *input;
+ u_int32_t ip;
+ int ret;
+};
+
+struct bio_get_host_ip_test bio_get_host_ip_tests[] = {
+ {"", 0, 0},
+ {".", 0, 0},
+ {"1", 0, 0},
+ {"1.2", 0, 0},
+ {"1.2.3", 0, 0},
+ {"1.2.3.", 0, 0},
+ {"1.2.3.4", 0x01020304, 1},
+ {"1.2.3.256", 0, 0},
+ {"1:2:3::4", 0, 0},
+ {"0.0.0.0", INADDR_ANY, 1},
+ {"127.0.0.1", INADDR_LOOPBACK, 1},
+ {"localhost", INADDR_LOOPBACK, 1},
+ {"255.255.255.255", INADDR_BROADCAST, 1},
+ {"0xff.0xff.0xff.0xff", 0, 0},
+};
+
+#define N_BIO_GET_IP_TESTS \
+ (sizeof(bio_get_host_ip_tests) / sizeof(*bio_get_host_ip_tests))
+
struct bio_get_port_test {
char *input;
unsigned short port;
@@ -46,6 +77,38 @@ struct bio_get_port_test bio_get_port_tests[] = {
(sizeof(bio_get_port_tests) / sizeof(*bio_get_port_tests))
static int
+do_bio_get_host_ip_tests(void)
+{
+ struct bio_get_host_ip_test *bgit;
+ unsigned char ip[4];
+ int failed = 0;
+ size_t i;
+ int ret;
+
+ for (i = 0; i < N_BIO_GET_IP_TESTS; i++) {
+ bgit = &bio_get_host_ip_tests[i];
+ memset(ip, 0, sizeof(*ip));
+
+ ret = BIO_get_host_ip(bgit->input, ip);
+ if (ret != bgit->ret) {
+ fprintf(stderr, "FAIL: test %zi (\"%s\") %s, want %s\n",
+ i, bgit->input, ret ? "success" : "failure",
+ bgit->ret ? "success" : "failure");
+ failed = 1;
+ continue;
+ }
+ if (ret && ntohl(*((u_int32_t *)ip)) != bgit->ip) {
+ fprintf(stderr, "FAIL: test %zi (\"%s\") returned ip "
+ "%x != %x\n", i, bgit->input,
+ ntohl(*((u_int32_t *)ip)), bgit->ip);
+ failed = 1;
+ }
+ }
+
+ return failed;
+}
+
+static int
do_bio_get_port_tests(void)
{
struct bio_get_port_test *bgpt;
@@ -79,5 +142,10 @@ do_bio_get_port_tests(void)
int
main(int argc, char **argv)
{
- return do_bio_get_port_tests();
+ int ret = 0;
+
+ ret |= do_bio_get_host_ip_tests();
+ ret |= do_bio_get_port_tests();
+
+ return (ret);
}