فهرست منبع

Fix #457200 - FreeBSD support by Norbert Koch

Stéphane Raimbault 15 سال پیش
والد
کامیت
f20a18605a
5فایلهای تغییر یافته به همراه37 افزوده شده و 6 حذف شده
  1. 3 1
      NEWS
  2. 15 3
      src/modbus.c
  3. 11 0
      src/modbus.h
  4. 2 1
      tests/unit-test-master.c
  5. 6 1
      tests/unit-test.h

+ 3 - 1
NEWS

@@ -15,10 +15,12 @@ libmodbus 2.2.0 (2009-XX-01)
 - Fix #378981 - CRC error on RTU response doesn't return negative value
   Reported by Henrik Munktell.
 - Fix report slave ID request
-  Patch (bzr) provided by Paul Fertser .
+  Patch (bzr) provided by Paul Fertser.
 - Fix #425604 - Conditional jump or move depends on uninitialised value(s)
   Occurs on first occurence of slave timeout.
   Reported by Henrik Munktell.
+- Fix #457200 - FreeBSD support
+  Patch provided by Norbert Koch.
 
 libmodbus 2.0.3 (2009-03-22)
 ============================

+ 15 - 3
src/modbus.c

@@ -31,7 +31,12 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <termios.h>
 #include <sys/time.h>
 #include <unistd.h>
@@ -43,11 +48,18 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
+#if defined(__FreeBSD__ ) && __FreeBSD__ < 5
+#include <netinet/in_systm.h>
+#endif
 #include <netinet/in.h>
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
 #include <arpa/inet.h>
 
+#if !defined(UINT16_MAX)
+#define UINT16_MAX 0xFFFF
+#endif
+
 #include "config.h"
 #include "modbus.h"
 
@@ -1714,7 +1726,7 @@ static int modbus_connect_tcp(modbus_param_t *mb_param)
         ret = setsockopt(mb_param->fd, IPPROTO_TCP, TCP_NODELAY,
                          (const void *)&option, sizeof(int));
         if (ret < 0) {
-                perror("setsockopt");
+                perror("setsockopt TCP_NODELAY");
                 close(mb_param->fd);
                 return ret;
         }
@@ -1726,10 +1738,10 @@ static int modbus_connect_tcp(modbus_param_t *mb_param)
          **/
         /* Set the IP low delay option */
         option = IPTOS_LOWDELAY;
-        ret = setsockopt(mb_param->fd, IPPROTO_TCP, IP_TOS,
+        ret = setsockopt(mb_param->fd, IPPROTO_IP, IP_TOS,
                          (const void *)&option, sizeof(int));
         if (ret < 0) {
-                perror("setsockopt");
+                perror("setsockopt IP_TOS");
                 close(mb_param->fd);
                 return ret;
         }

+ 11 - 0
src/modbus.h

@@ -18,8 +18,19 @@
 #ifndef _MODBUS_H_
 #define _MODBUS_H_
 
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <termios.h>
+#if defined(__FreeBSD__ ) && __FreeBSD__ < 5
+#include <netinet/in_systm.h>
+#endif
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
 #include <arpa/inet.h>
 
 #ifdef __cplusplus

+ 2 - 1
tests/unit-test-master.c

@@ -30,6 +30,7 @@ int main(void)
 {
         uint8_t *tab_rp_status;
         uint16_t *tab_rp_registers;
+        uint16_t *tab_rp_registers_bad;
         modbus_param_t mb_param;
         int i;
         uint8_t value;
@@ -475,7 +476,7 @@ int main(void)
         printf("\nTEST BAD RESPONSE ERROR:\n");
 
         /* Allocate only the required space */
-        uint16_t *tab_rp_registers_bad = (uint16_t *) malloc(
+        tab_rp_registers_bad = (uint16_t *) malloc(
                 UT_HOLDING_REGISTERS_NB_POINTS_SPECIAL * sizeof(uint16_t));
         ret = read_holding_registers(&mb_param,
                                      UT_HOLDING_REGISTERS_ADDRESS,

+ 6 - 1
tests/unit-test.h

@@ -18,13 +18,18 @@
 #ifndef _UNIT_TEST_H_
 #define _UNIT_TEST_H_
 
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 
 #define SLAVE 0x11
 
 const uint16_t UT_COIL_STATUS_ADDRESS = 0x13;
 const uint16_t UT_COIL_STATUS_NB_POINTS = 0x25;
-const uint8_t UT_COIL_STATUS_TAB[] = { 0xCD, 0x6B, 0xB2, 0x0E, 0x1B }; 
+const uint8_t UT_COIL_STATUS_TAB[] = { 0xCD, 0x6B, 0xB2, 0x0E, 0x1B };
 
 const uint16_t UT_INPUT_STATUS_ADDRESS = 0xC4;
 const uint16_t UT_INPUT_STATUS_NB_POINTS = 0x16;