Combined the interface set into the datalink_init for all the datalink layers. Changed all the demo programs to use datalink_init instead of specific datalink functions.
This commit is contained in:
@@ -99,13 +99,32 @@ static void cleanup(void)
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
|
||||
/* on Windows, ifname is the dotted ip address of the interface */
|
||||
void bip_set_interface(char *ifname)
|
||||
{
|
||||
(void) ifname;
|
||||
/* dummy function */
|
||||
struct in_addr address;
|
||||
|
||||
/* setup local address */
|
||||
if (bip_get_addr() == 0) {
|
||||
bip_set_addr(inet_addr(ifname));
|
||||
}
|
||||
#ifdef BIP_DEBUG
|
||||
fprintf(stderr, "IP Address: %s\n", inet_ntoa(address));
|
||||
#endif
|
||||
/* setup local broadcast address */
|
||||
if (bip_get_broadcast_addr() == 0) {
|
||||
address.s_addr = htonl(bip_get_addr());
|
||||
set_broadcast_address(address.s_addr);
|
||||
}
|
||||
#ifdef BIP_DEBUG
|
||||
address.s_addr = htonl(bip_get_broadcast_addr());
|
||||
fprintf(stderr, "Broadcast Address: %s\n",
|
||||
inet_ntoa(address));
|
||||
#endif
|
||||
}
|
||||
|
||||
bool bip_init(void)
|
||||
bool bip_init(char *ifname)
|
||||
{
|
||||
int rv = 0; /* return from socket lib calls */
|
||||
struct sockaddr_in sin = { -1 };
|
||||
@@ -126,7 +145,9 @@ bool bip_init(void)
|
||||
exit(1);
|
||||
}
|
||||
atexit(cleanup);
|
||||
|
||||
|
||||
if (ifname)
|
||||
bip_set_interface(ifname);
|
||||
/* has address been set? */
|
||||
address.s_addr = htonl(bip_get_addr());
|
||||
if (address.s_addr == 0) {
|
||||
|
||||
@@ -214,11 +214,8 @@ int main(int argc, char *argv[])
|
||||
Device_Set_Object_Instance_Number(124);
|
||||
Init_Service_Handlers();
|
||||
/* init the data link layer */
|
||||
/* configure standard BACnet/IP port */
|
||||
bip_set_port(0xBAC0);
|
||||
if (!bip_init())
|
||||
if (!datalink_init(NULL))
|
||||
return 1;
|
||||
|
||||
datalink_get_broadcast_address(&broadcast_address);
|
||||
print_address("Broadcast", &broadcast_address);
|
||||
datalink_get_my_address(&my_address);
|
||||
@@ -230,10 +227,8 @@ int main(int argc, char *argv[])
|
||||
/* input */
|
||||
|
||||
/* returns 0 bytes on timeout */
|
||||
pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||
|
||||
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||
/* process */
|
||||
|
||||
if (pdu_len) {
|
||||
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user