From 65935ceb6f7957ee4c071b4f9147cfd4edec0d67 Mon Sep 17 00:00:00 2001
From: Hans-Werner Hilse <hwhilse@gmail.com>
Date: Mon, 11 May 2015 23:37:47 +0200
Subject: [PATCH] Fix maximum payload size to UDP constraints

The constant MAX_PAYLOAD specifies the maximum UDP payload size.
This is the maximum of the UDP header's length field (0xFFFF)
minus the size of the UDP header, which is included in the length
stored in the header (8 bytes), so that the maximum payload is
65527 bytes.

This is still a suboptimal situation since UDP packets so large
are in most practical cases fragmented on the IP layer. However,
it is a larger design issue to switch over to smaller packets.

Signed-off-by: Hans-Werner Hilse <hwhilse@gmail.com>
---
 alfred.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/alfred.h b/alfred.h
index 8fc8ab1..9aa312b 100644
--- a/alfred.h
+++ b/alfred.h
@@ -137,7 +137,8 @@ struct globals {
 #define debugMalloc(size, num)	malloc(size)
 #define debugFree(ptr, num)	free(ptr)
 
-#define MAX_PAYLOAD ((1 << 16) - 1)
+/* UDP packet size is max. 65535, including the UDP header itself */
+#define MAX_PAYLOAD (65535 - 8)
 
 extern const struct in6_addr in6addr_localmcast;
 
-- 
2.4.0

