Skip to content

Commit

Permalink
Force resolution of soft AP UDP address to IPv4 (#2)
Browse files Browse the repository at this point in the history
On devices with a cellular connection both the local network connection check and connections to the Soft AP seem to resolve to the cellular interface. Added hard-coding to skip DNS resolution.
  • Loading branch information
stonehouse authored Nov 29, 2023
1 parent 3996c41 commit dad52ed
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Source/GCD/GCDAsyncUdpSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,23 @@ - (void)asyncResolveHost:(NSString *)aHost
NSMutableArray *addresses = [NSMutableArray arrayWithCapacity:2];
NSError *error = nil;

if ([host isEqualToString:@"localhost"] || [host isEqualToString:@"loopback"])
if ([host hasPrefix:@"172.16.0."])
{
struct sockaddr_in sockaddr4;
sockaddr4.sin_len = sizeof(struct sockaddr_in);
sockaddr4.sin_family = AF_INET;
sockaddr4.sin_port = htons(port);
// Grab last octet from IP and convert to int
unsigned int lastByte = [host componentsSeparatedByString:@"."].lastObject.intValue;
// 172.16.0.x
unsigned int address = 0xAC100000 | lastByte;

sockaddr4.sin_addr.s_addr = htonl(address);
memset(&(sockaddr4.sin_zero), 0, sizeof(sockaddr4.sin_zero));

[addresses addObject:[NSData dataWithBytes:&sockaddr4 length:sizeof(sockaddr4)]];
}
else if ([host isEqualToString:@"localhost"] || [host isEqualToString:@"loopback"])
{
// Use LOOPBACK address
struct sockaddr_in sockaddr4;
Expand Down

0 comments on commit dad52ed

Please sign in to comment.