1680 else |
1679 else |
1681 return -1; |
1680 return -1; |
1682 } |
1681 } |
1683 #endif |
1682 #endif |
1684 |
1683 |
|
1684 #ifdef __SYMBIAN32__ |
|
1685 static long int |
|
1686 explore_hostname(pai, hostname, servname, res, hints) |
|
1687 struct addrinfo *pai; |
|
1688 const char *hostname; |
|
1689 const char *servname; |
|
1690 struct addrinfo **res; |
|
1691 const struct addrinfo *hints; |
|
1692 { |
|
1693 const struct afd *afd; |
|
1694 struct addrinfo *cur; |
|
1695 struct addrinfo sentinel; |
|
1696 int error; |
|
1697 int family_flag=0; |
|
1698 *res = NULL; |
|
1699 |
|
1700 sentinel.ai_next = NULL; |
|
1701 cur = &sentinel; |
|
1702 |
|
1703 /* |
|
1704 * if the servname does not match socktype/protocol, ignore it. |
|
1705 */ |
|
1706 |
|
1707 if (get_portmatch(pai, servname) != 0) |
|
1708 return 0; |
|
1709 if (pai->ai_family == PF_UNSPEC) |
|
1710 { |
|
1711 #ifdef PF_INET6 |
|
1712 #ifdef __SYMBIAN32__ |
|
1713 // XXX: Fix this |
|
1714 pai->ai_family = PF_INET; |
|
1715 #else |
|
1716 pai->ai_family = PF_INET6; |
|
1717 #endif // __SYMBIAN32__ |
|
1718 #else |
|
1719 pai->ai_family = PF_INET; |
|
1720 #endif |
|
1721 family_flag=1; |
|
1722 } |
|
1723 |
|
1724 afd = find_afd(pai->ai_family); |
|
1725 if (afd == NULL && family_flag) |
|
1726 { |
|
1727 if (pai->ai_family == PF_INET6) |
|
1728 { |
|
1729 pai->ai_family = PF_INET; |
|
1730 } |
|
1731 else |
|
1732 { |
|
1733 pai->ai_family = PF_INET6; |
|
1734 } |
|
1735 afd = find_afd(pai->ai_family); |
|
1736 } |
|
1737 |
|
1738 if (afd == NULL) |
|
1739 { |
|
1740 return 0; |
|
1741 } |
|
1742 |
|
1743 if (pai->ai_family == PF_UNSPEC || pai->ai_family == afd->a_af) |
|
1744 { |
|
1745 struct addrinfo *resNative; |
|
1746 struct addrinfo *currNative; |
|
1747 int haveV6asV4 = 0; |
|
1748 int haveV4asV6 = 0; |
|
1749 /* Get the list of addresses using the native api */ |
|
1750 int ret = getaddrinfo_private(hostname, pai, &resNative); |
|
1751 if (ret != 0) |
|
1752 { |
|
1753 ERR(ret); |
|
1754 } |
|
1755 |
|
1756 /* copy the addresses to the local list */ |
|
1757 currNative = resNative; |
|
1758 while (currNative) |
|
1759 { |
|
1760 if (currNative->ai_family == PF_INET && (hints->ai_family == PF_INET || hints->ai_family == PF_UNSPEC)) |
|
1761 { |
|
1762 if (currNative->ai_flags & AI_V4CONVERTED) |
|
1763 { |
|
1764 haveV6asV4 = 1; |
|
1765 } |
|
1766 else |
|
1767 { |
|
1768 struct sockaddr_in* sAddrTmp = (struct sockaddr_in*) (currNative->ai_addr); |
|
1769 GET_AI(cur->ai_next, afd, (char*)&(sAddrTmp->sin_addr)); |
|
1770 cur->ai_next->ai_addr->sa_family = cur->ai_next->ai_family = PF_INET; |
|
1771 GET_PORT(cur->ai_next, servname); |
|
1772 |
|
1773 if (pai->ai_flags & AI_CANONNAME) |
|
1774 { |
|
1775 GET_CANONNAME(cur->ai_next, currNative->ai_canonname); |
|
1776 } |
|
1777 |
|
1778 cur = cur->ai_next; |
|
1779 } |
|
1780 } |
|
1781 |
|
1782 if (currNative->ai_family == PF_INET6 && (hints->ai_family == PF_INET6 || hints->ai_family == PF_UNSPEC)) |
|
1783 { |
|
1784 if (currNative->ai_flags & AI_V4MAPPED) |
|
1785 { |
|
1786 haveV4asV6 = 1; |
|
1787 } |
|
1788 else |
|
1789 { |
|
1790 struct sockaddr_in6* sAddrTmp = (struct sockaddr_in6*) (currNative->ai_addr); |
|
1791 GET_AI(cur->ai_next, afd, (char*)&(sAddrTmp->sin6_addr)); |
|
1792 cur->ai_next->ai_addr->sa_family = cur->ai_next->ai_family = PF_INET6; |
|
1793 GET_PORT(cur->ai_next, servname); |
|
1794 |
|
1795 if (pai->ai_flags & AI_CANONNAME) |
|
1796 { |
|
1797 GET_CANONNAME(cur->ai_next, currNative->ai_canonname); |
|
1798 } |
|
1799 |
|
1800 cur = cur->ai_next; |
|
1801 } |
|
1802 } |
|
1803 |
|
1804 currNative = currNative->ai_next; |
|
1805 } |
|
1806 |
|
1807 if (hints->ai_family == PF_INET6 && hints->ai_flags & AI_V4MAPPED && !sentinel.ai_next && haveV4asV6) |
|
1808 { |
|
1809 currNative = resNative; |
|
1810 while (currNative) |
|
1811 { |
|
1812 // check for addresses converted from v4 to v6 |
|
1813 if (currNative->ai_flags & AI_V4MAPPED) |
|
1814 { |
|
1815 struct sockaddr_in6* sAddrTmp = (struct sockaddr_in6*) (currNative->ai_addr); |
|
1816 GET_AI(cur->ai_next, afd, (char*)&(sAddrTmp->sin6_addr)); |
|
1817 cur->ai_next->ai_addr->sa_family = cur->ai_next->ai_family = PF_INET6; |
|
1818 GET_PORT(cur->ai_next, servname); |
|
1819 currNative->ai_flags &= ~AI_V4MAPPED; |
|
1820 |
|
1821 if (pai->ai_flags & AI_CANONNAME) |
|
1822 { |
|
1823 GET_CANONNAME(cur->ai_next, currNative->ai_canonname); |
|
1824 } |
|
1825 |
|
1826 cur = cur->ai_next; |
|
1827 } |
|
1828 |
|
1829 currNative = currNative->ai_next; |
|
1830 } |
|
1831 } |
|
1832 |
|
1833 if (haveV6asV4) |
|
1834 { |
|
1835 if ((hints->ai_family == PF_INET && !sentinel.ai_next) || (hints->ai_flags & (AI_V4MAPPED|AI_ALL))) |
|
1836 { |
|
1837 currNative = resNative; |
|
1838 while (currNative) |
|
1839 { |
|
1840 // check for addresses converted from v6 to v4 |
|
1841 if (currNative->ai_flags & AI_V4CONVERTED) |
|
1842 { |
|
1843 struct sockaddr_in* sAddrTmp = (struct sockaddr_in*) (currNative->ai_addr); |
|
1844 GET_AI(cur->ai_next, afd, (char*)&(sAddrTmp->sin_addr)); |
|
1845 cur->ai_next->ai_addr->sa_family = cur->ai_next->ai_family = PF_INET; |
|
1846 GET_PORT(cur->ai_next, servname); |
|
1847 currNative->ai_flags &= ~AI_V4CONVERTED; |
|
1848 |
|
1849 if (pai->ai_flags & AI_CANONNAME) |
|
1850 { |
|
1851 GET_CANONNAME(cur->ai_next, currNative->ai_canonname); |
|
1852 } |
|
1853 |
|
1854 cur = cur->ai_next; |
|
1855 } |
|
1856 |
|
1857 currNative = currNative->ai_next; |
|
1858 } |
|
1859 } |
|
1860 } |
|
1861 |
|
1862 /* free the address list returned by native api */ |
|
1863 freeaddrinfo_private(resNative); |
|
1864 } |
|
1865 else |
|
1866 { |
|
1867 ERR(EAI_FAMILY); |
|
1868 } |
|
1869 |
|
1870 *res = sentinel.ai_next; |
|
1871 return 0; |
|
1872 |
|
1873 free: |
|
1874 bad: |
|
1875 if (sentinel.ai_next) |
|
1876 { |
|
1877 freeaddrinfo(sentinel.ai_next); |
|
1878 } |
|
1879 return error; |
|
1880 } |
|
1881 |
|
1882 #endif//__SYMBIAN32__ |
|
1883 |
1685 /* |
1884 /* |
1686 * FQDN hostname, DNS lookup |
1885 * FQDN hostname, DNS lookup |
1687 */ |
1886 */ |
1688 #ifndef __SYMBIAN32__ |
1887 #ifndef __SYMBIAN32__ |
1689 static int |
1888 static int |
2728 } |
2928 } |
2729 return (res_queryN(longname, target)); |
2929 return (res_queryN(longname, target)); |
2730 } |
2930 } |
2731 #endif /*__SYMBIAN32__*/ |
2931 #endif /*__SYMBIAN32__*/ |
2732 |
2932 |
2733 #ifdef __SYMBIAN32__ |
|
2734 static long int |
|
2735 explore_hostname(pai, hostname, servname, res, hints) |
|
2736 struct addrinfo *pai; |
|
2737 const char *hostname; |
|
2738 const char *servname; |
|
2739 struct addrinfo **res; |
|
2740 const struct addrinfo *hints; |
|
2741 { |
|
2742 const struct afd *afd; |
|
2743 struct addrinfo *cur; |
|
2744 struct addrinfo sentinel; |
|
2745 int error; |
|
2746 int family_flag=0; |
|
2747 *res = NULL; |
|
2748 |
|
2749 sentinel.ai_next = NULL; |
|
2750 cur = &sentinel; |
|
2751 |
|
2752 /* |
|
2753 * if the servname does not match socktype/protocol, ignore it. |
|
2754 */ |
|
2755 |
|
2756 if (get_portmatch(pai, servname) != 0) |
|
2757 return 0; |
|
2758 if (pai->ai_family == PF_UNSPEC) { |
|
2759 #ifdef PF_INET6 |
|
2760 #ifdef __SYMBIAN32__ |
|
2761 // XXX: Fix this |
|
2762 pai->ai_family = PF_INET; |
|
2763 #else |
|
2764 pai->ai_family = PF_INET6; |
|
2765 #endif // __SYMBIAN32__ |
|
2766 #else |
|
2767 pai->ai_family = PF_INET; |
|
2768 #endif |
|
2769 family_flag=1; |
|
2770 } |
|
2771 |
|
2772 afd = find_afd(pai->ai_family); |
|
2773 if( afd==NULL && family_flag ) |
|
2774 { |
|
2775 if(pai->ai_family==PF_INET6) |
|
2776 { |
|
2777 pai->ai_family=PF_INET; |
|
2778 } |
|
2779 else |
|
2780 { |
|
2781 pai->ai_family=PF_INET6; |
|
2782 } |
|
2783 afd=find_afd(pai->ai_family); |
|
2784 } |
|
2785 |
|
2786 if (afd == NULL) |
|
2787 { |
|
2788 return 0; |
|
2789 } |
|
2790 |
|
2791 if ( pai->ai_family == PF_UNSPEC ||pai->ai_family == afd->a_af) |
|
2792 { |
|
2793 struct addrinfo *resNative; |
|
2794 struct addrinfo *currNative; |
|
2795 int haveV4Mapped = 0; |
|
2796 /* Get the list of addresses using the native api */ |
|
2797 int ret = getaddrinfo_private(hostname, pai, &resNative); |
|
2798 if(ret != 0) |
|
2799 ERR(ret); |
|
2800 |
|
2801 /* copy the addresses to the local list */ |
|
2802 currNative = resNative; |
|
2803 while(currNative) |
|
2804 { |
|
2805 if(currNative->ai_family == PF_INET && (hints->ai_family == PF_INET || hints->ai_family == PF_UNSPEC)) |
|
2806 { |
|
2807 if(currNative->ai_flags & AI_V4MAPPED) |
|
2808 { |
|
2809 haveV4Mapped = 1; |
|
2810 } |
|
2811 else |
|
2812 { |
|
2813 struct sockaddr_in* sAddrTmp = (struct sockaddr_in*) (currNative->ai_addr); |
|
2814 GET_AI(cur->ai_next, afd, (char*)&(sAddrTmp->sin_addr)); |
|
2815 cur->ai_next->ai_addr->sa_family = cur->ai_next->ai_family = PF_INET; |
|
2816 GET_PORT(cur->ai_next, servname); |
|
2817 |
|
2818 if((pai->ai_flags & AI_CANONNAME)) |
|
2819 GET_CANONNAME(cur->ai_next, currNative->ai_canonname); |
|
2820 |
|
2821 cur = cur->ai_next; |
|
2822 } |
|
2823 } |
|
2824 |
|
2825 if(currNative->ai_family == PF_INET6 && (hints->ai_family == PF_INET6 || hints->ai_family == PF_UNSPEC)) |
|
2826 { |
|
2827 struct sockaddr_in6* sAddrTmp = (struct sockaddr_in6*) (currNative->ai_addr); |
|
2828 GET_AI(cur->ai_next, afd, (char*)&(sAddrTmp->sin6_addr)); |
|
2829 cur->ai_next->ai_addr->sa_family = cur->ai_next->ai_family = PF_INET6; |
|
2830 GET_PORT(cur->ai_next, servname); |
|
2831 |
|
2832 if((pai->ai_flags & AI_CANONNAME)) |
|
2833 GET_CANONNAME(cur->ai_next, currNative->ai_canonname); |
|
2834 |
|
2835 cur = cur->ai_next; |
|
2836 } |
|
2837 |
|
2838 currNative = currNative->ai_next; |
|
2839 } |
|
2840 |
|
2841 if(hints->ai_family == PF_INET && !sentinel.ai_next && haveV4Mapped) |
|
2842 { |
|
2843 currNative = resNative; |
|
2844 while(currNative) |
|
2845 { |
|
2846 //This is the set of Mapped Addresses. |
|
2847 if(currNative->ai_flags & AI_V4MAPPED) |
|
2848 { |
|
2849 struct sockaddr_in* sAddrTmp = (struct sockaddr_in*) (currNative->ai_addr); |
|
2850 currNative->ai_flags &= ~AI_V4MAPPED; |
|
2851 GET_AI(cur->ai_next, afd, (char*)&(sAddrTmp->sin_addr)); |
|
2852 cur->ai_next->ai_addr->sa_family = cur->ai_next->ai_family = PF_INET; |
|
2853 GET_PORT(cur->ai_next, servname); |
|
2854 |
|
2855 if((pai->ai_flags & AI_CANONNAME)) |
|
2856 GET_CANONNAME(cur->ai_next, currNative->ai_canonname); |
|
2857 cur = cur->ai_next; |
|
2858 } |
|
2859 |
|
2860 currNative = currNative->ai_next; |
|
2861 } |
|
2862 } |
|
2863 /* free the address list returned by native api */ |
|
2864 freeaddrinfo_private(resNative); |
|
2865 } |
|
2866 else |
|
2867 ERR(EAI_FAMILY); |
|
2868 |
|
2869 *res = sentinel.ai_next; |
|
2870 return 0; |
|
2871 |
|
2872 free: |
|
2873 bad: |
|
2874 if (sentinel.ai_next) |
|
2875 freeaddrinfo(sentinel.ai_next); |
|
2876 return error; |
|
2877 } |
|
2878 |
|
2879 #endif//__SYMBIAN32__ |
|