- /* Set the socket to non-blocking mode */
- silc_net_set_socket_nonblock(sock);
-
- /* Connect to the host */
- rval = connect(sock, (struct sockaddr *)&desthost, sizeof(desthost));
- if (rval < 0) {
- if (errno != EINPROGRESS) {
- SILC_LOG_ERROR(("Cannot connect to remote host: %s", strerror(errno)));
- shutdown(sock, 2);
- close(sock);
- return -1;
- }
+bool silc_net_gethostbyname(const char *name, char *address,
+ uint32 address_len)
+{
+#ifdef HAVE_IPV6
+ struct addrinfo hints, *ai;
+ char hbuf[NI_MAXHOST];
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_socktype = SOCK_STREAM;
+ if (getaddrinfo(name, NULL, &hints, &ai))
+ return FALSE;
+
+ if (getnameinfo(ai->ai_addr, ai->ai_addrlen, hbuf,
+ sizeof(hbuf), NULL, 0, NI_NUMERICHOST))
+ return FALSE;
+
+ if (ai->ai_family == AF_INET) {
+ if (!inet_ntop(ai->ai_family,
+ &((struct sockaddr_in *)ai->ai_addr)->sin_addr,
+ address, address_len))
+ return FALSE;
+ } else {
+ if (!inet_ntop(ai->ai_family,
+ &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr,
+ address, address_len))
+ return FALSE;