Changeset 43673 in vbox for trunk/src/VBox/Devices/Network/slirp
- Timestamp:
- Oct 17, 2012 5:02:43 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 81471
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/slirp_dns.c
r43663 r43673 178 178 } 179 179 180 static int slirpOpenResolvConfFile(PRTFILE pResolvConfFile) 181 { 182 int rc; 183 char buff[512]; 184 char *etc = NULL; 185 char *home = NULL; 186 AssertPtrReturn(pResolvConfFile, VERR_INVALID_PARAMETER); 187 # ifdef RT_OS_OS2 188 /* Try various locations. */ 189 NOREF(home); 190 etc = getenv("ETC"); 191 if (etc) 192 { 193 RTStrmPrintf(buff, sizeof(buff), "%s/RESOLV2", etc); 194 rc = RTFileOpen(pResolvConfFile, buff, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 195 } 196 if (RT_FAILURE(rc)) 197 { 198 RTStrmPrintf(buff, sizeof(buff), "%s/RESOLV2", _PATH_ETC); 199 rc = RTFileOpen(pResolvConfFile, buff, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 200 } 201 if (RT_FAILURE(rc)) 202 { 203 RTStrmPrintf(buff, sizeof(buff), "%s/resolv.conf", _PATH_ETC); 204 rc = RTFileOpen(pResolvConfFile, buff, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 205 } 206 # else /* !RT_OS_OS2 */ 207 # ifndef DEBUG_vvl 208 rc = RTFileOpen(pResolvConfFile, "/etc/resolv.conf", RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 209 # else 210 NOREF(etc); 211 home = getenv("HOME"); 212 RTStrPrintf(buff, sizeof(buff), "%s/resolv.conf", home); 213 rc = RTFileOpen(pResolvConfFile, buff, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 214 if (RT_SUCCESS(rc)) 215 Log(("NAT: DNS we're using %s\n", buff)); 216 else 217 { 218 rc = RTFileOpen(pResolvConfFile, "/etc/resolv.conf", RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 219 Log(("NAT: DNS we're using %s\n", buff)); 220 } 221 # endif 222 # endif /* !RT_OS_OS2 */ 223 return rc; 224 } 180 225 static int get_dns_addr_domain(PNATState pData, const char **ppszDomain) 181 226 { 182 char buff[ 512];227 char buff[256]; 183 228 char buff2[256]; 184 RTFILE f;229 RTFILE ResolvConfFile; 185 230 int cNameserversFound = 0; 186 231 bool fWarnTooManyDnsServers = false; … … 189 234 size_t bytes; 190 235 191 # ifdef RT_OS_OS2 192 /* Try various locations. */ 193 char *etc = getenv("ETC"); 194 if (etc) 195 { 196 RTStrmPrintf(buff, sizeof(buff), "%s/RESOLV2", etc); 197 rc = RTFileOpen(&f, buff, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 198 } 236 rc = slirpOpenResolvConfFile(&ResolvConfFile); 199 237 if (RT_FAILURE(rc)) 200 238 { 201 RTStrmPrintf(buff, sizeof(buff), "%s/RESOLV2", _PATH_ETC); 202 rc = RTFileOpen(&f, buff, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 203 } 204 if (RT_FAILURE(rc)) 205 { 206 RTStrmPrintf(buff, sizeof(buff), "%s/resolv.conf", _PATH_ETC); 207 rc = RTFileOpen(&f, buff, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 208 } 209 # else /* !RT_OS_OS2 */ 210 # ifndef DEBUG_vvl 211 rc = RTFileOpen(&f, "/etc/resolv.conf", RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 212 # else 213 char *home = getenv("HOME"); 214 RTStrPrintf(buff, sizeof(buff), "%s/resolv.conf", home); 215 rc = RTFileOpen(&f, buff, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 216 if (RT_SUCCESS(rc)) 217 Log(("NAT: DNS we're using %s\n", buff)); 218 else 219 { 220 rc = RTFileOpen(&f, "/etc/resolv.conf", RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 221 Log(("NAT: DNS we're using %s\n", buff)); 222 } 223 # endif 224 # endif /* !RT_OS_OS2 */ 225 if (RT_FAILURE(rc)) 226 return -1; 239 LogRel(("NAT: there're some problems with accessing resolv.conf (or known analog), thus NAT switches to use host resolver mechanism\n")); 240 pData->fUseHostResolver = 1; 241 return VINF_SUCCESS; 242 } 227 243 228 244 if (ppszDomain) … … 230 246 231 247 Log(("NAT: DNS Servers:\n")); 232 while ( RT_SUCCESS(rc = RTFileGets( f, buff, sizeof(buff), &bytes))248 while ( RT_SUCCESS(rc = RTFileGets(ResolvConfFile, buff, sizeof(buff), &bytes)) 233 249 && rc != VERR_EOF) 234 250 { … … 306 322 } 307 323 } 308 RTFileClose( f);324 RTFileClose(ResolvConfFile); 309 325 if (!cNameserversFound) 310 326 return -1;
Note:
See TracChangeset
for help on using the changeset viewer.