• 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
NSSocketPort ipv6 vs ipv4 nightmare
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSSocketPort ipv6 vs ipv4 nightmare


  • Subject: NSSocketPort ipv6 vs ipv4 nightmare
  • From: AurĂ©lien HugelĂ© <email@hidden>
  • Date: Fri, 2 Sep 2005 09:16:49 +0200

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://developer.apple.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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSSocketPort ipv6 vs ipv4 nightmare
      • From: Yann Bizeul <email@hidden>
    • Re: NSSocketPort ipv6 vs ipv4 nightmare
      • From: j o a r <email@hidden>
  • Prev by Date: Finding all Apple Events
  • Next by Date: Re: NSSocketPort ipv6 vs ipv4 nightmare
  • Previous by thread: Re: Finding all Apple Events
  • Next by thread: Re: NSSocketPort ipv6 vs ipv4 nightmare
  • Index(es):
    • Date
    • Thread