Accept bracketed ipv6 addresses

This commit is contained in:
Justin Azoff 2020-08-05 17:18:36 -04:00
parent 8f4138262f
commit 211789bbb3
3 changed files with 16 additions and 6 deletions

View file

@ -80,9 +80,12 @@ threading::Value::addr_t Formatter::ParseAddr(const std::string &s) const
else else
{ {
val.family = IPv6; val.family = IPv6;
if ( inet_pton(AF_INET6, s.c_str(), val.in.in6.s6_addr) <=0 ) std::string clean_s = s;
if(s.front() == '[' && s.back() == ']')
clean_s = s.substr(1, s.length() - 2);
if ( inet_pton(AF_INET6, clean_s.c_str(), val.in.in6.s6_addr) <=0 )
{ {
thread->Warning(thread->Fmt("Bad address: %s", s.c_str())); thread->Warning(thread->Fmt("Bad address: %s", clean_s.c_str()));
memset(val.in.in6.s6_addr, 0, sizeof(val.in.in6.s6_addr)); memset(val.in.in6.s6_addr, 0, sizeof(val.in.in6.s6_addr));
} }
} }

View file

@ -3,7 +3,7 @@
#empty_field (empty) #empty_field (empty)
#unset_field - #unset_field -
#path config #path config
#open 2018-08-10-18-16-52 #open 2020-08-05-21-07-37
#fields ts id old_value new_value location #fields ts id old_value new_value location
#types time string string string string #types time string string string string
1533925012.140634 testbool T F ../configfile 1533925012.140634 testbool T F ../configfile
@ -15,11 +15,14 @@
1533925012.140634 testporttcp 40/udp 42/tcp ../configfile 1533925012.140634 testporttcp 40/udp 42/tcp ../configfile
1533925012.140634 testportudp 40/tcp 42/udp ../configfile 1533925012.140634 testportudp 40/tcp 42/udp ../configfile
1533925012.140634 testaddr 127.0.0.1 127.0.0.1 ../configfile 1533925012.140634 testaddr 127.0.0.1 127.0.0.1 ../configfile
1533925012.140634 testaddr 127.0.0.1 2607:f8b0:4005:801::200e ../configfile 1533925012.140634 testaddr 127.0.0.1 2607:f8b0:4005:801::1 ../configfile
1533925012.140634 testaddr 2607:f8b0:4005:801::1 2607:f8b0:4005:801::2 ../configfile
1533925012.140634 testsub 0.0.0.0/0 2607:f8b0:4001::/48 ../configfile
1533925012.140634 testsub 2607:f8b0:4001::/48 2607:f8b0:4002::/48 ../configfile
1533925012.140634 testinterval 1.0 sec 1.0 min ../configfile 1533925012.140634 testinterval 1.0 sec 1.0 min ../configfile
1533925012.140634 testtime 0.0 1507321987.0 ../configfile 1533925012.140634 testtime 0.0 1507321987.0 ../configfile
1533925012.140634 test_set (empty) b,c,a,d,erdbeerschnitzel ../configfile 1533925012.140634 test_set (empty) b,c,a,d,erdbeerschnitzel ../configfile
1533925012.140634 test_vector (empty) 1,2,3,4,5,6 ../configfile 1533925012.140634 test_vector (empty) 1,2,3,4,5,6 ../configfile
1533925012.140634 test_set b,c,a,d,erdbeerschnitzel (empty) ../configfile 1533925012.140634 test_set b,c,a,d,erdbeerschnitzel (empty) ../configfile
1533925012.140634 test_set (empty) \x2d ../configfile 1533925012.140634 test_set (empty) \x2d ../configfile
#close 2018-08-10-18-16-52 #close 2020-08-05-21-07-37

View file

@ -20,7 +20,10 @@ testport 45
testporttcp 42/tcp testporttcp 42/tcp
testportudp 42/udp testportudp 42/udp
testaddr 127.0.0.1 testaddr 127.0.0.1
testaddr 2607:f8b0:4005:801::200e testaddr 2607:f8b0:4005:801::1
testaddr [2607:f8b0:4005:801::2]
testsub 2607:f8b0:4001:801::/48
testsub [2607:f8b0:4002:801::]/48
testinterval 60 testinterval 60
testtime 1507321987 testtime 1507321987
test_set a,b,c,d,erdbeerschnitzel test_set a,b,c,d,erdbeerschnitzel
@ -41,6 +44,7 @@ export {
option testporttcp = 40/udp; option testporttcp = 40/udp;
option testportudp = 40/tcp; option testportudp = 40/tcp;
option testaddr = 127.0.0.1; option testaddr = 127.0.0.1;
option testsub = 0.0.0.0/0;
option testtime = network_time(); option testtime = network_time();
option testinterval = 1sec; option testinterval = 1sec;
option teststring = "a"; option teststring = "a";