1 /*
2  * NAXSI, a web application firewall for NGINX
3  * Copyright (C) NBS System – All Rights Reserved
4  * Licensed under GNU GPL v3.0 – See the LICENSE notice for details
5  */
6 
7 #ifndef __NAXSI_NET_H__
8 #define __NAXSI_NET_H__
9 
10 #if defined(__DragonFly__)
11 #include <netinet/in.h>
12 #include <sys/socket.h>
13 #include <sys/types.h>
14 #endif
15 
16 #include <arpa/inet.h>
17 #include <stdint.h>
18 #include <string.h>
19 
20 typedef union
21 {
22   uint64_t v6[2];
23   uint32_t v4;
24 } ip_t;
25 
26 typedef enum
27 {
28   IPv4 = 0,
29   IPv6
30 } ip_type_t;
31 
32 typedef struct
33 {
34   uint32_t version;
35   ip_t     mask;
36   ip_t     subnet;
37 } cidr_t;
38 
39 int
40 parse_ipv6(const char* addr, ip_t* ip, char* ip_str);
41 int
42 parse_ipv4(const char* addr, ip_t* ip, char* ip_str);
43 
44 int
45 is_in_subnet(const cidr_t* cidr, const ip_t* ip, int is_ipv6);
46 
47 #endif /* __NAXSI_NET_H__ */
48