keygen/src/iam.c
/**
 * ip_version() - Determines if given "network" is a network, address or invalid
 * @src: The IPv6 address or network as a string
 *
 * Takes an IPv6 address or subnet (including /128 subnets) and returns what type
 * of format the address is to XIAM. /64 subnets are validated that the address doesn't
 * supply too many bits.
 *
 * Return: NETWORK if
 */
Determines if given "network" is a network, address or invalid
@src: The IPv6 address or network as a string

Takes an IPv6 address or subnet (including /128 subnets) and returns what type
of format the address is to XIAM. /64 subnets are validated that the address doesn't
supply too many bits.

NETWORK if
Determines if given " network " is a network address or invalid @src : The IPv6 address or network as a string Takes an IPv6 address or subnet ( including / 128 subnets ) and returns what type of format the address is to XIAM . / 64 subnets are validated that the address doesn ' t supply too many bits . NETWORK if
static enum addr_type ip_version(const char *src) {
    char buf[16] = {0};
    char *ip_str = NULL;
    int ip_valid = 0;
    int ret = TYPE_NONE;
    char *subnet;
    ip_str = malloc(strlen(src) + 1);
    if (!ip_str) {
        fprintf(stderr, "%s ERR: Memory error\n", __func__);
        goto out;
    }
    strcpy(ip_str, src);
    subnet = strchr(ip_str, '/');
    if (subnet)
        *(subnet++) = '\0';
    ip_valid = inet_pton(AF_INET6, ip_str, buf);
    if (ip_valid && subnet && strcmp(subnet, "64") == 0 && countZeroBytes(buf, sizeof(buf)) >= 8) {
        ret = TYPE_IPV6_NETWORK;
    }
    if (ip_valid && inet_pton(AF_INET6, ip_str, buf) && (!subnet || strcmp(subnet,"128")==0)) {
        ret = TYPE_IPV6_ADDR;
    }
    free(ip_str);
out:
    return ret;
}
static enum addr_type ip_version ( const char * src ) { char buf [ 16 ] = { 0 } ; char * ip_str = NULL ; int ip_valid = 0 ; int ret = TYPE_NONE ; char * subnet ; ip_str = malloc ( strlen ( src ) + 1 ) ; if ( ! ip_str ) { fprintf ( stderr , " \n " , __func__ ) ; goto out ; } strcpy ( ip_str , src ) ; subnet = strchr ( ip_str , ' ' ) ; if ( subnet ) * ( subnet ++ ) = ' \0 ' ; ip_valid = inet_pton ( AF_INET6 , ip_str , buf ) ; if ( ip_valid && subnet && strcmp ( subnet , " " ) == 0 && countZeroBytes ( buf , sizeof ( buf ) ) >= 8 ) { ret = TYPE_IPV6_NETWORK ; } if ( ip_valid && inet_pton ( AF_INET6 , ip_str , buf ) && ( ! subnet || strcmp ( subnet , " " ) == 0 ) ) { ret = TYPE_IPV6_ADDR ; } free ( ip_str ) ; out : return ret ; }
ip_version() - Determines if given "network" is a network, address or invalid
 @src: The IPv6 address or network as a string
ip_version () - Determines if given " network " is a network address or invalid @src : The IPv6 address or network as a string
/* Copy the IP as we can modify it */ /* Seperate the subnet specifier */ /* Parse the IP address portion */ /* Check for a ::/128 */ /* A full address can be a ::/128 network or no subnet specified. */