From 44b8ac3d4665f60d98f69c9df73c89838b8f03e6 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 26 Apr 2000 07:35:11 +0000 Subject: [PATCH] Improve handling of host/net config errors git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6518 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 +++++++- Source/GSTcpPort.m | 7 ++++++- Source/NSHost.m | 32 ++++++++++++++++++++++++++------ Source/TcpPort.m | 11 +++++++++++ 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index e282a4930..c11f5b214 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,14 @@ +2000-04-26 Richard Frith-Macdonald + + * Source/NSHost.m: Improve logging of host/net configuration errors + * Source/GSTcpPort.m: ditto + * Source/TcpPort.m: ditto + 2000-04-25 Adam Fedor * Source/NSBundle.m (+initialize): retain _executable_path. -2000-04-23 Richard Frith-Macdonald +2000-04-25 Richard Frith-Macdonald * Source/NSAttributedString.m: Optimised - cache method implementations wherever possible in order to avoid objc runtime overheads. diff --git a/Source/GSTcpPort.m b/Source/GSTcpPort.m index 63ab0df7f..c699ba30e 100644 --- a/Source/GSTcpPort.m +++ b/Source/GSTcpPort.m @@ -1018,13 +1018,18 @@ static NSMapTable *tcpPortMap = 0; NSHost *thisHost = [NSHost currentHost]; NSMapTable *thePorts; + if (thisHost == nil) + { + NSLog(@"attempt to create port on host without networking set up!"); + return nil; + } if (aHost == nil) { aHost = thisHost; } if (addr != nil && [[aHost addresses] containsObject: addr] == NO) { - NSLog(@"attempt to use address '%@' on whost without that address", addr); + NSLog(@"attempt to use address '%@' on host without that address", addr); return nil; } if (number == 0 && [thisHost isEqual: aHost] == NO) diff --git a/Source/NSHost.m b/Source/NSHost.m index 16c82718b..998c3ee5f 100644 --- a/Source/NSHost.m +++ b/Source/NSHost.m @@ -69,13 +69,16 @@ static NSMutableDictionary *_hostCache = nil; { return nil; } - if (name == nil) + if (name == nil || [name isEqual: @""] == YES) { + NSLog(@"Host init failed - empty name/address supplied"); RELEASE(self); return nil; } if (entry == (struct hostent*)NULL) { + NSLog(@"Host '%@' init failed - perhaps the name/address is wrong or " + @"networking is not set up on your machine", name); RELEASE(self); return nil; } @@ -168,9 +171,17 @@ static NSString *myHost = nil; struct hostent *h; h = gethostbyname((char*)[name cString]); - - host = [[self alloc] _initWithHostEntry: h key: name]; - AUTORELEASE(host); + if (h == 0) + { + NSLog(@"Host '%@' not found using 'gethostbyname()' - perhaps " + @"the hostname is wrong or networking is not set up on your " + @"machine", name); + } + else + { + host = [[self alloc] _initWithHostEntry: h key: name]; + AUTORELEASE(host); + } } [_hostCacheLock unlock]; return host; @@ -213,8 +224,17 @@ static NSString *myHost = nil; if (addrOk == YES) { h = gethostbyaddr((char*)&hostaddr, sizeof(hostaddr), AF_INET); - host = [[self alloc] _initWithHostEntry: h key: address]; - AUTORELEASE(host); + if (h == 0) + { + NSLog(@"Host '%@' not found using 'gethostbyaddr()' - perhaps " + @"the address is wrong or networking is not set up on your " + @"machine", address); + } + else + { + host = [[self alloc] _initWithHostEntry: h key: address]; + AUTORELEASE(host); + } } } [_hostCacheLock unlock]; diff --git a/Source/TcpPort.m b/Source/TcpPort.m index d9519b1b5..41d8e6a6f 100644 --- a/Source/TcpPort.m +++ b/Source/TcpPort.m @@ -493,6 +493,12 @@ static NSMapTable* port_number_2_port; Distributed Objects connection to another machine, they get our unique host address that can identify us across the network. */ hostname = [[NSHost currentHost] name]; + if (hostname == nil) + { + [p release]; + [NSException raise: NSInternalInconsistencyException + format: @"[TcpInPort +newForReceivingFromPortNumber:] no hostname"]; + } hp = gethostbyname ([hostname cString]); if (!hp) hp = gethostbyname ("localhost"); @@ -1233,6 +1239,11 @@ static NSMapTable *out_port_bag = NULL; if (!hostname || ![hostname length]) { hostname = [[NSHost currentHost] name]; + if (hostname == nil) + { + NSLog(@"No local host set upt!"); + return nil; + } } host_cstring = [hostname cString]; hp = gethostbyname ((char*)host_cstring);