VirtualBox

Changeset 57955 in vbox


Ignore:
Timestamp:
Sep 29, 2015 10:26:31 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
102934
Message:

IPRT: Add RTUdpCreateClientSocket.

Location:
trunk
Files:
3 edited

Legend:

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

    r57835 r57955  
    18511851# define RTTraceGetDefaultBuf                           RT_MANGLER(RTTraceGetDefaultBuf)
    18521852# define RTTraceSetDefaultBuf                           RT_MANGLER(RTTraceSetDefaultBuf)
     1853# define RTUdpCreateClientSocket                        RT_MANGLER(RTUdpCreateClientSocket)
    18531854# define RTUdpRead                                      RT_MANGLER(RTUdpRead)
    18541855# define RTUdpServerCreate                              RT_MANGLER(RTUdpServerCreate)
  • trunk/include/iprt/udp.h

    r57944 r57955  
    150150                          size_t cbBuffer, PCRTNETADDR pDstAddr);
    151151
     152/**
     153 * Create and connect a data socket.
     154 *
     155 * @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.
     159 */
     160RTR3DECL(int) RTUdpCreateClientSocket(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock);
     161
    152162/** @} */
    153163RT_C_DECLS_END
  • trunk/src/VBox/Runtime/r3/udp.cpp

    r57944 r57955  
    687687}
    688688
     689
     690RTR3DECL(int) RTUdpCreateClientSocket(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock)
     691{
     692    /*
     693     * Validate input.
     694     */
     695    AssertReturn(uPort > 0, VERR_INVALID_PARAMETER);
     696    AssertPtrReturn(pszAddress, VERR_INVALID_POINTER);
     697
     698    /*
     699     * Resolve the address.
     700     */
     701    RTNETADDR Addr;
     702    int rc = RTSocketParseInetAddress(pszAddress, uPort, &Addr);
     703    if (RT_FAILURE(rc))
     704        return rc;
     705
     706    /*
     707     * Create the socket and connect.
     708     */
     709    RTSOCKET Sock;
     710    rc = rtSocketCreate(&Sock, AF_INET, SOCK_DGRAM, 0);
     711    if (RT_SUCCESS(rc))
     712    {
     713        RTSocketSetInheritance(Sock, false /* fInheritable */);
     714        rc = rtSocketBind(Sock, &Addr);
     715        if (RT_SUCCESS(rc))
     716        {
     717            *pSock = Sock;
     718            return VINF_SUCCESS;
     719        }
     720        RTSocketClose(Sock);
     721    }
     722    return rc;
     723}
Note: See TracChangeset for help on using the changeset viewer.

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