Skip to content

Commit b2c3c3f

Browse files
authored
Update udpfwd.c
adds reuse for ip adress and ports
1 parent 95b4dee commit b2c3c3f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

udpfwd.c

+34
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,40 @@ static int handle_data(const char *port_name, int baudrate,
233233
out_sock2 = socket(AF_INET, SOCK_DGRAM, 0);
234234
int in_sock = socket(AF_INET, SOCK_DGRAM, 0);
235235

236+
int reuse = 1;
237+
238+
239+
//in
240+
int reuse = 1;
241+
if (setsockopt(out_sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)) < 0)
242+
perror("setsockopt(SO_REUSEADDR) failed");
243+
244+
#ifdef SO_REUSEPORT
245+
if (setsockopt(out_sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)) < 0)
246+
perror("setsockopt(SO_REUSEPORT) failed");
247+
#endif
248+
249+
//out1
250+
int reuse = 1;
251+
if (setsockopt(out_sock2, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)) < 0)
252+
perror("setsockopt(SO_REUSEADDR) failed");
253+
254+
#ifdef SO_REUSEPORT
255+
if (setsockopt(out_sock2, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)) < 0)
256+
perror("setsockopt(SO_REUSEPORT) failed");
257+
#endif
258+
259+
//out2
260+
int reuse = 1;
261+
if (setsockopt(in_sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)) < 0)
262+
perror("setsockopt(SO_REUSEADDR) failed");
263+
264+
#ifdef SO_REUSEPORT
265+
if (setsockopt(in_sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)) < 0)
266+
perror("setsockopt(SO_REUSEPORT) failed");
267+
#endif
268+
269+
236270
struct sockaddr_in sin_in = {
237271
.sin_family = AF_INET,
238272
};

0 commit comments

Comments
 (0)