friendev EtherDune TCP/IP library
/home/jander/temp/etherdune/ICMPPinger.cpp
Go to the documentation of this file.
1 // EtherDune ICMP Pinger class
2 // Author: Javier Peletier <jm@friendev.com>
3 // Summary: Implements an ICMP Echo request service
4 //
5 // Copyright (c) 2015 All Rights Reserved, http://friendev.com
6 //
7 // This source is subject to the GPLv2 license.
8 // Please see the License.txt file for more information.
9 // All other rights reserved.
10 //
11 // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
12 // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13 // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
14 // PARTICULAR PURPOSE.
15 
16 #include "ICMPPinger.h"
17 
18 bool ICMPPinger::onICMPMessage()
19 {
21  return false;
22 
23  if (!loadAll())
24  return true; //checksum error, drop packet.
25 
26  uint8_t len = ICMP_PING_DATA_LENGTH;
27  for (uint8_t* ptr = (uint8_t*)(&packet.icmp) + sizeof(ICMPHeader); len > 0; len--, ptr++)
28  {
29  if (*ptr != 0x79)
30  return true;
31  }
32 
33  onPingReply(millis() - packet.icmp.timestamp);
34  return true;
35 }
36 
37 
44 void ICMPPinger::ping(const IPAddress& targetIP)
45 {
46  memset(packet.icmp.dataStart(), 0x79, ICMP_PING_DATA_LENGTH);
48  packet.icmp.code = 0;
49  packet.icmp.timestamp = millis();
50 
51  packet.icmp.checksum = 0;
52 
54 }
uint16_t checksum
Error checking data.
Definition: inet.h:435
static const uint8_t ICMP_TYPE_ECHOREPLY
ICMP echo reply operation type.
Definition: inet.h:574
ICMPHeader icmp
Definition: inet.h:509
bool loadAll()
Loads the entire ICMP packet into memory.
Definition: ICMP.cpp:40
static EthBuffer packet
in-memory packet buffer currently being processed.
virtual void onPingReply(uint16_t roundtripTime)=0
represents an IP address in memory
Definition: inet.h:181
void ping(const IPAddress &targetIP)
Send an ICMP Echo request (ping) to the specified target IP address.
Definition: ICMPPinger.cpp:44
uint8_t code
ICMP subtype.
Definition: inet.h:434
static const uint8_t ICMP_TYPE_ECHOREQUEST
ICMP echo request operation type.
Definition: inet.h:575
uint8_t type
ICMP type.
Definition: inet.h:433
ICMP Header and Echo request/reply.
Definition: inet.h:431
void sendICMPPacket(const IPAddress &targetIP, uint16_t dataLength)
Sends an ICMP packet
Definition: ICMP.cpp:69
uint32_t timestamp
convenient merge of both identifier and sequence number to use as storage for millis() ...
Definition: inet.h:443
uint8_t * dataStart()
Points to the beginning of the ICMP echo data.
Definition: inet.h:450
static const uint8_t ICMP_PING_DATA_LENGTH
size of data to send as part of an echo request
Definition: config.h:229