• 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
Address from NSSocketPort
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Address from NSSocketPort


  • Subject: Address from NSSocketPort
  • From: j o a r <email@hidden>
  • Date: Wed, 19 Jun 2002 01:10:42 +0200

Hello,

Does anyone have some idea why this method fails to return the correct address for a connected NSSocketPort:

id socketPort = [myConnection receivePort];
NSString *address = [self addressFromSocketPort:(NSSocketPort *)socketPort];

- (NSString *) addressFromSocketPort:(NSSocketPort *)socketPort
{
NSData *addrData = [socketPort address];
struct sockaddr_in addrIn = *(struct sockaddr_in *)addrData;

NSString *address = [NSString stringWithFormat:@"%s", inet_ntoa(addrIn.sin_addr)];

NSLog(@"Address: %@", address);
NSLog(@"Port: %d", addrIn.sin_port);

return address;
}

It always returns the address 128.0.0.0 and port 44824, when they should be 10.0.1.1 and port 36666.
I'm at this point already using the NSConnection from this NSSocketPort, and since it is working I'm fairly confident that it is using the addresses I have provided. This example is executed at the server, on one of the connections spawned from my vended connection (as far as I have understood how that works).
When I printed out "addrData" I got this:

<10028f3a 00000000 00000000 00000000 >

Seems to be a few too many zeros...

Douglas Davidson gave me the information about the contents of the NSData in a thread over at Mac OS X Dev:

That said, almost all users of NSSocketPort use it with TCP, and in that
case the addresses are IP addresses, and the NSData will hold a struct
sockaddr_in. There are convenience methods for dealing with this case.

...but perhaps I mess up somehow?

Any hints welcome!

Regards,

j o a r
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Address from NSSocketPort
      • From: Douglas Davidson <email@hidden>
    • Re: Address from NSSocketPort
      • From: Sherm Pendley <email@hidden>
  • Prev by Date: Re: Locating Library/Preferences folder...
  • Next by Date: Re: Rotated display of bitmap images?
  • Previous by thread: Re: Locating Library/Preferences folder...
  • Next by thread: Re: Address from NSSocketPort
  • Index(es):
    • Date
    • Thread