Browse code

- set IP_RECVERR on linux

Andrei Pelinescu-Onciul authored on 05/09/2002 09:35:59
Showing 2 changed files
... ...
@@ -13,6 +13,10 @@
13 13
 #include <sys/socket.h>
14 14
 #include <netinet/in.h>
15 15
 #include <arpa/inet.h>
16
+#ifdef __linux__
17
+#include <linux/types.h>
18
+#include <linux/errqueue.h>
19
+#endif
16 20
 
17 21
 
18 22
 static char *id="$Id$";
... ...
@@ -48,6 +52,9 @@ int main (int argc, char** argv)
48 48
 	char *fname;
49 49
 	char *dst;
50 50
 	int port;
51
+#ifdef __linux__
52
+	int optval;
53
+#endif
51 54
 	
52 55
 	/* init */
53 56
 	count=0;
... ...
@@ -164,12 +171,14 @@ int main (int argc, char** argv)
164 164
 		fprintf(stderr, "ERROR: socket: %s\n", strerror(errno));
165 165
 		goto error;
166 166
 	}
167
-/*
168
-	if (connect(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr))!=0){
169
-		fprintf(stderr, "ERROR: connect: %s\n", strerror(errno));
170
-		goto error;
167
+#ifdef __linux__
168
+	/* enable error receiving on unconnected sockets*/
169
+	optval=1;
170
+	if(setsockopt(sock,SOL_IP,IP_RECVERR,(void*)&optval,sizeof(optval))==-1){
171
+		fprintf(stderr, "Error: setsockopt: %s\n", strerror(errno));
172
+		exit(1);
171 173
 	}
172
-*/
174
+#endif
173 175
 
174 176
 
175 177
 	/* flood loop */
... ...
@@ -9,6 +9,10 @@
9 9
 #include <netinet/in.h>
10 10
 #include <errno.h>
11 11
 #include <arpa/inet.h>
12
+#ifdef __linux__
13
+	#include <linux/types.h>
14
+	#include <linux/errqueue.h>
15
+#endif
12 16
 
13 17
 
14 18
 #include "udp_server.h"
... ...
@@ -137,11 +141,20 @@ int udp_init(struct socket_info* sock_info)
137 137
 	/* set sock opts? */
138 138
 	optval=1;
139 139
 	if (setsockopt(sock_info->socket, SOL_SOCKET, SO_REUSEADDR ,
140
-					(void*)&optval, sizeof(optval)) ==-1)
141
-	{
140
+					(void*)&optval, sizeof(optval)) ==-1){
141
+		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
142
+		goto error;
143
+	}
144
+#ifdef __linux__
145
+	optval=1;
146
+	/* enable error receiving on unconnected sockets */
147
+	if(setsockopt(sock_info->socket, SOL_IP, IP_RECVERR,
148
+					(void*)&optval, sizeof(optval)) ==-1){
142 149
 		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
143 150
 		goto error;
144 151
 	}
152
+#endif
153
+
145 154
 
146 155
 	if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error;
147 156