socketp.c
/* resolve IP address (decimal dotted or hostname) and service (port number or
 * service name)
 * return a list of addresses
 */
resolve IP address (decimal dotted or hostname) and service (port number or
service name)
return a list of addresses
resolve IP address ( decimal dotted or hostname ) and service ( port number or service name ) return a list of addresses
int resolve_hostname_and_service(char *host, char *service,
                                 struct addrinfo *hints, struct addrinfo **res)
{
    int n ;
    struct addrinfo *reshelp ;
    hints->ai_flags |= AI_NUMERICHOST ;
    if ((n = getaddrinfo(host, service, hints, res)) != 0) {
        if (verboseflag >= 2) {
            fprintf(stderr, "resolving %s ... ", host) ;
        }
        hints->ai_flags &= ~AI_NUMERICHOST ;
        if ((n = getaddrinfo(host, service, hints, res)) != 0) {
            if (verboseflag >= 2) {
                fprintf(stderr, "failed\n") ;
            }
            return n ;
        }
        if (verboseflag >= 2) {
            reshelp = *res ;
            do {
                fprintf(stderr, "%s",
                        get_ipaddr(reshelp->ai_addr, reshelp->ai_addrlen)) ;
                if (reshelp->ai_next != NULL) {
                    fprintf(stderr, ", ") ;
                }
            } while ((reshelp = reshelp->ai_next) != NULL) ;
            fprintf(stderr, "\n") ;
        }
    }
    return 0 ;
}
int resolve_hostname_and_service ( char * host , char * service , struct addrinfo * hints , struct addrinfo * * res ) { int n ; struct addrinfo * reshelp ; hints -> ai_flags |= AI_NUMERICHOST ; if ( ( n = getaddrinfo ( host , service , hints , res ) ) != 0 ) { if ( verboseflag >= 2 ) { fprintf ( stderr , " " , host ) ; } hints -> ai_flags &= ~ AI_NUMERICHOST ; if ( ( n = getaddrinfo ( host , service , hints , res ) ) != 0 ) { if ( verboseflag >= 2 ) { fprintf ( stderr , " \n " ) ; } return n ; } if ( verboseflag >= 2 ) { reshelp = * res ; do { fprintf ( stderr , " " , get_ipaddr ( reshelp -> ai_addr , reshelp -> ai_addrlen ) ) ; if ( reshelp -> ai_next != NULL ) { fprintf ( stderr , " " ) ; } } while ( ( reshelp = reshelp -> ai_next ) != NULL ) ; fprintf ( stderr , " \n " ) ; } } return 0 ; }
resolve IP address (decimal dotted or hostname) and service (port number or
 service name)
 return a list of addresses
resolve IP address ( decimal dotted or hostname ) and service ( port number or service name ) return a list of addresses