예제 #1
0
/*=========================================================================*/
int KnownDADiscover(struct timeval* timeout)
/* Returns: the number of DAs discovered                                   */
/*=========================================================================*/
{
    int         fd;
    int         result      = 0;

    /* TODO THIS FUNCTION MUST BE SYNCRONIZED !! */
    /* two threads must not be in here at the same time */
    
    /*----------------------------------------------------*/
    /* Check values from the net.slp.DAAddresses property */
    /*----------------------------------------------------*/
    result = KnownDADiscoveryByProperties(timeout);
    if (result)
    {
        KnownDASaveHints();
        return result;
    }
    

    /*------------------------------*/
    /* Check data from DHCP Options */
    /*------------------------------*/
    /* TODO put code here when you can */


    /*-----------------------------------*/
    /* Load G_KnownDAListhead from hints */
    /*-----------------------------------*/
    fd = open(SLPGetProperty("net.slp.HintsFile"),O_RDONLY);
    if (fd >= 0)
    {
        SLPDAEntryListRead(fd, &G_KnownDAList);
        close(fd);
        if (G_KnownDAList.count)
        {
            return G_KnownDAList.count;
        }
    }
    

    /*-------------------*/
    /* Multicast for DAs */
    /*-------------------*/
    if (SLPPropertyAsBoolean(SLPGetProperty("net.slp.activeDADetection")) &&
        SLPPropertyAsInteger(SLPGetProperty("net.slp.DAActiveDiscoveryInterval")))
    {
        result = KnownDADiscoveryByMulticast();
        if (result)
        {
            KnownDASaveHints();
            return result;
        }
    }
    
    return 0;
}
예제 #2
0
/*=========================================================================*/
void KnownDADiscover(struct timeval* timeout) 
/*=========================================================================*/
{
    int         fd;
    struct stat hintstat;
    const char* hintfile = SLPGetProperty("net.slp.HintsFile");

    
    /* TODO THIS FUNCTION MUST BE SYNCRONIZED !! */
    
    /*-------------------------------------------*/
    /* Check hints file to and load it if it     */
    /*-------------------------------------------*/
    if(stat(hintfile,&hintstat) == 0)
    {
        if(hintstat.st_mtime != G_HintStat.st_mtime)
        {
            fd = open(hintfile,O_RDONLY);
            if(fd >= 0)
            {
                SLPDAEntryListRead(fd, &G_KnownDAListHead);
                close(fd);
            }
        }
    }
    
    /* if (hints file changed)                   */
    /* {                                         */
    /*     if(load hints file)                   */
    /*     {                                     */
    /*         return;                           */
    /*     }                                     */
    /* }                                         */

    /* The logic of the following if(G_KnownDAListHead) statements is an   */
    /* attempt to reduce wasted time and network bandwidth due to unneeded */
    /* communication with DAs and multicast                                */
    
    if(G_KnownDAListHead == 0)
    {
        /*----------------------------------------------------*/
        /* Check values from the net.slp.DAAddresses property */
        /*----------------------------------------------------*/
        KnownDADiscoveryByProperties(timeout);
        
        /*------------------------------*/
        /* Check data from DHCP Options */
        /*------------------------------*/ 

        if(G_KnownDAListHead)
        {
            return;
        }
    }
    
    
    /*-------------*/
    /* IPC to slpd */
    /*-------------*/


    /*-------------------*/
    /* Multicast for DAs */
    /*-------------------*/ 
    if(SLPPropertyAsBoolean(SLPGetProperty("net.slp.activeDADetection")) &&
       SLPPropertyAsInteger(SLPGetProperty("net.slp.DAActiveDiscoveryInterval")))
    {
        KnownDADiscoveryByMulticast();
    }
    

    /*---------------------*/
    /* Save the hints file */
    /*---------------------*/
    fd = open(hintfile,
              O_RDONLY | O_CREAT,
              S_IROTH | S_IWOTH | S_IRGRP| S_IWGRP | S_IRUSR, S_IWUSR);
    if(fd >= 0)
    {
        SLPDAEntryListWrite(fd, &G_KnownDAListHead);
        close(fd);
        stat(hintfile,&G_HintStat);
    } 
}