From 2770cd1cdd472a06bfa9f779ec33bc6e47d8f459 Mon Sep 17 00:00:00 2001 From: Gregory Casamento Date: Fri, 24 Nov 2023 23:18:32 -0500 Subject: [PATCH] Update IPv6 changes --- Source/Additions/NSURL+GNUstepBase.m | 2 +- Source/GSSocketStream.h | 18 ++++++------- Source/GSSocketStream.m | 38 ++++++++++++++-------------- Source/win32/NSStream.m | 9 +++++++ 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/Source/Additions/NSURL+GNUstepBase.m b/Source/Additions/NSURL+GNUstepBase.m index 70c4302845..2143911851 100644 --- a/Source/Additions/NSURL+GNUstepBase.m +++ b/Source/Additions/NSURL+GNUstepBase.m @@ -87,7 +87,7 @@ - (id) initWithScheme: (NSString*)scheme if ([host length] > 0) { [urlString appendString: - [host stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]; + [host stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLHostAllowedCharacterSet]]]; } if ([port intValue] > 0) { diff --git a/Source/GSSocketStream.h b/Source/GSSocketStream.h index e71445e95b..1c03d112de 100644 --- a/Source/GSSocketStream.h +++ b/Source/GSSocketStream.h @@ -30,7 +30,7 @@ #import "GSNetwork.h" typedef union { - struct sockaddr s; + struct sockaddr_storage s; /* Increased memory allocation for IPv6 addresses*/ struct sockaddr_in i4; #ifdef AF_INET6 struct sockaddr_in6 i6; @@ -59,12 +59,12 @@ SOCKIVARS /** * get the sockaddr */ -- (struct sockaddr*) _address; +- (struct sockaddr_storage*) _address; /** * set the sockaddr */ -- (void) _setAddress: (struct sockaddr*)address; +- (void) _setAddress: (struct sockaddr_storage*)address; /** * setter for closing flag ... the remote end has stopped either sending @@ -116,8 +116,8 @@ SOCKIVARS SOCKIVARS @end @interface GSSocketInputStream (AddedBehaviors) -- (struct sockaddr*) _address; -- (void) _setAddress: (struct sockaddr*)address; +- (struct sockaddr_storage*) _address; +- (void) _setAddress: (struct sockaddr_storage*)address; - (NSInteger) _read: (uint8_t *)buffer maxLength: (NSUInteger)len; - (void) _setClosing: (BOOL)passive; - (void) _setHandler: (id)h; @@ -158,8 +158,8 @@ SOCKIVARS SOCKIVARS @end @interface GSSocketOutputStream (AddedBehaviors) -- (struct sockaddr*) _address; -- (void) _setAddress: (struct sockaddr*)address; +- (struct sockaddr_storage*) _address; +- (void) _setAddress: (struct sockaddr_storage*)address; - (void) _setClosing: (BOOL)passive; - (void) _setHandler: (id)h; - (void) _setPassive: (BOOL)passive; @@ -214,8 +214,8 @@ SOCKIVARS @end @interface GSSocketServerStream (AddedBehaviors) -- (struct sockaddr*) _address; -- (void) _setAddress: (struct sockaddr*)address; +- (struct sockaddr_storage*) _address; +- (void) _setAddress: (struct sockaddr_storage*)address; - (void) _setClosing: (BOOL)passive; - (void) _setHandler: (id)h; - (void) _setPassive: (BOOL)passive; diff --git a/Source/GSSocketStream.m b/Source/GSSocketStream.m index 323001fdab..5074a4b1fe 100644 --- a/Source/GSSocketStream.m +++ b/Source/GSSocketStream.m @@ -943,7 +943,7 @@ + (void) tryInput: (GSSocketInputStream*)i output: (GSSocketOutputStream*)o if (conf != nil) { GSSOCKS *h; - struct sockaddr *sa = [i _address]; + struct sockaddr_storage *sa = [i _address]; NSString *v; BOOL i6 = NO; @@ -958,15 +958,15 @@ + (void) tryInput: (GSSocketInputStream*)i output: (GSSocketOutputStream*)o } #if defined(AF_INET6) - if (sa->sa_family == AF_INET6) + if (sa->ss_family == AF_INET6) { i6 = YES; } else #endif - if (sa->sa_family != AF_INET) + if (sa->ss_family != AF_INET) { - GSOnceMLog(@"SOCKS not supported for socket type %d", sa->sa_family); + GSOnceMLog(@"SOCKS not supported for socket type %d", sa->ss_family); return; } @@ -1563,12 +1563,12 @@ - (id) init #endif _sock = INVALID_SOCKET; _handler = nil; - _address.s.sa_family = AF_UNSPEC; + _address.s.ss_family = AF_UNSPEC; } return self; } -- (struct sockaddr*) _address +- (struct sockaddr_storage*) _address { return &_address.s; } @@ -1577,7 +1577,7 @@ - (id) propertyForKey: (NSString *)key { id result = [super propertyForKey: key]; - if (result == nil && _address.s.sa_family != AF_UNSPEC) + if (result == nil && _address.s.ss_family != AF_UNSPEC) { SOCKET s = [self _sock]; sockaddr_any sin; @@ -1693,7 +1693,7 @@ - (BOOL) _setSocketAddress: (NSString*)address } else { - [self _setAddress: (struct sockaddr*)&peer]; + [self _setAddress: (struct sockaddr_storage*)&peer]; return YES; } } @@ -1715,7 +1715,7 @@ - (BOOL) _setSocketAddress: (NSString*)address else { strncpy(peer.sun_path, c_addr, sizeof(peer.sun_path)-1); - [self _setAddress: (struct sockaddr*)&peer]; + [self _setAddress: (struct sockaddr_storage*)&peer]; return YES; } } @@ -1726,7 +1726,7 @@ - (BOOL) _setSocketAddress: (NSString*)address } } -- (void) _setAddress: (struct sockaddr*)address +- (void) _setAddress: (struct sockaddr_storage*)address { memcpy(&_address.s, address, GSPrivateSockaddrLength(address)); } @@ -1831,7 +1831,7 @@ - (void) open { [GSSOCKS tryInput: self output: _sibling]; } - s = socket(_address.s.sa_family, SOCK_STREAM, 0); + s = socket(_address.s.ss_family, SOCK_STREAM, 0); if (BADSOCKET(s)) { [self _recordError]; @@ -1849,7 +1849,7 @@ - (void) open [GSTLSHandler tryInput: self output: _sibling]; } - result = connect([self _sock], &_address.s, + result = connect([self _sock], (struct sockaddr*)&_address.s, GSPrivateSockaddrLength(&_address.s)); if (socketError(result)) { @@ -2352,7 +2352,7 @@ - (void) open { [GSSOCKS tryInput: _sibling output: self]; } - s = socket(_address.s.sa_family, SOCK_STREAM, 0); + s = socket(_address.s.ss_family, SOCK_STREAM, 0); if (BADSOCKET(s)) { [self _recordError]; @@ -2370,7 +2370,7 @@ - (void) open [GSTLSHandler tryInput: _sibling output: self]; } - result = connect([self _sock], &_address.s, + result = connect([self _sock], (struct sockaddr*)&_address.s, GSPrivateSockaddrLength(&_address.s)); if (socketError(result)) { @@ -2756,7 +2756,7 @@ - (void) open return; } - s = socket(_address.s.sa_family, SOCK_STREAM, 0); + s = socket(_address.s.ss_family, SOCK_STREAM, 0); if (BADSOCKET(s)) { [self _recordError]; @@ -2769,9 +2769,9 @@ - (void) open } #ifndef BROKEN_SO_REUSEADDR - if (_address.s.sa_family == AF_INET + if (_address.s.ss_family == AF_INET #ifdef AF_INET6 - || _address.s.sa_family == AF_INET6 + || _address.s.ss_family == AF_INET6 #endif ) { @@ -2854,11 +2854,11 @@ - (void) acceptWithInputStream: (NSInputStream **)inputStream struct { uint8_t bytes[BUFSIZ]; } __attribute__((aligned(2)))buf; - struct sockaddr *addr = (struct sockaddr*)&buf; + struct sockaddr_storage *addr = (struct sockaddr_storage*)&buf; socklen_t len = sizeof(buf); int acceptReturn; - acceptReturn = accept([self _sock], addr, (OPTLEN*)&len); + acceptReturn = accept([self _sock], (struct sockaddr*)addr, (OPTLEN*)&len); _events &= ~NSStreamEventHasBytesAvailable; if (socketError(acceptReturn)) { // test for real error diff --git a/Source/win32/NSStream.m b/Source/win32/NSStream.m index b66e78deed..eab31f7045 100644 --- a/Source/win32/NSStream.m +++ b/Source/win32/NSStream.m @@ -961,6 +961,15 @@ + (void) getStreamsToHost: (NSHost *)host #endif } + //IPv6 + if(!ins) + { + #if defined(AF_INET6) + ins = (GSSocketStream*)AUTORELEASE([[GSInet6InputStream alloc] initToAddr: address port: port]); + outs = (GSSocketStream*)AUTORELEASE([[GSInet6OutputStream alloc] initToAddr: address port: port]); + #endif + } + /* * Windows only permits a single event to be associated with a socket * at any time, but the runloop system only allows an event handle to