example/ipsec_crypto/odp_ipsec_misc.h
static inline
int parse_ipv4_string(char *ipaddress, uint32_t *addr, uint32_t *mask)
{
	int b[4];
	int qualifier = 32;
	int converted;

	if (strchr(ipaddress, '/')) {
		converted = sscanf(ipaddress, "%d.%d.%d.%d/%d",
				   &b[3], &b[2], &b[1], &b[0],
				   &qualifier);
		if (5 != converted)
			return -1;
	} else {
		converted = sscanf(ipaddress, "%d.%d.%d.%d",
				   &b[3], &b[2], &b[1], &b[0]);
		if (4 != converted)
			return -1;
	}

	if ((b[0] > 255) || (b[1] > 255) || (b[2] > 255) || (b[3] > 255))
		return -1;
	if (!qualifier || (qualifier > 32))
		return -1;

	*addr = b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24;
	if (mask)
		*mask = ~(0xFFFFFFFF & ((1ULL << (32 - qualifier)) - 1));

	return 0;
}
/**
 * Parse text string representing an IPv4 address or subnet
 *
 * String is of the format "XXX.XXX.XXX.XXX(/W)" where
 * "XXX" is decimal value and "/W" is optional subnet length
 *
 * @param ipaddress  Pointer to IP address/subnet string to convert
 * @param addr       Pointer to return IPv4 address
 * @param mask       Pointer (optional) to return IPv4 mask
 *
 * @return 0 if successful else -1
 */


@param ipaddress  Pointer to IP address/subnet string to convert
@param addr       Pointer to return IPv4 address
@param mask       Pointer (optional) to return IPv4 mask

@return 0 if successful else -1
@param ipaddress Pointer to IP address / subnet string to convert @param addr Pointer to return IPv4 address @param mask Pointer ( optional ) to return IPv4 mask @return 0 if successful else - 1
static inline
int parse_ipv4_string(char *ipaddress, uint32_t *addr, uint32_t *mask)
{
	int b[4];
	int qualifier = 32;
	int converted;
	if (strchr(ipaddress, '/')) {
		converted = sscanf(ipaddress, "%d.%d.%d.%d/%d",
				   &b[3], &b[2], &b[1], &b[0],
				   &qualifier);
		if (5 != converted)
			return -1;
	} else {
		converted = sscanf(ipaddress, "%d.%d.%d.%d",
				   &b[3], &b[2], &b[1], &b[0]);
		if (4 != converted)
			return -1;
	}
	if ((b[0] > 255) || (b[1] > 255) || (b[2] > 255) || (b[3] > 255))
		return -1;
	if (!qualifier || (qualifier > 32))
		return -1;
	*addr = b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24;
	if (mask)
		*mask = ~(0xFFFFFFFF & ((1ULL << (32 - qualifier)) - 1));
	return 0;
}
static inline int parse_ipv4_string ( char * ipaddress , uint32_t * addr , uint32_t * mask ) { int b [ 4 ] ; int qualifier = 32 ; int converted ; if ( strchr ( ipaddress , ' ' ) ) { converted = sscanf ( ipaddress , " " , & b [ 3 ] , & b [ 2 ] , & b [ 1 ] , & b [ 0 ] , & qualifier ) ; if ( 5 != converted ) return -1 ; } else { converted = sscanf ( ipaddress , " " , & b [ 3 ] , & b [ 2 ] , & b [ 1 ] , & b [ 0 ] ) ; if ( 4 != converted ) return -1 ; } if ( ( b [ 0 ] > 255 ) || ( b [ 1 ] > 255 ) || ( b [ 2 ] > 255 ) || ( b [ 3 ] > 255 ) ) return -1 ; if ( ! qualifier || ( qualifier > 32 ) ) return -1 ; * addr = b [ 0 ] | b [ 1 ] << 8 | b [ 2 ] << 16 | b [ 3 ] << 24 ; if ( mask ) * mask = ~ ( 0xFFFFFFFF & ( ( 1ULL << ( 32 - qualifier ) ) - 1 ) ) ; return 0 ; }
Parse text string representing an IPv4 address or subnet
 String is of the format "XXX.XXX.XXX.XXX(/W)" where
 "XXX" is decimal value and "/W" is optional subnet length
Parse text string representing an IPv4 address or subnet String is of the format " XXX . XXX . XXX . XXX ( / W ) " where " XXX " is decimal value and " / W " is optional subnet length