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: eth/eth.cpp
- Revision:
- 42:222a4f45f916
- Parent:
- 37:793b39683406
- Child:
- 43:bc028d5a6424
--- a/eth/eth.cpp Fri Oct 06 10:18:01 2017 +0000 +++ b/eth/eth.cpp Sun Oct 15 17:54:09 2017 +0000 @@ -12,14 +12,14 @@ #define HEADER_SIZE 14 +//header variables __packed struct header { char dst[6]; char src[6]; uint16_t typ; }; - -uint16_t EthProtocol; +static uint16_t protocol; void EthProtocolToString(uint16_t prototype, int size, char* text) { @@ -38,10 +38,10 @@ struct header * pHeader = (header*)pPacket; - MacMake(action, EthProtocol, pHeader->dst); + MacMake(action, protocol, pHeader->dst); MacCopy(pHeader->src, MacLocal); //Put our MAC into the source - pHeader->typ = NetToHost16(EthProtocol); + pHeader->typ = NetToHost16(protocol); *pSize = HEADER_SIZE + dataLength; } @@ -71,11 +71,11 @@ if (!MacAccept(pHeader->dst)) return DO_NOTHING; - EthProtocol = NetToHost16(pHeader->typ); - if (EthProtocol < 1500) return DO_NOTHING; //drop 802.3 messages + protocol = NetToHost16(pHeader->typ); + if (protocol < 1500) return DO_NOTHING; //drop 802.3 messages int action = DO_NOTHING; - switch (EthProtocol) + switch (protocol) { case ARP: action = ArpHandleReceivedPacket(trace, pHeader->src, pData, &dataLength, pHeader->dst); break; case IPV4: action = Ip4HandleReceivedPacket(trace, pHeader->src, pData, &dataLength, pHeader->dst); break; @@ -87,7 +87,7 @@ case 0x8100: break; //Drop Sky Q VLAN 802.1Q packet case 0x887b: break; //Drop Sky Q packet default: - LogTimeF("ETH protocol %d not handled", EthProtocol); + LogTimeF("ETH protocol %d not handled", protocol); break; } @@ -103,25 +103,25 @@ void* pData = (char*)pPacket + HEADER_SIZE; int dataLength = 0; - EthProtocol = 0; + protocol = 0; int action = DO_NOTHING; if (action == DO_NOTHING) { action = ArpPollForPacketToSend(pData, &dataLength); - EthProtocol = ARP; + protocol = ARP; } if (action == DO_NOTHING) { action = Ip6PollForPacketToSend(pData, &dataLength, pHeader->dst); - EthProtocol = IPV6; + protocol = IPV6; } if (action == DO_NOTHING) { action = Ip4PollForPacketToSend(pData, &dataLength, pHeader->dst); - EthProtocol = IPV4; + protocol = IPV4; } finalisePacket(action, dataLength, pPacket, pSize);