Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,39 @@
package require Tcl 8.5
package require ip
proc parseIP {address} {
set result {}
set family [ip::version $address]
set port -1
if {$family == -1} {
if {[regexp {^\[(.*)\]:(\d+)$} $address -> address port]} {
dict set result port $port
set family [ip::version $address]
if {$family != 6} {
return -code error "bad address"
}
} elseif {[regexp {^(.*):(\d+)$} $address -> address port]} {
dict set result port $port
set family [ip::version $address]
if {$family != 4} {
return -code error "bad address"
}
} else {
return -code error "bad address"
}
}
# Only possible error in ports is to be too large an integer
if {$port > 65535} {
return -code error "bad port"
}
dict set result family $family
if {$family == 4} {
# IPv4 normalized form is dotted quad, but toInteger helps
dict set result addr [format %x [ip::toInteger $address]]
} else {
# IPv6 normalized form is colin-separated hex
dict set result addr [string map {: ""} [ip::normalize $address]]
}
# Return the descriptor dictionary
return $result
}

View file

@ -0,0 +1,27 @@
foreach address {
127.0.0.1
127.0.0.1:80
::1
[::1]:80
2605:2700:0:3::4713:93e3
[2605:2700:0:3::4713:93e3]:80
::ffff:192.168.0.1
[::ffff:192.168.0.1]:22
::ffff:127.0.0.0.1
a::b::1
127.0.0.1:100000
} {
if {[catch {
set parsed [parseIP $address]
} msg]} {
puts "error ${msg}: \"$address\""
continue
}
dict with parsed {
puts -nonewline "family: IPv$family addr: $addr"
if {[dict exists $parsed port]} {
puts -nonewline " port: $port"
}
puts ""
}
}