Re: NSSocketPort ipv6 vs ipv4 nightmare
Re: NSSocketPort ipv6 vs ipv4 nightmare
- Subject: Re: NSSocketPort ipv6 vs ipv4 nightmare
- From: Aurélien Hugelé <email@hidden>
- Date: Fri, 2 Sep 2005 14:56:32 +0200
Your are indeed right, my bad !
i was confusing local socket address and remote ip address...
On 2 sept. 05, at 09:47, Yann Bizeul wrote:
The socket binds on every interfaces, that seem logic to me that it
returns 0.0.0.0 as ip address :-)
Yann Bizeul • yann at tynsoe.org
Cocoa Developer
Tynsoe Projects
BuddyPop • GeekTool • SSH Tunnel Manager • ...
http://projects.tynsoe.org/
Le 2 sept. 05 à 09:16, Aurélien Hugelé a écrit :
Hi !
i would like to get the IP address (i would prefer IPv4 but can
manage using IPv6) of a NSSocketPort.
port = [[NSSocketPort alloc] initWithTCPPort:6301];
On the remote side, i'm displaying the ip of the source :
NSData* address = [port address];
Since the doc is unclear on this point, i'm trying to know if i
get the ipv6 address or the ipv4 one, so i 've tried both :
struct sockaddr *socketAddress = (struct sockaddr *)
[aAddressData bytes];
char stringBuffer[40];
NSString *addressAsString = nil;
if (socketAddress->sa_family == AF_INET) {
struct sockaddr_in *ipv4 = (struct sockaddr_in *)
socketAddress;
if (inet_ntop(AF_INET, &(ipv4->sin_addr), stringBuffer, 40))
addressAsString = [NSString
stringWithUTF8String:stringBuffer];
using this technique, i ALWAYS get : @"0.0.0.0", which is
explained everywhere : i'm trying to use a ipv4 technique to read
a ipv6 address (see http://developerapple.com/qa/qa2001/qa1298.html)
so it is almost SURE i have a ipv6 address... so i try to read it
(replace the code above by this one below) :
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)
[aAddressData bytes];
// IPv6 Addresses are "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"
char stringBuffer[40];
NSString *addressAsString = nil;
if (socketAddress->sin6_family == AF_INET6) {
if (inet_ntop(AF_INET6, &(ipv6->sin6_addr), stringBuffer,
40))
addressAsString = [NSString
stringWithUTF8String:stringBuffer];
else
addressAsString = @"not an ipv6 address";
using this technique is get strange results like :
"::a367:4b80:c008:0" which seems like a ipv6 address, but it does
not match the one i have in System Preferences -> network...
of course i tried to force IPv4 address by using :
port = [[NSSocketPort alloc] initWithProtocolFamily:PF_INET
socketType:SOCK_STREAM protocol:0 socket:peerSocket];
but i still get 0.0.0.0...
any idea ?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gumitech.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden