aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modbuslog.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/modbuslog.c b/modbuslog.c
index e9346eb..f9c85e4 100644
--- a/modbuslog.c
+++ b/modbuslog.c
@@ -46,7 +46,7 @@ void minute_check(int signum) {
alarm(60);
}
-void find_mac(unsigned char* mac_address) {
+char *mac_address() {
int s;
struct ifreq ifr;
@@ -56,8 +56,8 @@ void find_mac(unsigned char* mac_address) {
ioctl(s, SIOCGIFHWADDR, &ifr);
close(s);
- unsigned char mac_address_internal[6];
- sprintf(mac_address_internal, "%.2X%.2X%.2X%.2X%.2X%.2X",
+ static char mac_address[12];
+ sprintf(mac_address, "%.2X%.2X%.2X%.2X%.2X%.2X",
(unsigned char) ifr.ifr_hwaddr.sa_data[0],
(unsigned char) ifr.ifr_hwaddr.sa_data[1],
(unsigned char) ifr.ifr_hwaddr.sa_data[2],
@@ -65,7 +65,7 @@ void find_mac(unsigned char* mac_address) {
(unsigned char) ifr.ifr_hwaddr.sa_data[4],
(unsigned char) ifr.ifr_hwaddr.sa_data[5]);
- strcpy(mac_address, mac_address_internal);
+ return mac_address;
}
int main(int argc, char *argv[]) {
@@ -83,8 +83,6 @@ int main(int argc, char *argv[]) {
config_t cfg;
//config_setting_t *setting;
- unsigned char mac_address[6];
-
const char *modbus_device_address;
int modbus_baud_rate;
int modbus_data_bits;
@@ -93,8 +91,6 @@ int main(int argc, char *argv[]) {
config_init(&cfg);
- find_mac(mac_address);
-
if (!config_read_file(&cfg, configfile)) {
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
config_error_line(&cfg), config_error_text(&cfg));
@@ -114,7 +110,7 @@ int main(int argc, char *argv[]) {
}
if (DEBUG) {
- printf("%s %s %d %c %d %d\n", mac_address, modbus_device_address,
+ printf("%s %s %d %c %d %d\n", mac_address(), modbus_device_address,
modbus_baud_rate, modbus_parity[0], modbus_data_bits,
modbus_stop_bits);
}
@@ -213,7 +209,7 @@ int main(int argc, char *argv[]) {
char filename[50];
sprintf(filename, "%s_%04i_%02i_%02i_%02i_%02i_%02i.log",
- mac_address, midnight.tm_year + 1900,
+ mac_address(), midnight.tm_year + 1900,
midnight.tm_mon + 1, midnight.tm_mday, midnight.tm_hour,
midnight.tm_min, midnight.tm_sec);