If there is no /etc/hosts file, we now add a "localhost 127.0.0.1" definition
internally. This fixes #1688. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23218 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1985, 1988, 1993
|
* Copyright (c) 1985, 1988, 1993
|
||||||
* The Regents of the University of California. All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
@@ -105,6 +110,7 @@ static const char rcsid[] = "$Id$";
|
|||||||
|
|
||||||
struct pvt {
|
struct pvt {
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
|
int index;
|
||||||
struct hostent host;
|
struct hostent host;
|
||||||
char * h_addr_ptrs[MAXADDRS + 1];
|
char * h_addr_ptrs[MAXADDRS + 1];
|
||||||
char * host_aliases[MAXALIASES];
|
char * host_aliases[MAXALIASES];
|
||||||
@@ -333,9 +339,25 @@ ho_next(struct irs_ho *this) {
|
|||||||
if (!pvt->fp)
|
if (!pvt->fp)
|
||||||
ho_rewind(this);
|
ho_rewind(this);
|
||||||
if (!pvt->fp) {
|
if (!pvt->fp) {
|
||||||
RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
|
if (pvt->index > 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
|
strcpy(pvt->hostbuf, "localhost");
|
||||||
|
pvt->host_aliases[0] = pvt->hostbuf;
|
||||||
|
pvt->host_aliases[1] = NULL;
|
||||||
|
pvt->h_addr_ptrs[0] = (char *)pvt->host_addr;
|
||||||
|
pvt->h_addr_ptrs[1] = NULL;
|
||||||
|
pvt->host.h_addr_list = pvt->h_addr_ptrs;
|
||||||
|
pvt->host.h_length = INADDRSZ;
|
||||||
|
pvt->host.h_addrtype = AF_INET;
|
||||||
|
pvt->host.h_aliases = pvt->host_aliases;
|
||||||
|
((struct in_addr *)pvt->host_addr)->s_addr = INADDR_LOOPBACK;
|
||||||
|
pvt->index++;
|
||||||
|
|
||||||
|
RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS);
|
||||||
|
return (&pvt->host);
|
||||||
}
|
}
|
||||||
|
|
||||||
bufp = pvt->hostbuf;
|
bufp = pvt->hostbuf;
|
||||||
bufsiz = sizeof pvt->hostbuf;
|
bufsiz = sizeof pvt->hostbuf;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
@@ -433,8 +455,10 @@ ho_rewind(struct irs_ho *this) {
|
|||||||
return;
|
return;
|
||||||
(void)fclose(pvt->fp);
|
(void)fclose(pvt->fp);
|
||||||
}
|
}
|
||||||
if (!(pvt->fp = fopen(_PATH_HOSTS, "r")))
|
if (!(pvt->fp = fopen(_PATH_HOSTS, "r"))) {
|
||||||
|
pvt->index = 0;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if (fcntl(fileno(pvt->fp), F_SETFD, 1) < 0) {
|
if (fcntl(fileno(pvt->fp), F_SETFD, 1) < 0) {
|
||||||
(void)fclose(pvt->fp);
|
(void)fclose(pvt->fp);
|
||||||
pvt->fp = NULL;
|
pvt->fp = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user