190
189
sa4 = (const void *)ai->ai_addr;
191
190
ipaddr4 = &sa4->sin_addr;
192
return Curl_inet_ntop(ai->ai_family, (const void *)ipaddr4, buf, bufsize);
191
return Curl_inet_ntop(ai->ai_family, (const void *)ipaddr4, buf,
193
193
#ifdef ENABLE_IPV6
195
195
sa6 = (const void *)ai->ai_addr;
196
196
ipaddr6 = &sa6->sin6_addr;
197
return Curl_inet_ntop(ai->ai_family, (const void *)ipaddr6, buf, bufsize);
197
return Curl_inet_ntop(ai->ai_family, (const void *)ipaddr6, buf,
358
351
dns->inuse = 0; /* init to not used */
359
352
dns->addr = addr; /* this is the address(es) */
353
time(&dns->timestamp);
354
if(dns->timestamp == 0)
355
dns->timestamp = 1; /* zero indicates that entry isn't in hash table */
361
/* Store the resolved data in our DNS cache. This function may return a
362
pointer to an existing struct already present in the hash, and it may
363
return the same argument we pass in. Make no assumptions. */
357
/* Store the resolved data in our DNS cache. */
364
358
dns2 = Curl_hash_add(data->dns.hostcache, entry_id, entry_len+1,
367
/* Major badness, run away. */
375
dns->timestamp = now; /* used now */
376
367
dns->inuse++; /* mark entry as in-use */
378
369
/* free the allocated entry_id again */
574
565
timeout = timeoutms;
576
if(timeout && timeout < 1000)
568
/* USE_ALARM_TIMEOUT defined, but no timeout actually requested */
569
return Curl_resolv(conn, hostname, port, entry);
577
572
/* The alarm() function only provides integer second resolution, so if
578
573
we want to wait less than one second we must bail out already now. */
579
574
return CURLRESOLV_TIMEDOUT;
582
/* This allows us to time-out from the name resolver, as the timeout
583
will generate a signal and we will siglongjmp() from that here.
584
This technique has problems (see alarmfunc). */
585
if(sigsetjmp(curl_jmpenv, 1)) {
586
/* this is coming from a siglongjmp() after an alarm signal */
587
failf(data, "name lookup timed out");
588
return CURLRESOLV_ERROR;
591
/*************************************************************
592
* Set signal handler to catch SIGALRM
593
* Store the old value to be able to set it back later!
594
*************************************************************/
576
/*************************************************************
577
* Set signal handler to catch SIGALRM
578
* Store the old value to be able to set it back later!
579
*************************************************************/
595
580
#ifdef HAVE_SIGACTION
596
sigaction(SIGALRM, NULL, &sigact);
597
keep_sigact = sigact;
598
keep_copysig = TRUE; /* yes, we have a copy */
599
sigact.sa_handler = alarmfunc;
581
sigaction(SIGALRM, NULL, &sigact);
582
keep_sigact = sigact;
583
keep_copysig = TRUE; /* yes, we have a copy */
584
sigact.sa_handler = alarmfunc;
600
585
#ifdef SA_RESTART
601
/* HPUX doesn't have SA_RESTART but defaults to that behaviour! */
602
sigact.sa_flags &= ~SA_RESTART;
586
/* HPUX doesn't have SA_RESTART but defaults to that behaviour! */
587
sigact.sa_flags &= ~SA_RESTART;
604
/* now set the new struct */
605
sigaction(SIGALRM, &sigact, NULL);
589
/* now set the new struct */
590
sigaction(SIGALRM, &sigact, NULL);
606
591
#else /* HAVE_SIGACTION */
607
/* no sigaction(), revert to the much lamer signal() */
592
/* no sigaction(), revert to the much lamer signal() */
608
593
#ifdef HAVE_SIGNAL
609
keep_sigact = signal(SIGALRM, alarmfunc);
594
keep_sigact = signal(SIGALRM, alarmfunc);
611
596
#endif /* HAVE_SIGACTION */
613
/* alarm() makes a signal get sent when the timeout fires off, and that
614
will abort system calls */
615
prev_alarm = alarm((unsigned int) (timeout/1000L));
598
/* alarm() makes a signal get sent when the timeout fires off, and that
599
will abort system calls */
600
prev_alarm = alarm((unsigned int) (timeout/1000L));
602
/* This allows us to time-out from the name resolver, as the timeout
603
will generate a signal and we will siglongjmp() from that here.
604
This technique has problems (see alarmfunc).
605
This should be the last thing we do before calling Curl_resolv(),
606
as otherwise we'd have to worry about variables that get modified
607
before we invoke Curl_resolv() (and thus use "volatile"). */
608
if(sigsetjmp(curl_jmpenv, 1)) {
609
/* this is coming from a siglongjmp() after an alarm signal */
610
failf(data, "name lookup timed out");
611
rc = CURLRESOLV_ERROR;
630
627
rc = Curl_resolv(conn, hostname, port, entry);
632
629
#ifdef USE_ALARM_TIMEOUT
633
/* deactivate a possibly active alarm before uninstalling the handler */
635
636
#ifdef HAVE_SIGACTION
637
/* we got a struct as it looked before, now put that one back nice
639
sigaction(SIGALRM, &keep_sigact, NULL); /* put it back */
638
/* we got a struct as it looked before, now put that one back nice
640
sigaction(SIGALRM, &keep_sigact, NULL); /* put it back */
642
643
#ifdef HAVE_SIGNAL
643
/* restore the previous SIGALRM handler */
644
signal(SIGALRM, keep_sigact);
644
/* restore the previous SIGALRM handler */
645
signal(SIGALRM, keep_sigact);
646
647
#endif /* HAVE_SIGACTION */
648
/* switch back the alarm() to either zero or to what it was before minus
649
the time we spent until now! */
651
/* there was an alarm() set before us, now put it back */
652
unsigned long elapsed_ms = Curl_tvdiff(Curl_tvnow(), conn->created);
654
/* the alarm period is counted in even number of seconds */
655
unsigned long alarm_set = prev_alarm - elapsed_ms/1000;
658
((alarm_set >= 0x80000000) && (prev_alarm < 0x80000000)) ) {
659
/* if the alarm time-left reached zero or turned "negative" (counted
660
with unsigned values), we should fire off a SIGALRM here, but we
661
won't, and zero would be to switch it off so we never set it to
664
rc = CURLRESOLV_TIMEDOUT;
665
failf(data, "Previous alarm fired off!");
668
alarm((unsigned int)alarm_set);
649
/* switch back the alarm() to either zero or to what it was before minus
650
the time we spent until now! */
652
/* there was an alarm() set before us, now put it back */
653
unsigned long elapsed_ms = Curl_tvdiff(Curl_tvnow(), conn->created);
655
/* the alarm period is counted in even number of seconds */
656
unsigned long alarm_set = prev_alarm - elapsed_ms/1000;
659
((alarm_set >= 0x80000000) && (prev_alarm < 0x80000000)) ) {
660
/* if the alarm time-left reached zero or turned "negative" (counted
661
with unsigned values), we should fire off a SIGALRM here, but we
662
won't, and zero would be to switch it off so we never set it to
665
rc = CURLRESOLV_TIMEDOUT;
666
failf(data, "Previous alarm fired off!");
671
alarm(0); /* just shut it off */
669
alarm((unsigned int)alarm_set);
673
671
#endif /* USE_ALARM_TIMEOUT */
714
720
return Curl_hash_alloc(7, Curl_hash_str, Curl_str_key_compare, freednsentry);
717
#ifdef CURLRES_ADDRINFO_COPY
719
/* align on even 64bit boundaries */
720
#define MEMALIGN(x) ((x)+(8-(((unsigned long)(x))&0x7)))
723
* Curl_addrinfo_copy() performs a "deep" copy of a hostent into a buffer and
724
* returns a pointer to the malloc()ed copy. You need to call free() on the
725
* returned buffer when you're done with it.
727
Curl_addrinfo *Curl_addrinfo_copy(const void *org, int port)
729
const struct hostent *orig = org;
731
return Curl_he2ai(orig, port);
733
#endif /* CURLRES_ADDRINFO_COPY */