Indented.

This commit is contained in:
skarg
2007-11-29 15:56:53 +00:00
parent c585241c03
commit 411d6c1b24
236 changed files with 17864 additions and 15724 deletions
+56 -45
View File
@@ -32,8 +32,8 @@
-------------------------------------------
####COPYRIGHTEND####*/
#include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */
#include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */
#include <assert.h>
#include <direct.h>
#include <io.h>
@@ -78,19 +78,24 @@ static unsigned eth_timeout = 100;
/* couple of external func for runtime error logging, you can simply */
/* replace them with standard "printf(...)" */
/* Logging extern functions: Info level */
extern void LogInfo(const char *msg);
extern void LogInfo(
const char *msg);
/* Logging extern functions: Error level*/
extern void LogError(const char *msg);
extern void LogError(
const char *msg);
/* Logging extern functions: Debug level*/
extern void LogDebug(const char *msg);
extern void LogDebug(
const char *msg);
bool ethernet_valid(void)
bool ethernet_valid(
void)
{
return (pcap_eth802_fp != NULL);
}
void ethernet_cleanup(void)
void ethernet_cleanup(
void)
{
if (pcap_eth802_fp) {
pcap_close(pcap_eth802_fp);
@@ -99,7 +104,8 @@ void ethernet_cleanup(void)
LogInfo("ethernet.c: ethernet_cleanup() ok.\n");
}
void ethernet_set_timeout(unsigned timeout)
void ethernet_set_timeout(
unsigned timeout)
{
eth_timeout = timeout;
}
@@ -129,7 +135,8 @@ int setNonblocking(int fd)
}
*/
bool ethernet_init(char *if_name)
bool ethernet_init(
char *if_name)
{
PPACKET_OID_DATA pOidData;
LPADAPTER lpAdapter;
@@ -197,11 +204,11 @@ bool ethernet_init(char *if_name)
*/
/* Open the output device */
pcap_eth802_fp = pcap_open(if_name, /* name of the device */
MAX_MPDU, /* portion of the packet to capture */
MAX_MPDU, /* portion of the packet to capture */
PCAP_OPENFLAG_PROMISCUOUS, /* promiscuous mode */
eth_timeout, /* read timeout */
NULL, /* authentication on the remote machine */
pcap_errbuf /* error buffer */
eth_timeout, /* read timeout */
NULL, /* authentication on the remote machine */
pcap_errbuf /* error buffer */
);
if (pcap_eth802_fp == NULL) {
PacketCloseAdapter(lpAdapter);
@@ -222,10 +229,11 @@ bool ethernet_init(char *if_name)
/* function to send a packet out the 802.2 socket */
/* returns bytes sent success, negative on failure */
int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
int ethernet_send(
BACNET_ADDRESS * dest, /* destination address */
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len /* number of bytes of data */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len /* number of bytes of data */
)
{
int bytes = 0;
@@ -235,8 +243,7 @@ int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
/* don't waste time if the socket is not valid */
if (!ethernet_valid()) {
LogError
("ethernet.c: invalid 802.2 ethernet interface descriptor!\n");
LogError("ethernet.c: invalid 802.2 ethernet interface descriptor!\n");
return -1;
}
/* load destination ethernet MAC address */
@@ -265,8 +272,7 @@ int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
return -4;
}
/* packet length */
mtu_len +=
encode_unsigned16(&mtu[12], 3 /*DSAP,SSAP,LLC */ + pdu_len);
mtu_len += encode_unsigned16(&mtu[12], 3 /*DSAP,SSAP,LLC */ + pdu_len);
/* Logical PDU portion */
mtu[mtu_len++] = 0x82; /* DSAP for BACnet */
mtu[mtu_len++] = 0x82; /* SSAP for BACnet */
@@ -290,12 +296,13 @@ int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
/* function to send a packet out the 802.2 socket */
/* returns number of bytes sent on success, negative on failure */
int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len /* number of bytes of data */
int ethernet_send_pdu(
BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len /* number of bytes of data */
)
{
int i = 0; /* counter */
int i = 0; /* counter */
BACNET_ADDRESS src = { 0 }; /* source address */
for (i = 0; i < 6; i++) {
@@ -305,18 +312,19 @@ int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
/* function to send a packet out the 802.2 socket */
/* returns 1 on success, 0 on failure */
return ethernet_send(dest, /* destination address */
&src, /* source address */
pdu, /* any data to be sent - may be null */
pdu_len /* number of bytes of data */
&src, /* source address */
pdu, /* any data to be sent - may be null */
pdu_len /* number of bytes of data */
);
}
/* receives an 802.2 framed packet */
/* returns the number of octets in the PDU, or zero on failure */
uint16_t ethernet_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout /* number of milliseconds to wait for a packet. we ommit it due to winpcap API. */
uint16_t ethernet_receive(
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout /* number of milliseconds to wait for a packet. we ommit it due to winpcap API. */
)
{
struct pcap_pkthdr *header;
@@ -326,8 +334,7 @@ uint16_t ethernet_receive(BACNET_ADDRESS * src, /* source address */
/* Make sure the socket is open */
if (!ethernet_valid()) {
LogError
("ethernet.c: invalid 802.2 ethernet interface descriptor!\n");
LogError("ethernet.c: invalid 802.2 ethernet interface descriptor!\n");
return 0;
}
@@ -374,7 +381,8 @@ uint16_t ethernet_receive(BACNET_ADDRESS * src, /* source address */
return pdu_len;
}
void ethernet_set_my_address(BACNET_ADDRESS * my_address)
void ethernet_set_my_address(
BACNET_ADDRESS * my_address)
{
int i = 0;
@@ -385,7 +393,8 @@ void ethernet_set_my_address(BACNET_ADDRESS * my_address)
return;
}
void ethernet_get_my_address(BACNET_ADDRESS * my_address)
void ethernet_get_my_address(
BACNET_ADDRESS * my_address)
{
int i = 0;
@@ -403,9 +412,10 @@ void ethernet_get_my_address(BACNET_ADDRESS * my_address)
return;
}
void ethernet_get_broadcast_address(BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
void ethernet_get_broadcast_address(
BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
for (i = 0; i < 6; i++) {
@@ -413,7 +423,7 @@ void ethernet_get_broadcast_address(BACNET_ADDRESS * dest)
}
dest->mac_len = 6;
dest->net = BACNET_BROADCAST_NETWORK;
dest->len = 0; /* denotes broadcast address */
dest->len = 0; /* denotes broadcast address */
for (i = 0; i < MAX_MAC_LEN; i++) {
dest->adr[i] = 0;
}
@@ -422,9 +432,11 @@ void ethernet_get_broadcast_address(BACNET_ADDRESS * dest)
return;
}
void ethernet_debug_address(const char *info, BACNET_ADDRESS * dest)
void ethernet_debug_address(
const char *info,
BACNET_ADDRESS * dest)
{
int i = 0; /* counter */
int i = 0; /* counter */
char msgBuf[200];
if (info) {
@@ -439,15 +451,14 @@ void ethernet_debug_address(const char *info, BACNET_ADDRESS * dest)
for (i = 0; i < MAX_MAC_LEN; i++) {
sprintf(msgBuf, "%02X ", (unsigned) dest->mac[i]);
LogInfo(msgBuf);
} /* for */
} /* for */
LogInfo("\n");
sprintf(msgBuf,
" Net=%hu\n Len=%d\n Adr=", dest->net, dest->len);
sprintf(msgBuf, " Net=%hu\n Len=%d\n Adr=", dest->net, dest->len);
LogInfo(msgBuf);
for (i = 0; i < MAX_MAC_LEN; i++) {
sprintf(msgBuf, "%02X ", (unsigned) dest->adr[i]);
LogInfo(msgBuf);
} /* for */
} /* for */
LogInfo("\n");
}
/* if ( dest ) */