Re: NSNetService & NSURLConnection on Tiger
Re: NSNetService & NSURLConnection on Tiger
- Subject: Re: NSNetService & NSURLConnection on Tiger
- From: Houdah - ML Pierre Bernard <email@hidden>
- Date: Tue, 17 Feb 2009 23:51:42 +0100
Hi!
This is what I came up with:
@implementation NSNetService (ipv4)
- (NSArray*)ipv4addresses
{
NSMutableArray * ipv4addresses = [NSMutableArray array];
NSArray *addresses = [self addresses];
int aCount = [addresses count];
char addr[256];
for (int i = 0; i < aCount; i++) {
struct sockaddr *socketAddress = (struct sockaddr *)[[addresses
objectAtIndex:i] bytes];
if (socketAddress && socketAddress->sa_family == AF_INET) {
if (inet_ntop(AF_INET, &((struct sockaddr_in *)socketAddress)-
>sin_addr, addr, sizeof(addr))) {
uint16_t port = ntohs(((struct sockaddr_in *)socketAddress)-
>sin_port);
[ipv4addresses addObject:[NSString stringWithFormat:@"%s:%d",
addr, port]];
}
}
}
return ipv4addresses;
}
@end
Pierre
On 17 Feb 2009, at 21:32, Kyle Sluder wrote:
See the documentation for -[NSNetService addresses]. You can use that
to go from NSNetService -> NSData -> sockaddr_in -> NSURL ->
NSURLConnection.
--Kyle Sluder
_______________________________________________
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
- - -
Houdah Software s. à r. l.
http://www.houdah.com
HoudahGeo: One-stop photo geocoding
HoudahSpot: Powerful Spotlight frontend
_______________________________________________
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