Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -1180,10 +1180,11 @@ AC_SUBST(USE_SRCS_SOCKETS, '${SRCS_SOCKETS}') AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket") AC_CHECK_LIB(network, socket, LIBS="$LIBS -lnetwork") AC_CHECK_LIB(ws2_32, main, LIBS="$LIBS -lws2_32") + AC_CHECK_LIB(iphlpapi, main, LIBS="$LIBS -liphlpapi") AC_CHECK_HEADER(sys/socket.h, [ AC_DEFINE(OF_HAVE_SYS_SOCKET_H, 1, [Whether we have sys/socket.h]) ]) Index: src/OFDNSResolver.m ================================================================== --- src/OFDNSResolver.m +++ src/OFDNSResolver.m @@ -30,16 +30,27 @@ #ifdef OF_WINDOWS # import "OFWindowsRegistryKey.h" #endif #import "OFOpenItemFailedException.h" + +#ifdef OF_WINDOWS +# define interface struct +# include +# 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) @@ -103,12 +114,17 @@ # 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]; @@ -214,10 +230,11 @@ _staticHosts = [staticHosts copy]; objc_autoreleasePoolPop(pool); } +# ifndef OF_WINDOWS - (void)of_parseResolvConf: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFCharacterSet *whitespaceCharacterSet = [OFCharacterSet whitespaceCharacterSet]; @@ -307,7 +324,48 @@ 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