]>
Commit | Line | Data |
---|---|---|
b76037eb P |
1 | /* |
2 | * proxyscanext.c: | |
3 | * This file deals with extended ports to scan. | |
4 | */ | |
5 | ||
6 | #include "proxyscan.h" | |
7 | #include <time.h> | |
8 | #include <stdio.h> | |
9 | #include "../core/error.h" | |
10 | #include <string.h> | |
11 | ||
12 | extrascan *addextrascan(unsigned short port, unsigned char type) { | |
13 | extrascan *esp; | |
14 | ||
15 | esp=getextrascan(); | |
16 | esp->port=port; | |
17 | esp->type=type; | |
18 | ||
19 | return esp; | |
20 | } | |
21 | ||
22 | void delextrascan(extrascan *esp) { | |
23 | freeextrascan(esp); | |
24 | } | |
25 | ||
26 | /* | |
27 | * Returns a cachehost * for the named IP | |
28 | */ | |
29 | ||
30 | extrascan *findextrascan(patricia_node_t *node) { | |
31 | extrascan *esp; | |
32 | ||
33 | if( (extrascan *)node->exts[ps_extscan_ext] ) { | |
34 | esp = (extrascan *)node->exts[ps_extscan_ext]; | |
35 | if (esp) { | |
36 | /* valid: return it */ | |
37 | return esp; | |
38 | } | |
39 | } | |
40 | ||
41 | /* Not found: return NULL */ | |
42 | return NULL; | |
43 | } | |
44 | ||
45 | void loadextrascans() { | |
46 | FILE *fp; | |
47 | unsigned short port; | |
48 | char buf[512]; | |
49 | extrascan *esp=NULL; | |
50 | char ip[512]; | |
51 | int res; | |
52 | struct irc_in_addr sin; | |
53 | unsigned char bits; | |
54 | patricia_node_t *node; | |
55 | ||
7eb07f57 | 56 | if ((fp=fopen("data/ports.txt","r"))==NULL) { |
b76037eb P |
57 | Error("proxyscan",ERR_ERROR,"Unable to open ports file for reading!"); |
58 | return; | |
59 | } | |
60 | ||
61 | ||
62 | while (!feof(fp)) { | |
63 | fgets(buf,512,fp); | |
64 | if (feof(fp)) { | |
65 | break; | |
66 | } | |
67 | ||
e56240af | 68 | res=sscanf(buf,"%s %hu",ip,&port); |
b76037eb P |
69 | |
70 | if (res<2) | |
71 | continue; | |
72 | ||
73 | if (0 == ipmask_parse(ip,&sin, &bits)) { | |
74 | /* invalid mask */ | |
75 | } else { | |
76 | node = refnode(iptree, &sin, bits); | |
77 | if( node ) { | |
78 | esp=addextrascan(port, STYPE_SOCKS4); | |
79 | esp->nextbynode = (extrascan *)node->exts[ps_extscan_ext]; | |
80 | node->exts[ps_extscan_ext] = esp; | |
81 | ||
82 | esp=addextrascan(port, STYPE_SOCKS5); | |
83 | esp->nextbynode = (extrascan *)node->exts[ps_extscan_ext]; | |
84 | node->exts[ps_extscan_ext] = esp; | |
85 | ||
86 | esp=addextrascan(port, STYPE_HTTP); | |
87 | esp->nextbynode = (extrascan *)node->exts[ps_extscan_ext]; | |
88 | node->exts[ps_extscan_ext] = esp; | |
89 | } | |
90 | } | |
91 | } | |
92 | } | |
93 | ||
94 | ||
95 | unsigned int extrascancount() { | |
b76037eb P |
96 | unsigned int total=0; |
97 | extrascan *esp; | |
98 | patricia_node_t *node; | |
99 | ||
100 | PATRICIA_WALK (iptree->head, node) { | |
101 | if ( node->exts[ps_extscan_ext] ) { | |
102 | esp = (extrascan *) node->exts[ps_extscan_ext]; | |
103 | if (esp) | |
104 | total++; | |
105 | } | |
106 | } PATRICIA_WALK_END; | |
107 | ||
108 | return total; | |
109 | } | |
110 |