Best ways of parsing a URL using C?

Personally, I steal the HTParse.c module from the W3C (it is used in the lynx Web browser, for instance). Then, you can do things like:

 strncpy(hostname, HTParse(url, "", PARSE_HOST), size)

The important thing about using a well-established and debugged library is that you do not fall into the typical
traps of URL parsing (many regexps fail when the host is an IP address, for instance, specially an IPv6 one).

Leave a Comment