Răsfoiți Sursa

* Removed gethostbyname() dependency. This fixes Linux binary compatibility issues / crashes on startup.

Bryan Drewery 16 ani în urmă
părinte
comite
be4d02bd49
2 a modificat fișierele cu 15 adăugiri și 31 ștergeri
  1. 2 0
      doc/UPDATES
  2. 13 31
      src/net.c

+ 2 - 0
doc/UPDATES

@@ -1,3 +1,5 @@
+* Removed gethostbyname() dependency. This fixes Linux binary compatibility issues / crashes on startup.
+
 1.2.17 - http://wraith.botpack.net/milestone/1.2.17
 * Binary / shell / startup changes
   * Binary error messages are no longer obscure numbers or fake segfaults. (Compile with OBSCURE_ERRORS to re-enable)

+ 13 - 31
src/net.c

@@ -120,41 +120,23 @@ static int get_ip(char *hostname, union sockaddr_union *so)
   memset(so, 0, sizeof(union sockaddr_union));
   debug1("get_ip(%s)", hostname);
 
-#ifdef USE_IPV6
-  struct addrinfo hints, *ai = NULL, *res = NULL;
-  int error = 0;
-
-  memset(&hints, 0, sizeof(struct addrinfo));
-  hints.ai_socktype = SOCK_STREAM;
+  bd::Array<bd::String> hosts = dns_lookup_block(hostname, 20);
+  if (hosts.length() == 0)
+    return -1;
 
-  if ((error = getaddrinfo(hostname, NULL, &hints, &res))) {
-    if (res)
-      freeaddrinfo(res);
-    return error;
-  }
+  my_addr_t addr;
+  get_addr(bd::String(hosts[0]).c_str(), &addr);
 
-  error = 1;
-  for (ai = res; ai != NULL; ai = ai->ai_next) {
-    if ((ai->ai_family == AF_INET6) || (ai->ai_family == AF_INET)) {
-      memcpy(so, ai->ai_addr, ai->ai_addrlen);
-      error = 0;
-      break;
-    }
+  if (addr.family == AF_INET) {
+    so->sin.sin_family = AF_INET;
+    memcpy(&so->sin.sin_addr, &addr.u.addr, sizeof(addr.u.addr));
+#ifdef USE_IPV6
+  } else if (addr.family == AF_INET6) {
+    so->sin6.sin6_family = AF_INET6;
+    memcpy(&so->sin6.sin6_addr, &addr.u.addr6, sizeof(addr.u.addr6));
+#endif
   }
-
-  if (res)
-    freeaddrinfo(res);
-  return error;
-#else
-  struct hostent *hp = NULL;
-
-  if (!(hp = gethostbyname(hostname)))
-    return -1;
-
-  memcpy(&so->sin.sin_addr, hp->h_addr, 4);
-  so->sin.sin_family = AF_INET;
   return 0;
-#endif /* USE_IPV6 */
 }
 
 /* Initialize the socklist