AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/demo/handler/dlenv.c
int dlenv_register_as_foreign_device(
    void)
{
    int retval = 0;
#if defined(BACDL_BIP)
    char *pEnv = NULL;

    pEnv = getenv("BACNET_BBMD_PORT");
    if (pEnv) {
        bbmd_port = strtol(pEnv, NULL, 0);
        if (bbmd_port > 0xFFFF) {
            bbmd_port = 0xBAC0;
        }
    }
    pEnv = getenv("BACNET_BBMD_TIMETOLIVE");
    if (pEnv) {
        bbmd_timetolive_seconds = strtol(pEnv, NULL, 0);
        if (bbmd_timetolive_seconds > 0xFFFF) {
            bbmd_timetolive_seconds = 0xFFFF;
        }
    }
    pEnv = getenv("BACNET_BBMD_ADDRESS");
    if (pEnv) {
        bbmd_address = bip_getaddrbyname(pEnv);
    }
    if (bbmd_address) {
        struct in_addr addr;
        addr.s_addr = bbmd_address;
        fprintf(stderr, "Registering with BBMD at %s:%ld for %ld seconds\n",
            inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
        retval =
            bvlc_register_with_bbmd(bbmd_address, htons((uint16_t) bbmd_port),
            (uint16_t) bbmd_timetolive_seconds);
        if (retval < 0)
            fprintf(stderr, "FAILED to Register with BBMD at %s \n",
                inet_ntoa(addr));
        BBMD_Timer_Seconds = (uint16_t) bbmd_timetolive_seconds;
    }

    bbmd_result = retval;
#endif
    return retval;
}
/** Register as a Foreign Device with the designated BBMD.
 * @ingroup DataLink
 * The BBMD's address, port, and lease time must be provided by
 * internal variables or Environment variables.
 * If no address for the BBMD is provided, no BBMD registration will occur.
 *
 * The Environment Variables depend on define of BACDL_BIP:
 *     - BACNET_BBMD_PORT - 0..65534, defaults to 47808
 *     - BACNET_BBMD_TIMETOLIVE - 0..65535 seconds, defaults to 60000
 *     - BACNET_BBMD_ADDRESS - dotted IPv4 address
 * @return Positive number (of bytes sent) on success,
 *         0 if no registration request is sent, or
 *         -1 if registration fails.
 */
Register as a Foreign Device with the designated BBMD.
@ingroup DataLink
The BBMD's address, port, and lease time must be provided by
internal variables or Environment variables.
If no address for the BBMD is provided, no BBMD registration will occur.


Register as a Foreign Device with the designated BBMD . @ingroup DataLink The BBMD ' s address port and lease time must be provided by internal variables or Environment variables . If no address for the BBMD is provided no BBMD registration will occur .
int dlenv_register_as_foreign_device(
    void)
{
    int retval = 0;
#if defined(BACDL_BIP)
    char *pEnv = NULL;
    pEnv = getenv("BACNET_BBMD_PORT");
    if (pEnv) {
        bbmd_port = strtol(pEnv, NULL, 0);
        if (bbmd_port > 0xFFFF) {
            bbmd_port = 0xBAC0;
        }
    }
    pEnv = getenv("BACNET_BBMD_TIMETOLIVE");
    if (pEnv) {
        bbmd_timetolive_seconds = strtol(pEnv, NULL, 0);
        if (bbmd_timetolive_seconds > 0xFFFF) {
            bbmd_timetolive_seconds = 0xFFFF;
        }
    }
    pEnv = getenv("BACNET_BBMD_ADDRESS");
    if (pEnv) {
        bbmd_address = bip_getaddrbyname(pEnv);
    }
    if (bbmd_address) {
        struct in_addr addr;
        addr.s_addr = bbmd_address;
        fprintf(stderr, "Registering with BBMD at %s:%ld for %ld seconds\n",
            inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
        retval =
            bvlc_register_with_bbmd(bbmd_address, htons((uint16_t) bbmd_port),
            (uint16_t) bbmd_timetolive_seconds);
        if (retval < 0)
            fprintf(stderr, "FAILED to Register with BBMD at %s \n",
                inet_ntoa(addr));
        BBMD_Timer_Seconds = (uint16_t) bbmd_timetolive_seconds;
    }
    bbmd_result = retval;
#endif
    return retval;
}
int dlenv_register_as_foreign_device ( void ) { int retval = 0 ; #if defined ( BACDL_BIP ) char * pEnv = NULL ; pEnv = getenv ( " " ) ; if ( pEnv ) { bbmd_port = strtol ( pEnv , NULL , 0 ) ; if ( bbmd_port > 0xFFFF ) { bbmd_port = 0xBAC0 ; } } pEnv = getenv ( " " ) ; if ( pEnv ) { bbmd_timetolive_seconds = strtol ( pEnv , NULL , 0 ) ; if ( bbmd_timetolive_seconds > 0xFFFF ) { bbmd_timetolive_seconds = 0xFFFF ; } } pEnv = getenv ( " " ) ; if ( pEnv ) { bbmd_address = bip_getaddrbyname ( pEnv ) ; } if ( bbmd_address ) { struct in_addr addr ; addr . s_addr = bbmd_address ; fprintf ( stderr , " \n " , inet_ntoa ( addr ) , bbmd_port , bbmd_timetolive_seconds ) ; retval = bvlc_register_with_bbmd ( bbmd_address , htons ( ( uint16_t ) bbmd_port ) , ( uint16_t ) bbmd_timetolive_seconds ) ; if ( retval < 0 ) fprintf ( stderr , " \n " , inet_ntoa ( addr ) ) ; BBMD_Timer_Seconds = ( uint16_t ) bbmd_timetolive_seconds ; } bbmd_result = retval ; #endif return retval ; }
Register as a Foreign Device with the designated BBMD.
Register as a Foreign Device with the designated BBMD .