- (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)
[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 {