]>
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 | ||
56 | if ((fp=fopen("ports.txt","r"))==NULL) { | |
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 | ||
68 | res=sscanf(buf,"%s %hu",&ip,&port); | |
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() { | |
96 | int i; | |
97 | unsigned int total=0; | |
98 | extrascan *esp; | |
99 | patricia_node_t *node; | |
100 | ||
101 | PATRICIA_WALK (iptree->head, node) { | |
102 | if ( node->exts[ps_extscan_ext] ) { | |
103 | esp = (extrascan *) node->exts[ps_extscan_ext]; | |
104 | if (esp) | |
105 | total++; | |
106 | } | |
107 | } PATRICIA_WALK_END; | |
108 | ||
109 | return total; | |
110 | } | |
111 |