Browse code

zero terminater in packet end ignored now

Jiri Kuthan authored on 08/09/2002 16:22:22
Showing 1 changed files
... ...
@@ -145,7 +145,7 @@ int udp_init(struct socket_info* sock_info)
145 145
 		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
146 146
 		goto error;
147 147
 	}
148
-#ifdef __linux__
148
+#if defined (__linux__) && defined(UDP_ERRORS)
149 149
 	optval=1;
150 150
 	/* enable error receiving on unconnected sockets */
151 151
 	if(setsockopt(sock_info->socket, SOL_IP, IP_RECVERR,
... ...
@@ -223,6 +223,17 @@ int udp_rcv_loop()
223 223
 		}
224 224
 		/*debugging, make print* msg work */
225 225
 		buf[len+1]=0;
226
+
227
+#ifndef NO_ZERO_CHECKS
228
+		if (len==0) {
229
+			LOG(L_WARN, "WARNING: empty packet received\n");
230
+			continue;
231
+		}
232
+		if (buf[len-1]==0) {
233
+			LOG(L_WARN, "WARNING: upstream bug - 0-terminated packet\n");
234
+			len--;
235
+		}
236
+#endif
226 237
 		
227 238
 		/* receive_msg must free buf too!*/
228 239
 		receive_msg(buf, len, from);
... ...
@@ -242,19 +253,14 @@ error:
242 242
 
243 243
 
244 244
 
245
-/* which socket to use? main socket or new one? */
246
-int udp_send(struct socket_info *source, char *buf, unsigned len,
247
-				union sockaddr_union*  to, unsigned tolen)
248
-{
249
-
250
-	int n;
251
-
245
+#ifdef DBG_MSG_QA
252 246
 /* message quality assurance -- frequently, bugs in ser have
253 247
    been indicated by zero characters or long whitespaces
254 248
    in generated messages; this debugging option aborts if
255 249
    any such message is sighted
256 250
 */
257
-#ifdef DBG_MSG_QA
251
+void dbg_msg_qa(char *buf, int len)
252
+{
258 253
 #define _DBG_WS_LEN 3
259 254
 #define _DBG_WS "   "
260 255
 
... ...
@@ -308,9 +314,24 @@ int udp_send(struct socket_info *source, char *buf, unsigned len,
308 308
 
309 309
 
310 310
 qa_passed:
311
+	return;
312
+}
311 313
 
312 314
 #endif
313 315
 
316
+/* which socket to use? main socket or new one? */
317
+int udp_send(struct socket_info *source, char *buf, unsigned len,
318
+				union sockaddr_union*  to, unsigned tolen)
319
+{
320
+
321
+	int n;
322
+
323
+#ifdef DBG_MSG_QA
324
+	/* aborts on error, does nothing otherwise */
325
+	dbg_msg_qa( buf, len );
326
+#endif
327
+
328
+
314 329
 again:
315 330
 	n=sendto(source->socket, buf, len, 0, &to->s, tolen);
316 331
 #ifdef XL_DEBUG