VirtualBox

Changeset 21663 in vbox


Ignore:
Timestamp:
Jul 17, 2009 5:03:48 AM (16 years ago)
Author:
vboxsync
Message:

NAT: better indentation

File:
1 edited

Legend:

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

    r21049 r21663  
    368368udp_attach(PNATState pData, struct socket *so, int service_port)
    369369{
    370     struct sockaddr_in addr;
     370    struct sockaddr_in *addr;
    371371    struct sockaddr sa_addr;
    372372    socklen_t socklen = sizeof(struct sockaddr);
    373373    int status;
    374 
    375     if ((so->s = socket(AF_INET, SOCK_DGRAM, 0)) != -1)
    376     {
    377         /*
    378          * Here, we bind() the socket.  Although not really needed
    379          * (sendto() on an unbound socket will bind it), it's done
    380          * here so that emulation of ytalk etc. don't have to do it
    381          */
    382         memset(&addr, 0, sizeof(addr));
     374    int opt = 1;
     375
     376    if ((so->s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
     377        goto error;
     378    /*
     379     * Here, we bind() the socket.  Although not really needed
     380     * (sendto() on an unbound socket will bind it), it's done
     381     * here so that emulation of ytalk etc. don't have to do it
     382     */
     383    memset(&sa_addr, 0, sizeof(struct sockaddr));
     384    addr = (struct sockaddr_in *)&sa_addr;
    383385#ifdef RT_OS_DARWIN
    384         addr.sin_len = sizeof(addr);
     386   addr->sin_len = sizeof(struct sockaddr_in);
    385387#endif
    386         addr.sin_family = AF_INET;
    387         addr.sin_port = service_port;
    388         addr.sin_addr.s_addr = pData->bindIP.s_addr;
    389         fd_nonblock(so->s);
    390         if (bind(so->s, (struct sockaddr *)&addr, sizeof(addr)) < 0)
    391         {
    392             int lasterrno = errno;
    393             closesocket(so->s);
    394             so->s = -1;
     388    addr->sin_family = AF_INET;
     389    addr->sin_port = service_port;
     390    addr->sin_addr.s_addr = pData->bindIP.s_addr;
     391    fd_nonblock(so->s);
     392    if (bind(so->s, &sa_addr, sizeof(struct sockaddr_in)) < 0)
     393    {
     394        int lasterrno = errno;
     395        closesocket(so->s);
     396        so->s = -1;
    395397#ifdef RT_OS_WINDOWS
    396             WSASetLastError(lasterrno);
     398        WSASetLastError(lasterrno);
    397399#else
    398             errno = lasterrno;
     400        errno = lasterrno;
    399401#endif
    400         }
    401         else
    402         {
    403             int opt = 1;
    404             /* success, insert in queue */
    405             so->so_expire = curtime + SO_EXPIRE;
    406             /* enable broadcast for later use */
    407             setsockopt(so->s, SOL_SOCKET, SO_BROADCAST, (const char *)&opt, sizeof(opt));
    408             status = getsockname(so->s, &sa_addr, &socklen);
    409             Assert(status == 0 && sa_addr.sa_family == AF_INET);
    410             so->so_hlport = ((struct sockaddr_in *)&sa_addr)->sin_port;
    411             so->so_hladdr.s_addr = ((struct sockaddr_in *)&sa_addr)->sin_addr.s_addr;
    412             SOCKET_LOCK_CREATE(so);
    413             QSOCKET_LOCK(udb);
    414             insque(pData, so, &udb);
    415             NSOCK_INC();
    416             QSOCKET_UNLOCK(udb);
    417         }
    418     }
    419     else
    420     {
    421         LogRel(("NAT: can't create datagramm socket\n"));
    422     }
     402        goto error;
     403    }
     404    /* success, insert in queue */
     405    so->so_expire = curtime + SO_EXPIRE;
     406    /* enable broadcast for later use */
     407    setsockopt(so->s, SOL_SOCKET, SO_BROADCAST, (const char *)&opt, sizeof(opt));
     408    status = getsockname(so->s, &sa_addr, &socklen);
     409    Assert(status == 0 && sa_addr.sa_family == AF_INET);
     410    so->so_hlport = ((struct sockaddr_in *)&sa_addr)->sin_port;
     411    so->so_hladdr.s_addr = ((struct sockaddr_in *)&sa_addr)->sin_addr.s_addr;
     412    SOCKET_LOCK_CREATE(so);
     413    QSOCKET_LOCK(udb);
     414    insque(pData, so, &udb);
     415    NSOCK_INC();
     416    QSOCKET_UNLOCK(udb);
    423417    return so->s;
     418error:
     419    LogRel(("NAT: can't create datagramm socket\n"));
     420    return -1;
    424421}
    425422
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