-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutiles.cpp
More file actions
200 lines (160 loc) · 3.37 KB
/
Copy pathutiles.cpp
File metadata and controls
200 lines (160 loc) · 3.37 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "utiles.h"
#include <Windows.h>
#include "stdio.h"
#include <stdarg.h>
#include <process.h>
#define __DEBUG__
void _sshwp_debug( char * fmt, ... )
{
#ifdef __DEBUG__
if ( !OPENDEBUG )
return;
va_list valist;
int argn = 0;
char *para = NULL;
va_start( valist, fmt );
//printf("[debug: file: %s, line: %d] ", __FILE__, __LINE__ );
vprintf( fmt, valist );
va_end( valist );
#endif
}
void _sshwp_show( char * fmt, ... )
{
va_list valist;
int argn = 0;
char *para = NULL;
va_start( valist, fmt );
vprintf( fmt, valist );
va_end( valist );
}
int node_malloc( PIP_LIST * node )
{
*node = (PIP_LIST)malloc( sizeof( IP_LIST ) );
if ( * node == NULL )
return -1;
return 0;
}
int copy_node( PIP_LIST * node, char * ip )
{
if ( node_malloc( node ) == 0 )
{
strcpy( (*node)->ip, ip );
return 0;
}
return -1;
}
void del_node( PIP_LIST * head, char * ip )
{
PIP_LIST p;
PIP_LIST p2;
PIP_LIST frp = NULL;
p = *head;
p2 = p->next;
if ( strcmp( (*head)->ip, ip ) == 0 )
{
frp = *head;
*head = (*head)->next;
free(frp);
return;
}
while( p2->next != NULL )
{
if( strcmp( p2->ip, ip ) == 0 )
{
frp = p2;
p->next = p2->next;
free(frp);
break;
}
p = p->next;
p2 = p2->next;
}
}
bool get_one_node( PIP_LIST * head, char *ip )
{
PIP_LIST p = *head;
if ( *head )
strcpy( ip, (*head)->ip );
else
return false;
if ( (*head)->next != NULL )
*head = (*head)->next;
else
*head = NULL;
if (p)
free(p);
return true;
}
int checkip( char * ip )
{
int i = 0;
char *p = NULL;
char ip_check[16] = {0};
strcpy( ip_check, ip );
while( (i++) <= 4 )
{
p = strchr(ip_check, '.');
if ( !p )
return 0;
p + 1;
strcpy( ip_check, p );
}
return 1;
}
PIP_LIST ipsplit( char * ip_bnet )
{
char netb[16] = {0};
char ip[16] = {0};
strcpy ( netb, ip_bnet );
char *p = NULL;
p = strchr( netb, '.' );
if ( !p )
{
_sshwp_debug( "ip parse failed.");
goto err;
}
if ( strchr( p + 1, '.') )
{
PIP_LIST t;
copy_node( &t, ip_bnet );
t->next = NULL;
return t;
}
*p = 0;
int net1 = 0;
int net2 = 0;
net1 = atoi( netb );
net2 = atoi( p + 1 );
long start = 0;
long end = 0;
start = 1 | 0 << 8 | net2 << 16 | net1 << 24;
end = 255 | 255 << 8 | net2 << 16 | net1 << 24;
PIP_LIST iphead = NULL;
PIP_LIST pip = NULL;
PIP_LIST pip2 = NULL;
for ( ;start != end; start++ )
{
//if ( (byte)(start) == 255 || (byte)(start) == 0 )
// continue;
sprintf( ip, "%d.%d.%d.%d",
(byte)(start >> 24), (byte)(start >> 16),
(byte)(start >> 8), (byte)(start) );
// create ip list
if ( iphead == NULL )
{
if ( copy_node( &pip, ip ) == -1 )
goto err;
iphead = pip;
}
else
{
if ( copy_node( &pip->next, ip ) == -1 )
goto err;
pip = pip->next;
}
}
pip->next = NULL;
return iphead;
err:
return NULL;
}