In bip.c getter and setter functions of IP address and Port number expect and return values in the network byte order. All ntoh and hton were eliminated from bip.c.

All other modules changed to be consistent.
arm7 port left unchanged.
This commit is contained in:
bacpack
2010-11-04 13:30:26 +00:00
parent 437112cc52
commit a639864cc8
9 changed files with 46 additions and 46 deletions
+2 -2
View File
@@ -919,7 +919,7 @@ int main(
* My_BIP_Port will be non-zero in this case.
*/
if (My_BIP_Port > 0)
bip_set_port(My_BIP_Port);
bip_set_port(htons(My_BIP_Port));
address_init();
Init_Service_Handlers();
dlenv_init();
@@ -929,7 +929,7 @@ int main(
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
if (My_BIP_Port > 0)
bip_set_port(0xBAC0); /* Set back to std BACnet/IP port */
bip_set_port(htons(0xBAC0)); /* Set back to std BACnet/IP port */
/* try to bind with the target device */
found =
address_bind_request(Target_Device_Object_Instance, &max_apdu,
+2 -2
View File
@@ -169,11 +169,11 @@ void Initialize_Device_Addresses( )
#if defined(BACDL_BIP)
struct in_addr *netPtr; /* Lets us cast to this type */
uint8_t *gatewayMac = NULL;
uint32_t myAddr = ntohl( bip_get_addr() );
uint32_t myAddr = bip_get_addr();
pDev = Get_Routed_Device_Object( i );
gatewayMac = pDev->bacDevAddr.mac; /* Keep pointer to the main MAC */
memcpy( pDev->bacDevAddr.mac, &myAddr, 4 );
myPort = ntohs( bip_get_port() );
myPort = bip_get_port();
memcpy( &pDev->bacDevAddr.mac[4], &myPort, 2 );
pDev->bacDevAddr.mac_len = 6;
#elif defined(BACDL_MSTP)
+3 -3
View File
@@ -167,7 +167,7 @@ void dlenv_init(
#endif
pEnv = getenv("BACNET_IP_PORT");
if (pEnv) {
bip_set_port((uint16_t) strtol(pEnv, NULL, 0));
bip_set_port(htons((uint16_t) strtol(pEnv, NULL, 0)));
} else {
/* BIP_Port is statically initialized to 0xBAC0,
* so if it is different, then it was programmatically altered,
@@ -175,8 +175,8 @@ void dlenv_init(
* Unless it is set below 1024, since:
* "The range for well-known ports managed by the IANA is 0-1023."
*/
if (bip_get_port() < 1024)
bip_set_port(0xBAC0);
if (ntohs(bip_get_port()) < 1024)
bip_set_port(htons(0xBAC0));
}
#elif defined(BACDL_MSTP)
pEnv = getenv("BACNET_MAX_INFO_FRAMES");
+4 -4
View File
@@ -89,24 +89,24 @@ extern "C" {
uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); /* milliseconds to wait for a packet */
/* use host byte order for setting */
/* use network byte order for setting */
void bip_set_port(
uint16_t port);
/* returns host byte order */
/* returns network byte order */
uint16_t bip_get_port(
void);
/* use network byte order for setting */
void bip_set_addr(
uint32_t net_address);
/* returns host byte order */
/* returns network byte order */
uint32_t bip_get_addr(
void);
/* use network byte order for setting */
void bip_set_broadcast_addr(
uint32_t net_address);
/* returns host byte order */
/* returns network byte order */
uint32_t bip_get_broadcast_addr(
void);
+3 -3
View File
@@ -128,8 +128,8 @@ static void bip_set_interface(
if (BIP_Debug) {
fprintf(stderr, "IP Broadcast Address: %s\n",
inet_ntoa(broadcast_address));
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", bip_get_port(),
bip_get_port());
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", ntohs(bip_get_port()),
ntohs(bip_get_port()));
}
}
@@ -191,7 +191,7 @@ bool bip_init(
/* bind the socket to the local port number and IP address */
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(bip_get_port());
sin.sin_port = bip_get_port();
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
status =
bind(sock_fd, (const struct sockaddr *) &sin, sizeof(struct sockaddr));
+2 -2
View File
@@ -258,7 +258,7 @@ bool bip_init(
RTIP_To_Network_Address(TargetIP, &my_addr);
bip_set_addr(my_addr.s_addr);
set_broadcast_address(my_addr.s_addr);
bip_set_port(0xBAC0);
bip_set_port(htons((0xBAC0));
/* assumes that the driver has already been initialized */
sock_fd = socket(AF_INET, SOCK_DGRAM, IPROTO_UDP);
@@ -269,7 +269,7 @@ bool bip_init(
/* bind the socket to the local port number and IP address */
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(bip_get_port());
sin.sin_port = bip_get_port();
memset(&(sin.sin_zero), '\0', 8);
rv = bind(sock_fd, (const struct sockaddr *) &sin,
sizeof(struct sockaddr));
+8 -8
View File
@@ -191,12 +191,12 @@ void bip_set_interface(
bip_set_addr(inet_addr(ifname));
}
if (BIP_Debug) {
address.s_addr = htonl(bip_get_addr());
address.s_addr = bip_get_addr();
fprintf(stderr, "Interface: %s\n", ifname);
}
/* setup local broadcast address */
if (bip_get_broadcast_addr() == 0) {
address.s_addr = htonl(bip_get_addr());
address.s_addr = bip_get_addr();
set_broadcast_address(address.s_addr);
}
}
@@ -339,7 +339,7 @@ bool bip_init(
if (ifname)
bip_set_interface(ifname);
/* has address been set? */
address.s_addr = htonl(bip_get_addr());
address.s_addr = bip_get_addr();
if (address.s_addr == 0) {
address.s_addr = gethostaddr();
if (address.s_addr == (unsigned) -1) {
@@ -358,11 +358,11 @@ bool bip_init(
set_broadcast_address(address.s_addr);
}
if (BIP_Debug) {
broadcast_address.s_addr = htonl(bip_get_broadcast_addr());
broadcast_address.s_addr = bip_get_broadcast_addr();
fprintf(stderr, "IP Broadcast Address: %s\n",
inet_ntoa(broadcast_address));
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", bip_get_port(),
bip_get_port());
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", ntohs(bip_get_port()),
ntohs(bip_get_port()));
}
/* assumes that the driver has already been initialized */
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
@@ -424,13 +424,13 @@ bool bip_init(
note: already in network byte order */
sin.sin_addr.s_addr = address.s_addr;
#endif
sin.sin_port = htons(bip_get_port());
sin.sin_port = bip_get_port();
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
rv = bind(sock_fd, (const struct sockaddr *) &sin,
sizeof(struct sockaddr));
if (rv < 0) {
fprintf(stderr, "bip: failed to bind to %s port %hu\n",
inet_ntoa(sin.sin_addr), bip_get_port());
inet_ntoa(sin.sin_addr), ntohs(bip_get_port()));
close(sock_fd);
bip_set_socket(-1);
return false;
+8 -8
View File
@@ -97,11 +97,11 @@ void bip_set_addr(
BIP_Address.s_addr = net_address;
}
/* returns host byte order */
/* returns network byte order */
uint32_t bip_get_addr(
void)
{
return ntohl(BIP_Address.s_addr);
return BIP_Address.s_addr;
}
void bip_set_broadcast_addr(
@@ -110,25 +110,25 @@ void bip_set_broadcast_addr(
BIP_Broadcast_Address.s_addr = net_address;
}
/* returns host byte order */
/* returns network byte order */
uint32_t bip_get_broadcast_addr(
void)
{
return ntohl(BIP_Broadcast_Address.s_addr);
return BIP_Broadcast_Address.s_addr;
}
void bip_set_port(
uint16_t port) /* in host byte order */
uint16_t port) /* in network byte order */
{
BIP_Port = htons(port);
BIP_Port = port;
}
/* returns host byte order */
/* returns network byte order */
uint16_t bip_get_port(
void)
{
return ntohs(BIP_Port);
return BIP_Port;
}
static int bip_decode_bip_address(
+14 -14
View File
@@ -682,13 +682,13 @@ static void bvlc_bdt_forward_npdu(
s_addr) | BBMD_Table[i].dest_address.s_addr));
bip_dest.sin_port = htons(BBMD_Table[i].dest_port);
/* don't send to my broadcast address and same port */
if ((bip_dest.sin_addr.s_addr == htonl(bip_get_broadcast_addr()))
&& (bip_dest.sin_port == htons(bip_get_port()))) {
if ((bip_dest.sin_addr.s_addr == bip_get_broadcast_addr())
&& (bip_dest.sin_port == bip_get_port())) {
continue;
}
/* don't send to my ip address and same port */
if ((bip_dest.sin_addr.s_addr == htonl(bip_get_addr())) &&
(bip_dest.sin_port == htons(bip_get_port()))) {
if ((bip_dest.sin_addr.s_addr == bip_get_addr()) &&
(bip_dest.sin_port == bip_get_port())) {
continue;
}
bvlc_send_mpdu(&bip_dest, mtu, mtu_len);
@@ -713,8 +713,8 @@ static void bvlc_forward_npdu(
mtu_len =
(uint16_t) bvlc_encode_forwarded_npdu(&mtu[0], sin, npdu, npdu_length);
bip_dest.sin_addr.s_addr = htonl(bip_get_broadcast_addr());
bip_dest.sin_port = htons(bip_get_port());
bip_dest.sin_addr.s_addr = bip_get_broadcast_addr();
bip_dest.sin_port = bip_get_port();
bvlc_send_mpdu(&bip_dest, mtu, mtu_len);
debug_printf("BVLC: Sent Forwarded-NPDU as local broadcast.\n");
}
@@ -737,8 +737,8 @@ static void bvlc_fdt_forward_npdu(
bip_dest.sin_addr.s_addr = htonl(FD_Table[i].dest_address.s_addr);
bip_dest.sin_port = htons(FD_Table[i].dest_port);
/* don't send to my ip address and same port */
if ((bip_dest.sin_addr.s_addr == htonl(bip_get_addr())) &&
(bip_dest.sin_port == htons(bip_get_port()))) {
if ((bip_dest.sin_addr.s_addr == bip_get_addr()) &&
(bip_dest.sin_port == bip_get_port())) {
continue;
}
/* don't send to src ip address and same port */
@@ -992,8 +992,8 @@ uint16_t bvlc_receive(
npdu_len -= 6;
/* Broadcast locally if received via unicast from a BDT member */
if (bvlc_bdt_member_mask_is_unicast(&sin)) {
dest.sin_addr.s_addr = htonl(bip_get_broadcast_addr());
dest.sin_port = htons(bip_get_port());
dest.sin_addr.s_addr = bip_get_broadcast_addr();
dest.sin_port = bip_get_port();
bvlc_send_mpdu(&dest, &npdu[4 + 6], npdu_len);
}
/* use the original addr from the BVLC for src */
@@ -1102,8 +1102,8 @@ uint16_t bvlc_receive(
case BVLC_ORIGINAL_UNICAST_NPDU:
debug_printf("BVLC: Received Original-Unicast-NPDU.\n");
/* ignore messages from me */
if ((sin.sin_addr.s_addr == htonl(bip_get_addr())) &&
(sin.sin_port == htons(bip_get_port()))) {
if ((sin.sin_addr.s_addr == bip_get_addr()) &&
(sin.sin_port == bip_get_port())) {
npdu_len = 0;
} else {
bvlc_internet_to_bacnet_address(src, &sin);
@@ -1182,8 +1182,8 @@ int bvlc_send_pdu(
port = ntohs(Remote_BBMD.sin_port);
debug_printf("BVLC: Sent Distribute-Broadcast-to-Network.\n");
} else {
address.s_addr = bip_get_broadcast_addr();
port = bip_get_port();
address.s_addr = ntohl(bip_get_broadcast_addr());
port = ntohs(bip_get_port());
mtu[1] = BVLC_ORIGINAL_BROADCAST_NPDU;
debug_printf("BVLC: Sent Original-Broadcast-NPDU.\n");
}