• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Resolving address on 10.4 (ppc) - problem with endianness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Resolving address on 10.4 (ppc) - problem with endianness


  • Subject: Resolving address on 10.4 (ppc) - problem with endianness
  • From: Alexander Hartner <email@hidden>
  • Date: Tue, 12 May 2009 02:05:05 +0100

I am using the following to resolve a Bonjour discovered service address. However it seems that getnameinfo on 10.4 (ppc) does not translate correctly. However using inet_ntoa correctly resolved to an IP address. Ideally I am after the hostname, and if that cannot be resolved then the IP address. This is done nicely by getnameinfo on 10.5 (intel) but seems to fail on 10.4 (ppc).


- (void)netServiceDidResolveAddress:(NSNetService *)aNetService
{
NSString * hostname = [aNetService hostName];
NSLog(@"Host : %@",hostname);
NSLog(@"Name : %@",[aNetService name]);

NSArray * addresses = [aNetService addresses];
struct sockaddr *address;
if([addresses count] > 0)
{
address = (struct sockaddr *) [[addresses objectAtIndex:0] bytes];
int port = -1;

if(address->sa_family == AF_INET)
{
port = ntohs(((struct sockaddr_in *)address)->sin_port);
}
else if(address->sa_family == AF_INET6)
{
port = ntohs(((struct sockaddr_in6 *)address)->sin6_port);
}
else
{
NSLog(@"Socket Error: The socket supplied is not IPv4 or IPv6");
return;
}

char * some_addr;
some_addr = inet_ntoa(((struct sockaddr_in *)address)->sin_addr); // return the IP
printf("HostName inet_ntoa : %s\n", some_addr); // prints "10.0.0.1"


//Do a reverse lookup on the DNS server or use the IP address of the server
char hostbuffer[NI_MAXHOST], serverbuffer[NI_MAXSERV];
if (getnameinfo(address, address->sa_len, hostbuffer, sizeof(hostbuffer), serverbuffer, sizeof(serverbuffer), NI_NUMERICSERV))
{
NSLog(@"Could not get numeric hostname");
}
NSLog(@"HostName nslog + getnameinfo : %s Server: %s",hostbuffer,serverbuffer);

printf("HostName printf + getnameinfo : %s \n", hostbuffer);
}
}


Any suggestions on how to resolve this are truly appreciated.

Thanks in advance
Alex

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: NSToolbarItem with custom view in Interface Builder 3 (Leopard)
  • Next by Date: Re: quick and dirty NSData implosion
  • Previous by thread: DVDPlayer & Deinterlacing
  • Next by thread: NSAccessibilityAttributeValue exception raised when hovering mouse over top menu bar
  • Index(es):
    • Date
    • Thread