Re: NSNetService address resolution crash
Re: NSNetService address resolution crash
- Subject: Re: NSNetService address resolution crash
- From: Marc Krochmal <email@hidden>
- Date: Thu, 18 Nov 2004 22:10:14 -0800
Philippe,
Could you try using the code from PictureSharingBrowser on the web.
It's slightly improved.
<http://developer.apple.com/samplecode/PictureSharingBrowser/
PictureSharingBrowser.html>
-Marc
On Nov 14, 2004, at 6:16 PM, Philippe Hausler wrote:
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 sizeof(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 == sizeof(struct sockaddr_in))
break;
}
index = 0;
if (socketAddress) {
int sasa_len = ;
switch(socketAddress->sa_len) {
case sizeof(struct sockaddr_in):
if (inet_ntop(AF_INET, &((struct sockaddr_in
*)socketAddress)->sin_addr, buffer, sizeof(buffer)))
ipAddressString = [NSString
stringWithCString:buffer];
break;
case sizeof(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
_______________________________________________
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