src/tcpkali_iface.c
struct addresses
detect_listen_addresses(const char *local_hostname, int listen_port) {
    struct addresses addresses = {0, 0};
    struct addrinfo hints = {
        .ai_family = AF_UNSPEC,
        .ai_socktype = SOCK_STREAM,
        .ai_protocol = IPPROTO_TCP,
        .ai_flags = AI_PASSIVE | AI_NUMERICSERV | AI_ADDRCONFIG};
    char service[32];
    snprintf(service, sizeof(service), "%d", listen_port);

    struct addrinfo *res;
    int err = getaddrinfo(local_hostname, service, &hints, &res);
    if(err != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(err));
        exit(EXIT_FAILURE);
    }

    /* Move all of the addresses into the separate storage */
    for(struct addrinfo *tmp = res; tmp; tmp = tmp->ai_next) {
        address_add(&addresses, tmp->ai_addr);
    }

    freeaddrinfo(res);

    fprint_addresses(stderr, "Listen on: ", "\nListen on: ", "\n", addresses);

    return addresses;
}
/*
 * Given a port, detect which addresses we can listen on, using this port.
 */
Given a port, detect which addresses we can listen on, using this port.
Given a port detect which addresses we can listen on using this port .
struct addresses
detect_listen_addresses(const char *local_hostname, int listen_port) {
    struct addresses addresses = {0, 0};
    struct addrinfo hints = {
        .ai_family = AF_UNSPEC,
        .ai_socktype = SOCK_STREAM,
        .ai_protocol = IPPROTO_TCP,
        .ai_flags = AI_PASSIVE | AI_NUMERICSERV | AI_ADDRCONFIG};
    char service[32];
    snprintf(service, sizeof(service), "%d", listen_port);
    struct addrinfo *res;
    int err = getaddrinfo(local_hostname, service, &hints, &res);
    if(err != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(err));
        exit(EXIT_FAILURE);
    }
    for(struct addrinfo *tmp = res; tmp; tmp = tmp->ai_next) {
        address_add(&addresses, tmp->ai_addr);
    }
    freeaddrinfo(res);
    fprint_addresses(stderr, "Listen on: ", "\nListen on: ", "\n", addresses);
    return addresses;
}
struct addresses detect_listen_addresses ( const char * local_hostname , int listen_port ) { struct addresses addresses = { 0 , 0 } ; struct addrinfo hints = { . ai_family = AF_UNSPEC , . ai_socktype = SOCK_STREAM , . ai_protocol = IPPROTO_TCP , . ai_flags = AI_PASSIVE | AI_NUMERICSERV | AI_ADDRCONFIG } ; char service [ 32 ] ; snprintf ( service , sizeof ( service ) , " " , listen_port ) ; struct addrinfo * res ; int err = getaddrinfo ( local_hostname , service , & hints , & res ) ; if ( err != 0 ) { fprintf ( stderr , " \n " , gai_strerror ( err ) ) ; exit ( EXIT_FAILURE ) ; } for ( struct addrinfo * tmp = res ; tmp ; tmp = tmp -> ai_next ) { address_add ( & addresses , tmp -> ai_addr ) ; } freeaddrinfo ( res ) ; fprint_addresses ( stderr , " " , " \n " , " \n " , addresses ) ; return addresses ; }
Given a port, detect which addresses we can listen on, using this port.
Given a port detect which addresses we can listen on using this port .
/* Move all of the addresses into the separate storage */