src/standard.c
int url2ipv4(const char *addr, struct in_addr *dst)
{
	int saw_digit, octets, ch;
	u_char tmp[4], *tp;
	const char *cp = addr;

	saw_digit = 0;
	octets = 0;
	*(tp = tmp) = 0;

	while (*addr) {
		unsigned char digit = (ch = *addr++) - '0';
		if (digit > 9 && ch != '.')
			break;
		if (digit <= 9) {
			u_int new = *tp * 10 + digit;
			if (new > 255)
				return 0;
			*tp = new;
			if (!saw_digit) {
				if (++octets > 4)
					return 0;
				saw_digit = 1;
			}
		} else if (ch == '.' && saw_digit) {
			if (octets == 4)
				return 0;
			*++tp = 0;
			saw_digit = 0;
		} else
			return 0;
	}

	if (octets < 4)
		return 0;

	memcpy(&dst->s_addr, tmp, 4);
	return addr-cp-1;
}
/*
 * Parse IPv4 address found in url.
 */
Parse IPv4 address found in url.
Parse IPv4 address found in url .
int url2ipv4(const char *addr, struct in_addr *dst)
{
	int saw_digit, octets, ch;
	u_char tmp[4], *tp;
	const char *cp = addr;
	saw_digit = 0;
	octets = 0;
	*(tp = tmp) = 0;
	while (*addr) {
		unsigned char digit = (ch = *addr++) - '0';
		if (digit > 9 && ch != '.')
			break;
		if (digit <= 9) {
			u_int new = *tp * 10 + digit;
			if (new > 255)
				return 0;
			*tp = new;
			if (!saw_digit) {
				if (++octets > 4)
					return 0;
				saw_digit = 1;
			}
		} else if (ch == '.' && saw_digit) {
			if (octets == 4)
				return 0;
			*++tp = 0;
			saw_digit = 0;
		} else
			return 0;
	}
	if (octets < 4)
		return 0;
	memcpy(&dst->s_addr, tmp, 4);
	return addr-cp-1;
}
int url2ipv4 ( const char * addr , struct in_addr * dst ) { int saw_digit , octets , ch ; u_char tmp [ 4 ] , * tp ; const char * cp = addr ; saw_digit = 0 ; octets = 0 ; * ( tp = tmp ) = 0 ; while ( * addr ) { unsigned char digit = ( ch = * addr ++ ) - ' ' ; if ( digit > 9 && ch != ' ' ) break ; if ( digit <= 9 ) { u_int new = * tp * 10 + digit ; if ( new > 255 ) return 0 ; * tp = new ; if ( ! saw_digit ) { if ( ++ octets > 4 ) return 0 ; saw_digit = 1 ; } } else if ( ch == ' ' && saw_digit ) { if ( octets == 4 ) return 0 ; * ++ tp = 0 ; saw_digit = 0 ; } else return 0 ; } if ( octets < 4 ) return 0 ; memcpy ( & dst -> s_addr , tmp , 4 ) ; return addr - cp - 1 ; }
Parse IPv4 address found in url.
Parse IPv4 address found in url .