# HG changeset patch # User Mario de Sousa # Date 1575994069 0 # Node ID 9334c8280602f23daef5570006e33f5c44ef00dd # Parent fe4088d5573a137ebb162a842eb15ac904060209# Parent 1223f413e0540e15b7ac71fb0b6b90d7c3306e22 merge diff -r fe4088d5573a -r 9334c8280602 Makefile --- a/Makefile Tue Dec 10 15:51:32 2019 +0000 +++ b/Makefile Tue Dec 10 16:07:49 2019 +0000 @@ -6,10 +6,10 @@ OBJ_FILES = mb_ascii.o mb_rtu.o mb_tcp.o mb_master.o mb_slave.o mb_slave_and_master.o sin_util.o libmb.a: $(OBJ_FILES) - ar cr libmb.a $(OBJ_FILES) + $(AR) cr libmb.a $(OBJ_FILES) libmb.so: $(OBJ_FILES) - gcc -shared -fPIC -o libmb.so $(OBJ_FILES) + $(CC) -shared -fPIC -o libmb.so $(OBJ_FILES) clean: -rm -rf *.o libmb.a libmb.so @@ -17,12 +17,12 @@ # use gcc -CC = gcc +# CC = gcc #get warnings, debugging information and optimization -CFLAGS = -Wall -Wpointer-arith -Wstrict-prototypes -Wwrite-strings +# CFLAGS = -Wall -Wpointer-arith -Wstrict-prototypes -Wwrite-strings # CFLAGS += -Werror -CFLAGS += -ggdb -O3 -funroll-loops +# CFLAGS += -ggdb -O3 -funroll-loops # Note: if the optimizer crashes, we'll leave out the -O3 for those files # Required for compilation with beremiz, and to create shared object library diff -r fe4088d5573a -r 9334c8280602 sin_util.c --- a/sin_util.c Tue Dec 10 15:51:32 2019 +0000 +++ b/sin_util.c Tue Dec 10 16:07:49 2019 +0000 @@ -153,6 +153,10 @@ if ((type = gettypebyname(protocol)) == SOCK_PACKET) return -1; /* create the socket */ if ((s = socket(PF_INET, type, 0)) < 0) {perror("socket()"); return -1;} + if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int)) < 0) { + perror("setsockopt(SO_REUSEADDR) failed"); + return -1; + } /* bind the socket */ if (bind(s, (struct sockaddr *)&sin, sizeof (sin)) < 0) {perror("bind()"); return -1;}