...
|
...
|
@@ -27,8 +27,10 @@
|
27
|
27
|
#include <stdlib.h>
|
28
|
28
|
#include <arpa/inet.h>
|
29
|
29
|
#include <string.h>
|
|
30
|
+#include <unistd.h>
|
30
|
31
|
#include "../../str.h"
|
31
|
32
|
#include "detailed_ip_type.h"
|
|
33
|
+#include "../../dprint.h"
|
32
|
34
|
|
33
|
35
|
static ip4_node IPv4ranges[IPv4RANGES_SIZE] = {
|
34
|
36
|
{ 0xffffffff, "BROADCAST", 0xffffffff }, // 255.255.255.255/32
|
...
|
...
|
@@ -43,10 +45,10 @@ static ip4_node IPv4ranges[IPv4RANGES_SIZE] = {
|
43
|
45
|
{ 0xac100000, "PRIVATE", 0xfffe0000 }, // 172.16/12
|
44
|
46
|
{ 0x64400000, "SHARED", 0xffc00000 }, // 100.64/10
|
45
|
47
|
{ 0x7f000000, "LOOPBACK", 0xff000000 }, // 127.0/8
|
46
|
|
- { 0xa0000000, "PRIVATE", 0xff000000 }, // 10/8
|
|
48
|
+ { 0x0a000000, "PRIVATE", 0xff000000 }, // 10/8
|
47
|
49
|
{ 0x0, "PRIVATE", 0xff000000 }, // 0/8
|
48
|
50
|
{ 0xf0000000, "RESERVED", 0xf0000000 }, // 240/4
|
49
|
|
- { 0xe0000000, "MULTICAST", 0xf0000000 } // 224/4
|
|
51
|
+ { 0xe0000000, "MULTICAST", 0xf0000000 } // 224/4
|
50
|
52
|
};
|
51
|
53
|
|
52
|
54
|
static ip6_node IPv6ranges[IPv6RANGES_SIZE] = {
|
...
|
...
|
@@ -75,10 +77,10 @@ static ip6_node IPv6ranges[IPv6RANGES_SIZE] = {
|
75
|
77
|
{ {0x04000000, 0x00000000, 0x00000000, 0x00000000} , "RESERVED", {0xFC000000, 0x00000000, 0x00000000, 0x00000000} }, //400::/6
|
76
|
78
|
{ {0xF8000000, 0x00000000, 0x00000000, 0x00000000} , "RESERVED", {0xFC000000, 0x00000000, 0x00000000, 0x00000000} }, //F800::/6
|
77
|
79
|
{ {0xF8000000, 0x00000000, 0x00000000, 0x00000000} , "RESERVED", {0xFC000000, 0x00000000, 0x00000000, 0x00000000} }, // F800::/6
|
78
|
|
- { {0x08000000, 0x00000000, 0x00000000, 0x00000000} , "RESERVED", {0xF8000000, 0x00000000, 0x00000000, 0x00000000} }, //0800::/5
|
|
80
|
+ { {0x08000000, 0x00000000, 0x00000000, 0x00000000} , "RESERVED", {0xF8000000, 0x00000000, 0x00000000, 0x00000000} }, //0800::/5
|
79
|
81
|
{ {0xF0000000, 0x00000000, 0x00000000, 0x00000000} , "RESERVED", {0xF8000000, 0x00000000, 0x00000000, 0x00000000} }, // F000::/5
|
80
|
82
|
{ {0xE0000000, 0x00000000, 0x00000000, 0x00000000} , "RESERVED", {0xF0000000, 0x00000000, 0x00000000, 0x00000000} }, // E000::/4
|
81
|
|
- { {0xC0000000, 0x00000000, 0x00000000, 0x00000000} , "RESERVED", {0xE0000000, 0x00000000, 0x00000000, 0x00000000} } // C000::/3
|
|
83
|
+ { {0xC0000000, 0x00000000, 0x00000000, 0x00000000} , "RESERVED", {0xE0000000, 0x00000000, 0x00000000, 0x00000000} } // C000::/3
|
82
|
84
|
};
|
83
|
85
|
|
84
|
86
|
|
...
|
...
|
@@ -98,12 +100,12 @@ int ip6_iptype(str string_ip, char **res)
|
98
|
100
|
((in6_addr[1] & IPv6ranges[i].sub_mask[1]) == IPv6ranges[i].value[1]) &&
|
99
|
101
|
((in6_addr[2] & IPv6ranges[i].sub_mask[2]) == IPv6ranges[i].value[2]) &&
|
100
|
102
|
((in6_addr[3] & IPv6ranges[i].sub_mask[3]) == IPv6ranges[i].value[3])) {
|
101
|
|
-
|
102
|
103
|
*res = IPv6ranges[i].ip_type;
|
|
104
|
+ return 1;
|
103
|
105
|
}
|
104
|
106
|
}
|
105
|
|
-
|
106
|
|
- return 1;
|
|
107
|
+ /* the ip must be in the interval, else there is some problem */
|
|
108
|
+ return 0;
|
107
|
109
|
}
|
108
|
110
|
|
109
|
111
|
int ip4_iptype(str string_ip, char **res)
|
...
|
...
|
@@ -121,35 +123,12 @@ int ip4_iptype(str string_ip, char **res)
|
121
|
123
|
for (i = 0; i < IPv4RANGES_SIZE; i++) {
|
122
|
124
|
if ( (in4_addr & IPv4ranges[i].sub_mask) == IPv4ranges[i].value ) {
|
123
|
125
|
*res = IPv4ranges[i].ip_type;
|
|
126
|
+ return 1;
|
124
|
127
|
}
|
125
|
128
|
}
|
126
|
129
|
return 1;
|
127
|
130
|
}
|
128
|
131
|
|
129
|
|
-/*char* ip6_iptype(str s, uint32_t *ip) {
|
130
|
|
- int i;
|
131
|
|
- for (i = 0; i < IPv6RANGES_SIZE; i++) {
|
132
|
|
- if (((ip[0] & IPv6ranges[i].sub_mask[0]) == IPv6ranges[i].value[0]) &&
|
133
|
|
- ((ip[1] & IPv6ranges[i].sub_mask[1]) == IPv6ranges[i].value[1]) &&
|
134
|
|
- ((ip[2] & IPv6ranges[i].sub_mask[2]) == IPv6ranges[i].value[2]) &&
|
135
|
|
- ((ip[3] & IPv6ranges[i].sub_mask[3]) == IPv6ranges[i].value[3])) {
|
136
|
|
- return IPv6ranges[i].ip_type;
|
137
|
|
- }
|
138
|
|
- }
|
139
|
|
- return "PUBLIC";
|
140
|
|
-}
|
141
|
|
-
|
142
|
|
-char* ip4_iptype(uint32_t ip) {
|
143
|
|
- int i;
|
144
|
|
- for (i = 0; i < IPv4RANGES_SIZE; i++) {
|
145
|
|
- if ( (ip & IPv4ranges[i].sub_mask) == IPv4ranges[i].value ) {
|
146
|
|
- return IPv4ranges[i].ip_type;
|
147
|
|
- }
|
148
|
|
- }
|
149
|
|
- return "PUBLIC";
|
150
|
|
-}
|
151
|
|
-*/
|
152
|
|
-
|
153
|
132
|
void ipv4ranges_hton() {
|
154
|
133
|
int pos;
|
155
|
134
|
uint32_t tmp;
|