A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.
Dependents: oldheating gps motorhome heating
Diff: ip6/icmp/icmp6.cpp
- Revision:
- 47:73af5c0b0dc2
- Parent:
- 46:40d33e9037e4
- Child:
- 48:952dddb74b8b
--- a/ip6/icmp/icmp6.cpp Tue Oct 24 07:01:35 2017 +0000 +++ b/ip6/icmp/icmp6.cpp Thu Oct 26 14:50:24 2017 +0000 @@ -24,18 +24,18 @@ static int dataLength; static void* pData; -static void typeToString(uint8_t type, int size, char* text) +static void logType(uint8_t type) { switch (type) { - case 128: strncpy (text, "Echo Request" , size); break; - case 129: strncpy (text, "Echo Reply" , size); break; - case 133: strncpy (text, "Router solicit" , size); break; - case 134: strncpy (text, "Router advertisement" , size); break; - case 135: strncpy (text, "Neighbour solicit" , size); break; - case 136: strncpy (text, "Neighbour advertisement", size); break; - case 137: strncpy (text, "Redirect" , size); break; - default: snprintf(text, size, "unknown type %u", type); break; + case 128: Log ("Echo Request" ); break; + case 129: Log ("Echo Reply" ); break; + case 133: Log ("Router solicit" ); break; + case 134: Log ("Router advertisement" ); break; + case 135: Log ("Neighbour solicit" ); break; + case 136: Log ("Neighbour advertisement"); break; + case 137: Log ("Redirect" ); break; + default: LogF("Unknown type %u", type ); break; } } static uint16_t calculateChecksum(char* pSrcIp, char* pDstIp, int size, void* pPacket) @@ -61,12 +61,10 @@ } static void logHeader() { - char text[100]; if (NetTraceVerbose) { Log ("ICMP6 header\r\n"); - typeToString(type, sizeof(text), text); - LogF(" Type %s\r\n", text); + Log (" Type "); logType(type); Log("\r\n"); LogF(" Code %u\r\n", code); LogF(" Checksum (hex) %04hX\r\n", checksum); LogF(" Calculated %04hX\r\n", calculatedChecksum); @@ -75,8 +73,7 @@ else { Log ("ICMP6 header "); - typeToString(type, sizeof(text), text); - Log(text); + logType(type); Log("\r\n"); } } @@ -96,7 +93,8 @@ pHeader->type = type; pHeader->code = code; pHeader->checksum = 0; - pHeader->checksum = calculateChecksum(pSrcIp, pDstIp, size, pPacket); + checksum = calculateChecksum(pSrcIp, pDstIp, size, pPacket); + pHeader->checksum = checksum; calculatedChecksum = 0; } static void (*pTraceBack)(void); @@ -135,8 +133,8 @@ if (!action) return DO_NOTHING; Ip6Copy(pDstIp, pSrcIp); - Ip6SrcIpFromScope(scope, pSrcIp); - Ip6DstIpFromDest(ActionGetDestPart(action), pDstIp); + Ip6SrcIpFromScope(scope, pSrcIp); + Ip6DstIpFromDest (ActionGetDestPart(action), pDstIp); *pSize = HEADER_LENGTH + dataLength; @@ -155,8 +153,8 @@ if (!action) return DO_NOTHING; int scope = SCOPE_LOCAL; - Ip6SrcIpFromScope(scope, pSrcIp); - Ip6DstIpFromDest(ActionGetDestPart(action), pDstIp); + Ip6SrcIpFromScope(scope, pSrcIp); + Ip6DstIpFromDest (ActionGetDestPart(action), pDstIp); *pSize = HEADER_LENGTH + dataLength;