VirtualBox

Changeset 57957 in vbox


Ignore:
Timestamp:
Sep 29, 2015 10:47:47 PM (9 years ago)
Author:
vboxsync
Message:

Runtime: Allow specifying the default destination address on the UDP client socket.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/udp.h

    r57955 r57957  
    154154 *
    155155 * @returns iprt status code.
    156  * @param   pszAddress      The address to connect to.
    157  * @param   uPort           The port to connect to.
    158  * @param   pSock           Where to store the handle to the established connection.
     156 * @param   pszAddress          The address to connect to.
     157 * @param   uPort               The port to connect to.
     158 * @param   pDefaultDstAddr     A default destination address for sending data
     159 *                              through this socket, can be NULL.
     160 * @param   pSock               Where to store the handle to the established connection.
    159161 */
    160 RTR3DECL(int) RTUdpCreateClientSocket(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock);
     162RTR3DECL(int) RTUdpCreateClientSocket(const char *pszAddress, uint32_t uPort, PRTNETADDR pDefaultDstAddr, PRTSOCKET pSock);
    161163
    162164/** @} */
  • trunk/src/VBox/Runtime/r3/udp.cpp

    r57955 r57957  
    688688
    689689
    690 RTR3DECL(int) RTUdpCreateClientSocket(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock)
     690RTR3DECL(int) RTUdpCreateClientSocket(const char *pszAddress, uint32_t uPort, PRTNETADDR pDefaultDstAddr, PRTSOCKET pSock)
    691691{
    692692    /*
     
    715715        if (RT_SUCCESS(rc))
    716716        {
    717             *pSock = Sock;
    718             return VINF_SUCCESS;
     717            if (pDefaultDstAddr)
     718                rc = rtSocketConnect(Sock, pDefaultDstAddr, 0);
     719            if (RT_SUCCESS(rc))
     720            {
     721                *pSock = Sock;
     722                return VINF_SUCCESS;
     723            }
    719724        }
    720725        RTSocketClose(Sock);
     
    722727    return rc;
    723728}
     729
  • trunk/src/VBox/Runtime/testcase/tstRTUdp-1.cpp

    r57956 r57957  
    9999    int rc;
    100100    RTSOCKET hSocket;
    101     RTTESTI_CHECK_RC(rc = RTUdpCreateClientSocket(RT_TEST_UDP_CLIENT_ADDRESS, RT_TEST_UDP_CLIENT_PORT, &hSocket),
     101    RTTESTI_CHECK_RC(rc = RTUdpCreateClientSocket(RT_TEST_UDP_CLIENT_ADDRESS, RT_TEST_UDP_CLIENT_PORT, &ServerAddress, &hSocket),
    102102                     VINF_SUCCESS);
    103103    if (RT_SUCCESS(rc))
     
    107107            char szBuf[512];
    108108            RT_ZERO(szBuf);
    109             RTTESTI_CHECK_RC_BREAK(RTSocketWriteTo(hSocket, "dude!\n", sizeof("dude!\n") - 1, &ServerAddress), VINF_SUCCESS);
     109            RTTESTI_CHECK_RC_BREAK(RTSocketWrite(hSocket, "dude!\n", sizeof("dude!\n") - 1), VINF_SUCCESS);
    110110
    111111            RTTESTI_CHECK_RC_BREAK(RTSocketRead(hSocket, szBuf, sizeof("hello\n") - 1, NULL), VINF_SUCCESS);
     
    113113            RTTESTI_CHECK_BREAK(strcmp(szBuf, "hello\n") == 0);
    114114
    115             RTTESTI_CHECK_RC_BREAK(RTSocketWriteTo(hSocket, "byebye\n", sizeof("byebye\n") - 1, &ServerAddress), VINF_SUCCESS);
     115            RTTESTI_CHECK_RC_BREAK(RTSocketWrite(hSocket, "byebye\n", sizeof("byebye\n") - 1), VINF_SUCCESS);
    116116            RT_ZERO(szBuf);
    117117            RTTESTI_CHECK_RC_BREAK(RTSocketRead(hSocket, szBuf, sizeof("buh bye\n") - 1, NULL), VINF_SUCCESS);
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