summaryrefslogtreecommitdiff
path: root/src/lbtest_ttl.hh
blob: 5d49dc240f49a332a7275d5b77f1b3f7e10ddb90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Module: lbtest_ttl.hh
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation.
 */
#ifndef __LBTEST_TTL_HH__
#define __LBTEST_TTL_HH__

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <iostream>
#include "lbtest.hh"

using namespace std;

/**
 *
 *
 **/
class LBTestTTL : public LBTest 
{
public:
  LBTestTTL(bool debug) : 
    LBTest(debug),
    _ttl(0),
    _port(0),
    _min_port_id(32767),
    _max_port_id(55000)
  {}
  LBTestTTL(bool debug, unsigned short ttl, unsigned short port) : 
    LBTest(debug),
    _ttl(ttl),
    _port(port),
    _min_port_id(32767),
    _max_port_id(55000)
  {}
  ~LBTestTTL() {}

  void
  init() {_status_line=name();}

  void
  send(LBHealth &health);

  unsigned short
  get_ttl() const {return _ttl;}

  unsigned short
  get_port() const {return _port;}

  void
  set_ttl(unsigned short ttl) {_ttl = ttl;}

  void
  set_port(unsigned short port) {_port = port;}

  string
  dump();

  string
  name() {return string("ttl");}

private:
  unsigned short
  udp_checksum(unsigned char ucProto, char *pPacket, int iLength, unsigned long ulSourceAddress, unsigned long ulDestAddress);

  unsigned short
  in_checksum(unsigned short *pAddr, int iLen);

  void
  send(int sock, const string &iface, const string &target_addr, unsigned short packet_id, string address, int ttl, unsigned short port);

  unsigned short
  get_new_packet_id();



private:
  unsigned short _ttl;
  unsigned short _port;
  unsigned short _min_port_id;
  unsigned long _max_port_id;
};

#endif //__LBTEST_TTL_HH__