Re: Conversion of CFSocketCreateWithNative -> NSSocketPort
Re: Conversion of CFSocketCreateWithNative -> NSSocketPort
- Subject: Re: Conversion of CFSocketCreateWithNative -> NSSocketPort
- From: Michael Ash <email@hidden>
- Date: Fri, 27 Nov 2009 09:48:04 -0500
On Fri, Nov 27, 2009 at 6:46 AM, René v Amerongen <email@hidden> wrote:
> Hello,
>
> I' am busy to make an old app up to date and want to use 100% 10.6 cocoa.
> I have +75% percent done, but there is something what I can't figure out.
>
> Network calls are now using NSSocketPort, except a few that uses a fileHandle or fileDescriptor to get an IP address, like:
>
> (NSFileHandle *) fh ... is known and come from another class
> ...
> CFSocketRef socket;
> socket = CFSocketCreateWithNative (kCFAllocatorDefault, [fh fileDescriptor], kCFSocketNoCallBack, NULL, NULL);
> CFDataRef adrData = CFSocketCopyPeerAddress (socket);
> struct sockaddr_in *sock = (struct sockaddr_in *)CFDataGetBytePtr(adrData);
> NSString *address = [NSString stringWithCString:inet_ntoa(sock->sin_addr)]];
> ...
>
> How can I get the IP address from a fileHandle using Cocoa?
> What is the Cocoa alternative of CFSocketCreateWithNative and CFSocketCopyPeerAddress?
There's no Cocoa version of this, as far as I know. However,
CFSocketCopyPeerAddress is just a wrapper around the POSIX function
getpeername(), so you can just get the native socket from your
NSSocketPort and then call that.
Mike
_______________________________________________
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