openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rsyslog/8.1903.0-r0/rsyslog-8.1903.0/runtime/nsd_ptcp.c
static rsRetVal Connect(nsd_t* pNsd, int family, uchar* port, uchar* host,
                        char* device)
{
    nsd_ptcp_t* pThis = (nsd_ptcp_t*)pNsd;
    struct addrinfo* res = NULL;
    struct addrinfo hints;

    DEFiRet;
    ISOBJ_TYPE_assert(pThis, nsd_ptcp);
    assert(port != NULL);
    assert(host != NULL);
    assert(pThis->sock == -1);

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = family;
    hints.ai_socktype = SOCK_STREAM;
    if (getaddrinfo((char*)host, (char*)port, &hints, &res) != 0)
    {
        LogError(errno, RS_RET_IO_ERROR, "cannot resolve hostname '%s'", host);
        ABORT_FINALIZE(RS_RET_IO_ERROR);
    }

    if ((pThis->sock =
             socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1)
    {
        LogError(errno, RS_RET_IO_ERROR, "cannot bind socket for %s:%s", host,
                 port);
        ABORT_FINALIZE(RS_RET_IO_ERROR);
    }

    if (device)
    {
#if defined(SO_BINDTODEVICE)
        if (setsockopt(pThis->sock, SOL_SOCKET, SO_BINDTODEVICE, device,
                       strlen(device) + 1) < 0)
#endif
        {
            dbgprintf("setsockopt(SO_BINDTODEVICE) failed\n");
            ABORT_FINALIZE(RS_RET_IO_ERROR);
        }
    }

    if (connect(pThis->sock, res->ai_addr, res->ai_addrlen) != 0)
    {
        LogError(errno, RS_RET_IO_ERROR, "cannot connect to %s:%s", host, port);
        ABORT_FINALIZE(RS_RET_IO_ERROR);
    }

finalize_it:
    if (res != NULL)
        freeaddrinfo(res);

    if (iRet != RS_RET_OK)
    {
        sockClose(&pThis->sock);
    }

    RETiRet;
}
/* open a connection to a remote host (server).
 * rgerhards, 2008-03-19
 */
open a connection to a remote host (server).
open a connection to a remote host ( server ) .
static rsRetVal Connect(nsd_t* pNsd, int family, uchar* port, uchar* host,
                        char* device)
{
    nsd_ptcp_t* pThis = (nsd_ptcp_t*)pNsd;
    struct addrinfo* res = NULL;
    struct addrinfo hints;
    DEFiRet;
    ISOBJ_TYPE_assert(pThis, nsd_ptcp);
    assert(port != NULL);
    assert(host != NULL);
    assert(pThis->sock == -1);
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = family;
    hints.ai_socktype = SOCK_STREAM;
    if (getaddrinfo((char*)host, (char*)port, &hints, &res) != 0)
    {
        LogError(errno, RS_RET_IO_ERROR, "cannot resolve hostname '%s'", host);
        ABORT_FINALIZE(RS_RET_IO_ERROR);
    }
    if ((pThis->sock =
             socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1)
    {
        LogError(errno, RS_RET_IO_ERROR, "cannot bind socket for %s:%s", host,
                 port);
        ABORT_FINALIZE(RS_RET_IO_ERROR);
    }
    if (device)
    {
#if defined(SO_BINDTODEVICE)
        if (setsockopt(pThis->sock, SOL_SOCKET, SO_BINDTODEVICE, device,
                       strlen(device) + 1) < 0)
#endif
        {
            dbgprintf("setsockopt(SO_BINDTODEVICE) failed\n");
            ABORT_FINALIZE(RS_RET_IO_ERROR);
        }
    }
    if (connect(pThis->sock, res->ai_addr, res->ai_addrlen) != 0)
    {
        LogError(errno, RS_RET_IO_ERROR, "cannot connect to %s:%s", host, port);
        ABORT_FINALIZE(RS_RET_IO_ERROR);
    }
finalize_it:
    if (res != NULL)
        freeaddrinfo(res);
    if (iRet != RS_RET_OK)
    {
        sockClose(&pThis->sock);
    }
    RETiRet;
}
static rsRetVal Connect ( nsd_t * pNsd , int family , uchar * port , uchar * host , char * device ) { nsd_ptcp_t * pThis = ( nsd_ptcp_t * ) pNsd ; struct addrinfo * res = NULL ; struct addrinfo hints ; DEFiRet ; ISOBJ_TYPE_assert ( pThis , nsd_ptcp ) ; assert ( port != NULL ) ; assert ( host != NULL ) ; assert ( pThis -> sock == -1 ) ; memset ( & hints , 0 , sizeof ( hints ) ) ; hints . ai_family = family ; hints . ai_socktype = SOCK_STREAM ; if ( getaddrinfo ( ( char * ) host , ( char * ) port , & hints , & res ) != 0 ) { LogError ( errno , RS_RET_IO_ERROR , " " , host ) ; ABORT_FINALIZE ( RS_RET_IO_ERROR ) ; } if ( ( pThis -> sock = socket ( res -> ai_family , res -> ai_socktype , res -> ai_protocol ) ) == -1 ) { LogError ( errno , RS_RET_IO_ERROR , " " , host , port ) ; ABORT_FINALIZE ( RS_RET_IO_ERROR ) ; } if ( device ) { #if defined ( SO_BINDTODEVICE ) if ( setsockopt ( pThis -> sock , SOL_SOCKET , SO_BINDTODEVICE , device , strlen ( device ) + 1 ) < 0 ) #endif { dbgprintf ( " \n " ) ; ABORT_FINALIZE ( RS_RET_IO_ERROR ) ; } } if ( connect ( pThis -> sock , res -> ai_addr , res -> ai_addrlen ) != 0 ) { LogError ( errno , RS_RET_IO_ERROR , " " , host , port ) ; ABORT_FINALIZE ( RS_RET_IO_ERROR ) ; } finalize_it : if ( res != NULL ) freeaddrinfo ( res ) ; if ( iRet != RS_RET_OK ) { sockClose ( & pThis -> sock ) ; } RETiRet ; }
open a connection to a remote host (server).
open a connection to a remote host ( server ) .