1 /* 2 * Hans - IP over ICMP 3 * Copyright (C) 2009 Friedrich Schöller <hans@schoeller.se> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 #ifndef ECHO_H 21 #define ECHO_H 22 23 #include <string> 24 #include <stdint.h> 25 26 class Echo 27 { 28 public: 29 Echo(int maxPayloadSize); 30 ~Echo(); 31 getFd()32 int getFd() { return fd; } 33 34 void send(int payloadLength, uint32_t realIp, bool reply, uint16_t id, uint16_t seq); 35 int receive(uint32_t &realIp, bool &reply, uint16_t &id, uint16_t &seq); 36 sendPayloadBuffer()37 char *sendPayloadBuffer() { return sendBuffer + headerSize(); } receivePayloadBuffer()38 char *receivePayloadBuffer() { return receiveBuffer + headerSize(); } 39 40 static int headerSize(); 41 protected: 42 struct EchoHeader 43 { 44 uint8_t type; 45 uint8_t code; 46 uint16_t chksum; 47 uint16_t id; 48 uint16_t seq; 49 }; // size = 8 50 51 uint16_t icmpChecksum(const char *data, int length); 52 53 int fd; 54 int bufferSize; 55 char *sendBuffer, *receiveBuffer; 56 }; 57 58 #endif 59