mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Make NSHost more tolerant of bad system setups.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8673 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4e4436b376
commit
5dc51ab6df
3 changed files with 43 additions and 8 deletions
|
@ -1,3 +1,9 @@
|
|||
2001-01-18 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSHost.m: New method ([-_addName:]) to add a name to a host.
|
||||
Use it to add the local hostname to the 127.0.0.1 host if there is
|
||||
no IP address set up for the local machine.
|
||||
|
||||
2001-01-17 Mirko Viviani <mirko.viviani@rccr.cremona.it>
|
||||
|
||||
* Source/GSXML.m|.h ([GSXMLDocument -stringValue]): dump document in a
|
||||
|
|
|
@ -242,15 +242,15 @@ loadEntityFunction(const char *url, const char *eid, xmlParserCtxtPtr *ctxt);
|
|||
xmlSaveFile([filename cString], lib);
|
||||
}
|
||||
|
||||
- (NSString *) stringValue
|
||||
- (NSString*) stringValue
|
||||
{
|
||||
NSString *string = nil;
|
||||
xmlChar *buf = NULL;
|
||||
int length;
|
||||
NSString *string = nil;
|
||||
xmlChar *buf = NULL;
|
||||
int length;
|
||||
|
||||
xmlDocDumpMemory(lib, &buf, &length);
|
||||
|
||||
if(buf && length)
|
||||
if (buf != 0 && length > 0)
|
||||
{
|
||||
string = [NSString_class stringWithCString: buf length: length];
|
||||
xmlFree(buf);
|
||||
|
|
|
@ -57,6 +57,7 @@ static NSString *myHostName = nil;
|
|||
|
||||
|
||||
@interface NSHost (Private)
|
||||
- (void) _addName: (NSString*)name;
|
||||
+ (struct hostent*) _entryForAddress: (NSString*)address;
|
||||
- (id) _initWithHostEntry: (struct hostent*)entry key: (NSString*)key;
|
||||
+ (NSMutableSet*) _localAddresses;
|
||||
|
@ -64,6 +65,21 @@ static NSString *myHostName = nil;
|
|||
|
||||
@implementation NSHost (Private)
|
||||
|
||||
- (void) _addName: (NSString*)name
|
||||
{
|
||||
NSMutableSet *s = [_names mutableCopy];
|
||||
|
||||
name = [name copy];
|
||||
[s addObject: name];
|
||||
ASSIGNCOPY(_names, s);
|
||||
RELEASE(s);
|
||||
if (_hostCacheEnabled == YES)
|
||||
{
|
||||
[_hostCache setObject: self forKey: name];
|
||||
}
|
||||
RELEASE(name);
|
||||
}
|
||||
|
||||
+ (struct hostent*) _entryForAddress: (NSString*)address
|
||||
{
|
||||
struct hostent *h = 0;
|
||||
|
@ -287,9 +303,22 @@ static NSString *myHostName = nil;
|
|||
h = gethostbyname((char*)[name cString]);
|
||||
if (h == 0)
|
||||
{
|
||||
NSLog(@"Host '%@' not found using 'gethostbyname()' - perhaps "
|
||||
@"the hostname is wrong or networking is not set up on your "
|
||||
@"machine", name);
|
||||
if ([name isEqualToString: myHostName] == YES)
|
||||
{
|
||||
NSLog(@"No network address appears to be available "
|
||||
@"for this machine (%@) - using loopback address "
|
||||
@"(127.0.0.1)", name);
|
||||
NSLog(@"You probably need a line like '"
|
||||
@"127.0.0.1 %@ localhost' in your /etc/hosts file");
|
||||
host = [self hostWithAddress: @"127.0.0.1"];
|
||||
[host _addName: name];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Host '%@' not found using 'gethostbyname()' - "
|
||||
@"perhaps the hostname is wrong or networking is not "
|
||||
@"set up on your machine", name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue