-/*
- free a conn_list_t element and all its pointers
-*/
-void free_conn_element(conn_list_t *p)
-{
-cp
- if(p->sq)
- destroy_queue(p->sq);
- if(p->rq)
- destroy_queue(p->rq);
- if(p->vpn_hostname)
- free(p->vpn_hostname);
- if(p->real_hostname)
- free(p->real_hostname);
- free_key(p->public_key);
- free_key(p->key);
- free(p);
-cp
+sockaddr_t str2sockaddr(const char *address, const char *port) {
+ struct addrinfo *ai, hint = {0};
+ sockaddr_t result = {{0}};
+ int err;
+
+ hint.ai_family = AF_UNSPEC;
+ hint.ai_flags = AI_NUMERICHOST;
+ hint.ai_socktype = SOCK_STREAM;
+
+ err = getaddrinfo(address, port, &hint, &ai);
+
+ if(err || !ai) {
+ logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Unknown type address %s port %s", address, port);
+ result.sa.sa_family = AF_UNKNOWN;
+ result.unknown.address = xstrdup(address);
+ result.unknown.port = xstrdup(port);
+ return result;
+ }
+
+ memcpy(&result, ai->ai_addr, ai->ai_addrlen);
+ freeaddrinfo(ai);
+
+ return result;