コード例 #1
0
ファイル: libslp_knownda.c プロジェクト: ncultra/openslp
/*-------------------------------------------------------------------------*/
void KnownDASaveHints()
/*-------------------------------------------------------------------------*/
{
  int         fd;
#ifdef WIN32
  fd = creat(SLPGetProperty("net.slp.HintsFile"),
             _S_IREAD | _S_IWRITE);
#else
  fd = creat(SLPGetProperty("net.slp.HintsFile"),
             S_IROTH | S_IWOTH | S_IRGRP| S_IWGRP | S_IRUSR | S_IWUSR);
#endif
  if (fd >= 0)
  {
    SLPDAEntryListWrite(fd, &G_KnownDAList);
    close(fd);
  }
 
}
コード例 #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);
    } 
}