]> err.no Git - sope/blobdiff - sope-core/NGStreams/NGInternetSocketAddress.m
fixed OGo bug #1896
[sope] / sope-core / NGStreams / NGInternetSocketAddress.m
index 7634e803a095352214e5e81d5979d551399d9c86..6263eca32da0b6471df196b6bc33da81ca1eb26e 100644 (file)
@@ -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 {