mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
More host updates.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@5525 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3cbac61b46
commit
2f7945b57f
3 changed files with 67 additions and 59 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
Wed Dec 15 18:50:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
* Source/NSHost.m: Update again - record current host name for duration
|
||||||
|
of process and cache hosts keyed on the name under which they were
|
||||||
|
created. This can result in multiple cache entries for the same host,
|
||||||
|
but this seems to be necessary as DNS name <--> address mappings can
|
||||||
|
be asymmetric.
|
||||||
|
Thanks to dan@services.iiruc.ro for pointing this out.
|
||||||
|
|
||||||
Wed Dec 15 17:30:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
Wed Dec 15 17:30:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
* Source/Foundation/NSObject.h: dealloc notification stuff for Helge
|
* Source/Foundation/NSObject.h: dealloc notification stuff for Helge
|
||||||
|
|
105
Source/NSHost.m
105
Source/NSHost.m
|
@ -69,6 +69,11 @@ static NSMutableDictionary *_hostCache = nil;
|
||||||
{
|
{
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
if (name == nil)
|
||||||
|
{
|
||||||
|
RELEASE(self);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
if (entry == (struct hostent*)NULL)
|
if (entry == (struct hostent*)NULL)
|
||||||
{
|
{
|
||||||
RELEASE(self);
|
RELEASE(self);
|
||||||
|
@ -99,26 +104,7 @@ static NSMutableDictionary *_hostCache = nil;
|
||||||
|
|
||||||
if (_hostCacheEnabled == YES)
|
if (_hostCacheEnabled == YES)
|
||||||
{
|
{
|
||||||
NSEnumerator *enumerator;
|
[_hostCache setObject: self forKey: name];
|
||||||
NSString *key;
|
|
||||||
|
|
||||||
enumerator = [_names objectEnumerator];
|
|
||||||
while ((key = [enumerator nextObject]) != nil)
|
|
||||||
{
|
|
||||||
[_hostCache setObject: self forKey: key];
|
|
||||||
}
|
|
||||||
enumerator = [_addresses objectEnumerator];
|
|
||||||
while ((key = [enumerator nextObject]) != nil)
|
|
||||||
{
|
|
||||||
[_hostCache setObject: self forKey: key];
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* In addition to official names, use the name we were called with.
|
|
||||||
*/
|
|
||||||
if (name != nil)
|
|
||||||
{
|
|
||||||
[_hostCache setObject: self forKey: name];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -128,38 +114,38 @@ static NSMutableDictionary *_hostCache = nil;
|
||||||
|
|
||||||
@implementation NSHost
|
@implementation NSHost
|
||||||
|
|
||||||
- (id) init
|
|
||||||
{
|
|
||||||
[self dealloc];
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (void) initialize
|
|
||||||
{
|
|
||||||
if (self == [NSHost class])
|
|
||||||
{
|
|
||||||
_hostCacheLock = [[NSLock alloc] init];
|
|
||||||
_hostCache = [NSMutableDictionary new];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Max hostname length in line with RFC 1123
|
* Max hostname length in line with RFC 1123
|
||||||
*/
|
*/
|
||||||
#define GSMAXHOSTNAMELEN 255
|
#define GSMAXHOSTNAMELEN 255
|
||||||
|
|
||||||
|
static NSString *myHost = nil;
|
||||||
|
|
||||||
|
+ (void) initialize
|
||||||
|
{
|
||||||
|
if (self == [NSHost class])
|
||||||
|
{
|
||||||
|
char buf[GSMAXHOSTNAMELEN+1];
|
||||||
|
int res;
|
||||||
|
|
||||||
|
res = gethostname(buf, GSMAXHOSTNAMELEN);
|
||||||
|
if (res < 0)
|
||||||
|
{
|
||||||
|
NSLog(@"Unable to get name of current host - using 'localhost'");
|
||||||
|
myHost = @"localhost";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myHost = [[NSString alloc] initWithCString: buf];
|
||||||
|
}
|
||||||
|
_hostCacheLock = [[NSLock alloc] init];
|
||||||
|
_hostCache = [NSMutableDictionary new];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+ (NSHost*) currentHost
|
+ (NSHost*) currentHost
|
||||||
{
|
{
|
||||||
char name[GSMAXHOSTNAMELEN+1];
|
return [self hostWithName: myHost];
|
||||||
int res;
|
|
||||||
|
|
||||||
res = gethostname(name, GSMAXHOSTNAMELEN);
|
|
||||||
if (res < 0)
|
|
||||||
{
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
name[GSMAXHOSTNAMELEN] = '\0';
|
|
||||||
return [self hostWithName: [NSString stringWithCString: name]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSHost*) hostWithName: (NSString*)name
|
+ (NSHost*) hostWithName: (NSString*)name
|
||||||
|
@ -168,7 +154,7 @@ static NSMutableDictionary *_hostCache = nil;
|
||||||
|
|
||||||
if (name == nil)
|
if (name == nil)
|
||||||
{
|
{
|
||||||
NSLog(@"Nil host name sent to +[NSHost hostWithName]");
|
NSLog(@"Nil host name sent to [NSHost +hostWithName:]");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +182,7 @@ static NSMutableDictionary *_hostCache = nil;
|
||||||
|
|
||||||
if (address == nil)
|
if (address == nil)
|
||||||
{
|
{
|
||||||
NSLog(@"Nil host address sent to +[NSHost hostWithName]");
|
NSLog(@"Nil host address sent to [NSHost +hostWithName:]");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,6 +275,19 @@ static NSMutableDictionary *_hostCache = nil;
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
RELEASE(_names);
|
||||||
|
RELEASE(_addresses);
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) init
|
||||||
|
{
|
||||||
|
[self dealloc];
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The OpenStep spec says that [-hash] must be the same for any two
|
* The OpenStep spec says that [-hash] must be the same for any two
|
||||||
* objects that [-isEqual: ] returns YES for. We have a problem in
|
* objects that [-isEqual: ] returns YES for. We have a problem in
|
||||||
|
@ -326,11 +325,6 @@ static NSMutableDictionary *_hostCache = nil;
|
||||||
if ([_addresses containsObject: [a objectAtIndex: i]])
|
if ([_addresses containsObject: [a objectAtIndex: i]])
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
a = [aHost names];
|
|
||||||
for (i = 0; i < [a count]; i++)
|
|
||||||
if ([_addresses containsObject: [a objectAtIndex: i]])
|
|
||||||
return YES;
|
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,11 +354,4 @@ static NSMutableDictionary *_hostCache = nil;
|
||||||
[self name], [self names], [self addresses]];
|
[self name], [self names], [self addresses]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
|
||||||
{
|
|
||||||
RELEASE(_names);
|
|
||||||
RELEASE(_addresses);
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -37,12 +37,24 @@ main ()
|
||||||
displayHost(a);
|
displayHost(a);
|
||||||
|
|
||||||
printf("c:%lx, n:%lx, a:%lx\n", c, n, a);
|
printf("c:%lx, n:%lx, a:%lx\n", c, n, a);
|
||||||
|
printf("c isEqual: n ... %d\n", [c isEqual: n]);
|
||||||
|
printf("n isEqual: c ... %d\n", [n isEqual: c]);
|
||||||
|
printf("c isEqual: a ... %d\n", [c isEqual: a]);
|
||||||
|
printf("a isEqual: c ... %d\n", [a isEqual: c]);
|
||||||
|
printf("n isEqual: a ... %d\n", [n isEqual: a]);
|
||||||
|
printf("a isEqual: n ... %d\n", [a isEqual: n]);
|
||||||
|
|
||||||
[NSHost setHostCacheEnabled:NO];
|
[NSHost setHostCacheEnabled:NO];
|
||||||
|
|
||||||
n = [NSHost hostWithName:[c name]];
|
n = [NSHost hostWithName:[c name]];
|
||||||
displayHost(n);
|
displayHost(n);
|
||||||
printf("c:%lx, n:%lx, a:%lx\n", c, n, a);
|
printf("c:%lx, n:%lx, a:%lx\n", c, n, a);
|
||||||
|
printf("c isEqual: n ... %d\n", [c isEqual: n]);
|
||||||
|
printf("n isEqual: c ... %d\n", [n isEqual: c]);
|
||||||
|
printf("c isEqual: a ... %d\n", [c isEqual: a]);
|
||||||
|
printf("a isEqual: c ... %d\n", [a isEqual: c]);
|
||||||
|
printf("n isEqual: a ... %d\n", [n isEqual: a]);
|
||||||
|
printf("a isEqual: n ... %d\n", [a isEqual: n]);
|
||||||
|
|
||||||
[arp release];
|
[arp release];
|
||||||
exit (0);
|
exit (0);
|
||||||
|
|
Loading…
Reference in a new issue