• 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
Re: Returning Distant IP Address from CFReadStream
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Returning Distant IP Address from CFReadStream


  • Subject: Re: Returning Distant IP Address from CFReadStream
  • From: Quinn <email@hidden>
  • Date: Mon, 9 Mar 2009 15:14:02 +0000

At 10:14 -0400 9/3/09, Vincent Lecours wrote:
I have some troubles getting back the IP address back from the CFReadStream in my program.

Some points:

o kCFStreamPropertySocketNativeHandle won't return anything useful until the stream has been opened. You'll get back NULL in that case.

o You don't need the CFSocketRef stuff. Once you have CFSocketNativeHandle, you can pass that directly to <x-man-page://2/getpeername>.

o In your CFDataGetBytes call you should be passing in the sizeof(native) rather than CFDataGetLength(nativeProp). That way, if nativeProp is the wrong size (very unlikely), you won't have a buffer overrun.

o You don't need the CFDataGetBytes call at all. You can just get a pointer to the bytes and indirect it.

Here's some code I wrote to do this just today. It assumes that self.output is a NSOutputStream, which is toll-free bridged to CFWriteStream.

- (int)fdOutput
{
    int         result;
    CFDataRef   fdData;

    result = -1;
    if (self.output != nil) {
        fdData = CFWriteStreamCopyProperty(
            (CFWriteStreamRef) self.output,
            kCFStreamPropertySocketNativeHandle
        );
        if (fdData != nil) {
            assert(CFDataGetLength(fdData) == sizeof(result));
            result = *(int *) CFDataGetBytePtr(fdData);
            CFRelease(fdData);
        }
    }
    return result;
}

S+E
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Returning Distant IP Address from CFReadStream
      • From: Vincent Lecours <email@hidden>
References: 
 >Returning Distant IP Address from CFReadStream (From: Vincent Lecours <email@hidden>)

  • Prev by Date: Returning Distant IP Address from CFReadStream
  • Next by Date: Re: Returning Distant IP Address from CFReadStream
  • Previous by thread: Returning Distant IP Address from CFReadStream
  • Next by thread: Re: Returning Distant IP Address from CFReadStream
  • Index(es):
    • Date
    • Thread