Added some error checking to DNSQuery::GetDNSServers(), since it could fail.
Temporarily enabled debug to help with ticket #5655. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35970 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
#include <NetEndpoint.h>
|
#include <NetEndpoint.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
|
||||||
// #define DEBUG 1
|
#define DEBUG 1
|
||||||
|
|
||||||
#undef PRINT
|
#undef PRINT
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -149,9 +149,11 @@ BRawNetBuffer::_ReadSubString(BString& string, off_t pos)
|
|||||||
// #pragma mark - DNSTools
|
// #pragma mark - DNSTools
|
||||||
|
|
||||||
|
|
||||||
void
|
status_t
|
||||||
DNSTools::GetDNSServers(BObjectList<BString>* serverList)
|
DNSTools::GetDNSServers(BObjectList<BString>* serverList)
|
||||||
{
|
{
|
||||||
|
// TODO: reading resolv.conf ourselves shouldn't be needed.
|
||||||
|
// we should have some function to retrieve the dns list
|
||||||
#define MATCH(line, name) \
|
#define MATCH(line, name) \
|
||||||
(!strncmp(line, name, sizeof(name) - 1) && \
|
(!strncmp(line, name, sizeof(name) - 1) && \
|
||||||
(line[sizeof(name) - 1] == ' ' || \
|
(line[sizeof(name) - 1] == ' ' || \
|
||||||
@@ -159,7 +161,7 @@ DNSTools::GetDNSServers(BObjectList<BString>* serverList)
|
|||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
if (find_directory(B_COMMON_SETTINGS_DIRECTORY, &path) != B_OK)
|
if (find_directory(B_COMMON_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
return;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
path.Append("network/resolv.conf");
|
path.Append("network/resolv.conf");
|
||||||
|
|
||||||
@@ -167,7 +169,7 @@ DNSTools::GetDNSServers(BObjectList<BString>* serverList)
|
|||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
fprintf(stderr, "failed to open '%s' to read nameservers: %s\n",
|
fprintf(stderr, "failed to open '%s' to read nameservers: %s\n",
|
||||||
path.Path(), strerror(errno));
|
path.Path(), strerror(errno));
|
||||||
return;
|
return B_ENTRY_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nserv = 0;
|
int nserv = 0;
|
||||||
@@ -198,6 +200,8 @@ DNSTools::GetDNSServers(BObjectList<BString>* serverList)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -271,16 +275,14 @@ DNSQuery::ReadDNSServer(in_addr* add)
|
|||||||
{
|
{
|
||||||
// list owns the items
|
// list owns the items
|
||||||
BObjectList<BString> dnsServerList(5, true);
|
BObjectList<BString> dnsServerList(5, true);
|
||||||
DNSTools::GetDNSServers(&dnsServerList);
|
status_t status = DNSTools::GetDNSServers(&dnsServerList);
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
BString* firstDNS = dnsServerList.ItemAt(0);
|
BString* firstDNS = dnsServerList.ItemAt(0);
|
||||||
int status = -1;
|
if (firstDNS == NULL || inet_aton(firstDNS->String(), add) != 1)
|
||||||
if (firstDNS)
|
|
||||||
status = inet_aton(firstDNS->String(), add);
|
|
||||||
else
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
if (status != 1)
|
|
||||||
return B_ERROR;
|
|
||||||
PRINT("dns server found: %s \n", firstDNS->String());
|
PRINT("dns server found: %s \n", firstDNS->String());
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ private:
|
|||||||
|
|
||||||
class DNSTools {
|
class DNSTools {
|
||||||
public:
|
public:
|
||||||
static void GetDNSServers(BObjectList<BString>* serverList);
|
static status_t GetDNSServers(BObjectList<BString>* serverList);
|
||||||
static BString ConvertToDNSName(const BString& string);
|
static BString ConvertToDNSName(const BString& string);
|
||||||
static BString ConvertFromDNSName(const BString& string);
|
static BString ConvertFromDNSName(const BString& string);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user