-/*
- creates new conn_list element, and initializes it
-*/
-conn_list_t *new_conn_list(void)
-{
- conn_list_t *p = xmalloc(sizeof(*p));
-cp
- /* initialise all those stupid pointers at once */
- memset(p, '\0', sizeof(*p));
- p->vpn_mask = (ip_t)(~0L); /* If this isn't done, it would be a
- wastebucket for all packets with
- unknown destination. */
- p->nexthop = p;
-cp
- return p;
+char *sockaddr2hostname(const sockaddr_t *sa) {
+ char *str;
+ char address[NI_MAXHOST] = "unknown";
+ char port[NI_MAXSERV] = "unknown";
+ int err;
+
+ if(sa->sa.sa_family == AF_UNSPEC) {
+ xasprintf(&str, "unspec port unspec");
+ return str;
+ } else if(sa->sa.sa_family == AF_UNKNOWN) {
+ xasprintf(&str, "%s port %s", sa->unknown.address, sa->unknown.port);
+ return str;
+ }
+
+ err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof address, port, sizeof port,
+ hostnames ? 0 : (NI_NUMERICHOST | NI_NUMERICSERV));
+ if(err) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Error while looking up hostname: %s", err == EAI_SYSTEM ? strerror(errno) : gai_strerror(err));
+ }
+
+ xasprintf(&str, "%s port %s", address, port);
+
+ return str;