From d9e20073d0bd1cc30227e0342d83c242121164a0 Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 18 Jan 2001 08:27:00 +0000 Subject: [PATCH] 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 --- ChangeLog | 6 ++++++ Source/GSXML.m | 10 +++++----- Source/NSHost.m | 35 ++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4531ed97e..223dbc161 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2001-01-18 Richard Frith-Macdonald + + * 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 * Source/GSXML.m|.h ([GSXMLDocument -stringValue]): dump document in a diff --git a/Source/GSXML.m b/Source/GSXML.m index 68fd907ba..500ab3857 100644 --- a/Source/GSXML.m +++ b/Source/GSXML.m @@ -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); diff --git a/Source/NSHost.m b/Source/NSHost.m index 40a2d86cd..98bffc7f7 100644 --- a/Source/NSHost.m +++ b/Source/NSHost.m @@ -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 {