24 |
|
#include "util_windows.h" |
25 |
|
#include "main.h" |
26 |
|
|
27 |
+ |
#include <list> |
28 |
+ |
using std::list; |
29 |
+ |
|
30 |
+ |
#include <string> |
31 |
+ |
using std::string; |
32 |
+ |
|
33 |
|
BOOL exists( const char *path ) |
34 |
|
{ |
35 |
|
HFILE h; |
59 |
|
if(SetEndOfFile(h)) { |
60 |
|
ok = true; |
61 |
|
if(SetFilePointer( h, 0, NULL, FILE_BEGIN) != 0xFFFFFFFF) { |
62 |
< |
DWORD written, zeroed_size = min(1024*1024,size); |
62 |
> |
DWORD written; |
63 |
> |
DWORD zeroed_size = size; |
64 |
> |
if (zeroed_size > 1024*1024) |
65 |
> |
zeroed_size = 1024*1024; |
66 |
|
char *b = (char *)malloc(zeroed_size); |
67 |
|
if(b) { |
68 |
|
memset( b, 0, zeroed_size ); |
144 |
|
|
145 |
|
return true; |
146 |
|
} |
147 |
+ |
|
148 |
+ |
|
149 |
+ |
/* |
150 |
+ |
* Network control panel helpers |
151 |
+ |
*/ |
152 |
+ |
|
153 |
+ |
struct panel_reg { |
154 |
+ |
string name; |
155 |
+ |
string guid; |
156 |
+ |
}; |
157 |
+ |
|
158 |
+ |
static list<panel_reg> network_registry; |
159 |
+ |
typedef list<panel_reg>::const_iterator network_registry_iterator; |
160 |
+ |
|
161 |
+ |
#define NETWORK_CONNECTIONS_KEY \ |
162 |
+ |
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}" |
163 |
+ |
|
164 |
+ |
static void get_network_registry(void) |
165 |
+ |
{ |
166 |
+ |
LONG status; |
167 |
+ |
HKEY network_connections_key; |
168 |
+ |
DWORD len; |
169 |
+ |
int i = 0; |
170 |
+ |
|
171 |
+ |
if (network_registry.size() > 0) |
172 |
+ |
return; |
173 |
+ |
|
174 |
+ |
status = RegOpenKeyEx( |
175 |
+ |
HKEY_LOCAL_MACHINE, |
176 |
+ |
NETWORK_CONNECTIONS_KEY, |
177 |
+ |
0, |
178 |
+ |
KEY_READ, |
179 |
+ |
&network_connections_key); |
180 |
+ |
|
181 |
+ |
if (status != ERROR_SUCCESS) |
182 |
+ |
return; |
183 |
+ |
|
184 |
+ |
while (true) { |
185 |
+ |
char enum_name[256]; |
186 |
+ |
char connection_string[256]; |
187 |
+ |
HKEY connection_key; |
188 |
+ |
char name_data[256]; |
189 |
+ |
DWORD name_type; |
190 |
+ |
const char name_string[] = "Name"; |
191 |
+ |
|
192 |
+ |
len = sizeof (enum_name); |
193 |
+ |
status = RegEnumKeyEx( |
194 |
+ |
network_connections_key, |
195 |
+ |
i, |
196 |
+ |
enum_name, |
197 |
+ |
&len, |
198 |
+ |
NULL, |
199 |
+ |
NULL, |
200 |
+ |
NULL, |
201 |
+ |
NULL); |
202 |
+ |
if (status != ERROR_SUCCESS) |
203 |
+ |
break; |
204 |
+ |
|
205 |
+ |
snprintf (connection_string, sizeof(connection_string), |
206 |
+ |
"%s\\%s\\Connection", |
207 |
+ |
NETWORK_CONNECTIONS_KEY, enum_name); |
208 |
+ |
|
209 |
+ |
status = RegOpenKeyEx( |
210 |
+ |
HKEY_LOCAL_MACHINE, |
211 |
+ |
connection_string, |
212 |
+ |
0, |
213 |
+ |
KEY_READ, |
214 |
+ |
&connection_key); |
215 |
+ |
|
216 |
+ |
if (status == ERROR_SUCCESS) { |
217 |
+ |
len = sizeof (name_data); |
218 |
+ |
status = RegQueryValueEx( |
219 |
+ |
connection_key, |
220 |
+ |
name_string, |
221 |
+ |
NULL, |
222 |
+ |
&name_type, |
223 |
+ |
(BYTE *)name_data, |
224 |
+ |
&len); |
225 |
+ |
|
226 |
+ |
if (status == ERROR_SUCCESS && name_type == REG_SZ) { |
227 |
+ |
panel_reg pr; |
228 |
+ |
pr.name = name_data; |
229 |
+ |
pr.guid = enum_name; |
230 |
+ |
network_registry.push_back(pr); |
231 |
+ |
} |
232 |
+ |
RegCloseKey (connection_key); |
233 |
+ |
} |
234 |
+ |
++i; |
235 |
+ |
} |
236 |
+ |
|
237 |
+ |
RegCloseKey (network_connections_key); |
238 |
+ |
} |
239 |
+ |
|
240 |
+ |
const char *ether_name_to_guid(const char *name) |
241 |
+ |
{ |
242 |
+ |
get_network_registry(); |
243 |
+ |
|
244 |
+ |
for (network_registry_iterator it = network_registry.begin(); it != network_registry.end(); it++) { |
245 |
+ |
if (strcmp((*it).name.c_str(), name) == 0) |
246 |
+ |
return (*it).guid.c_str(); |
247 |
+ |
} |
248 |
+ |
|
249 |
+ |
return NULL; |
250 |
+ |
} |
251 |
+ |
|
252 |
+ |
const char *ether_guid_to_name(const char *guid) |
253 |
+ |
{ |
254 |
+ |
get_network_registry(); |
255 |
+ |
|
256 |
+ |
for (network_registry_iterator it = network_registry.begin(); it != network_registry.end(); it++) { |
257 |
+ |
if (strcmp((*it).guid.c_str(), guid) == 0) |
258 |
+ |
return (*it).name.c_str(); |
259 |
+ |
} |
260 |
+ |
|
261 |
+ |
return NULL; |
262 |
+ |
} |