NSNetService addresses returns empty array
NSNetService addresses returns empty array
- Subject: NSNetService addresses returns empty array
- From: Greg Hulands <email@hidden>
- Date: Thu, 26 Sep 2002 22:57:05 +1000
Hi,
I am setting up a client server discovery using NSNetServiceBrowser and
have a table that lists the service names, ip address, and port. I have
the delegate method
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser
didFindService:(NSNetService *)aNetService
moreComing:(BOOL)moreComing
{
[services addObject:aNetService];
[aNetService setDelegate:self];
[aNetService resolve];
if(!moreComing) {
[servicesTable reloadData];
}
}
services is just a mutable array. The table datasource method is as
follows:
- (id)tableView:(NSTableView *)theTableView
objectValueForTableColumn:(NSTableColumn *)theColumn row:(int)rowIndex
{
NSString *ident = [theColumn identifier];
id obj = [services objectAtIndex:rowIndex];
if ([ident isEqualToString:@"server"])
return [obj name];
else if ([ident isEqualToString:@"ip"])
{
int firstOctet, secondOctet, thirdOctet, fourthOctet;
NSData *address = [[obj addresses] objectAtIndex:0];
struct sockaddr_in *socketAddress = (struct sockaddr_in
*)[address bytes];
firstOctet = (socketAddress->sin_addr.s_addr & 0xFF000000) >>
24;
secondOctet = (socketAddress->sin_addr.s_addr & 0x00FF0000) >>
16;
thirdOctet = (socketAddress->sin_addr.s_addr & 0x0000FF00) >> 8;
fourthOctet = (socketAddress->sin_addr.s_addr & 0x000000FF) >>
0;
return [NSString stringWithFormat:@"%d.%d.%d.%d", firstOctet,
secondOctet, thirdOctet, fourthOctet];
}
else if ([ident isEqualToString:@"port"])
{
NSData * address = [[obj addresses] objectAtIndex:0];
struct sockaddr_in *socketAddress = (struct sockaddr_in
*)[address bytes];
return [NSString stringWithFormat:@"%d",
socketAddress->sin_port];
}
return nil;
}
When trying to format the IP address, the addresses returns an empty
array. Both the client and server are on the same machine, but i don't
think that is the cause as the NSNetService example works fine. The
documentation says
If no addresses were resolved for the service, the returned NSArray
contains zero elements.
What would cause the non-resolution of the address when it is on the
same machine?
Any help is appreciated,
Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.