Example #1
0
/*=========================================================================*/
int KnownDAConnect(int scopelistlen,
                   const char* scopelist,
                   struct sockaddr_in* peeraddr)
/* Get a connected socket to a DA that supports the specified scope        */
/*                                                                         */
/* scopelistlen (IN) stringlen of the scopelist                            */
/*                                                                         */
/* scopelist (IN) DA must support this scope                               */
/*                                                                         */
/* peeraddr (OUT) the peer that was connected to                           */
/*                                                                         */
/*                                                                         */
/* returns: valid socket file descriptor or -1 if no DA is found           */
/*=========================================================================*/
{
    struct timeval  timeout;
    SLPDAEntry*     daentry;
    int             sock = -1;

    /* Set up connect timeout */
    timeout.tv_sec = SLPPropertyAsInteger(SLPGetProperty("net.slp.DADiscoveryMaximumWait"));
    timeout.tv_usec = (timeout.tv_sec % 1000) * 1000;
    timeout.tv_sec = timeout.tv_sec / 1000;

    while(1)
    {
        daentry = KnownDAFromCache(scopelistlen,scopelist);
        if(daentry == 0)
        {
            break;
        }

        memset(peeraddr,0,sizeof(peeraddr));
        peeraddr->sin_family = AF_INET;
        peeraddr->sin_port = htons(SLP_RESERVED_PORT);
        peeraddr->sin_addr   = daentry->daaddr;

        sock = SLPNetworkConnectStream(peeraddr,&timeout);
        if(sock >= 0)
        {
            break;
        }

        KnownDAListRemove(&G_KnownDACache,daentry);
    }

    return sock;
}
Example #2
0
/*=========================================================================*/
int KnownDAConnect(PSLPHandleInfo handle,
                   int scopelistlen,
                   const char* scopelist,
                   struct sockaddr_in* peeraddr)
/* Get a connected socket to a DA that supports the specified scope        */
/*                                                                         */
/* scopelistlen (IN) stringlen of the scopelist                            */
/*                                                                         */
/* scopelist (IN) DA must support this scope                               */
/*                                                                         */
/* peeraddr (OUT) the peer that was connected to                           */
/*                                                                         */
/*                                                                         */
/* returns: valid socket file descriptor or -1 if no DA is found           */
/*=========================================================================*/
{
    struct timeval  timeout;
    int             sock = -1;
    int                 spistrlen   = 0;
    char*               spistr      = 0;
#ifdef ENABLE_SLPv2_SECURITY
    if(SLPPropertyAsBoolean(SLPGetProperty("net.slp.securityEnabled")))
    {
        SLPSpiGetDefaultSPI(handle->hspi,
                            SLPSPI_KEY_TYPE_PUBLIC,
                            &spistrlen,
                            &spistr);
    }
#endif

    /* Set up connect timeout */
    timeout.tv_sec = SLPPropertyAsInteger(SLPGetProperty("net.slp.DADiscoveryMaximumWait"));
    timeout.tv_usec = (timeout.tv_sec % 1000) * 1000;
    timeout.tv_sec = timeout.tv_sec / 1000;

    while(1)
    {
        memset(peeraddr,0,sizeof(peeraddr));
        
        if(KnownDAFromCache(scopelistlen,
                            scopelist,
                            spistrlen,
                            spistr,
                            &(peeraddr->sin_addr)) == 0)
        {
            break;
        }
        peeraddr->sin_family = PF_INET;
        peeraddr->sin_port = htons(SLP_RESERVED_PORT);
        
        sock = SLPNetworkConnectStream(peeraddr,&timeout);
        if(sock >= 0)
        {
            break;
        }

        KnownDABadDA(&(peeraddr->sin_addr));
    }


#ifdef ENABLE_SLPv2_SECURITY
    if(spistr) xfree(spistr);
#endif

    return sock;
}