sync with 0.8.1cvs17
[claws.git] / src / socket.c
index 3f3457ffc96d3f2c78c32ee4087d1ddaf6d60c3d..c0430a22e7c46616adf57ae80a03844ecdf82c93 100644 (file)
@@ -240,6 +240,37 @@ static gint sock_connect_with_timeout(gint sock,
        return ret;
 }
 
+struct hostent *my_gethostbyname(const gchar *hostname)
+{
+       struct hostent *hp;
+       void (*prev_handler)(gint);
+       guint timeout_secs = IO_TIMEOUT;
+
+       alarm(0);
+       prev_handler = signal(SIGALRM, timeout_handler);
+       if (sigsetjmp(jmpenv, 1)) {
+               alarm(0);
+               signal(SIGALRM, prev_handler);
+               fprintf(stderr, "%s: host lookup timed out.\n", hostname);
+               errno = 0;
+               return NULL;
+       }
+       alarm(timeout_secs);
+
+       if ((hp = gethostbyname(hostname)) == NULL) {
+               alarm(0);
+               signal(SIGALRM, prev_handler);
+               fprintf(stderr, "%s: unknown host.\n", hostname);
+               errno = 0;
+               return NULL;
+       }
+
+       alarm(0);
+       signal(SIGALRM, prev_handler);
+
+       return hp;
+}
+
 #ifndef INET6
 static gint my_inet_aton(const gchar *hostname, struct in_addr *inp)
 {
@@ -273,30 +304,12 @@ static gint sock_connect_by_hostname(gint sock, const gchar *hostname,
        ad.sin_port = htons(port);
 
        if (!my_inet_aton(hostname, &ad.sin_addr)) {
-               void (*prev_handler)(gint);
-
-               alarm(0);
-               prev_handler = signal(SIGALRM, timeout_handler);
-               if (sigsetjmp(jmpenv, 1)) {
-                       alarm(0);
-                       signal(SIGALRM, prev_handler);
-                       fprintf(stderr, "%s: host lookup timed out.\n", hostname);
-                       errno = 0;
-                       return -1;
-               }
-               alarm(timeout_secs);
-
-               if ((hp = gethostbyname(hostname)) == NULL) {
-                       alarm(0);
-                       signal(SIGALRM, prev_handler);
+               if ((hp = my_gethostbyname(hostname)) == NULL) {
                        fprintf(stderr, "%s: unknown host.\n", hostname);
                        errno = 0;
                        return -1;
                }
 
-               alarm(0);
-               signal(SIGALRM, prev_handler);
-
                if (hp->h_length != 4 && hp->h_length != 8) {
                        fprintf(stderr, "illegal address length received for host %s\n", hostname);
                        errno = 0;