1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#! /bin/sh /usr/share/dpatch/dpatch-run
## 25_fix_setsockopt.dpatch by Daniel Kahn Gillmor <dkg@fifthhorseman.net>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Ensure that the server socket has SO_REUSEADDR and SO_LINGER set properly.
@DPATCH@
diff -urNad redir~/redir.c redir/redir.c
--- redir~/redir.c 2009-03-03 17:35:12.022427586 -0500
+++ redir/redir.c 2009-03-03 17:45:28.998426896 -0500
@@ -90,8 +90,8 @@
/* let's set up some globals... */
int dodebug = 0;
int dosyslog = 0;
-unsigned char reuse_addr = 1;
-unsigned char linger_opt = 0;
+int reuse_addr = 1; /* allow address reuse */
+struct linger linger_opt = { 0, 0}; /* do not linger */
char * bind_addr = NULL;
struct sockaddr_in addr_out;
int timeout = 0;
@@ -906,6 +906,7 @@
int servsock;
struct sockaddr_in server;
+ int ret;
/*
* Get a socket to work with. This socket will
@@ -944,8 +945,30 @@
server.sin_addr.s_addr = htonl(inet_addr("0.0.0.0"));
}
- setsockopt(servsock, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr));
- setsockopt(servsock, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof(SO_LINGER));
+ ret = setsockopt(servsock, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr));
+ if (ret != 0) {
+ if(fail) {
+ return -1;
+ }
+ else {
+ perror("server: setsockopt (SO_REUSEADDR)");
+ if (dosyslog)
+ syslog(LOG_ERR, "setsockopt failed with SO_REUSEADDR: %s",strerror(errno));
+ exit(1);
+ }
+ }
+ ret = setsockopt(servsock, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof(linger_opt));
+ if (ret != 0) {
+ if(fail) {
+ return -1;
+ }
+ else {
+ perror("server: setsockopt (SO_LINGER)");
+ if (dosyslog)
+ syslog(LOG_ERR, "setsockopt failed with SO_LINGER: %s",strerror(errno));
+ exit(1);
+ }
+ }
/*
* Try to bind the address to the socket.
|