-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
103 lines (93 loc) · 2.78 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <stdint.h>
#include "spider_hash_bitmap.h"
//typedef struct {
// uint16_t spider_id;
// uint16_t ipmask_16;
// char *name;
// BITMAP *ip_map;
//}l7_spider_t;
//
//
//int init_spider_ip(ohtal_t *spider_htbl);
//int add_spider_ip(int spider_id, char *spider_name, int ip, int mask, ohtal_t *spider_htbl);
//int del_spider_ip(int spider_id, int ip, int mask, ohtal_t *spider_htbl);
//int check_spider_ip(int spider_id, int ip, ohtal_t *spider_htbl);
//void destory_spider_ip(ohtal_t *spider_htbl);
int main()
{
int mask=30, ret=0;
uint32_t ip;
struct in_addr s;
int spider_id1=1, spider_id2=2;
char *ipn="192.168.0.4";//30
char *ip1="192.168.0.6";
char *ip2="192.168.0.17";
char *spider_name="ccy";
ohtbl_t *g_spider_htbl= (ohtbl_t *)calloc(1, sizeof(ohtbl_t));
ret = init_spider_ip(g_spider_htbl);
if (!ret) {
printf("init spider ip fail\n");
}
printf("init spider ip sucess\n");
//0
if (inet_pton(AF_INET, ipn, (void *)&s) == -1) {
printf("turn ip fail\n");
return -1;
}
ip = ntohl(s.s_addr);
//ip = s.s_addr;
ret = add_spider_ip(spider_id1, spider_name, ip, mask, g_spider_htbl);
if (!ret) {
printf("add spider %d-%s fail\n", spider_id1, ipn);
return -1;
}
printf("add spider %d-0x%x sucess\n", spider_id1, ip);
//1
if (inet_pton(AF_INET, ip1, (void *)&s) == -1) {
printf("turn ip fail\n");
return -1;
}
ip = ntohl(s.s_addr);
//ip = s.s_addr;
printf("check spider %d-0x%x sucess\n", spider_id1, ip);
ret = check_spider_ip(spider_id1, ip, g_spider_htbl);
if (!ret) {
printf("%d-%s not in the spider lib\n", spider_id1, ip1);
} else {
printf("%d-%s in the spider lib\n", spider_id1, ip1);
}
//2
if (inet_pton(AF_INET, ip2, (void *)&s) == -1) {
printf("turn ip fail\n");
return -1;
}
ip = ntohl(s.s_addr);
//ip = s.s_addr;
printf("check spider %d-0x%x sucess\n", spider_id1, ip);
ret = check_spider_ip(spider_id1, ip, g_spider_htbl);
if (!ret) {
printf("%d-%s not in the spider lib\n", spider_id1, ip2);
} else {
printf("%d-%s in the spider lib\n", spider_id1, ip2);
}
//3
if (inet_pton(AF_INET, ip1, (void *)&s) == -1) {
printf("turn ip fail\n");
return -1;
}
ip = ntohl(s.s_addr);
//ip = s.s_addr;
printf("check spider %d-0x%x sucess\n", spider_id2, ip);
ret = check_spider_ip(spider_id2, ip, g_spider_htbl);
if (!ret) {
printf("%d-%s not in the spider lib\n", spider_id2, ip1);
} else {
printf("%d-%s in the spider lib\n", spider_id2, ip1);
}
destory_spider_ip(g_spider_htbl);
return 0;
}