Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Support for raw IPv6 addresses in http package (Tcl 8.6!)

194 views
Skip to first unread message

Emmanuel Frecon

unread,
May 25, 2012, 9:56:01 AM5/25/12
to
Folks!

I am trying to put my hands dirty on IPv6. My goal is to be able to talk to sensors (and actuators) in IPv6-only sensor networks. The sensors run an IPSO interop inspired profile, which in short means REST/json constructs. That was for the background, now to my question.

Is there anyone who has been able to modify the code of the http package from the core so that it can support raw IP addresses, e.g. 2001:5c0:1400:b::d623 to take my current address as an example. I've checked in the latest version at core.tcl.tk and the implementation of ::http::geturl still starts with a URL validation that is based on a regexp that does NOT support raw addresses as the one above (they should be enclosed in brackets in URLs). The problem is that the atom of the regexp that should match the host part of the authority is written as [^/:\#?]+ which will not work since IPv6 addresses are written using : as separators (well, not entirely true, but almost). I have been trying to merge the code from this "super" IPv6 matcher regexp without any success: http://forums.intermapper.com/viewtopic.php?t=452.

Anyone with a solution or a better idea?

/Emmanuel

Emmanuel Frecon

unread,
May 25, 2012, 10:51:53 AM5/25/12
to
I thought that I should answer myself a little bit. I have modified the current content of the http::geturl implementation to provide support for IPv6 addresses. My current version minimises the regexp parsing and adds a number of string operations. It's not perfect, but at least solve the issue. It stands as:

set URLmatcher {(?x) # this is _expanded_ syntax
^
(?: (\w+) : ) ? # <protocol scheme>
(?: //
( [^/\#?]+ ) # <location=userinfo + host + port>
)?
( / [^\#]*)? # <path> (including query)
(?: \# (.*) )? # <fragment>
$
}

# Phase one: parse, the URL match
if {![regexp -- $URLmatcher $url -> proto location srvurl]} {
unset $token
return -code error "Unsupported URL: $url"
}
if { [string first "@" $location] >= 0 } {
foreach {user hostport} [split $location "@"] break
} else {
set user ""
set hostport $location
}
set idx [string last ":" $hostport]
if { $idx >= 0 } {
set port [string trimleft [string range $hostport $idx end] ":"]
if { [string is integer $port] } {
set host [string trimright [string range $hostport 0 $idx] ":"]
} else {
set port ""
set host $hostport
}
} else {
set port ""
set host $hostport
}

# Phase two: validate


This is the only code that needs to be modified for doing the job. The idea is still not to do any check on the hostname (or IP in that case) and let the resolution fail when opening the socket.

I am biased. This code solves the problem, but is far from being elegant. I *think* that it covers all the cases and could then act as a replacement in the implementation. However, the http has cult status, it's existed for a long while, is widely tested and modifying it feels awkward. Any opinion, from an http.tcl expert?

/Emmanuel

Emmanuel Frecon

unread,
May 25, 2012, 6:08:31 PM5/25/12
to
Obviously, I had to post a bug... :(

There should be an additional line just before the Phast two comment:
set host [string trim $host "\[\]"]

# Phase two: validate

The line trims away the brackets that come from the URL RFC and that are not part of the ip address of the server. Being perfect, we would use a regexp to make sure we only remove brackets around an IPv6 address (and not around anything).

Emmanuel Frecon

unread,
May 27, 2012, 7:44:22 AM5/27/12
to
Any reaction? This feels important since tcl 8.6 is tout to be ipv6 compatible. The ground libraries that come with it should also be compatible, shouldn't they?

Donal K. Fellows

unread,
May 28, 2012, 10:59:40 AM5/28/12
to
Have you filed a bug/patch report yet? I don't know how often the main
maintainer of the http package reads c.l.t…

Donal.

Emmanuel Frecon

unread,
May 30, 2012, 6:38:13 PM5/30/12
to
No, not yet. Where do I file the bug?

ma...@empus.net

unread,
Apr 19, 2013, 10:12:31 PM4/19/13
to
Any update on this?

Harald Oehlmann

unread,
Apr 20, 2013, 8:18:41 AM4/20/13
to
On 20 Apr., 04:12, m...@empus.net wrote:
> Any update on this?

As the http package is part of the core, you should file the bug at
tcl sourceforge:

http://sourceforge.net/projects/tcl/

Thank you,
Harald
0 new messages