Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add print of MDNS detail from UDP packet #2

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
37 changes: 32 additions & 5 deletions src/utility/NetDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,45 @@ static void netDumpTCP (Print& out, const char* ethdata, size_t size)
out.println();
}

static void netDumpDNS(Print& out, const char* dnsdata )
{
out.printf("TXID=0x%04x ",ntoh16(dnsdata));
out.printf("Flags=0x%04x ",ntoh16(dnsdata+2));
out.printf("Q=%d ",ntoh16(dnsdata+4));
out.printf("ANR=%d ",ntoh16(dnsdata+6));
out.printf("ATR=%d ",ntoh16(dnsdata+8));
out.printf("ADR=%d ",ntoh16(dnsdata+10));
}

static void netDumpUDP (Print& out, const char* ethdata, size_t size)
{
out.print(F(" UDP "));
if (size < ETH_HDR_LEN + 20 + 8)
return snap(out);

netDumpPort(out, ethdata);
uint16_t udplen = netDump_getUdpUsrLen(ethdata);
uint16_t iplen = netDump_getIpUsrLen(ethdata) - 8/*udp hdr size*/;
if (udplen != iplen)
out.printf(" len=%d?", iplen);
out.printf(" len=%d\r\n", udplen);

if ((netDump_getDstPort(ethdata) == 5353) || (netDump_getSrcPort(ethdata) == 5353))
{
out.print(F(" MDNS "));
netDumpDNS(out, ethdata + ETH_HDR_LEN + netDump_getIpHdrLen(ethdata) + 8);
}
else
if ((netDump_getDstPort(ethdata) == 53) || (netDump_getSrcPort(ethdata) == 53))
{
out.print(F(" DNS "));
netDumpDNS(out, ethdata + ETH_HDR_LEN + netDump_getIpHdrLen(ethdata) + 8);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks !
What do you think of factorizing ?

bool mdns = netDump_getDstPort(ethdata) == 5353) || (netDump_getSrcPort(ethdata) == 5353;
bool dns = netDump_getDstPort(ethdata) == 53) || (netDump_getSrcPort(ethdata) == 53;
if (mdns || dns)
{
   if (mdns) out.print(F(" MDNS ")); else out.print(F(" DNS "));
   ...
}

}
else
{
uint16_t udplen = netDump_getUdpUsrLen(ethdata);
uint16_t iplen = netDump_getIpUsrLen(ethdata) - 8/*udp hdr size*/;
if (udplen != iplen)
out.printf(" len=%d?", iplen);
out.printf(" len=%d", udplen);
}
out.printf("\r\n");

}

static void netDumpIPv4 (Print& out, const char* ethdata, size_t size)
Expand Down