コード例 #1
0
/*=========================================================================*/
SLPDSocket* SLPDOutgoingConnect(struct in_addr* addr)
/* Get a pointer to a connected socket that is associated with the         */
/* outgoing socket list.  If a connected socket already exists on the      */
/* outgoing list, a pointer to it is returned, otherwise a new connection  */
/* is made and added to the outgoing list                                  */
/*                                                                         */
/* addr (IN) the address of the peer a connection is desired for           */
/*                                                                         */
/* returns: pointer to socket or null on error                             */
/*=========================================================================*/
{
    SLPDSocket* sock = (SLPDSocket*)G_OutgoingSocketList.head;
    while ( sock )
    {
        if ( sock->state == STREAM_CONNECT_IDLE ||
             sock->state > SOCKET_PENDING_IO )
        {
            if ( sock->peeraddr.sin_addr.s_addr == addr->s_addr )
            {
                break;
            }
        }
        sock = (SLPDSocket*)sock->listitem.next;    
    }

    if ( sock == 0 )
    {
        sock = SLPDSocketCreateConnected(addr);
        SLPListLinkTail(&(G_OutgoingSocketList),(SLPListItem*)sock);
    }

    return sock;
}
コード例 #2
0
/*=========================================================================*/
void SLPDKnownDARegister(SLPDPeerInfo* peerinfo,
                         SLPMessage msg,
                         SLPBuffer buf)
/* Echo a message to a known DA                                            */
/*									   */
/* peerinfo (IN) the peer that the registration came from                   */    
/*                                                                         */ 
/* msg (IN) the translated message to echo                                 */
/*                                                                         */
/* buf (IN) the message buffer to echo                                     */
/*                                                                         */
/* Returns:  Zero on success, non-zero on error                            */
/*=========================================================================*/
{
    SLPDAEntry* daentry;
    SLPDSocket* sock;
    SLPBuffer   dup;

    daentry = (SLPDAEntry*)G_KnownDAList.head;
    while (daentry)
    {
        sock = (SLPDSocket*)G_OutgoingSocketList.head;
        while (sock)
        {
            if (sock->peerinfo.peeraddr.sin_addr.s_addr == daentry->daaddr.s_addr)
            {
                break;
            }
            sock = (SLPDSocket*)sock->listitem.next;
        }

        if (sock == 0)
        {
            /* Create a new socket to the known DA */
            sock = SLPDSocketCreateConnected(&(daentry->daaddr));
            if (sock)
            {
                sock->daentry = daentry;
                SLPListLinkTail(&G_OutgoingSocketList,(SLPListItem*)sock);
            }
        }

        /* Load the socket with the message to send */
        dup = SLPBufferDup(buf);
        if (dup)
        {
            if (sock->state == STREAM_CONNECT_IDLE)
            {
                sock->state = STREAM_WRITE_FIRST;
            }
            SLPListLinkTail(&(sock->sendlist),(SLPListItem*)dup);
        }
        daentry = (SLPDAEntry*)daentry->listitem.next;
    }
}
コード例 #3
0
ファイル: slpd_outgoing.c プロジェクト: Distrotech/openslp
/** Connect for outbound traffic to a specified remote address.
 *
 * @param[in] is_TCP - if non-0, this is a tcp connection to the remote device
 * @param[in] addr - The address to be connected to.
 *
 * @remarks Get a pointer to a connected socket that is associated with
 * the outgoing socket list. If a connected socket already exists on the
 * outgoing list, a pointer to it is returned, otherwise a new connection
 * is made and added to the outgoing list
 *
 * @return A pointer to socket, or null on error.
 */
SLPDSocket * SLPDOutgoingConnect(int is_TCP, struct sockaddr_storage * addr)
{
   SLPDSocket * sock = 0;
   
   if(is_TCP)
   {
      sock = (SLPDSocket *) G_OutgoingSocketList.head;
      while (sock)
      {
        if (sock->state == STREAM_CONNECT_IDLE
            || sock->state > STREAM_CONNECT_CLOSE)
        {
           if (SLPNetCompareAddrs(&(sock->peeraddr), addr) == 0)
              break;
        }
        sock = (SLPDSocket *) sock->listitem.next;
      }

      if (sock == 0)
      {
         sock = SLPDSocketCreateConnected(addr);
         if (sock)
            SLPListLinkTail(&(G_OutgoingSocketList), (SLPListItem *) sock);
      }
   }
   else
   {
      sock = SLPDSocketCreateDatagram(addr, DATAGRAM_UNICAST);
      if (sock)
      {
         SLPListLinkTail(&(G_OutgoingSocketList), (SLPListItem *) sock);
         sock->reconns = 0;
         sock->age = 0;
      }
   }

   return sock;
}
コード例 #4
0
/*=========================================================================*/
void SLPDKnownDARegister(SLPDDatabaseEntry* dbhead, SLPDSocketList* sockets)
/*                                                                         */
/* Modify the specified socket list to register all entries of the         */
/* specified database list with all known DAs                              */
/*                                                                         */
/* Returns:  Zero on success, non-zero on error                            */
/*=========================================================================*/
{
    SLPDDatabaseEntry*  dbentry;
    SLPDSocket*         sockentry;
    SLPDAEntry*         daentry;

    
    if(dbhead)
    {
        daentry = G_KnownDAListHead;
        while(daentry)
        {
            /* check to see if a socket is already connected to this DA */
            sockentry = sockets->head;
            while(sockentry)
            {
                if(sockentry->peerinfo.peertype == SLPD_PEER_CONNECTED)
                {
                    if (memcmp(&sockentry->peerinfo.peeraddr.sin_addr,
                               &daentry->daaddr,
                               sizeof(daentry->daaddr)) == 0)
                    {
                        break;
                    }
                }
                sockentry = (SLPDSocket*)sockentry->listitem.next;                                                            
            }

            if(sockentry == 0)
            {
                /* Could not find a connected socket */
                /* Create a connected socket         */
                sockentry = SLPDSocketCreateConnected(&daentry->daaddr);
                if(sockentry == 0)
                {
                    /* Could not create connected socket */
                    
                    /* TODO: should we log here?         */

                    /* Remove the  known DA entry we could not connect to */
                    daentry = SLPDKnownDARemove(daentry);
                }
                else
                {
                    SLPDSocketListAdd(sockets, sockentry);   
                }
                                                             
            }

            if(sockentry != 0)
            {
                /* Load the send buffer with reg stuff */
                dbentry = dbhead;
                while(dbentry)
                {
                    
                    /* TODO: put a whole bunch of registration stuff here */

                    dbentry = (SLPDDatabaseEntry*)dbentry->listitem.next;
                }
            }
            
            daentry = (SLPDAEntry*)daentry->listitem.next;
        } 
    }
}