AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/arduino_uno/bip-init.c
bool bip_init(char *ifname)
{
    uint8_t sock_fd = 0;
    bool isOpen = false;

    if (ifname)
        bip_set_interface(ifname);
    else
        bip_set_interface("eth0");

    /* assumes that the driver has already been initialized */
    for (sock_fd = 0; sock_fd < MAX_SOCK_NUM; sock_fd++) {
        if (readSnSR_func(CW5100Class_new(), sock_fd) == SnSR_CLOSED()) {
            socket_func(sock_fd, SnMR_UDP(), (uint16_t) 47808, 0);
            listen_func(sock_fd);
            isOpen = true;
            break;
        }
    }

    if (!isOpen) {
        bip_set_socket(MAX_SOCK_NUM);
        return false;
    } else {
        bip_set_socket(sock_fd);
    }

    return true;
}
/** Initialize the BACnet/IP services at the given interface.
 * @ingroup DLBIP
 * -# Gets the local IP address and local broadcast address from the system,
 *  and saves it into the BACnet/IP data structures.
 * -# Opens a UDP socket
 * -# Configures the socket for sending and receiving
 * -# Configures the socket so it can send broadcasts
 * -# Binds the socket to the local IP address at the specified port for
 *    BACnet/IP (by default, 0xBAC0 = 47808).
 *
 * @note For Linux, ifname is eth0, ath0, arc0, and others.
 *
 * @param ifname [in] The named interface to use for the network layer.
 *        If NULL, the "eth0" interface is assigned.
 * @return True if the socket is successfully opened for BACnet/IP,
 *         else False if the socket functions fail.
 */
Initialize the BACnet/IP services at the given interface.
@ingroup DLBIP
-# Gets the local IP address and local broadcast address from the system,
and saves it into the BACnet/IP data structures.
-# Opens a UDP socket
-# Configures the socket for sending and receiving
-# Configures the socket so it can send broadcasts
-# Binds the socket to the local IP address at the specified port for
BACnet/IP (by default, 0xBAC0 = 47808).

@note For Linux, ifname is eth0, ath0, arc0, and others.

@param ifname [in] The named interface to use for the network layer.
If NULL, the "eth0" interface is assigned.
@return True if the socket is successfully opened for BACnet/IP,
else False if the socket functions fail.
Initialize the BACnet / IP services at the given interface . @ingroup DLBIP - # Gets the local IP address and local broadcast address from the system and saves it into the BACnet / IP data structures . - # Opens a UDP socket - # Configures the socket for sending and receiving - # Configures the socket so it can send broadcasts - # Binds the socket to the local IP address at the specified port for BACnet / IP ( by default 0xBAC0 = 47808 ) . @note For Linux ifname is eth0 ath0 arc0 and others . @param ifname [ in ] The named interface to use for the network layer . If NULL the " eth0 " interface is assigned . @return True if the socket is successfully opened for BACnet / IP else False if the socket functions fail .
bool bip_init(char *ifname)
{
    uint8_t sock_fd = 0;
    bool isOpen = false;
    if (ifname)
        bip_set_interface(ifname);
    else
        bip_set_interface("eth0");
    for (sock_fd = 0; sock_fd < MAX_SOCK_NUM; sock_fd++) {
        if (readSnSR_func(CW5100Class_new(), sock_fd) == SnSR_CLOSED()) {
            socket_func(sock_fd, SnMR_UDP(), (uint16_t) 47808, 0);
            listen_func(sock_fd);
            isOpen = true;
            break;
        }
    }
    if (!isOpen) {
        bip_set_socket(MAX_SOCK_NUM);
        return false;
    } else {
        bip_set_socket(sock_fd);
    }
    return true;
}
bool bip_init ( char * ifname ) { uint8_t sock_fd = 0 ; bool isOpen = false ; if ( ifname ) bip_set_interface ( ifname ) ; else bip_set_interface ( " " ) ; for ( sock_fd = 0 ; sock_fd < MAX_SOCK_NUM ; sock_fd ++ ) { if ( readSnSR_func ( CW5100Class_new ( ) , sock_fd ) == SnSR_CLOSED ( ) ) { socket_func ( sock_fd , SnMR_UDP ( ) , ( uint16_t ) 47808 , 0 ) ; listen_func ( sock_fd ) ; isOpen = true ; break ; } } if ( ! isOpen ) { bip_set_socket ( MAX_SOCK_NUM ) ; return false ; } else { bip_set_socket ( sock_fd ) ; } return true ; }
Initialize the BACnet/IP services at the given interface.
Initialize the BACnet / IP services at the given interface .
/* assumes that the driver has already been initialized */