Hi, I've written the following patch for NetSurf.
This should replace 'bool url_host_is_ip_address(const char *host)'
in 'utils/url.c'
-------------------------------------------------------------------------------
/* Each digit of an octet is represented as a character
* so the maximum 'length' of an octet is 3
*/
#define MAX_OCTET_LEN 3
#define N_OCTETS 4 /* ipv4 addresses consist of 4 octets */
#define DECIMAL 10 /* octets are in base 10 */
/**
* Determine if host is a valid ipv4 address.
*
* \param host Address to validate.
*
* \return Boolean: true if host is valid, else false.
*/
bool url_host_is_ip4_address(const char *host)
{
/* We accept an ipv4 address written in dot-decimal notation
* ipv4 addresses consist of 4 octets of the address
* separately in decimal and separated by periods
* for example 123.0.42.255
*/
assert(host != NULL);
char *p;
int octet_count = 0;
int octet;
do {
octet = strtol(host, &p, DECIMAL);
host = p + 1;
if (octet >= 0 && octet <= 255)
octet_count++;
else
return false;
} while (*p != '\0');
/* If we don't have 4 octets then host is invalid */
return (octet_count == N_OCTETS);
}
-------------------------------------------------------------------------------
The new function is called 'url_host_is_ip4_address'
to reflect that we're only dealing with ipv4 addresses.
Hope this helps,
Richard
--
Richard Kenyon <http://cosmia.org.uk>
Do not settle for answers. Do not even seek them. Demand solutions.
cat , undeterred by brahma ! plenty , seat me at whole of broad day by daylight
." once the