Skip to content

Commit

Permalink
Avoid name resolving when we are just trying to ping an ip address
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelle Alten authored and Jelle Alten committed May 28, 2017
1 parent 1a4ab4b commit 2cb0c1c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion MMLanScan/Misc/PingOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ -(instancetype)initWithIPToPing:(NSString*)ip andCompletionHandler:(nullable voi
if (self) {
self.name = ip;
self.ipStr= ip;
self.simplePing = [SimplePing simplePingWithHostName:ip];
self.simplePing = [SimplePing simplePingWithHostAddress:self.addrDataFromIp];
self.simplePing.delegate = self;
self.result = result;
_isExecuting = NO;
Expand All @@ -49,6 +49,17 @@ -(instancetype)initWithIPToPing:(NSString*)ip andCompletionHandler:(nullable voi
return self;
};

- (NSData *)addrDataFromIp {
struct sockaddr_in remoteAddr;
remoteAddr.sin_len = sizeof(remoteAddr);
remoteAddr.sin_family = AF_INET;
remoteAddr.sin_port = htons(161);
const char *ipCStr = [self.ipStr UTF8String];
inet_pton(AF_INET, ipCStr, &remoteAddr.sin_addr);

return [NSData dataWithBytes:&remoteAddr length:remoteAddr.sin_len];
};

-(void)start {


Expand Down

0 comments on commit 2cb0c1c

Please sign in to comment.