28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
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
|
+
+
+
+
+
+
+
+
+
+
+
|
#import "OFLocalization.h"
#import "OFString.h"
#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif
#import "OFOpenItemFailedException.h"
#ifdef OF_WINDOWS
# define interface struct
# include <iphlpapi.h>
# undef interface
#endif
@interface OFDNSResolver ()
#ifdef OF_HAVE_FILES
- (void)of_parseHosts: (OFString *)path;
# ifndef OF_WINDOWS
- (void)of_parseResolvConf: (OFString *)path;
- (void)of_parseResolvConfOption: (OFString *)option;
# endif
#endif
#ifdef OF_WINDOWS
- (void)of_parseNetworkParams;
#endif
@end
static OFString *
domainFromHostname(void)
{
char hostname[256];
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
+
+
+
+
+
|
# elif defined(OF_AMIGAOS4)
[self of_parseHosts: @"DEVS:Internet/hosts"];
# elif defined(OF_AMIGAOS)
[self of_parseHosts: @"AmiTCP:db/hosts"];
# else
[self of_parseHosts: @"/etc/hosts"];
# endif
# ifndef OF_WINDOWS
[self of_parseResolvConf: @"/etc/resolv.conf"];
[self of_parseResolvConf: @"/etc/resolv.conf.tail"];
# endif
#endif
#ifdef OF_WINDOWS
[self of_parseNetworkParams];
#endif
if (_staticHosts == nil)
_staticHosts = [[OFDictionary alloc] init];
if (_nameServers == nil)
_nameServers = [[OFArray alloc] initWithObjects:
|
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
+
|
[_staticHosts release];
_staticHosts = [staticHosts copy];
objc_autoreleasePoolPop(pool);
}
# ifndef OF_WINDOWS
- (void)of_parseResolvConf: (OFString *)path
{
void *pool = objc_autoreleasePoolPush();
OFCharacterSet *whitespaceCharacterSet =
[OFCharacterSet whitespaceCharacterSet];
OFCharacterSet *commentCharacters = [OFCharacterSet
characterSetWithCharactersInString: @"#;"];
|
305
306
307
308
309
310
311
312
313
|
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
(size_t)[option decimalValue];
} @catch (id e) {
return;
}
} else if ([option isEqual: @"tcp"])
_usesTCP = true;
}
# endif
#endif
#ifdef OF_WINDOWS
- (void)of_parseNetworkParams
{
void *pool = objc_autoreleasePoolPush();
of_string_encoding_t encoding = [OFLocalization encoding];
OFMutableArray *nameServers;
OFString *localDomain;
/*
* We need more space than FIXED_INFO in case we have more than one
* name server, but we also want it to be properly aligned, meaning we
* can't just get a buffer of bytes. Thus, we just get space for 8.
*/
FIXED_INFO fixedInfo[8];
ULONG length = sizeof(fixedInfo);
PIP_ADDR_STRING iter;
if (GetNetworkParams(fixedInfo, &length) != ERROR_SUCCESS)
return;
nameServers = [OFMutableArray array];
localDomain = [OFString stringWithCString: fixedInfo->DomainName
encoding: encoding];
for (iter = &fixedInfo->DnsServerList; iter != NULL; iter = iter->Next)
[nameServers addObject:
[OFString stringWithCString: iter->IpAddress.String
encoding: encoding]];
if ([nameServers count] > 0) {
[nameServers makeImmutable];
_nameServers = [nameServers copy];
}
if ([localDomain length] > 0)
_localDomain = [localDomain copy];
objc_autoreleasePoolPop(pool);
}
#endif
@end
|