| 634 |
634 |
| 635 #elif defined _WIN32 /* end __unix__ */ |
635 #elif defined _WIN32 /* end __unix__ */ |
| 636 |
636 |
| 637 /* Note: The below win32 implementation is actually platform independent. |
637 /* Note: The below win32 implementation is actually platform independent. |
| 638 Perhaps this can be used in place of the above platform dependent code. |
638 Perhaps this can be used in place of the above platform dependent code. |
| 639 */ |
639 */ |
| 640 |
640 |
| 641 typedef struct _dns_tdata { |
641 typedef struct _dns_tdata { |
| 642 char *hostname; |
642 char *hostname; |
| 643 int port; |
643 int port; |
| 644 dns_callback_t callback; |
644 dns_callback_t callback; |
| 658 static gpointer dns_thread(gpointer data) { |
658 static gpointer dns_thread(gpointer data) { |
| 659 struct sockaddr_in sin; |
659 struct sockaddr_in sin; |
| 660 dns_tdata *td = (dns_tdata*)data; |
660 dns_tdata *td = (dns_tdata*)data; |
| 661 struct hostent *hp; |
661 struct hostent *hp; |
| 662 |
662 |
| 663 if(!(hp = gethostbyname(td->hostname))) |
663 if(!(hp = gethostbyname(td->hostname))) { |
| 664 goto failure; |
664 g_free(td->hostname); |
| |
665 g_free(td); |
| |
666 return 0; |
| |
667 } |
| |
668 |
| 665 memset(&sin, 0, sizeof(struct sockaddr_in)); |
669 memset(&sin, 0, sizeof(struct sockaddr_in)); |
| 666 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); |
670 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); |
| 667 sin.sin_family = hp->h_addrtype; |
671 sin.sin_family = hp->h_addrtype; |
| 668 sin.sin_port = htons(td->port); |
672 sin.sin_port = htons(td->port); |
| 669 |
673 |
| 670 td->hosts = g_slist_append(td->hosts, GINT_TO_POINTER(sizeof(sin))); |
674 td->hosts = g_slist_append(td->hosts, GINT_TO_POINTER(sizeof(sin))); |
| 671 td->hosts = g_slist_append(td->hosts, g_memdup(&sin, sizeof(sin))); |
675 td->hosts = g_slist_append(td->hosts, g_memdup(&sin, sizeof(sin))); |
| 672 /* back to main thread */ |
676 /* back to main thread */ |
| 673 g_idle_add(dns_main_thread_cb, td); |
677 g_idle_add(dns_main_thread_cb, td); |
| 674 return 0; |
678 return 0; |
| 675 failure: |
679 } |
| 676 g_free(td->hostname); |
|
| 677 g_free(td); |
|
| 678 return 0; |
|
| 679 } |
|
| 680 |
680 |
| 681 int gaim_gethostbyname_async(const char *hostname, int port, |
681 int gaim_gethostbyname_async(const char *hostname, int port, |
| 682 dns_callback_t callback, gpointer data) { |
682 dns_callback_t callback, gpointer data) { |
| 683 dns_tdata *td; |
683 dns_tdata *td; |
| 684 struct sockaddr_in sin; |
684 struct sockaddr_in sin; |