IPPOLib
 All Classes Files Functions Variables Typedefs Macros
probereply.h
Go to the documentation of this file.
1 /*
2  * ippo-lib - IP oPtion-based active PrObing
3  * An Active Probing Library for IP Options Equipped probes (http://traffic.comics.unina.it/ippolib)
4  *
5  * Copyright : (C) 2012 by Pietro Marchetta, Walter de Donato, Francesco Cesareo,
6  * Antonio Pescape' (PI)
7  * of the COMICS (COMputer for Interaction and
8  * CommunicationS) Group, Dipartimento di Informatica
9  * e Sistemistica of the University of Napoli "Federico II".
10  *
11  * email : pietro.marchetta@unina.it , walter.dedonato@unina.it , cesareo.francesco@gmail.com
12  * pescape@unina.it
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26  *
27  */
28 
29 #ifndef PROBEREPLY_H
30 #define PROBEREPLY_H
31 
32 #include <string>
33 #include <sstream>
34 
35 #include <netinet/in.h>
36 #include <netinet/ip.h>
37 #include <netinet/ip_icmp.h>
38 #include <netinet/udp.h>
39 #include <netinet/tcp.h>
40 
41 #define MAX_PACKET 1500
42 
43 #define IP_SIZE 20
44 #define IP_SIZE_TS 56
45 
46 #define ICMP 0
47 #define ICMP_SIZE 8
48 
49 #define UDP 1
50 #define UDP_SIZE 8
51 
52 #define TCP_SIZE 20
53 
54 #define NO_RESPONSE -1
55 #define ERROR -8
56 
57 #define TCP_RST_FLAG 60;
58 #define TCP_SYN_ACK 61;
59 #define TCP_UNKNOWN 62;
60 
61 typedef unsigned short uint16;
62 typedef unsigned int uint32;
63 
64 typedef struct TSOption{
65  #if __BYTE_ORDER == __LITTLE_ENDIAN
66  char type;
67  char length;
68  char pointer;
69  char overflag;
70  # elif __BYTE_ORDER == __BIG_ENDIAN
71  char overflag;
72  char pointer;
73  char length;
74  char type;
75  # endif
76 
77  uint32_t ip1;
78  uint32_t ts1;
79 
80  uint32_t ip2;
81  uint32_t ts2;
82 
83  uint32_t ip3;
84  uint32_t ts3;
85 
86  uint32_t ip4;
87  uint32_t ts4;
88 }TSOption;
89 
91 {
92 private:
93 
94  char _probe[MAX_PACKET];
95 
96  uint32 _src_addr_raw;
97  uint32 _dst_addr_raw;
98 
99  int _protocol;
100  int _ihl;
101  int _code;
102  int _subcode;
103  int _scan_result;
104 
105  struct iphdr* _ip_buf;
106  struct icmp * _icmp_buf;
107  struct iphdr* _iperror_buf;
108  struct tcphdr* _tcp_buf;
109 
110  bool _has_response;
111  bool _options;
112 
113  void _dissect();
114  void _dissect_icmp(int offset);
115  void _dissect_iperror(int offset);
116  void _dissect_tcp(int offset);
117 
118  void _set_dst_addr();
119 
120 public:
121  ProbeReply();
122  ~ProbeReply();
123 
124  void set_probe(char probe[MAX_PACKET]);
125 
126  std::string src_addr(); // response IP
128 
129  std::string dst_addr(); // sender IP
131 
132  std::string iperror_dst_addr();
134 
135  uint16 dst_port();
136 
137  int ip_protocol();
138  int iperror_ip_protocol();
139  int ihl();
140  int code();
141  int subcode();
142 
143  bool has_response();
144  bool options(); // true if options
145 
146  bool outer_options(TSOption** opt);
147  bool inner_options(TSOption** opt);
148 
149  char* probe();
150  char* transport_probe();
151  char* payload_probe();
152 
153  int scan_result();
154  void set_scan_result(int scan_result);
155 
156  void print();
157  void reset();
158 };
159 
160 #endif // PROBEREPLY_H