IPPOLib
 All Classes Files Functions Variables Typedefs Macros
generaloption.cpp
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 #include "generaloption.h"
30 
36 {
37  _default_value();
38 
39  // Socket
40  if ((_socketudp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
41  {
42  perror("General UDP socket - socket");
43  close(_socketudp);
44  exit(1);
45  }
46 
47  // Enable address reuse
48  int on = 1;
49  int status = 0;
50 
51  if ((status == setsockopt(_socketudp, IPPROTO_IP, IP_TTL, &_ttl, sizeof(_ttl))) < 0)
52  {
53  perror("General UDP socket - setsockopt");
54  close(_socketudp);
55  exit(1);
56  }
57 
58  if ((status == setsockopt(_socketudp, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) < 0)
59  {
60  perror("General UDP socket - setsockopt");
61  close(_socketudp);
62  exit(1);
63  }
64 
65  struct sockaddr_in src_addr;
66 
67  src_addr.sin_family = AF_INET;
68  src_addr.sin_addr.s_addr = htonl(INADDR_ANY);
69  src_addr.sin_port = htons(_src_port);
70 
71  if (bind(_socketudp, (struct sockaddr *)&src_addr, sizeof(src_addr))<0)
72  perror("General UDP socket - bind");
73 }
74 
81 {
82  _default_value();
83  _socketudp = socketudp;
84 }
85 
92 GeneralOption::GeneralOption(int socketudp, pthread_mutex_t lock)
93 {
94  _default_value();
95  _socketudp = socketudp;
96  _lock = lock;
97 }
98 
100 {
101 
102 }
103 
104 /**********************/
106 /**********************/
107 
111 void GeneralOption::_default_value()
112 {
113  _verbose_mode = false;
114 
115  _src_port = 33456;
116  _dst_port = 33457;
117  _retries = 3;
118  _timeout = 2000;
119  _ttl = 255;
120 
121  _ipid = getpid();
122  _protocol_number = 57;
123 
124  _eth = "eth0";
125 
126 }
127 
128 
129 
130 /*********************/
132 /*********************/
133 
140 {
141  return _retries;
142 }
143 
149 void GeneralOption::set_retries(int retries)
150 {
151  _retries = retries;
152 }
153 
160 {
161  return _timeout;
162 }
163 
169 void GeneralOption::set_timeout(int timeout)
170 {
171  _timeout = timeout;
172 }
173 
180 {
181  return _ttl;
182 }
183 
190 {
191  _ttl = ttl;
192 }
193 
200 {
201  return _ipid;
202 }
203 
209 std::string GeneralOption::eth()
210 {
211  return _eth;
212 }
213 
219 void GeneralOption::set_eth(std::string eth)
220 {
221  _eth = eth;
222 }
223 
230 {
231  return _socketudp;
232 }
233 
239 void GeneralOption::set_socketudp(int socketudp)
240 {
241  _socketudp = socketudp;
242 }
243 
249 pthread_mutex_t GeneralOption::lock()
250 {
251  return _lock;
252 }
253 
259 void GeneralOption::set_lock(pthread_mutex_t lock)
260 {
261  _lock = lock;
262 }
263 
270 {
271  return _protocol_number;
272 }
273 
279 void GeneralOption::set_protocol_number(int protocol_number)
280 {
281  _protocol_number = protocol_number;
282 }
283 
290 {
291  return _verbose_mode;
292 }
293 
299 void GeneralOption::set_verbose_mode(bool verbose_mode)
300 {
301  _verbose_mode = verbose_mode;
302 }
303 
310 {
311  return _src_port;
312 }
313 
320 {
321  _src_port = src_port;
322 }
323 
330 {
331  return _dst_port;
332 }
333 
340 {
341  _dst_port = dst_port;
342 }
343