slirp_dns.c revision 55c6dd0c4e495858f1681a45e28e04c791ef066e
/* $Id$ */
/** @file
* NAT - dns initialization.
*/
/*
* Copyright (C) 2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "slirp.h"
#ifdef RT_OS_OS2
# include <paths.h>
#endif
#ifdef RT_OS_WINDOWS
# include <Winnls.h>
# define _WINSOCK2API_
# include <IPHlpApi.h>
const char **ppszDomain)
{
ULONG flags = GAA_FLAG_INCLUDE_PREFIX; /*GAA_FLAG_INCLUDE_ALL_INTERFACES;*/ /* all interfaces registered in NDIS */
int wlen = 0;
char *pszSuffix;
/* @todo add SKIPing flags to get only required information */
/* determine size of buffer */
size = 0;
if (ret != ERROR_BUFFER_OVERFLOW)
{
return -1;
}
if (size == 0)
{
Log(("NAT: Win socket API returns non capacity\n"));
return -1;
}
if (!pAdapterAddr)
{
Log(("NAT: No memory available\n"));
return -1;
}
if (ret != ERROR_SUCCESS)
{
return -1;
}
{
int found;
continue;
{
continue;
/* add dns server to list */
if (!pDns)
{
Log(("NAT: Can't allocate buffer for DNS entry\n"));
return VERR_NO_MEMORY;
}
else
continue;
/* uniq */
{
continue;
}
found = 0;
{
{
found = 1;
break;
}
}
if (!found)
{
if (!pDomain)
{
Log(("NAT: not enough memory\n"));
return VERR_NO_MEMORY;
}
}
}
}
return 0;
}
#else /* !RT_OS_WINDOWS */
{
char bTest;
int rc = VERR_NO_MEMORY;
*pcbRead = 0;
{
if (cbRead == 0)
return VERR_EOF;
{
*pu8Buf = 0;
return VINF_SUCCESS;
}
pu8Buf++;
(*pcbRead)++;
}
return rc;
}
{
int rc;
char buff[512];
# ifdef RT_OS_OS2
/* Try various locations. */
if (etc)
{
}
if (RT_FAILURE(rc))
{
}
if (RT_FAILURE(rc))
{
}
# else /* !RT_OS_OS2 */
# ifndef DEBUG_vvl
rc = RTFileOpen(pResolvConfFile, "/etc/resolv.conf", RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
# else
if (RT_SUCCESS(rc))
else
{
rc = RTFileOpen(pResolvConfFile, "/etc/resolv.conf", RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
}
# endif
# endif /* !RT_OS_OS2 */
return rc;
}
{
char buff[256];
char buff2[256];
int cNameserversFound = 0;
bool fWarnTooManyDnsServers = false;
int rc;
if (RT_FAILURE(rc))
{
LogRel(("NAT: there're some problems with accessing resolv.conf (or known analog), thus NAT switches to use host resolver mechanism\n"));
return VINF_SUCCESS;
}
if (ppszDomain)
*ppszDomain = NULL;
Log(("NAT: DNS Servers:\n"));
{
if ( cNameserversFound == 4
{
fWarnTooManyDnsServers = true;
LogRel(("NAT: too many nameservers registered.\n"));
}
{
continue;
/* localhost mask */
if (!pDns)
{
Log(("can't alloc memory for DNS entry\n"));
return -1;
}
/* check */
if ((pDns->de_addr.s_addr & RT_H2N_U32_C(IN_CLASSA_NET)) == RT_N2H_U32_C(INADDR_LOOPBACK & IN_CLASSA_NET))
{
else
{
/* Modern Ubuntu register 127.0.1.1 as DNS server */
LogRel(("NAT: DNS server %RTnaipv4 registration detected, switching to the host resolver.\n",
/* Releasing fetched DNS information. */
return VINF_SUCCESS;
}
}
}
{
char *tok;
char *saveptr;
int fFoundDomain = 0;
{
{
fFoundDomain = 1;
break;
}
}
{
if (!pDomain)
{
Log(("NAT: not enought memory to add domain list\n"));
return VERR_NO_MEMORY;
}
}
}
}
if (!cNameserversFound)
return -1;
return 0;
}
#endif /* !RT_OS_WINDOWS */
{
int rc = VINF_SUCCESS;
if (!pData->fUseHostResolverPermanent)
{
/**
* Some distributions haven't got /etc/resolv.conf
* so we should other way to configure DNS settings.
*/
{
/* Load the DNS handler if host resolver mode was not used before. */
if (!pData->fUseHostResolver)
pData->fUseHostResolver = true;
}
else
{
/* Unload to not intercept in the future. */
if (pData->fUseHostResolver)
pData->fUseHostResolver = false;
}
if (!pData->fUseHostResolver)
{
int cDNSListEntry = 0;
{
}
}
}
return rc;
}
{
int rc = VINF_SUCCESS;
{
}
{
}
return rc;
}