+#if HAVE_GETADDRINFO
+/* resolve using getaddrinfo */
+struct addrinfo *tcpip_getaddrinfo(const char *str, const char *port)
+{
+ struct addrinfo hints, *res;
+ int error;
+ char host[512], *p;
+
+ hints.ai_flags = 0;
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = 0;
+ hints.ai_addrlen = 0;
+ hints.ai_addr = NULL;
+ hints.ai_canonname = NULL;
+ hints.ai_next = NULL;
+
+ strncpy(host, str, sizeof(host)-1);
+ host[sizeof(host)-1] = 0;
+ if ((p = strchr(host, '/')))
+ *p = 0;
+ if ((p = strrchr(host, ':')))
+ {
+ *p = '\0';
+ port = p+1;
+ }
+
+ if (!strcmp("@", host))
+ {
+ hints.ai_flags = AI_PASSIVE;
+ hints.ai_family = AF_INET;
+ error = getaddrinfo(0, port, &hints, &res);
+ }
+ else if (!strcmp("@6", host))
+ {
+ hints.ai_flags = AI_PASSIVE;
+ hints.ai_family = AF_INET6;
+ error = getaddrinfo(0, port, &hints, &res);
+ }
+ else
+ {
+ error = getaddrinfo(host, port, &hints, &res);
+ }
+ if (error)
+ return 0;
+ return res;
+}
+
+#endif
+/* gethostbyname .. old systems */