From 78c3cebc389a2b0d426d74900a65b8656edb426d Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 26 Oct 2026 18:13:27 +0100 Subject: Third run of making variable and function names more readable, integer scans and ip parsers --- tests/t_ip.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'tests/t_ip.c') diff --git a/tests/t_ip.c b/tests/t_ip.c index 2fe3a72..8d71679 100644 --- a/tests/t_ip.c +++ b/tests/t_ip.c @@ -95,27 +95,27 @@ static void case_scan_forms(void) { char ip[16]; test_case("2.2 form 1, every group spelled out"); - CHECK_INT(ip_scan("1111:2222:3333:4444:5555:6666:7777:8888", ip), 39); + CHECK_INT(ip_parse("1111:2222:3333:4444:5555:6666:7777:8888", ip), 39); CHECK_MEM(ip, "\x11\x11\x22\x22\x33\x33\x44\x44\x55\x55\x66\x66\x77\x77\x88\x88", 16); test_case("2.2 form 2, zero groups abbreviated"); - CHECK_INT(ip_scan("2001:db8::1", ip), 11); + CHECK_INT(ip_parse("2001:db8::1", ip), 11); CHECK_MEM(ip, "\x20\x01\x0d\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", 16); - CHECK_INT(ip_scan("::1", ip), 3); + CHECK_INT(ip_parse("::1", ip), 3); CHECK_MEM(ip, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", 16); - CHECK_INT(ip_scan("::", ip), 2); + CHECK_INT(ip_parse("::", ip), 2); CHECK_MEM(ip, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); - CHECK_INT(ip_scan("1::", ip), 3); + CHECK_INT(ip_parse("1::", ip), 3); CHECK_MEM(ip, "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); test_case("2.2 form 3, a dotted quad in the last two groups"); - CHECK_INT(ip_scan("::ffff:1.2.3.4", ip), 14); + CHECK_INT(ip_parse("::ffff:1.2.3.4", ip), 14); CHECK_MEM(ip, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x01\x02\x03\x04", 16); - CHECK_INT(ip_scan("1:2:3:4:5:6:1.2.3.4", ip), 19); + CHECK_INT(ip_parse("1:2:3:4:5:6:1.2.3.4", ip), 19); CHECK_MEM(ip, "\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x01\x02\x03\x04", 16); test_case("upper case input is accepted"); - CHECK_INT(ip_scan("2001:DB8::1", ip), 11); + CHECK_INT(ip_parse("2001:DB8::1", ip), 11); CHECK_MEM(ip, "\x20\x01\x0d\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", 16); } @@ -125,7 +125,7 @@ static void case_scan_accepts_bare_ipv4(void) { /* Every address opentracker holds is sixteen bytes, so an operator writing a plain IPv4 address in the config has to land as the v4 mapped form */ test_case("a bare IPv4 address is stored v4 mapped"); - CHECK_INT(ip_scan("10.0.0.1", ip), 8); + CHECK_INT(ip_parse("10.0.0.1", ip), 8); CHECK_MEM(ip, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x0a\x00\x00\x01", 16); CHECK(ip_is_v4mapped(ip)); } @@ -136,39 +136,39 @@ static void case_scan_reports_length(void) { /* The config parser continues from where the address ended, which is how "address:port" and "address/bits" are read */ test_case("scanning stops at the character after the address"); - CHECK_INT(ip_scan("10.0.0.1:6969", ip), 8); - CHECK_INT(ip_scan("2001:db8::1/64", ip), 11); - CHECK_INT(ip_scan("::1]", ip), 3); - CHECK_INT(ip_scan("1:2:3:4:5:6:7:8 trailing", ip), 15); + CHECK_INT(ip_parse("10.0.0.1:6969", ip), 8); + CHECK_INT(ip_parse("2001:db8::1/64", ip), 11); + CHECK_INT(ip_parse("::1]", ip), 3); + CHECK_INT(ip_parse("1:2:3:4:5:6:7:8 trailing", ip), 15); } static void case_scan_rejects(void) { char ip[16]; test_case("an empty or junk string is refused"); - CHECK_INT(ip_scan("", ip), 0); - CHECK_INT(ip_scan("x", ip), 0); - CHECK_INT(ip_scan(":", ip), 0); - CHECK_INT(ip_scan(":1:2", ip), 0); + CHECK_INT(ip_parse("", ip), 0); + CHECK_INT(ip_parse("x", ip), 0); + CHECK_INT(ip_parse(":", ip), 0); + CHECK_INT(ip_parse(":1:2", ip), 0); test_case("too few groups without :: are refused"); - CHECK_INT(ip_scan("1:2:3:4:5:6:7", ip), 0); - CHECK_INT(ip_scan("2001:db8:1", ip), 0); + CHECK_INT(ip_parse("1:2:3:4:5:6:7", ip), 0); + CHECK_INT(ip_parse("2001:db8:1", ip), 0); /* libowfat accepted a prefix of each of these and carried on. Taking only part of a malformed address is worse than refusing it, especially where the text comes from a config file or an X-Forwarded-For header. */ test_case("a second :: is refused rather than truncated"); - CHECK_INT(ip_scan("1::2::3", ip), 0); - CHECK_INT(ip_scan("::1::", ip), 0); - CHECK_INT(ip_scan("::::", ip), 0); + CHECK_INT(ip_parse("1::2::3", ip), 0); + CHECK_INT(ip_parse("::1::", ip), 0); + CHECK_INT(ip_parse("::::", ip), 0); test_case("more than eight groups is refused"); - CHECK_INT(ip_scan("1:2:3:4:5:6:7:8:9", ip), 0); + CHECK_INT(ip_parse("1:2:3:4:5:6:7:8:9", ip), 0); test_case("a group of more than four digits is refused, not truncated"); - CHECK_INT(ip_scan("12345::1", ip), 0); - CHECK_INT(ip_scan("fffff::1", ip), 0); + CHECK_INT(ip_parse("12345::1", ip), 0); + CHECK_INT(ip_parse("fffff::1", ip), 0); } static void case_round_trip(void) { @@ -187,7 +187,7 @@ static void case_round_trip(void) { test_case("every formatted address scans back to the same bytes"); for (i = 0; samples[i]; ++i) { - size_t n = ip_scan(samples[i], ip); + size_t n = ip_parse(samples[i], ip); if (n != strlen(samples[i])) { test_failf(__FILE__, __LINE__, "\"%s\" consumed %zu of %zu", samples[i], n, strlen(samples[i])); return; @@ -197,7 +197,7 @@ static void case_round_trip(void) { test_failf(__FILE__, __LINE__, "\"%s\" formatted back as \"%s\"", samples[i], text); return; } - if (!ip_scan(text, again) || memcmp(ip, again, 16)) { + if (!ip_parse(text, again) || memcmp(ip, again, 16)) { test_failf(__FILE__, __LINE__, "\"%s\" did not survive a second pass", samples[i]); return; } -- cgit v1.3