$OpenBSD$
--- modbus/modbus.c.orig	Sun Mar 22 05:01:17 2009
+++ modbus/modbus.c	Wed Oct 20 09:15:32 2010
@@ -40,6 +40,9 @@
 #include <fcntl.h>
 
 /* TCP */
+
+#include <netinet/in_systm.h>
+
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
@@ -340,8 +343,8 @@ static int check_crc16(modbus_param_t *mb_param,
                 ret = 0;
         } else {
                 char s_error[64];
-                sprintf(s_error,
-                        "invalid crc received %0X - crc_calc %0X", 
+                snprintf(s_error, sizeof(s_error) - 1,
+                        "invalid crc received %0X - crc_calc %0X",
                         crc_received, crc_calc);
                 ret = INVALID_CRC;
                 error_treat(mb_param, ret, s_error);
@@ -654,7 +657,8 @@ static int modbus_receive(modbus_param_t *mb_param, 
                         ret = response_nb_value;
                 } else {
                         char *s_error = malloc(64 * sizeof(char));
-                        sprintf(s_error, "Quantity (%d) not corresponding to the query (%d)",
+                        snprintf(s_error, sizeof(s_error) - 1, 
+                                "Quantity (%d) not corresponding to the query (%d)",
                                 response_nb_value, query_nb_value);
                         ret = ILLEGAL_DATA_VALUE;
                         error_treat(mb_param, ILLEGAL_DATA_VALUE, s_error);
@@ -694,7 +698,7 @@ static int modbus_receive(modbus_param_t *mb_param, 
                                            case but it can avoid a vicious
                                            segfault */
                                         char *s_error = malloc(64 * sizeof(char));
-                                        sprintf(s_error,
+                                        snprintf(s_error, sizeof(s_error) - 1,
                                                 "Invalid exception code %d",
                                                 response[offset + 2]);
                                         error_treat(mb_param, INVALID_EXCEPTION_CODE,
@@ -1314,9 +1318,9 @@ void modbus_init_rtu(modbus_param_t *mb_param, const c
                      int stop_bit)
 {
         memset(mb_param, 0, sizeof(modbus_param_t));
-        strcpy(mb_param->device, device);
+        strlcpy(mb_param->device, device, sizeof(mb_param->device));
         mb_param->baud = baud;
-        strcpy(mb_param->parity, parity);
+        strlcpy(mb_param->parity, parity, sizeof(mb_param->parity));
         mb_param->debug = FALSE;
         mb_param->data_bit = data_bit;
         mb_param->stop_bit = stop_bit;
@@ -1648,20 +1652,6 @@ static int modbus_connect_tcp(modbus_param_t *mb_param
                 return ret;
         }
 
-        /* Set the IP low delay option */
-        option = IPTOS_LOWDELAY;
-        ret = setsockopt(mb_param->fd, IPPROTO_TCP, IP_TOS,
-                         (const void *)&option, sizeof(int));
-        if (ret < 0) {
-                perror("setsockopt");
-                close(mb_param->fd);
-                return ret;
-        }
-
-        if (mb_param->debug) {
-                printf("Connecting to %s\n", mb_param->ip);
-        }
-        
         ret = connect(mb_param->fd, (struct sockaddr *)&addr,
                       sizeof(struct sockaddr_in));
         if (ret < 0) {
