embkernel
 All Classes Functions Variables Typedefs Groups Pages
NetIcmp.cpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #include "NetIcmp.hpp"
7 #include "NetChecksum.hpp"
8 #include "NetIp.hpp"
9 #include "Net.hpp"
10 
11 void NetIcmp::processFrame(NetDefs::FRAME& frame, NetDefs::ICMP_HEADER& header, int len) {
12  //Reply to Echo Request
13  if (header.type == NetDefs::ICMP_TYPE_ECHO_REQUEST) {
14  frame.types.icmp.icmpHeader.type = NetDefs::ICMP_TYPE_ECHO_REPLY;
15  frame.types.icmp.icmpHeader.checkSum = 0;
16  frame.types.icmp.icmpHeader.checkSum = NetChecksum::finalizeCheckSum(NetChecksum::calcPartialChecksum((uint8_t*) &frame.types.icmp.icmpHeader, len));
17  NetIp::putHeader(frame, frame.types.mac.macHeader.srcAddr, frame.types.ip.ipHeader.srcAddr, len, NetDefs::IP_PROTOCOL_ICMP);
18  NetIp::flush(frame, len, true);
19  }
20  else {
21  Net::freeFrame(frame);
22  }
23 }
24