VirtualBox

Changeset 17222 in vbox


Ignore:
Timestamp:
Mar 2, 2009 5:06:30 AM (16 years ago)
Author:
vboxsync
Message:

NAT: Multi DNS takes DNS servers IP addresses only from UP interfaces

Location:
trunk/src/VBox/Devices/Network/slirp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/ip_icmp.c

    r17191 r17222  
    110110        pData->pfIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))
    111111                                    GetProcAddress(pData->hmIcmpLibrary, "IcmpCloseHandle");
    112     }
     112# ifdef VBOX_WITH_MULTI_DNS
     113        pData->pfGetAdaptersAddresses = (ULONG (WINAPI *)(HANDLE))
     114                                    GetProcAddress(pData->hmIcmpLibrary, "GetAdaptersAddresses");
     115        if (pData->pfGetAdaptersAddresses == NULL)
     116        {
     117            LogRel(("NAT: Can't find GetAdapterAddresses in Iphlpapi.dll"));
     118        }
     119# endif
     120    }
     121
    113122    if (pData->pfIcmpParseReplies == NULL)
    114123    {
     124# ifdef VBOX_WITH_MULTI_DNS
     125        if(pData->pfGetAdaptersAddresses == NULL)
     126            FreeLibrary(pData->hmIcmpLibrary);
     127# else
    115128        FreeLibrary(pData->hmIcmpLibrary);
     129# endif
    116130        pData->hmIcmpLibrary = LoadLibrary("Icmp.dll");
    117131        if (pData->hmIcmpLibrary == NULL)
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r17191 r17222  
    88#include <iprt/assert.h>
    99#ifndef RT_OS_WINDOWS
    10 #include <sys/ioctl.h>
    11 #include <poll.h>
     10# include <sys/ioctl.h>
     11# include <poll.h>
     12#else
     13# define _WINSOCK2API_
     14# include <IPHlpApi.h>
    1215#endif
    1316
     
    225228
    226229#ifdef RT_OS_WINDOWS
    227 
     230# ifndef VBOX_WITH_MULTI_DNS
    228231static int get_dns_addr_domain(PNATState pData, bool fVerbose,
    229232                               struct in_addr *pdns_addr,
     
    265268    }
    266269
    267 #ifndef VBOX_WITH_MULTI_DNS
    268270    pIPAddr = &(FixedInfo->DnsServerList);
    269271    inet_aton(pIPAddr->IpAddress.String, &tmp_addr);
     
    280282        pIPAddr = pIPAddr ->Next;
    281283    }
    282 #else
    283     /*localhost mask */
    284     for (pIPAddr = &FixedInfo->DnsServerList; pIPAddr != NULL; pIPAddr = pIPAddr->Next)
    285     {
    286         struct dns_entry *da;
    287         if(!inet_aton(pIPAddr->IpAddress.String, &tmp_addr))
    288             continue;
    289         da = RTMemAllocZ(sizeof (struct dns_entry));
    290         if (da == NULL)
    291         {
    292             LogRel(("can't alloc memory for DNS entry\n"));
    293             return -1;
    294         }
    295         /*check */
    296         if ((da->de_addr.s_addr & htonl(IN_CLASSA_NET)) == ntohl(INADDR_LOOPBACK & IN_CLASSA_NET)) {
    297             da->de_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS);
    298         }
    299         LIST_INSERT_HEAD(&pData->dns_list_head, da, de_list);
    300     }
    301 #endif
    302284    if (FixedInfo)
    303285    {
     
    339321    return rc;
    340322}
    341 
    342 #else
     323# else /* !VBOX_WITH_MULTI_DNS */
     324static int get_dns_addr_domain(PNATState pData, bool fVerbose,
     325                               struct in_addr *pdns_addr,
     326                               const char **ppszDomain)
     327{
     328    OSVERSIONINFOEX osvi;
     329    DWORDLONG condition = 0;
     330    int op = VER_GREATER_EQUAL;
     331
     332    /* DNS information retriving is window's version specific,
     333     * so the OS version should be defined first
     334     */
     335    memset(&osvi, 0, sizeof(OSVERSIONINFOEX));
     336    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
     337    osvi.dwMajorVersion = 5; /* Win XP*/
     338    osvi.dwMinorVersion = 1;
     339   
     340    VER_SET_CONDITION(condition, VER_MAJORVERSION, op);
     341    VER_SET_CONDITION(condition, VER_MINORVERSION, op);
     342   
     343    if (VerifyVersionInfo(&osvi,
     344                VER_MAJORVERSION
     345            | VER_MINORVERSION,
     346             condition))
     347    {
     348        /* WinXP sp1 and latter */
     349        /* Get amount of memory required for operation */
     350        ULONG flags = GAA_FLAG_INCLUDE_PREFIX; /*GAA_FLAG_INCLUDE_ALL_INTERFACES;*/ /* all interfaces registered in NDIS */
     351        PIP_ADAPTER_ADDRESSES addresses = NULL;
     352        PIP_ADAPTER_ADDRESSES addr = NULL;
     353        PIP_ADAPTER_DNS_SERVER_ADDRESS dns = NULL;
     354        ULONG size = 0;
     355        char *suffix;
     356        struct dns_entry *da = NULL;
     357        ULONG ret = ERROR_SUCCESS;
     358       
     359        /* @todo add SKIPing flags to get only required information */
     360
     361        ret = pData->pfGetAdaptersAddresses(AF_INET, 0, NULL /* reserved */, addresses, &size);
     362        if (ret != ERROR_BUFFER_OVERFLOW)
     363        {
     364            LogRel(("NAT: error %lu occured on capacity detection operation\n", ret));
     365            return VERR_INVALID_PARAMETER; /* @todo: find better error code */
     366        }
     367       
     368        if (size == 0)
     369        {
     370            LogRel(("NAT: Win socket API returns non capacity\n"));
     371            return VERR_INVALID_PARAMETER; /* @todo: find better error code */
     372        }
     373       
     374        addresses = RTMemAllocZ(size);
     375        if (addresses == NULL)
     376        {
     377            LogRel(("NAT: No memory available \n"));
     378            return VERR_NO_MEMORY;
     379        }
     380
     381        ret = pData->pfGetAdaptersAddresses(AF_INET, 0, NULL /* reserved */, addresses, &size);
     382        if (ret != ERROR_SUCCESS)
     383        {
     384            LogRel(("NAT: error %lu occured on fetching adapters info\n", ret));
     385            return VERR_INVALID_PARAMETER; /* @todo: find better error code */
     386        }
     387        addr = addresses;
     388        while(addr != NULL)
     389        {
     390            size_t buff_size;
     391            if (addr->OperStatus != IfOperStatusUp)
     392                goto next;
     393            dns = addr->FirstDnsServerAddress;
     394            while (dns != NULL)
     395            {
     396                struct sockaddr *saddr = dns->Address.lpSockaddr;
     397                if (saddr->sa_family != AF_INET)
     398                    goto next_dns;
     399                /* add dns server to list */
     400                da = RTMemAllocZ(sizeof(struct dns_entry));
     401                if (da == NULL)
     402                {
     403                    LogRel(("NAT: Can't allocate buffer for DNS entry\n"));
     404                    return VERR_NO_MEMORY;
     405                }
     406                LogRel(("NAT: adding %R[IP4] to DNS server list\n", &((struct sockaddr_in *)saddr)->sin_addr));
     407                da->de_addr.s_addr = ((struct sockaddr_in *)saddr)->sin_addr.s_addr;
     408                LIST_INSERT_HEAD(&pData->dns_list_head, da, de_list);
     409            next_dns:   
     410                dns = dns->Next;
     411            }
     412            buff_size = wcstombs(NULL, addr->DnsSuffix, 0);
     413            if (buff_size == 0)
     414                goto next;
     415            suffix = RTMemAllocZ(buff_size);
     416            wcstombs(suffix, addr->DnsSuffix, buff_size);
     417            LogRel(("NAT: adding %s to DNS suffix list\n", suffix));
     418            *ppszDomain = suffix;
     419            next:
     420            addr = addr->Next;
     421        }
     422        /*@todo add dns suffix if required */
     423        LogRel(("NAT: adding dns suffix %s to the list \n", ppszDomain));
     424    }
     425    else
     426    {
     427        /* Win 2000 and earlier */
     428    }
     429    return VINF_SUCCESS;
     430}
     431# endif /* VBOX_WITH_MULTI_DNS */
     432
     433#else /* !RT_OS_WINDOWS */
    343434
    344435static int get_dns_addr_domain(PNATState pData, bool fVerbose,
     
    15691660    {
    15701661        case 500:
    1571             if (hsport == 500) service = 500;
     1662                /* service = sport; */
    15721663        break;
    15731664    }
  • trunk/src/VBox/Devices/Network/slirp/slirp_state.h

    r16946 r17222  
    107107    struct in_addr dns_addr;
    108108#else
     109# ifdef RT_OS_WINDOWS
     110    ULONG (WINAPI * pfGetAdaptersAddresses)(ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG);
     111# endif
    109112    struct dns_list_head dns_list_head;
    110113#endif
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette