• 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: Vincent Lecours <email@hidden>
  • Date: Tue, 10 Mar 2009 10:55:02 -0400

Thanks for the great tips. They helped me a lot! But I still have my problem with the kCFStreamPropertySocketNativeHandle. I have changed my code to this (with the code provided previously):

CFReadStreamRef readStream = NULL;
CFWriteStreamRef writeStream = NULL;
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)distantHost, port, &readStream, &writeStream);
if (readStream && writeStream)
{
CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
}
CFReadStreamOpen(readStream);
CFWriteStreamOpen(writeStream);


int         result;
CFDataRef   fdData;


result = -1;
if (writeStream != nil) {
fdData = CFWriteStreamCopyProperty((CFWriteStreamRef) writeStream, kCFStreamPropertySocketNativeHandle);
if (fdData != nil) {
NSLog(@"fdData is not nil");
assert(CFDataGetLength(fdData) == sizeof(result));
result = *(int *) CFDataGetBytePtr(fdData);
CFRelease(fdData);
}
else
NSLog(@"fdData is nil");
}

readStream and writeStream are not null because further in the code I can read and write from them. distantHost is still an NSString containing either a domain name or an IP address. I open my stream with CFReadStreamOpen and CFWriteStreamOpen (Is it OK?) but when I go through the CFWriteStreamCopyProperty (or CFReadStreamCopyProperty) returns a nil because it logs "fdData is nil". I can't understand why fdData is nil. Am I doing something wrong?
 _______________________________________________
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: Quinn <email@hidden>
    • Re: Returning Distant IP Address from CFReadStream
      • From: Jeremy Wyld <email@hidden>
References: 
 >Returning Distant IP Address from CFReadStream (From: Vincent Lecours <email@hidden>)
 >Re: Returning Distant IP Address from CFReadStream (From: Quinn <email@hidden>)

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