Commit f20a18605ab6ea784f89823b9893d0ecf9298824
1 parent
5f65efd8
Fix #457200 - FreeBSD support by Norbert Koch
Showing
5 changed files
with
37 additions
and
6 deletions
NEWS
| @@ -15,10 +15,12 @@ libmodbus 2.2.0 (2009-XX-01) | @@ -15,10 +15,12 @@ libmodbus 2.2.0 (2009-XX-01) | ||
| 15 | - Fix #378981 - CRC error on RTU response doesn't return negative value | 15 | - Fix #378981 - CRC error on RTU response doesn't return negative value |
| 16 | Reported by Henrik Munktell. | 16 | Reported by Henrik Munktell. |
| 17 | - Fix report slave ID request | 17 | - Fix report slave ID request |
| 18 | - Patch (bzr) provided by Paul Fertser . | 18 | + Patch (bzr) provided by Paul Fertser. |
| 19 | - Fix #425604 - Conditional jump or move depends on uninitialised value(s) | 19 | - Fix #425604 - Conditional jump or move depends on uninitialised value(s) |
| 20 | Occurs on first occurence of slave timeout. | 20 | Occurs on first occurence of slave timeout. |
| 21 | Reported by Henrik Munktell. | 21 | Reported by Henrik Munktell. |
| 22 | +- Fix #457200 - FreeBSD support | ||
| 23 | + Patch provided by Norbert Koch. | ||
| 22 | 24 | ||
| 23 | libmodbus 2.0.3 (2009-03-22) | 25 | libmodbus 2.0.3 (2009-03-22) |
| 24 | ============================ | 26 | ============================ |
src/modbus.c
| @@ -31,7 +31,12 @@ | @@ -31,7 +31,12 @@ | ||
| 31 | #include <stdio.h> | 31 | #include <stdio.h> |
| 32 | #include <string.h> | 32 | #include <string.h> |
| 33 | #include <stdlib.h> | 33 | #include <stdlib.h> |
| 34 | +#ifdef HAVE_INTTYPES_H | ||
| 35 | +#include <inttypes.h> | ||
| 36 | +#endif | ||
| 37 | +#ifdef HAVE_STDINT_H | ||
| 34 | #include <stdint.h> | 38 | #include <stdint.h> |
| 39 | +#endif | ||
| 35 | #include <termios.h> | 40 | #include <termios.h> |
| 36 | #include <sys/time.h> | 41 | #include <sys/time.h> |
| 37 | #include <unistd.h> | 42 | #include <unistd.h> |
| @@ -43,11 +48,18 @@ | @@ -43,11 +48,18 @@ | ||
| 43 | #include <sys/types.h> | 48 | #include <sys/types.h> |
| 44 | #include <sys/socket.h> | 49 | #include <sys/socket.h> |
| 45 | #include <sys/ioctl.h> | 50 | #include <sys/ioctl.h> |
| 51 | +#if defined(__FreeBSD__ ) && __FreeBSD__ < 5 | ||
| 52 | +#include <netinet/in_systm.h> | ||
| 53 | +#endif | ||
| 46 | #include <netinet/in.h> | 54 | #include <netinet/in.h> |
| 47 | #include <netinet/ip.h> | 55 | #include <netinet/ip.h> |
| 48 | #include <netinet/tcp.h> | 56 | #include <netinet/tcp.h> |
| 49 | #include <arpa/inet.h> | 57 | #include <arpa/inet.h> |
| 50 | 58 | ||
| 59 | +#if !defined(UINT16_MAX) | ||
| 60 | +#define UINT16_MAX 0xFFFF | ||
| 61 | +#endif | ||
| 62 | + | ||
| 51 | #include "config.h" | 63 | #include "config.h" |
| 52 | #include "modbus.h" | 64 | #include "modbus.h" |
| 53 | 65 | ||
| @@ -1714,7 +1726,7 @@ static int modbus_connect_tcp(modbus_param_t *mb_param) | @@ -1714,7 +1726,7 @@ static int modbus_connect_tcp(modbus_param_t *mb_param) | ||
| 1714 | ret = setsockopt(mb_param->fd, IPPROTO_TCP, TCP_NODELAY, | 1726 | ret = setsockopt(mb_param->fd, IPPROTO_TCP, TCP_NODELAY, |
| 1715 | (const void *)&option, sizeof(int)); | 1727 | (const void *)&option, sizeof(int)); |
| 1716 | if (ret < 0) { | 1728 | if (ret < 0) { |
| 1717 | - perror("setsockopt"); | 1729 | + perror("setsockopt TCP_NODELAY"); |
| 1718 | close(mb_param->fd); | 1730 | close(mb_param->fd); |
| 1719 | return ret; | 1731 | return ret; |
| 1720 | } | 1732 | } |
| @@ -1726,10 +1738,10 @@ static int modbus_connect_tcp(modbus_param_t *mb_param) | @@ -1726,10 +1738,10 @@ static int modbus_connect_tcp(modbus_param_t *mb_param) | ||
| 1726 | **/ | 1738 | **/ |
| 1727 | /* Set the IP low delay option */ | 1739 | /* Set the IP low delay option */ |
| 1728 | option = IPTOS_LOWDELAY; | 1740 | option = IPTOS_LOWDELAY; |
| 1729 | - ret = setsockopt(mb_param->fd, IPPROTO_TCP, IP_TOS, | 1741 | + ret = setsockopt(mb_param->fd, IPPROTO_IP, IP_TOS, |
| 1730 | (const void *)&option, sizeof(int)); | 1742 | (const void *)&option, sizeof(int)); |
| 1731 | if (ret < 0) { | 1743 | if (ret < 0) { |
| 1732 | - perror("setsockopt"); | 1744 | + perror("setsockopt IP_TOS"); |
| 1733 | close(mb_param->fd); | 1745 | close(mb_param->fd); |
| 1734 | return ret; | 1746 | return ret; |
| 1735 | } | 1747 | } |
src/modbus.h
| @@ -18,8 +18,19 @@ | @@ -18,8 +18,19 @@ | ||
| 18 | #ifndef _MODBUS_H_ | 18 | #ifndef _MODBUS_H_ |
| 19 | #define _MODBUS_H_ | 19 | #define _MODBUS_H_ |
| 20 | 20 | ||
| 21 | +#ifdef HAVE_INTTYPES_H | ||
| 22 | +#include <inttypes.h> | ||
| 23 | +#endif | ||
| 24 | +#ifdef HAVE_STDINT_H | ||
| 21 | #include <stdint.h> | 25 | #include <stdint.h> |
| 26 | +#endif | ||
| 22 | #include <termios.h> | 27 | #include <termios.h> |
| 28 | +#if defined(__FreeBSD__ ) && __FreeBSD__ < 5 | ||
| 29 | +#include <netinet/in_systm.h> | ||
| 30 | +#endif | ||
| 31 | +#include <netinet/in.h> | ||
| 32 | +#include <netinet/ip.h> | ||
| 33 | +#include <netinet/tcp.h> | ||
| 23 | #include <arpa/inet.h> | 34 | #include <arpa/inet.h> |
| 24 | 35 | ||
| 25 | #ifdef __cplusplus | 36 | #ifdef __cplusplus |
tests/unit-test-master.c
| @@ -30,6 +30,7 @@ int main(void) | @@ -30,6 +30,7 @@ int main(void) | ||
| 30 | { | 30 | { |
| 31 | uint8_t *tab_rp_status; | 31 | uint8_t *tab_rp_status; |
| 32 | uint16_t *tab_rp_registers; | 32 | uint16_t *tab_rp_registers; |
| 33 | + uint16_t *tab_rp_registers_bad; | ||
| 33 | modbus_param_t mb_param; | 34 | modbus_param_t mb_param; |
| 34 | int i; | 35 | int i; |
| 35 | uint8_t value; | 36 | uint8_t value; |
| @@ -475,7 +476,7 @@ int main(void) | @@ -475,7 +476,7 @@ int main(void) | ||
| 475 | printf("\nTEST BAD RESPONSE ERROR:\n"); | 476 | printf("\nTEST BAD RESPONSE ERROR:\n"); |
| 476 | 477 | ||
| 477 | /* Allocate only the required space */ | 478 | /* Allocate only the required space */ |
| 478 | - uint16_t *tab_rp_registers_bad = (uint16_t *) malloc( | 479 | + tab_rp_registers_bad = (uint16_t *) malloc( |
| 479 | UT_HOLDING_REGISTERS_NB_POINTS_SPECIAL * sizeof(uint16_t)); | 480 | UT_HOLDING_REGISTERS_NB_POINTS_SPECIAL * sizeof(uint16_t)); |
| 480 | ret = read_holding_registers(&mb_param, | 481 | ret = read_holding_registers(&mb_param, |
| 481 | UT_HOLDING_REGISTERS_ADDRESS, | 482 | UT_HOLDING_REGISTERS_ADDRESS, |
tests/unit-test.h
| @@ -18,13 +18,18 @@ | @@ -18,13 +18,18 @@ | ||
| 18 | #ifndef _UNIT_TEST_H_ | 18 | #ifndef _UNIT_TEST_H_ |
| 19 | #define _UNIT_TEST_H_ | 19 | #define _UNIT_TEST_H_ |
| 20 | 20 | ||
| 21 | +#ifdef HAVE_INTTYPES_H | ||
| 22 | +#include <inttypes.h> | ||
| 23 | +#endif | ||
| 24 | +#ifdef HAVE_STDINT_H | ||
| 21 | #include <stdint.h> | 25 | #include <stdint.h> |
| 26 | +#endif | ||
| 22 | 27 | ||
| 23 | #define SLAVE 0x11 | 28 | #define SLAVE 0x11 |
| 24 | 29 | ||
| 25 | const uint16_t UT_COIL_STATUS_ADDRESS = 0x13; | 30 | const uint16_t UT_COIL_STATUS_ADDRESS = 0x13; |
| 26 | const uint16_t UT_COIL_STATUS_NB_POINTS = 0x25; | 31 | const uint16_t UT_COIL_STATUS_NB_POINTS = 0x25; |
| 27 | -const uint8_t UT_COIL_STATUS_TAB[] = { 0xCD, 0x6B, 0xB2, 0x0E, 0x1B }; | 32 | +const uint8_t UT_COIL_STATUS_TAB[] = { 0xCD, 0x6B, 0xB2, 0x0E, 0x1B }; |
| 28 | 33 | ||
| 29 | const uint16_t UT_INPUT_STATUS_ADDRESS = 0xC4; | 34 | const uint16_t UT_INPUT_STATUS_ADDRESS = 0xC4; |
| 30 | const uint16_t UT_INPUT_STATUS_NB_POINTS = 0x16; | 35 | const uint16_t UT_INPUT_STATUS_NB_POINTS = 0x16; |