[ipxe-devel] patch for RFC2732 literal IPv6s in URLs
James Carter
james at jfc.org.uk
Thu Feb 6 15:33:04 UTC 2014
Hi,
Here's a simple patch to allow literal IPv6 addresses in URLs.
--- a/src/core/uri.c
+++ b/src/core/uri.c
@@ -205,7 +205,13 @@ struct uri * parse_uri ( const char *uri_string ) {
}
/* Split host into host[:port] */
- if ( ( tmp = strchr ( uri->host, ':' ) ) ) {
+ if ( *(uri->host) == '[' && ( tmp = strchr( uri->host, ']' ) ) ) {
+ uri->host++;
+ *(tmp++) = '\0';
+ if ( *tmp == ':' ) {
+ uri->port = tmp++;
+ }
+ } else if ( ( tmp = strchr ( uri->host, ':' ) ) ) {
*(tmp++) = '\0';
uri->port = tmp;
}
@@ -296,6 +302,12 @@ int unparse_uri ( char *buf, size_t size, struct uri
*uri,
used += ssnprintf ( buf + used, size - used,
"%c", sep );
+ /* Prefix IPv6 addresses with [ */
+ if ( i == 4 && strchr( field, ':' ) ) {
+ used += ssnprintf ( buf + used, size - used,
+ "[" );
+ }
+
/* Print contents of field, possibly encoded */
if ( URI_ENCODED & ( 1 << i ) )
used += uri_encode ( field, buf + used,
@@ -303,6 +315,12 @@ int unparse_uri ( char *buf, size_t size, struct uri
*uri,
else
used += ssnprintf ( buf + used, size - used,
"%s", field );
+
+ /* Postfix IPv6 addresses with ] */
+ if ( i == 4 && strchr( field, ':' ) ) {
+ used += ssnprintf ( buf + used, size - used,
+ "]" );
+ }
}
}
--
James F. Carter www.jfc.org.uk podquiz.com starringthecomputer.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ipxe.org/pipermail/ipxe-devel/attachments/20140206/d677bb39/attachment.htm>
More information about the ipxe-devel
mailing list