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