In these days, when network adapters have many offloading facilities,
we can receive packet with length bigger than MTU. So pass the MSG_TRUNC
flag to the recvfrom() function (it gives us the on-wire length even if
the buffer is not big enough).
First 256B of the packet is enough to have all the needed
information about packet (we need packet headers only and
not its data).
Vitezslav Samel (2):
packet.c: getpacket(): get total on-wire length of packet
packet.c: getpacket(): capture first 256B of the packet only
src/packet.c | 2 +-
src/packet.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
--
1.7.8.4
Show replies by date
In these days, when network adapters have many offloading facilities,
we can receive packet with length bigger than MTU. So pass the MSG_TRUNC
flag to the recvfrom() function (it gives us the on-wire length even if
the buffer is not big enough).
I checked every getpacket() use and everything seems OK, but there
may be some corner cases, where this bigger length (bigger than buffer
size, ie. MAX_PACKET_SIZE) may cause troubles.
Reported-by: Walter Zimmer <Walter.Zimmer(a)dlr.de>
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/packet.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/packet.c b/src/packet.c
index e13b6b4..e65f879 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -163,7 +163,7 @@ void getpacket(int fd, char *buf, struct sockaddr_ll *fromaddr, int
*ch,
if (FD_ISSET(fd, &set)) {
fromlen = sizeof(struct sockaddr_ll);
- *br = recvfrom(fd, buf, MAX_PACKET_SIZE, 0,
+ *br = recvfrom(fd, buf, MAX_PACKET_SIZE, MSG_TRUNC,
(struct sockaddr *) fromaddr, &fromlen);
}
if (!daemonized && FD_ISSET(0, &set))
--
1.7.8.4
First 256B of the packet is enough to have all the needed
information about packet (we need packet headers only and
not its data).
Because we're capturing with MSG_TRUNC now, the correct length
is returned from recvfrom().
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/packet.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/packet.h b/src/packet.h
index d9a0915..bdf1d0d 100644
--- a/src/packet.h
+++ b/src/packet.h
@@ -15,7 +15,7 @@ Written by Gerard Paul Java
* with reasonable numbers of options.
*/
-#define MAX_PACKET_SIZE 17664
+#define MAX_PACKET_SIZE 256 /* 256B should be enough to see all headers */
#define INVALID_PACKET 0
#define PACKET_OK 1
--
1.7.8.4