hans/echo.h
Friedrich Schöller f20f1d50df initial commit
2009-07-22 23:28:52 +02:00

58 lines
1.4 KiB
C++

/*
* Hans - IP over ICMP
* Copyright (C) 2009 Friedrich Schöller <friedrich.schoeller@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ECHO_H
#define ECHO_H
#include <string>
#include <stdint.h>
class Echo
{
public:
Echo(int maxPayloadSize);
~Echo();
int getFd() { return fd; }
void send(int payloadLength, uint32_t realIp, bool reply, int id, int seq);
int receive(uint32_t &realIp, bool &reply, int &id, int &seq);
char *payloadBuffer() { return buffer + headerSize(); }
static int headerSize();
protected:
struct EchoHeader
{
uint8_t type;
uint8_t code;
uint16_t chksum;
uint16_t id;
uint16_t seq;
}; // size = 8
uint16_t icmpChecksum(const char *data, int length);
int fd;
int bufferSize;
char *buffer;
};
#endif