-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathranges.h
More file actions
40 lines (30 loc) · 1.66 KB
/
ranges.h
File metadata and controls
40 lines (30 loc) · 1.66 KB
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
#ifndef RANGES_H
#define RANGES_H
#include "config.h"
/* ─── external lists ──────────────────────────────────────────── */
extern ip_range_t *g_blacklist;
extern int g_blacklist_count;
extern ip_range_t *g_whitelist;
extern int g_whitelist_count;
/* ─── global / BR ranges ──────────────────────────────────────── */
extern const ip_range_t GLOBAL_RANGES[];
extern const int GLOBAL_RANGES_COUNT;
extern const ip_range_t BR_RANGES[];
extern const int BR_RANGES_COUNT;
/* ─── API ─────────────────────────────────────────────────────── */
/* CIDR string → allocated array of ip_range_t (returns count) */
int parse_ip_range (const char *cidr, ip_range_t **out);
/* "80,443,8080-8090" → allocated array of port_range_t */
int parse_port_range(const char *spec, port_range_t **out);
int load_range_file(const char *path, ip_range_t **out, int *cnt);
uint64_t calculate_total_ips(const ip_range_t *ranges, int n);
uint32_t get_ip_from_index (uint64_t idx,
const ip_range_t *ranges, int n);
/* is_blacklisted / is_whitelisted — host byte order */
int is_blacklisted(uint32_t ip);
int is_whitelisted(uint32_t ip);
/* helpers */
uint32_t ip_to_int (const char *s);
void int_to_ip (uint32_t ip, char *buf); /* buf >= 16 */
uint64_t parse_scaled_value(const char *s); /* "100M", "1G" … */
#endif /* RANGES_H */