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
This commit is contained in:
Richard Frith-MacDonald 2000-04-26 07:35:11 +00:00
parent 98a2cf5435
commit 49f0630b1a
4 changed files with 50 additions and 8 deletions

View file

@ -1,8 +1,14 @@
2000-04-26 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSHost.m: Improve logging of host/net configuration errors
* Source/GSTcpPort.m: ditto
* Source/TcpPort.m: ditto
2000-04-25 Adam Fedor <fedor@gnu.org>
* Source/NSBundle.m (+initialize): retain _executable_path.
2000-04-23 Richard Frith-Macdonald <rfm@gnu.org>
2000-04-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSAttributedString.m: Optimised - cache method implementations
wherever possible in order to avoid objc runtime overheads.

View file

@ -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)

View file

@ -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];

View file

@ -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);