FreeBSD/tools/tools/cxgbtool/cxgbtool.c
/*
 * Parse a string containing an IP address with an optional network prefix.
 */
Parse a string containing an IP address with an optional network prefix.
Parse a string containing an IP address with an optional network prefix .
static int
parse_ipaddr(const char *s, uint32_t *addr, uint32_t *mask)
{
	char *p, *slash;
	struct in_addr ia;
	*mask = 0xffffffffU;
	slash = strchr(s, '/');
	if (slash)
		*slash = 0;
	if (!inet_aton(s, &ia)) {
		if (slash)
			*slash = '/';
		*addr = 0;
		return -1;
	}
	*addr = ntohl(ia.s_addr);
	if (slash) {
		unsigned int prefix = strtoul(slash + 1, &p, 10);
		*slash = '/';
		if (p == slash + 1 || *p || prefix > 32)
			return -1;
		*mask <<= (32 - prefix);
	}
	return 0;
}
static int parse_ipaddr ( const char * s , uint32_t * addr , uint32_t * mask ) { char * p , * slash ; struct in_addr ia ; * mask = 0xffffffffU ; slash = strchr ( s , ' ' ) ; if ( slash ) * slash = 0 ; if ( ! inet_aton ( s , & ia ) ) { if ( slash ) * slash = ' ' ; * addr = 0 ; return -1 ; } * addr = ntohl ( ia . s_addr ) ; if ( slash ) { unsigned int prefix = strtoul ( slash + 1 , & p , 10 ) ; * slash = ' ' ; if ( p == slash + 1 || * p || prefix > 32 ) return -1 ; * mask <<= ( 32 - prefix ) ; } return 0 ; }
Parse a string containing an IP address with an optional network prefix.
Parse a string containing an IP address with an optional network prefix .