diff --git a/ChangeLog b/ChangeLog index 5a964d91d..4b1b373bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-08-18 Richard Frith-Macdonald + + * Source/NSFileHandle.m: Add methods to get local socket info + matching mthe existing methods which return remote address/port. + * Source/GSFileHandle.m: ditto. + 2004-08-17 David Ayers * Testing/GNUmakefile: Reactivate nsinvocation test. diff --git a/Headers/Foundation/NSFileHandle.h b/Headers/Foundation/NSFileHandle.h index f6ff1865e..caf1a05c1 100644 --- a/Headers/Foundation/NSFileHandle.h +++ b/Headers/Foundation/NSFileHandle.h @@ -182,6 +182,8 @@ GS_EXPORT NSString * const NSFileHandleOperationException; forModes: (NSArray*)modes; - (BOOL) readInProgress; - (NSString*) socketAddress; +- (NSString*) socketLocalAddress; +- (NSString*) socketLocalService; - (NSString*) socketService; - (NSString*) socketProtocol; - (BOOL) useCompression; diff --git a/Source/GSFileHandle.m b/Source/GSFileHandle.m index 482fe3e88..be07f8503 100644 --- a/Source/GSFileHandle.m +++ b/Source/GSFileHandle.m @@ -2331,6 +2331,41 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; return address; } +- (NSString*) socketLocalAddress +{ + NSString *str = nil; + struct sockaddr_in sin; + int size = sizeof(sin); + + if (getsockname(descriptor, (struct sockaddr*)&sin, &size) == SOCKET_ERROR) + { + NSLog(@"unable to get socket name - %s", GSLastErrorStr(errno)); + } + else + { + str = [NSString stringWithCString: (char*)inet_ntoa(sin.sin_addr)]; + } + return str; +} + +- (NSString*) socketLocalService +{ + NSString *str = nil; + struct sockaddr_in sin; + int size = sizeof(sin); + + if (getsockname(descriptor, (struct sockaddr*)&sin, &size) == SOCKET_ERROR) + { + NSLog(@"unable to get socket name - %s", GSLastErrorStr(errno)); + } + else + { + str = [NSString stringWithFormat: @"%d", + (int)GSSwapBigI16ToHost(sin.sin_port)]; + } + return str; +} + - (NSString*) socketProtocol { return protocol; diff --git a/Source/NSFileHandle.m b/Source/NSFileHandle.m index 2d9f8b346..0271fa750 100644 --- a/Source/NSFileHandle.m +++ b/Source/NSFileHandle.m @@ -613,6 +613,22 @@ NSString * const NSFileHandleOperationException return nil; } +/** + * Returns the local address of the network connection or nil. + */ +- (NSString*) socketLocalAddress +{ + return nil; +} + +/** + * Returns the local service/port of the network connection or nil. + */ +- (NSString*) socketLocalService +{ + return nil; +} + /** * Returns the name (or number) of the service (network port) in use for * the network connection represented by the file handle.