forked from robertdavidgraham/masscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmassip-rangesv6.h
188 lines (164 loc) · 5.08 KB
/
massip-rangesv6.h
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
List of IPv6 ranges.
Sames as the "ranges.h" module, but for IPv6 instead of IPv4.
*/
#ifndef RANGES6_H
#define RANGES6_H
#include "massip-addr.h"
#include <stdio.h>
#include <stdint.h>
struct Range;
/**
* A range of IPv6 ranges.
* Inclusive, so [n..m] includes both 'n' and 'm'.
*/
struct Range6
{
ipv6address begin;
ipv6address end;
};
/**
* An array of ranges in sorted order
*/
struct Range6List
{
struct Range6 *list;
size_t count;
size_t max;
size_t *picker;
unsigned is_sorted:1;
};
/**
* Adds the given range to the targets list. The given range can be a duplicate
* or overlap with an existing range, which will get combined with existing
* ranges.
* @param targets
* A list of IPv6 ranges.
* @param begin
* The first address of the range that'll be added.
* @param end
* The last address (inclusive) of the range that'll be added.
*/
void
range6list_add_range(struct Range6List *targets, ipv6address begin, ipv6address end);
/**
* Removes the given range from the target list. The input range doesn't
* have to exist, or can partial overlap with existing ranges.
* @param targets
* A list of IPv6 ranges.
* @param begin
* The first address of the range that'll be removed.
* @param end
* The last address of the range that'll be removed (inclusive).
*/
void
range6list_remove_range(struct Range6List *targets, const ipv6address begin, const ipv6address end);
/**
* Same as 'rangelist_remove_range()', except the input is a range
* structure instead of a start/stop numbers.
*/
void
range6list_remove_range2(struct Range6List *targets, struct Range6 range);
/**
* Returns 'true' if the indicated IPv6 address is in one of the target
* ranges.
* @param targets
* A list of IPv6 ranges
* @param ip
* An IPv6 address that might in be in the list of ranges
* @return
* 'true' if the ranges contain the item, or 'false' otherwise
*/
int
range6list_is_contains(const struct Range6List *targets, const ipv6address ip);
/**
* Tests if the range is bad/invalid.
* @return 1 is invalid, 0 if good.
*/
int range6_is_bad_address(const struct Range6 *range);
/**
* Remove things from the target list. The primary use of this is the
* "exclude-file" containing a list of IP addresses that we should
* not scan
* @param targets
* Our array of target IP address (or port) ranges that we'll be
* scanning.
* @param excludes
* A list, probably read in from --excludefile, of things that we
* should not be scanning, that will override anything we otherwise
* try to scan.
* @return
* the total number of IP addresses or ports removed.
*/
ipv6address
range6list_exclude( struct Range6List *targets,
const struct Range6List *excludes);
/**
* Counts the total number of IPv6 addresses in the target list. This
* iterates over all the ranges in the table, summing up the count within
* each range.
* @param targets
* A list of IP address or port ranges.
* @return
* The total number of address or ports.
*/
massint128_t
range6list_count(const struct Range6List *targets);
/**
* Given an index in a continuous range of [0...count], pick a corresponding
* number (IP address or port) from a list of non-continuous ranges (not
* necessarily starting from 0). In other words, given the two ranges
* 10-19 50-69
* we'll have a total of 30 possible numbers. Thus, the index goes from
* [0..29], with the values 0..9 picking the corresponding values from the
* first range, and the values 10..29 picking the corresponding values
* from the second range.
*
* NOTE: This is a fundamental part of this program's design, that the user
* can specify non-contiguous IP and port ranges, but yet we iterate over
* them using a monotonically increasing index variable.
*
* @param targets
* A list of IP address ranges, or a list of port ranges (one or the
* other, but not both).
* @param index
* An integer starting at 0 up to (but not including) the value returned
* by 'rangelist_count()' for this target list.
* @return
* an IP address or port corresponding to this index.
*/
ipv6address
range6list_pick(const struct Range6List *targets, uint64_t index);
/**
* Remove all the ranges in the range list.
*/
void
range6list_remove_all(struct Range6List *list);
/**
* Merge two range lists
*/
void
range6list_merge(struct Range6List *list1, const struct Range6List *list2);
/**
* Optimizes the target list, so that when we call "rangelist_pick()"
* from an index, it runs faster. It currently configures this for
* a binary-search, though in the future some more efficient
* algorithm may be chosen.
*/
void
range6list_optimize(struct Range6List *targets);
/**
* Sorts the list of target. We maintain the list of targets in sorted
* order internally even though we scan the targets in random order
* externally.
*/
void
range6list_sort(struct Range6List *targets);
/**
* Does a regression test of this module
* @return
* 0 if the regression test succeeds, or a positive value on failure
*/
int
ranges6_selftest(void);
#endif