src/tcpkali_iface.c
void
address_add(struct addresses *aseq, struct sockaddr *sa) {
    /* Reallocate a bigger list and continue. Don't laugh. */
    aseq->addrs =
        realloc(aseq->addrs, (aseq->n_addrs + 1) * sizeof(aseq->addrs[0]));
    assert(aseq->addrs);
    switch(sa->sa_family) {
    case AF_INET:
        *(struct sockaddr_in *)&aseq->addrs[aseq->n_addrs] =
            *(struct sockaddr_in *)sa;
        aseq->n_addrs++;
        break;
    case AF_INET6:
        *(struct sockaddr_in6 *)&aseq->addrs[aseq->n_addrs] =
            *(struct sockaddr_in6 *)sa;
        aseq->n_addrs++;
        break;
    default:
        assert(!"Not IPv4 and not IPv6");
        break;
    }
}
/*
 * Note: struct sockaddr_in6 is larger than struct sockaddr, hence
 * the storage should be bigger. However, we shall not dereference
 * the AF_INET (struct sockaddr_in *) as it were a larger structure.
 * Therefore this code is rather complex.
 */
struct sockaddr_in6 is larger than struct sockaddr, hence
the storage should be bigger. However, we shall not dereference
the AF_INET (struct sockaddr_in *) as it were a larger structure.
Therefore this code is rather complex.
struct sockaddr_in6 is larger than struct sockaddr hence the storage should be bigger . However we shall not dereference the AF_INET ( struct sockaddr_in * ) as it were a larger structure . Therefore this code is rather complex .
void
address_add(struct addresses *aseq, struct sockaddr *sa) {
    aseq->addrs =
        realloc(aseq->addrs, (aseq->n_addrs + 1) * sizeof(aseq->addrs[0]));
    assert(aseq->addrs);
    switch(sa->sa_family) {
    case AF_INET:
        *(struct sockaddr_in *)&aseq->addrs[aseq->n_addrs] =
            *(struct sockaddr_in *)sa;
        aseq->n_addrs++;
        break;
    case AF_INET6:
        *(struct sockaddr_in6 *)&aseq->addrs[aseq->n_addrs] =
            *(struct sockaddr_in6 *)sa;
        aseq->n_addrs++;
        break;
    default:
        assert(!"Not IPv4 and not IPv6");
        break;
    }
}
void address_add ( struct addresses * aseq , struct sockaddr * sa ) { aseq -> addrs = realloc ( aseq -> addrs , ( aseq -> n_addrs + 1 ) * sizeof ( aseq -> addrs [ 0 ] ) ) ; assert ( aseq -> addrs ) ; switch ( sa -> sa_family ) { case AF_INET : * ( struct sockaddr_in * ) & aseq -> addrs [ aseq -> n_addrs ] = * ( struct sockaddr_in * ) sa ; aseq -> n_addrs ++ ; break ; case AF_INET6 : * ( struct sockaddr_in6 * ) & aseq -> addrs [ aseq -> n_addrs ] = * ( struct sockaddr_in6 * ) sa ; aseq -> n_addrs ++ ; break ; default : assert ( ! " " ) ; break ; } }
Note: struct sockaddr_in6 is larger than struct sockaddr, hence
 the storage should be bigger.
Note : struct sockaddr_in6 is larger than struct sockaddr hence the storage should be bigger .
/* Reallocate a bigger list and continue. Don't laugh. */