X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=sope-core%2FNGStreams%2FNGInternetSocketAddress.m;fp=sope-core%2FNGStreams%2FNGInternetSocketAddress.m;h=6263eca32da0b6471df196b6bc33da81ca1eb26e;hb=d56d4f818a831ad0a2f29bcb06df47836ae97249;hp=7634e803a095352214e5e81d5979d551399d9c86;hpb=f7b4d7a55de6bd750dd30475da4f72c271650a59;p=sope diff --git a/sope-core/NGStreams/NGInternetSocketAddress.m b/sope-core/NGStreams/NGInternetSocketAddress.m index 7634e803..6263eca3 100644 --- a/sope-core/NGStreams/NGInternetSocketAddress.m +++ b/sope-core/NGStreams/NGInternetSocketAddress.m @@ -417,6 +417,7 @@ static inline NSString *_nameOfLocalhost(void) { - (id)initWithService:(NSString *)_serviceName onHost:(id)_host protocol:(NSString *)_protocol { + /* careful: the port in servent is in network byteorder! */ NSException *exc = nil; int port = -1; #if defined(HAVE_GETSERVBYNAME_R) @@ -437,20 +438,22 @@ static inline NSString *_nameOfLocalhost(void) { [systemLock lock]; { entry = getservbyname((char *)[_serviceName cString], [_protocol cString]); - if (entry == NULL) - exc = [[NGDidNotFindServiceException alloc] initWithServiceName:_serviceName]; + if (entry == NULL) { + exc = [[NGDidNotFindServiceException alloc] + initWithServiceName:_serviceName]; + } else port = entry->s_port; } [systemLock unlock]; #endif - if (exc) { + if (exc != nil) { self = [self autorelease]; [exc raise]; return nil; } - return [self initWithPort:port onHost:_host]; + return [self initWithPort:ntohs(port) onHost:_host]; } - (id)initWithPort:(int)_port {