Skip to content

Will the NAT64(IPv6-Only Networks) does not support ? #405

Closed
@tanshio

Description

@tanshio

Hi.

I use GCDAsyncSoclet.
Will the NAT64(IPv6-Only Networks) does not support ?
I did the work in accordance with the procedure.

719_your_app_and_next_generation_networks_pdf
link

But can't move CocoaAsyncSocket.

[socket connectToHost:SERVER onPort:PORT error:&err]

lost connect Error Domain=NSPOSIXErrorDomain Code=51 "Network is unreachable" UserInfo={NSLocalizedDescription=Network is unreachable, NSLocalizedFailureReason=Error in connect() function}

Won't you please,help me.

Activity

ogkent

ogkent commented on Feb 9, 2016

@ogkent

Set IPv4PreferredOverIPv6 = NO. See issue #315 for more info.

tanshio

tanshio commented on Feb 10, 2016

@tanshio
Author

Thanks.

IPv4PreferredOverIPv6 = NO

It was already set.

But,IP Address can't work.

Domain
[socket2 connectToHost:@"example.com" onPort:8084 error:&err]

Log

GCDAsyncSocket: Dispatching DNS lookup...
GCDAsyncSocket: lookupHost:port:error:
GCDAsyncSocket: readDataWithTimeout:buffer:bufferOffset:maxLength:tag:
GCDAsyncSocket: maybeDequeueRead
GCDAsyncSocket: lookup:didSucceedWithAddress4:address6:
GCDAsyncSocket: connectWithAddress4:address6:error:
GCDAsyncSocket: IPv4: xxx.xxx.xxx.xxx:8084
GCDAsyncSocket: IPv6: xx:xxxx::xxxx:xxxx:8084
GCDAsyncSocket: Creating IPv6 socket
GCDAsyncSocket: Binding socket...

It worked.

But

IP
[socket2 connectToHost:@"xxx.xxx.xxx.xxx" onPort:8084 error:&err]

Log

GCDAsyncSocket: Dispatching DNS lookup...
GCDAsyncSocket: lookupHost:port:error:
GCDAsyncSocket: readDataWithTimeout:buffer:bufferOffset:maxLength:tag:
GCDAsyncSocket: maybeDequeueRead
GCDAsyncSocket: lookup:didSucceedWithAddress4:address6:
GCDAsyncSocket: connectWithAddress4:address6:error:
GCDAsyncSocket: IPv4: xxx.xxx.xxx.xxx:0
GCDAsyncSocket: IPv6: xx:xxxx::xxxx:xxxx:0
GCDAsyncSocket: Creating IPv6 socket
GCDAsyncSocket: Binding socket...

Port Number set 0.
Why?

ogkent

ogkent commented on Feb 10, 2016

@ogkent

Looks like you're trying to use an IPv4 address. Of course IPv6 won't work. You need an IPv6 address, e.g. 2001:db8:85a3:0:0:8a2e:370:7334.

tanshio

tanshio commented on Feb 16, 2016

@tanshio
Author

Thanks.

I created method.

-(NSString *)convertHostToAddress:(NSString *)host {

    NSError *err = nil;

    NSMutableArray *addresses = [GCDAsyncSocket lookupHost:host port:0 error:&err];

    NSLog(@"address%@",addresses);

    NSData *address4 = nil;
    NSData *address6 = nil;

    for (NSData *address in addresses)
    {
        if (!address4 && [GCDAsyncSocket isIPv4Address:address])
        {
            address4 = address;
        }
        else if (!address6 && [GCDAsyncSocket isIPv6Address:address])
        {
            address6 = address;
        }
    }

    NSString *ip;

    if (address6) {
        NSLog(@"ipv6%@",[GCDAsyncSocket hostFromAddress:address6]);
        ip = [GCDAsyncSocket hostFromAddress:address6];
    }else {
        NSLog(@"ipv4%@",[GCDAsyncSocket hostFromAddress:address4]);
        ip = [GCDAsyncSocket hostFromAddress:address4];
    }

    return ip;

}

newacct

newacct commented on Mar 19, 2016

@newacct

You shouldn't need to do that because connectToHost: already calls lookupHost:

jadynJT

jadynJT commented on Jun 22, 2016

@jadynJT

great

JeroldLiu777

JeroldLiu777 commented on Nov 28, 2016

@JeroldLiu777

ok, share my answer.works for me.

1.- (BOOL)connectWithAddress4:(NSData *)address4 address6:(NSData *)address6 error:(NSError **)errPtr
{
      LogTrace();
      NSAssert(dispatch_get_specific(IsOnSocketQueueOrTargetQueueKey), @"Must be dispatched on socketQueue");
      LogVerbose(@"IPv4: %@:%hu", [[self class] hostFromAddress:address4], [[self class] portFromAddress:address4]);
      LogVerbose(@"IPv6: %@:%hu", [[self class] hostFromAddress:address6], [[self class] portFromAddress:address6]);
 
    //add codes blow
    if(address6)
    {
        [self setIPv6Enabled:YES];
    }
……
}

2.- (void)setIPv6Enabled:(BOOL)flag
{
      // Note:YES means kIPv6Disabled is OFF
     
      dispatch_block_t block = ^{
           
            if (flag)
                  config |= kPreferIPv6;   //replace by this
            else
                  config |= kIPv6Disabled;
      };
     ......
    
}

3.GCDAsyncSocket.m
- (BOOL)connectWithAddress4:(NSData *)address4 address6:(NSData *)address6 error:(NSError **)errPtr;
//add codes blow
...
if (address6) {
[self setIPv4PreferredOverIPv6:NO];
}
BOOL preferIPv6 = (config & kPreferIPv6) ? YES : NO;
...

4.
+ (NSMutableArray *)lookupHost:(NSString *)host port:(uint16_t)port error:(NSError **)errPtr; find else if (res->ai_family == AF_INET6)  branch, then replace by blow:
struct sockaddr_in6 *sockaddr = (struct sockaddr_in6 *)res->ai_addr;
in_port_t *portPtr = &sockaddr->sin6_port;
if ((portPtr != NULL) && (*portPtr == 0)) {
*portPtr = htons(port);
}
NSData *address6 = [NSData dataWithBytes:res->ai_addr length:res->ai_addrlen];
[addresses addObject:address6];

DONE

ashishgupta301

ashishgupta301 commented on Jun 7, 2017

@ashishgupta301

In the following method we get address4 and address6,
+(BOOL)connectWithAddress4:(NSData *)address4 address6:(NSData *)address6 error:(NSError **)errPtr

so not working for IPV4. Working fine with IPV6

Any idea about it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @newacct@ogkent@tanshio@jadynJT@ashishgupta301

        Issue actions

          Will the NAT64(IPv6-Only Networks) does not support ? · Issue #405 · robbiehanson/CocoaAsyncSocket