openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/systemd/1_242+AUTOINC+db2e367bfc-r0/git/src/basic/hostname-util.c
bool hostname_is_valid(const char* s, bool allow_trailing_dot)
{
    unsigned n_dots = 0;
    const char* p;
    bool dot, hyphen;

    if (isempty(s))
        return false;

    /* Doesn't accept empty hostnames, hostnames with
     * leading dots, and hostnames with multiple dots in a
     * sequence. Also ensures that the length stays below
     * HOST_NAME_MAX. */

    for (p = s, dot = hyphen = true; *p; p++)
        if (*p == '.')
        {
            if (dot || hyphen)
                return false;

            dot = true;
            hyphen = false;
            n_dots++;
        }
        else if (*p == '-')
        {
            if (dot)
                return false;

            dot = false;
            hyphen = true;
        }
        else
        {
            if (!valid_ldh_char(*p))
                return false;

            dot = false;
            hyphen = false;
        }

    if (dot && (n_dots < 2 || !allow_trailing_dot))
        return false;
    if (hyphen)
        return false;

    if (p - s > HOST_NAME_MAX) /* Note that HOST_NAME_MAX is 64 on
                                * Linux, but DNS allows domain names
                                * up to 255 characters */
        return false;

    return true;
}
/**
 * Check if s looks like a valid host name or FQDN. This does not do
 * full DNS validation, but only checks if the name is composed of
 * allowed characters and the length is not above the maximum allowed
 * by Linux (c.f. dns_name_is_valid()). Trailing dot is allowed if
 * allow_trailing_dot is true and at least two components are present
 * in the name. Note that due to the restricted charset and length
 * this call is substantially more conservative than
 * dns_name_is_valid().
 */
Check if s looks like a valid host name or FQDN. This does not do
full DNS validation, but only checks if the name is composed of
allowed characters and the length is not above the maximum allowed
by Linux (c.f.
Check if s looks like a valid host name or FQDN . This does not do full DNS validation but only checks if the name is composed of allowed characters and the length is not above the maximum allowed by Linux ( c . f .
bool hostname_is_valid(const char* s, bool allow_trailing_dot)
{
    unsigned n_dots = 0;
    const char* p;
    bool dot, hyphen;
    if (isempty(s))
        return false;
    for (p = s, dot = hyphen = true; *p; p++)
        if (*p == '.')
        {
            if (dot || hyphen)
                return false;
            dot = true;
            hyphen = false;
            n_dots++;
        }
        else if (*p == '-')
        {
            if (dot)
                return false;
            dot = false;
            hyphen = true;
        }
        else
        {
            if (!valid_ldh_char(*p))
                return false;
            dot = false;
            hyphen = false;
        }
    if (dot && (n_dots < 2 || !allow_trailing_dot))
        return false;
    if (hyphen)
        return false;
    if (p - s > HOST_NAME_MAX) 
        return false;
    return true;
}
bool hostname_is_valid ( const char * s , bool allow_trailing_dot ) { unsigned n_dots = 0 ; const char * p ; bool dot , hyphen ; if ( isempty ( s ) ) return false ; for ( p = s , dot = hyphen = true ; * p ; p ++ ) if ( * p == ' ' ) { if ( dot || hyphen ) return false ; dot = true ; hyphen = false ; n_dots ++ ; } else if ( * p == ' ' ) { if ( dot ) return false ; dot = false ; hyphen = true ; } else { if ( ! valid_ldh_char ( * p ) ) return false ; dot = false ; hyphen = false ; } if ( dot && ( n_dots < 2 || ! allow_trailing_dot ) ) return false ; if ( hyphen ) return false ; if ( p - s > HOST_NAME_MAX ) return false ; return true ; }
Check if s looks like a valid host name or FQDN.
Check if s looks like a valid host name or FQDN .
/* Doesn't accept empty hostnames, hostnames with
     * leading dots, and hostnames with multiple dots in a
     * sequence. Also ensures that the length stays below
     * HOST_NAME_MAX. */ /* Note that HOST_NAME_MAX is 64 on
                                * Linux, but DNS allows domain names
                                * up to 255 characters */