summaryrefslogtreecommitdiff
path: root/src/hosttool.h
blob: 06d03a0114d3457141aa64c071ad83ffb5771d65 (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
/**
 * Module: HostsTool
 * Description: Collects lists of hosts on the network responding to broadcast icmp.
 * This list of hosts are then dispatched for processing of results
 *
 * Author: Michael Larson
 * email: mike(at)lrlart.com
 * Date: August 2004
 **/
#ifndef HOSTSTOOL_HPP_
#define HOSTSTOOL_HPP_

//forward decls
class HostsResult;

//header includes
#include <vector>
#include "Task.hpp"
#include "Test.hpp"
#include "ToolBase.hpp"

/*********************************************
 **           HostsToolKonstants            **
 *********************************************/
class HostsToolKonstants
{
 public:
  static const int packet_data_len_;
  static const int recv_timeout_;
  static const int ip_offset_;
};

/*********************************************
 **                 HostsTool               **
 *********************************************/
class HostsTool : public ToolBase
{
 public:
  /*
   * Constructor and Destructor
   */
  HostsTool(Task<Test> *pCompleteTask, unsigned long local_ip, unsigned long bc_addr_);
  ~HostsTool();

  /*
   * compute test result
   */
   void
     compute();

   /*
    * finished tests
    */
   void
     finish();

   /*
    * send a new test
    */
   void
     send(unsigned long target_addr, unsigned short packet_id);

   /*
    * receive results
    */
   HostsResult*
     receive();
   
 private:
   /*
    * checksum for icmp packets
    */
   unsigned short
     in_checksum(const unsigned short *addr, int len) const;

 private:
   unsigned long local_ip_;
   int send_sock_;
   int recv_sock_;
   unsigned long bc_addr_;
   int packet_id_;
   bool test_in_progress_;
   PERF_MUTEX mutex_;
};

#endif //HOSTSTOOL_HPP_