Re: Address from NSSocketPort
Re: Address from NSSocketPort
- Subject: Re: Address from NSSocketPort
- From: Douglas Davidson <email@hidden>
- Date: Tue, 18 Jun 2002 16:47:03 -0700
On Tuesday, June 18, 2002, at 04:10 PM, j o a r wrote:
NSData *addrData = [socketPort address];
struct sockaddr_in addrIn = *(struct sockaddr_in *)addrData;
That's an NSData whose contents are a struct sockaddr_in. You need
(struct sockaddr_in *)[addrData bytes]. What you wrote constructs a
struct sockaddr_in from the object itself--the isa, ivars, etc.--rather
than from its contents.
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 >
That looks right. 10 is the length, 16; 02 is the family, AF_INET; 8f3a
is the port number, 36666. The IP address is left at 0, presumably
because that is how you created the socket; in other words, it is not
bound to a specific network interface. There is no reason to expect to
get the IP address of one of your network interfaces back from this.
You are free to create your NSSocketPort with an explicit address, if
you do not like the way that initWithTCPPort: is doing it.
Douglas Davidson
_______________________________________________
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.