![]() |
ICMPTwistSocket.hGo to the documentation of this file.00001 00006 /* 00007 Copyright (C) 2004 Anders Hedstrom 00008 Parts Copyright (c) Vergil of Ragestorm.net, 2003 00009 00010 This program is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU General Public License 00012 as published by the Free Software Foundation; either version 2 00013 of the License, or (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00023 */ 00024 #ifndef _ICMPTWISTSOCKET_H 00025 #define _ICMPTWISTSOCKET_H 00026 00027 #include "Socket.h" 00028 00029 00030 /* ICMP_TWIST.C: A program intended to demonstrate the usage 00031 * of ICMP Information Request (Type 15) messages. 00032 * What this program does and does not do: 00033 * It DOES implement an ICMP chat using raw sockets and Type 15 messages. 00034 * It DOES manipulate UNIX file system descriptors in creative ways. 00035 * It uses poll() (but not select()), a good call if we want to multiplex 00036 * input and output 00037 * It does NOT use the kernel headers for defining ICMP structs etc. 00038 * (see <linux/icmp.h> 00039 * It does NOT compile under Windows, although changes to allow that 00040 * would be minor. 00041 */ 00042 00043 // ICMP codes 00044 #define ICMP_INFO_REQUEST 15 00045 #define ICMP_INFO_REPLY 16 00046 00047 /* Should be between 530 and 1450 (MTU always >= 576, and in most 00048 * cases < 1500); 14 bytes go for the Ethernet header, 20 for the IP header 00049 * and 8 for the ICMP header. Fragmentation is not [yet] implemented 00050 */ 00051 #define INP_BUFFER 256 00052 00053 struct icmp_info // reply and request 00054 { 00055 uint8_t type; 00056 uint8_t code; 00057 uint16_t checksum; 00058 uint16_t id; 00059 uint16_t seq_no; 00060 char buffer[INP_BUFFER]; 00061 }; 00062 00063 00064 class ICMPTwistSocket : public Socket 00065 { 00066 public: 00067 ICMPTwistSocket(ISocketHandler& ); 00068 ~ICMPTwistSocket(); 00069 00070 void OnRead(); 00071 00072 void Connect(const std::string& ); 00073 void Send(const std::string& ); 00074 00075 void OnOptions(int,int,int,SOCKET) {} 00076 00077 private: 00078 uint16_t calc_crc(uint8_t * packet, size_t len); 00079 struct icmp_info m_info; 00080 uint16_t m_seq_no; 00081 }; 00082 00083 00084 #endif // _ICMPTWISTSOCKET_H |