src/tcpkali_iface.c
const char *
format_sockaddr(struct sockaddr_storage *ss, char *buf, size_t size) {
    void *in_addr;
    uint16_t nport;
    switch(ss->ss_family) {
    case AF_INET:
        in_addr = &((struct sockaddr_in *)ss)->sin_addr;
        nport = ((struct sockaddr_in *)ss)->sin_port;
        break;
    case AF_INET6:
        in_addr = &((struct sockaddr_in6 *)ss)->sin6_addr;
        nport = ((struct sockaddr_in6 *)ss)->sin6_port;
        break;
    default:
        assert(!"ipv4 or ipv6 expected");
        return "<unknown>";
    }
    char ipbuf[INET6_ADDRSTRLEN];
    const char *ip = inet_ntop(ss->ss_family, in_addr, ipbuf, sizeof(ipbuf));
    snprintf(buf, size, "[%s]:%d", ip, ntohs(nport));
    return buf;
}
/*
 * Printable representation of a sockaddr.
 */
Printable representation of a sockaddr.
Printable representation of a sockaddr .
const char *
format_sockaddr(struct sockaddr_storage *ss, char *buf, size_t size) {
    void *in_addr;
    uint16_t nport;
    switch(ss->ss_family) {
    case AF_INET:
        in_addr = &((struct sockaddr_in *)ss)->sin_addr;
        nport = ((struct sockaddr_in *)ss)->sin_port;
        break;
    case AF_INET6:
        in_addr = &((struct sockaddr_in6 *)ss)->sin6_addr;
        nport = ((struct sockaddr_in6 *)ss)->sin6_port;
        break;
    default:
        assert(!"ipv4 or ipv6 expected");
        return "<unknown>";
    }
    char ipbuf[INET6_ADDRSTRLEN];
    const char *ip = inet_ntop(ss->ss_family, in_addr, ipbuf, sizeof(ipbuf));
    snprintf(buf, size, "[%s]:%d", ip, ntohs(nport));
    return buf;
}
const char * format_sockaddr ( struct sockaddr_storage * ss , char * buf , size_t size ) { void * in_addr ; uint16_t nport ; switch ( ss -> ss_family ) { case AF_INET : in_addr = & ( ( struct sockaddr_in * ) ss ) -> sin_addr ; nport = ( ( struct sockaddr_in * ) ss ) -> sin_port ; break ; case AF_INET6 : in_addr = & ( ( struct sockaddr_in6 * ) ss ) -> sin6_addr ; nport = ( ( struct sockaddr_in6 * ) ss ) -> sin6_port ; break ; default : assert ( ! " " ) ; return " " ; } char ipbuf [ INET6_ADDRSTRLEN ] ; const char * ip = inet_ntop ( ss -> ss_family , in_addr , ipbuf , sizeof ( ipbuf ) ) ; snprintf ( buf , size , " " , ip , ntohs ( nport ) ) ; return buf ; }
Printable representation of a sockaddr.
Printable representation of a sockaddr .