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: ip4/ip4.cpp
- Revision:
- 53:77f8a49adf89
- Parent:
- 50:492f2d2954e4
- Child:
- 57:e0fb648acf48
--- a/ip4/ip4.cpp Wed Nov 08 20:46:36 2017 +0000 +++ b/ip4/ip4.cpp Thu Nov 09 15:44:29 2017 +0000 @@ -17,6 +17,8 @@ #define HEADER_LENGTH 20 +#define OFF_LINK_TTL 64 + __packed struct header { uint8_t versionIhl; @@ -174,9 +176,17 @@ } if (!action) return DO_NOTHING; - if (DhcpIpNeedsToBeRouted(dstIp)) Ar4IpToMac(DhcpRouter, pDstMac); //Send back to the router - else MacCopy(pDstMac, pSrcMac); //Send back to the source - + if (DhcpIpNeedsToBeRouted(dstIp)) + { + Ar4IpToMac(DhcpRouter, pDstMac); //Send back to the router + ttl = OFF_LINK_TTL; + } + else + { + MacCopy(pDstMac, pSrcMac); //Send back to the source + ttl = 255; + } + writeHeader(pHeader); *pSize = headerLength + dataLength; @@ -196,7 +206,6 @@ dontFragment = true; moreFragments = false; offset = 0; - ttl = 255; protocol = UDP; int action = DO_NOTHING; @@ -209,18 +218,27 @@ case UNICAST_DNS: case UNICAST_DHCP: case UNICAST_NTP: - if (DhcpIpNeedsToBeRouted(dstIp)) Ar4IpToMac(DhcpRouter, pDstMac); //send via router - else Ar4IpToMac(dstIp, pDstMac); //Send direct + if (DhcpIpNeedsToBeRouted(dstIp)) + { + Ar4IpToMac(DhcpRouter, pDstMac); //send via router + ttl = OFF_LINK_TTL; + } + else + { + Ar4IpToMac(dstIp, pDstMac); //Send direct + ttl = 255; + } break; case MULTICAST_NODE: case MULTICAST_ROUTER: case MULTICAST_MDNS: case MULTICAST_LLMNR: case BROADCAST: + ttl = 255; break; default: LogTimeF("Ip4PollForPacketToSend - undefined destination %d\r\n", dest); - break; + return DO_NOTHING; } writeHeader((header*)pPacket);