From e1f6a9ffcbbfa893f8e1edd0568e3c850596c307 Mon Sep 17 00:00:00 2001 From: Fred Klassen Date: Sun, 2 Jun 2024 16:26:01 -0700 Subject: [PATCH] Bug #863: test update to diagnose TOS test failure --- src/tcpedit/tcpedit.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/tcpedit/tcpedit.c b/src/tcpedit/tcpedit.c index 160ec75f..84bca728 100644 --- a/src/tcpedit/tcpedit.c +++ b/src/tcpedit/tcpedit.c @@ -183,11 +183,21 @@ tcpedit_packet(tcpedit_t *tcpedit, struct pcap_pkthdr **pkthdr, u_char **pktdata /* set TOS ? */ if (tcpedit->tos > -1) { volatile uint16_t oldval = *((uint16_t *)ip_hdr); - volatile uint16_t newval; + volatile uint16_t oldcsum, newval; - ip_hdr->ip_tos = tcpedit->tos; - newval = *((uint16_t *)ip_hdr); +// ip_hdr->ip_tos = tcpedit->tos; +// newval = *((uint16_t *)ip_hdr); + newval = htons(ntohs(*((uint16_t *)ip_hdr)) | (tcpedit->tos & 0xffff)); + oldcsum = ip_hdr->ip_sum; + static uint32_t cnt; csum_replace2(&ip_hdr->ip_sum, oldval, newval); + notice("tos %u: pkt=%u old/new: tos=0x%04x/0x%04x csum=0x%04x/0x%04x\n", + tcpedit->tos, + ++cnt, + htons(oldval), + htons(newval), + htons(oldcsum), + htons(ip_hdr->ip_sum)); } /* rewrite the TTL */