VirtualBox

Changeset 43923 in vbox


Ignore:
Timestamp:
Nov 21, 2012 8:47:57 AM (12 years ago)
Author:
vboxsync
Message:

DrvVD: IPv6 and new LWIP introduction.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r43861 r43923  
    4141/* All lwip header files are not C++ safe. So hack around this. */
    4242RT_C_DECLS_BEGIN
     43#include <lwip/opt.h>
    4344#include <lwip/inet.h>
    4445#include <lwip/tcp.h>
    4546#include <lwip/sockets.h>
     47# ifdef VBOX_WITH_NEW_LWIP
     48#  include <lwip/inet6.h>
     49# endif
    4650RT_C_DECLS_END
    4751#endif /* VBOX_WITH_INIP */
     
    616620*******************************************************************************/
    617621
     622/**
     623 * vvl: this structure duplicate meaning of sockaddr,
     624 * perhaps it'd be better to get rid of it.
     625 */
    618626typedef union INIPSOCKADDRUNION
    619627{
    620628    struct sockaddr     Addr;
    621629    struct sockaddr_in  Ipv4;
     630#ifdef VBOX_WITH_NEW_LWIP
     631    struct sockaddr_in6 Ipv6;
     632#endif
    622633} INIPSOCKADDRUNION;
    623634
     
    666677    int rc = VINF_SUCCESS;
    667678    PINIPSOCKET pSocketInt = (PINIPSOCKET)Sock;
    668 
     679    int iInetFamily = PF_INET;
     680    struct in_addr ip;
     681#ifdef VBOX_WITH_NEW_LWIP
     682    ip6_addr_t ip6;
     683#endif
     684   
    669685    /* Check whether lwIP is set up in this VM instance. */
    670686    if (!DevINIPConfigured())
     
    675691    /* Resolve hostname. As there is no standard resolver for lwIP yet,
    676692     * just accept numeric IP addresses for now. */
    677     struct in_addr ip;
    678     if (!lwip_inet_aton(pszAddress, &ip))
     693#ifdef VBOX_WITH_NEW_LWIP
     694    if (inet6_aton(pszAddress, &ip6))
     695        iInetFamily = PF_INET6;
     696    else /* concatination with if */
     697#endif   
     698      if (!lwip_inet_aton(pszAddress, &ip))
    679699    {
    680700        LogRelFunc(("cannot resolve IP %s\n", pszAddress));
     
    682702    }
    683703    /* Create socket and connect. */
    684     int iSock = lwip_socket(PF_INET, SOCK_STREAM, 0);
     704    int iSock = lwip_socket(iInetFamily, SOCK_STREAM, 0);
    685705    if (iSock != -1)
    686706    {
    687         struct sockaddr_in InAddr = {0};
    688         InAddr.sin_family = AF_INET;
    689         InAddr.sin_port = htons(uPort);
    690         InAddr.sin_addr = ip;
    691         if (!lwip_connect(iSock, (struct sockaddr *)&InAddr, sizeof(InAddr)))
     707        struct sockaddr *pSockAddr = NULL;
     708        if (iInetFamily == PF_INET)
     709        {
     710            struct sockaddr_in InAddr = {0};
     711            InAddr.sin_family = AF_INET;
     712            InAddr.sin_port = htons(uPort);
     713            InAddr.sin_addr = ip;
     714            InAddr.sin_len = sizeof(InAddr);
     715            pSockAddr = (struct sockaddr *)&InAddr;
     716        }
     717#ifdef VBOX_WITH_NEW_LWIP
     718        else
     719        {
     720            struct sockaddr_in6 In6Addr = {0};
     721            In6Addr.sin6_family = AF_INET6;
     722            In6Addr.sin6_port = htons(uPort);
     723            memcpy(&In6Addr.sin6_addr, &ip6, sizeof(ip6));
     724            In6Addr.sin6_len = sizeof(In6Addr);
     725            pSockAddr = (struct sockaddr *)&In6Addr;
     726        }
     727#endif
     728        if (   pSockAddr
     729            && !lwip_connect(iSock, pSockAddr, pSockAddr->sa_len))
    692730        {
    693731            pSocketInt->hSock = iSock;
     
    883921            pAddr->uAddr.IPv4.u = u.Ipv4.sin_addr.s_addr;
    884922        }
    885         else
     923#ifdef VBOX_WITH_NEW_LWIP
     924        else if (   cbAddr == sizeof(struct sockaddr_in6)
     925            && u.Addr.sa_family == AF_INET6)
     926        {
     927            RT_ZERO(*pAddr);
     928            pAddr->enmType      = RTNETADDRTYPE_IPV6;
     929            pAddr->uPort        = RT_N2H_U16(u.Ipv6.sin6_port);
     930            memcpy(&pAddr->uAddr.IPv6, &u.Ipv6.sin6_addr, sizeof(RTNETADDRIPV6));
     931        }
     932#endif
     933        else
    886934            return VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED;
    887935        return VINF_SUCCESS;
     
    910958            pAddr->uAddr.IPv4.u = u.Ipv4.sin_addr.s_addr;
    911959        }
     960#ifdef VBOX_WITH_NEW_LWIP
     961        else if (   cbAddr == sizeof(struct sockaddr_in6)
     962                 && u.Addr.sa_family == AF_INET6)
     963        {
     964            RT_ZERO(*pAddr);
     965            pAddr->enmType      = RTNETADDRTYPE_IPV6;
     966            pAddr->uPort        = RT_N2H_U16(u.Ipv6.sin6_port);
     967            memcpy(&pAddr->uAddr.IPv6, &u.Ipv6.sin6_addr, sizeof(RTNETADDRIPV6));
     968        }
     969#endif
    912970        else
    913971            return VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED;
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