#include #include #include #include #include #include "macros.h" #include "network.h" const char *addr_to_str(struct sockaddr *sa, socklen_t len) { const int family = sa->sa_family; static char ip[INET6_ADDRSTRLEN]; char *str = ip; switch (family) { case AF_INET6 : inet_ntop(family, &((struct sockaddr_in6 *)sa)->sin6_addr, ip, len); break; case AF_INET : inet_ntop(family, &((struct sockaddr_in *)sa)->sin_addr, ip, len); break; case AF_UNIX : str = ((struct sockaddr_un *)sa)->sun_path; break; } return str; }