src/siri/admin/client.c
/*
 * Try to get an ip address from dns.
 *
 * This function should return 0 when we can start an attempt for discovering
 * dns. When the result is not zero, CLIENT_on_resolved will not be called and
 * err_msg is set.
 */
Try to get an ip address from dns.
This function should return 0 when we can start an attempt for discovering
dns. When the result is not zero, CLIENT_on_resolved will not be called and
err_msg is set.
Try to get an ip address from dns . This function should return 0 when we can start an attempt for discovering dns . When the result is not zero CLIENT_on_resolved will not be called and err_msg is set .
static int CLIENT_resolve_dns(
        siri_admin_client_t * adm_client,
        int ai_family,
        char * err_msg)
{
    struct addrinfo hints;
    hints.ai_family = ai_family;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;
    hints.ai_flags = AI_NUMERICSERV;
    uv_getaddrinfo_t * resolver =
            (uv_getaddrinfo_t *) malloc(sizeof(uv_getaddrinfo_t));
    if (resolver == NULL)
    {
        sprintf(err_msg, "memory allocation error");
        return -1;
    }
    int result;
    resolver->data = adm_client;
    char port[6]= {'\0'};
    sprintf(port, "%u", adm_client->port);
    result = uv_getaddrinfo(
            siri.loop,
            resolver,
            (uv_getaddrinfo_cb) CLIENT_on_resolved,
            adm_client->host,
            port,
            &hints);
    if (result)
    {
        snprintf(
                err_msg,
                SIRI_MAX_SIZE_ERR_MSG,
                "getaddrinfo call error %s",
                uv_err_name(result));
        free(resolver);
    }
    return result;
}
static int CLIENT_resolve_dns ( siri_admin_client_t * adm_client , int ai_family , char * err_msg ) { struct addrinfo hints ; hints . ai_family = ai_family ; hints . ai_socktype = SOCK_STREAM ; hints . ai_protocol = IPPROTO_TCP ; hints . ai_flags = AI_NUMERICSERV ; uv_getaddrinfo_t * resolver = ( uv_getaddrinfo_t * ) malloc ( sizeof ( uv_getaddrinfo_t ) ) ; if ( resolver == NULL ) { sprintf ( err_msg , " " ) ; return -1 ; } int result ; resolver -> data = adm_client ; char port [ 6 ] = { ' \0 ' } ; sprintf ( port , " " , adm_client -> port ) ; result = uv_getaddrinfo ( siri . loop , resolver , ( uv_getaddrinfo_cb ) CLIENT_on_resolved , adm_client -> host , port , & hints ) ; if ( result ) { snprintf ( err_msg , SIRI_MAX_SIZE_ERR_MSG , " " , uv_err_name ( result ) ) ; free ( resolver ) ; } return result ; }
Try to get an ip address from dns.
Try to get an ip address from dns .