NSNetService address resolution crash
NSNetService address resolution crash
- Subject: NSNetService address resolution crash
- From: Philippe Hausler <email@hidden>
- Date: Sun, 14 Nov 2004 21:16:59 -0500
I am getting erroneous, random, crashes when I resolve IPv4 addresses in an application that scans for many types of services. After stepping through the code it SIGBUS's in the middle of the resolution of the IP address when it acesses
struct sockaddr_in). After firstly thinking that my code is at fault, I replaced the resolution function with the one from the PictureSharingBrowser example. This supprisingly enough results with the same random crash on load! Either I am doing something wrong in the debugger (which I am sure I am not) or there is something seriously wrong with NSNetServices addresses function in how it formats the sockaddrs or my code and Apple's sample code is at fault. None of these options are appealing to me. So I must be missing something.
Sample from my class (excerpted from PictureSharingBrowser) with the addresses passed directly to the function, everything else seems to be fine, it might not be. However this is where it crashes so the error is more than likely here.
if ([rawAddresses count] > 0) {
NSData * address;
struct sockaddr * socketAddress;
NSString * portString = nil;
int socketToRemoteServer;
char buffer[256];
int index;
for (index = 0; index < [rawAddresses count]; index++) {
address = [rawAddresses objectAtIndex:index];
socketAddress = (struct sockaddr *)[address bytes];
if (socketAddress->sa_len == struct sockaddr_in))
break;
}
index = 0;
if (socketAddress) {
int sasa_len = ;
switch(socketAddress->sa_len) {
case struct sockaddr_in):
if (inet_ntop(AF_INET, &((struct sockaddr_in *)socketAddress)->sin_addr, buffer, sizeof(buffer)))
ipAddressString = [NSString stringWithCString:buffer];
break;
case struct sockaddr_in6):
return;
default:
return;
}
}
}
Thanks in advance for anyone who has any thoughts on this.
Sincerely,
Philippe Hausler
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden