GithubHelp home page GithubHelp logo

gbping's Introduction

GBPing Version License

Highly accurate ICMP Ping controller for iOS (not based on Apple Sample Code, see "Details" section)

Details

This code is a low level ping library that gives extremely accurate round-trip timing results without being impacted by UI and other processing on the main thread. This is not the case with most other ping libraries such as the typical Apple SimplePing which are built as a single threaded class interleaved within the main thread of execution, causing them to suffer from all kinds of indeterministic errors. This library is a multi-threaded class built on top of BSD sockets and GCD, delivering the best possible timing accuracy regardless of system resource state or device performance.

Usage

First import header

#import <GBPing/GBPing.h>

Basic usage:

self.ping = [[GBPing alloc] init];
self.ping.host = @"google.com";
self.ping.delegate = self;
self.ping.timeout = 1.0;
self.ping.pingPeriod = 0.9;

[self.ping setupWithBlock:^(BOOL success, NSError *error) { //necessary to resolve hostname
    if (success) {
        //start pinging
        [self.ping startPinging];
        
        //stop it after 5 seconds
        [NSTimer scheduledTimerWithTimeInterval:5 repeats:NO withBlock:^{
            NSLog(@"stop it");
            [self.ping stop];
            self.ping = nil;
        }];
    }
    else {
        NSLog(@"failed to start");
    }
}];

Implement optional delegate methods:

-(void)ping:(GBPing *)pinger didReceiveReplyWithSummary:(GBPingSummary *)summary {
    NSLog(@"REPLY>  %@", summary);
}

-(void)ping:(GBPing *)pinger didReceiveUnexpectedReplyWithSummary:(GBPingSummary *)summary {
    NSLog(@"BREPLY> %@", summary);
}

-(void)ping:(GBPing *)pinger didSendPingWithSummary:(GBPingSummary *)summary {
    NSLog(@"SENT>   %@", summary);
}

-(void)ping:(GBPing *)pinger didTimeoutWithSummary:(GBPingSummary *)summary {
    NSLog(@"TIMOUT> %@", summary);
}

-(void)ping:(GBPing *)pinger didFailWithError:(NSError *)error {
    NSLog(@"FAIL>   %@", error);
}

-(void)ping:(GBPing *)pinger didFailToSendPingWithSummary:(GBPingSummary *)summary error:(NSError *)error {
    NSLog(@"FSENT>  %@, %@", summary, error);
}

Demo project

See: github.com/lmirosevic/GBPingDemo

Features

GBPing provides the following info (inside a GBPingSummaryObject exposed as properties):

  • NSUInteger sequenceNumber;
  • NSUInteger payloadSize;
  • NSUInteger ttl;
  • NSString *host;
  • NSDate *sendDate;
  • NSDate *receiveDate;
  • NSTimeInterval rtt;
  • GBPingStatus status;

Dependencies

None

Copyright & License

Copyright 2015 Luka Mirosevic

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

gbping's People

Contributors

bprodoehl avatar chorgo avatar froemic avatar lmirosevic avatar mohammad-rahchamani avatar mosobase avatar muer2000 avatar oliverletterer avatar petr-vysotskiy avatar poplax avatar ptescher avatar robnadin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gbping's Issues

OSX support

please make the library build on OS X also.

Crash: -[GBPing stop] (GBPing.m:635)

Fatal Exception: NSMallocException
*** attempt to create a temporary id buffer of length (576460752303423486) failed

Fatal Exception: NSMallocException
0  CoreFoundation                 0x18bf4afe0 __exceptionPreprocess
1  libobjc.A.dylib                0x18a9ac538 objc_exception_throw
2  CoreFoundation                 0x18be49f48 CFStringGetPascalStringPtr
3  GBPing                         0x100da3828 -[GBPing stop] (GBPing.m:635)
4  GBPing                         0x100da2404 -[GBPing listenOnce] (GBPing.m:448)
5  GBPing                         0x100da1ef0 -[GBPing listenLoop] (GBPing.m:352)
6  Foundation                     0x18ca3e2d8 __NSThread__start__
7  libsystem_pthread.dylib        0x18b00d68c _pthread_body
8  libsystem_pthread.dylib        0x18b00d59c _pthread_body
9  libsystem_pthread.dylib        0x18b00acb4 thread_start

I've never seen this before and the only StackOverflow post I can find on it (https://stackoverflow.com/questions/26549610/attempt-to-create-a-temporary-id-buffer-which-is-too-large-or-with-a-negative-c) isn't helpful, but here's the crash. Running 1.4.0, so line 635 is:

for (NSNumber *key in [self.timeoutTimers copy]) {

The whole loop is:

for (NSNumber *key in [self.timeoutTimers copy]) {
                NSTimer *timer = self.timeoutTimers[key];
                [timer invalidate];
            }

Since this code is in a @syncrhonized block I don't see anything wrong with it. Sorry I can't be of more help. Would love to hear anyone's insight on the matter though.

sendPing crash

Hi

I'm seeing a huge amount of crash reports that points to

dispatch_block_t callback = timer.userInfo;

in function _invokeTimeoutCallback in GBPing.m file.

I have no idea about it and can't reproduce it but trust me, there are tons of crashes.

any guess would be appreciated.

Using (very) low pingPeriod not working

I want to determine the network connection quality during app startup as quickly as possible. One idea was to send out a burst of a couple of pings, and measure average RTT and timeouts.

Using GBPing, I found that the time between 2 pings sent is approx. 1 second at minimum, regardless of whether I set the pingPeriod to be 1.0, 0.5 or 0.05. (Setting values greater than 1 second works correctly, though).

What do I need to do to send out more pings / with less delay between the pings?

Multiple zombie threads

Seems like GBPing is currently spawning multiple zombie threads.

    -(void)sendLoop {
        @autoreleasepool {
            while (self.isPinging) {
                [self sendPing];

                NSTimeInterval runUntil = CFAbsoluteTimeGetCurrent() + self.pingPeriod;
                NSTimeInterval time = 0;
                while (runUntil > time) {
                    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantFuture]];
                    time = CFAbsoluteTimeGetCurrent();
                }
            }
        }
    }

This is an infinite loop

IPv6 Support

My apologies if I'm missing this and it will already work, but this library could really use IPv6 support!

Ping result time

Hello , how can I get the response time with this library ? I want time in ms.
thanks.

RTT is not LATENCY

LATENCY: The amount of time physically required for media to travel depending on media length and distance that need to be covered

RTT: Round Trip Trime, A round trip time required to travel from source to destination and vice versa.

So there is no way of getting latency from this library in ms ?

TTL not set correctly

I noticed that the TTL of the returned PingSummary objects is not set correctly. In the current implementation it is set to the TTL with which the package was sent with, but it should be the TTL of the response.

Quick Fix: add the following code after line 410

const struct IPHeader   *ipPtr;
if ([packet length] >= sizeof(IPHeader)) {
    ipPtr = (const IPHeader *)[packet bytes];
                            
     pingSummary.ttl = ipPtr->timeToLive;
}

pingSummary.host = [[self class] sourceAddressInPacket:packet];

NSMallocException

I am having a lot of crashes (NSMallocException) that points to :

for (NSNumber *key in [self.timeoutTimers copy]) inside GBPing.m -> stop()

I am not able to reproduce the scenario but on Fabric, I have got 40+ crashes. Any idea what would be the reason or any checks do I need to add before calling stop() ?

Bad Access Error on listen thread when pinging multiple IPs

Hello again,

I'm trying to see if this library is capable of pinging multiple IP's. What I'm doing is basically making it ping an entire range of IPs. It seems possible, but occasionally I get this EXC_BAD_ACCESS error on this line of code that lives in the GBPing.m in the listenOnce method:

GBPingSummary *pingSummary = [(GBPingSummary *)self.pendingPings[key] copy];

I'm setting it up like this

GBPing *pinger;
    pinger = [[GBPing alloc] init];
    pinger.host = ipAddress;
    pinger.delegate = self;
    pinger.timeout = 1.0;
    pinger.pingPeriod = 0.9;

    [pinger setupWithBlock:^(BOOL success, NSError *error) { //necessary to resolve hostname
        if (success) {
            //start pinging
            [pinger startPinging];

            //stop it after 5 seconds
            [NSTimer scheduledTimerWithTimeInterval:5 repeats:NO withBlock:^{

                [pinger stop];
            }];
        }
        else {
            NSLog(@"failed to start");
        }
    }];

and pulling in the IP addresses like this - 5 at a time in 3 second chunks

-(void)pingIPRange{
    dispatch_async(backgroundQueue, ^{
        for (int i = hostCount; i < hostCount + 5; i++) {
            NSString *ip = [NSString stringWithFormat:@"192.168.11.%i", i];
            [self pingIPRangeForBroadcastIP:nil withIP:ip];
        }
        [self restartTimer];
    });
}

and then doing this in the reply delegate to kick off the next ping

- (void)restartTimer{
    hostCount += 5;
    if (hostCount > 254){
        hostCount = 101;
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [timer invalidate];
        timer = nil;
        timer = [NSTimer scheduledTimerWithTimeInterval:3.0
                                                 target:self
                                               selector:@selector(pingIPRange)
                                               userInfo:nil
                                                repeats:YES];
    });
}

starting the host count at 101. Apologies for my ignorance. Just want to see if this is possible at all and if so what the proper way might be to set it up. Thanks!

IPv6

What about IPv6 support?

-[GBPing isValidPing4ResponsePacket:] (GBPing.m:774)

libsystem_kernel.dylib __pthread_kill + 8
1 libsystem_pthread.dylib _pthread_kill$VARIANT$mp + 376
2 libsystem_c.dylib abort + 140
3 libsystem_c.dylib basename_r + 0
4 ?????? -[GBPing isValidPing4ResponsePacket:] (GBPing.m:774)
5 ?????? -[GBPing listenOnce] (GBPing.m:407)
6 ?????? -[GBPing listenLoop] (GBPing.m:354)
7 Foundation _NSThread__start + 1040
8 libsystem_pthread.dylib __pthread_body + 272
9 libsystem_pthread.dylib __pthread_body

concurrent modification

there is a problem with timeoutTimers dictionary that when we are trying to invalidate all timers in stop method we also try to remove an object from it in listenOnce method concurrently. I've faced it several times.

Issues with pinging broadcast IP

Thanks for such a nice clean piece of functionality. I was trying to see if I could use a broadcast IP (192.168.1.255) as a host name to see what sort of reply comes back. I was hoping for a reply from all devices (same as you get when pinging broadcast IP in terminal) but however the responses would come back with 2-3 hosts at best. Is there a way to return all hosts attempting to respond?

action

self.ping = [[GBPing alloc] init];
    self.ping.host = @"192.168.11.255";
    self.ping.delegate = self;
    self.ping.timeout = 1;
    self.ping.pingPeriod = 0.9;

    [self.ping setupWithBlock:^(BOOL success, NSError *error) { //necessary to resolve hostname
        if (success) {
            //start pinging
            [self.ping startPinging];

            //stop it after 5 seconds
            [NSTimer scheduledTimerWithTimeInterval:100 repeats:NO withBlock:^{
                NSLog(@"stop it");
                [_ping stop];
                _ping = nil;
            }];
        }
        else {
            NSLog(@"failed to start");
        }
    }];

response

2014-12-23 12:53:34.711 MACFinder[99136:28931931] SENT>   host: 192.168.11.255, seq: 0, status: 0, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:34 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:34.715 MACFinder[99136:28931931] REPLY>  host: 192.168.11.166, seq: 0, status: 1, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:34 +0000, receiveDate: 2014-12-23 01:53:34 +0000, rtt: 0.005246
2014-12-23 12:53:35.615 MACFinder[99136:28931931] BREPLY> host: 192.168.11.255, seq: 1, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:35 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:35.615 MACFinder[99136:28931931] SENT>   host: 192.168.11.255, seq: 1, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:35 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:35.686 MACFinder[99136:28931931] REPLY>  host: 192.168.11.241, seq: 1, status: 1, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:35 +0000, receiveDate: 2014-12-23 01:53:35 +0000, rtt: 0.071799
2014-12-23 12:53:36.515 MACFinder[99136:28931931] BREPLY> host: 192.168.11.255, seq: 2, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:36 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:36.515 MACFinder[99136:28931931] SENT>   host: 192.168.11.255, seq: 2, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:36 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:36.612 MACFinder[99136:28931931] REPLY>  host: 192.168.11.241, seq: 2, status: 1, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:36 +0000, receiveDate: 2014-12-23 01:53:36 +0000, rtt: 0.096322
2014-12-23 12:53:37.421 MACFinder[99136:28931931] SENT>   host: 192.168.11.255, seq: 3, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:37 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:37.421 MACFinder[99136:28931931] BREPLY> host: 192.168.11.255, seq: 3, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:37 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:37.460 MACFinder[99136:28931931] REPLY>  host: 192.168.11.241, seq: 3, status: 1, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:37 +0000, receiveDate: 2014-12-23 01:53:37 +0000, rtt: 0.039744
2014-12-23 12:53:38.324 MACFinder[99136:28931931] BREPLY> host: 192.168.11.255, seq: 4, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:38 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:38.324 MACFinder[99136:28931931] SENT>   host: 192.168.11.255, seq: 4, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:38 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:38.368 MACFinder[99136:28931931] REPLY>  host: 192.168.11.241, seq: 4, status: 1, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:38 +0000, receiveDate: 2014-12-23 01:53:38 +0000, rtt: 0.043432
2014-12-23 12:53:39.227 MACFinder[99136:28931931] SENT>   host: 192.168.11.255, seq: 5, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:39 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:39.227 MACFinder[99136:28931931] BREPLY> host: 192.168.11.255, seq: 5, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:39 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:39.285 MACFinder[99136:28931931] REPLY>  host: 192.168.11.241, seq: 5, status: 1, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:39 +0000, receiveDate: 2014-12-23 01:53:39 +0000, rtt: 0.058213
2014-12-23 12:53:40.131 MACFinder[99136:28931931] SENT>   host: 192.168.11.255, seq: 6, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:40 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:40.131 MACFinder[99136:28931931] BREPLY> host: 192.168.11.255, seq: 6, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:40 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:40.162 MACFinder[99136:28931931] REPLY>  host: 192.168.11.241, seq: 6, status: 1, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:40 +0000, receiveDate: 2014-12-23 01:53:40 +0000, rtt: 0.031371
2014-12-23 12:53:41.034 MACFinder[99136:28931931] SENT>   host: 192.168.11.255, seq: 7, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:41 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:41.035 MACFinder[99136:28931931] BREPLY> host: 192.168.11.255, seq: 7, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:41 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:41.062 MACFinder[99136:28931931] REPLY>  host: 192.168.11.241, seq: 7, status: 1, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:41 +0000, receiveDate: 2014-12-23 01:53:41 +0000, rtt: 0.027948
2014-12-23 12:53:41.935 MACFinder[99136:28931931] SENT>   host: 192.168.11.255, seq: 8, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:41 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:41.935 MACFinder[99136:28931931] BREPLY> host: 192.168.11.255, seq: 8, status: 2, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:41 +0000, receiveDate: (null), rtt: 0.000000
2014-12-23 12:53:41.951 MACFinder[99136:28931931] REPLY>  host: 192.168.11.241, seq: 8, status: 1, ttl: 49, payloadSize: 56, sendDate: 2014-12-23 01:53:41 +0000, receiveDate: 2014-12-23 01:53:41 +0000, rtt: 0.015854

timeoutTimers is nil sometimes

in sendPing function, sometimes self.timeoutTimer returns nil , so self.timeoutTimers[key] = timeoutTimer; throws exception.

_hostRef deallocation on separate thread causing EXC_BAD_ACCESS

Kind of hard to explain this one, mainly because its hard to test. The _hostRef variable used in -(void)setupWithBlock: is released in -(void)stop, this means theres a slim chance that even after checking that the value is !nil there is a small window where it could become nil causing this error, I ran into that today

Xcode 9 Beta 3 issues

GBPing is unable to compile with the latest Xcode 9 Beta 3.

There is alot of complaining about expected parameter declarations for ICMPHeader.h but I think thats just the tip of the ice berg as Apple LLVM 9.0 has too many errors emitted.

Has anyone else run into these issues?

Ping timeout delegate never called

So unless I'm not understanding how it works, the didTimeoutWithSummary delegate method never seems to get called even though the timeout is set to the default 2 seconds.

I'm testing with the link conditioner set to 100% loss so GBPing just sends out a bunch of pings but obviously never receives a response, so I would expect after a few pings the timeout delegate should have been called.

any pointers?

Cocoapods not working

I tried to install using cocoapods, but I get this error:
[!] Unable to find a specification for GBPing depended upon by Podfile.

EXC_BAD_ACCESS in hostAddressFamily - m:897

Very rarely, but more than once, I'm getting an EXC_BAD_ACCESS crash in the hostAddressFamily{} method.

I believe that self.hostAddress is the culprit:

  • (sa_family_t)hostAddressFamily {
    sa_family_t result;

    result = AF_UNSPEC;
    if ((self.hostAddress != nil) && (self.hostAddress.length >= sizeof(struct sockaddr)) ) {
    result = ((const struct sockaddr *) self.hostAddress.bytes)->sa_family; // crash here ***, EXC_BAD_ACCESS, KERN_INVALID_ADDRESS at 0x0000000000000001
    }
    return result;
    }

Excerpts from the crash report -----------------

Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: redacted [28472]
User ID: 501

Date/Time: 2018-02-04 22:38:48.506 -0700
OS Version: Mac OS X 10.13.3 (17D47)
Report Version: 12
Anonymous UUID: 9291B4DF-41B5-508A-2146-09CB031378C5

Time Awake Since Boot: 370000 seconds

System Integrity Protection: disabled

Crashed Thread: 8 listenThread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000001
Exception Note: EXC_CORPSE_NOTIFY

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]

System Profile:
Network Service: Ethernet, Ethernet, en0
Thunderbolt Bus: Mac mini, Apple Inc., 23.4
Boot Volume File System Type: apfs
Memory Module: BANK 0/DIMM0, 4 GB, DDR3, 1600 MHz, 0x85F7, 0x483634353155363447313630304700000000
Memory Module: BANK 1/DIMM0, 4 GB, DDR3, 1600 MHz, 0x85F7, 0x483634353155363447313630304700000000
USB Device: USB 2.0 Bus
USB Device: Hub
USB Device: Hub
USB Device: IR Receiver
USB Device: BRCM20702 Hub
USB Device: Bluetooth USB Host Controller
USB Device: USB 2.0 Bus
USB Device: Hub
USB Device: USB 3.0 Bus
USB Device: G-DRIVE mini5
USB Device: Keyspan USA-28Xb
Serial ATA Device: OWC Mercury EXTREME Pro 6G SSD, 480.1 GB
Model: Macmini6,1, BootROM MM61.010B.B00, 2 processors, Intel Core i5, 2.5 GHz, 8 GB, SMC 2.7f0
Graphics: Intel HD Graphics 4000, Intel HD Graphics 4000, Built-In
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x10E), Broadcom BCM43xx 1.0 (7.21.190.16.1a2)
Bluetooth: Version 6.0.2f2, 3 services, 27 devices, 1 incoming serial ports

Get result from delegate

Hi, I've implemented your classes in my xCode project.
Everything works fine but I have a specific problem with synchronicity.

I provide a method that pings N hosts in my LAN. I need to know if every Ping goes well or not, but I can know this only through delegate methods.

Code was inserted into PingHelper.m class.

`
for(int i=1; i< pow(2,(32-netmask)) -1; i++){

    ph[i] = [[PingHelper alloc] init];

    NSString *finalAddr = [IPHelper composeIPv4:addrs[0] netmask:netmask host:i];

    [ph[i] ping:finalAddr semaphore:NULL];

    data.generic_counter++;

}`

And PingHelper contains:

`-(BOOL)ping:(NSString*)host semaphore:(dispatch_semaphore_t)sem{
self->ping = [[GBPing alloc] init];
self->ping.host = host;
self->ping.delegate = self;
self->ping.timeout = 1.0;
self->ping.pingPeriod = 0.9;

[self->ping setupWithBlock:^(BOOL success, NSError *error) { //necessary to resolve hostname
    if (success) {
        //start pinging
        [self->ping startPinging];

    }
    else {
        NSLog(@"failed to start");
    }
}];

//while(!finished);
return result;

}`

Any help will be appreciated.
Thanks,
Emanuele

Enable OS X Support

It would be great if you could modify the podspec to include OS X compatibility. We are using GBPing on both iOS and OS X without issues, so I know it works properly.

Right now I have to add the GBPing sources to my own pod rather than being able to track the official pod. It would be great to not have to do the maintenance to keep in sync with the main tree.

ARC compilation issues

I'm unable to get GBPing to compile on the latest iOS SDK. In the section:

//clean up dispatch queue
if (self.setupQueue) {
    //foo check that this actually works
    dispatch_release(self.setupQueue);
    self.setupQueue = nil;
}

it complains that 'release' is not available in automatic reference counting mode for the dispatch_release call.

Prior to iOS 9, I was able to comment out the dispatch_release line and make setupQueue into a strong reference. However doing that with the new SDK causes a EXC_BAD_ACCESS exception at:
NSArray *addresses = (__bridge NSArray *)CFHostGetAddressing(_hostRef, &resolved);
because _hostRef is null.

I should note that we are pinging 3 different hosts, so that may be setting up some unusual conditions.

Crash: -[GBPing sendPing] (GBPing.m:550)

[self.timeoutTimers removeObjectForKey:key]; makes the crash.
I'm not sure how to fix it and do not know how to reproduce it. It happens only twice during last 30 days.

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000

Crashed: sendThread
0  CoreFoundation                 0x182e14b40 -[__NSDictionaryM removeObjectForKey:] + 440
1  ??????                         0x1006ff578 __18-[GBPing sendPing]_block_invoke.217 (GBPing.m:550)
2  Foundation                     0x183e34374 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16
3  Foundation                     0x183d871a0 -[NSBlockOperation main] + 96
4  Foundation                     0x183e50e6c __NSFireTimer + 88
5  CoreFoundation                 0x182ec4c3c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
6  CoreFoundation                 0x182ec48e0 __CFRunLoopDoTimer + 884
7  CoreFoundation                 0x182ec1ff4 __CFRunLoopRun + 1520
8  CoreFoundation                 0x182df0ca0 CFRunLoopRunSpecific + 384
9  Foundation                     0x183d692bc -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 308
10 Foundation                     0x183d8a408 -[NSRunLoop(NSRunLoop) runUntilDate:] + 96
11 ??????                         0x1006fea04 -[GBPing sendLoop] (GBPing.m:463)
12 Foundation                     0x183e4fc80 __NSThread__start__ + 1000
13 libsystem_pthread.dylib        0x198ddfb28 _pthread_body + 156
14 libsystem_pthread.dylib        0x198ddfa8c _pthread_body + 154
15 libsystem_pthread.dylib        0x198ddd028 thread_start + 4

Crash: -[GBPing stop] (GBPing.m:633)

Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x181529b90 objc_msgSend + 16
1  CoreFoundation                 0x181ddeefc -[__NSDictionaryM removeAllObjects] + 512
2  ??????                         0x10069a554 -[GBPing stop] (GBPing.m:633)
3  ??????                         0x100313c70 specialized Ping.(start(completion : ([String : [String]]?) -> ()) -> ()).(closure #2).(closure #1).(closure #1) (Ping.swift:103)
4  ??????                         0x100314d6c partial apply for Ping.(start(completion : ([String : [String]]?) -> ()) -> ()).(closure #2).(closure #1).(closure #1) (Ping.swift)
5  libdispatch.dylib              0x1818fd4bc _dispatch_call_block_and_release + 24
6  libdispatch.dylib              0x1818fd47c _dispatch_client_callout + 16
7  libdispatch.dylib              0x181908d08 _dispatch_after_timer_callback + 92
8  libdispatch.dylib              0x1818fd47c _dispatch_client_callout + 16
9  libdispatch.dylib              0x181914090 _dispatch_source_latch_and_call + 2556
10 libdispatch.dylib              0x1818ff970 _dispatch_source_invoke + 808
11 libdispatch.dylib              0x18190263c _dispatch_main_queue_callback_4CF + 492
12 CoreFoundation                 0x181e68d50 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
13 CoreFoundation                 0x181e66bb8 __CFRunLoopRun + 1628
14 CoreFoundation                 0x181d90c50 CFRunLoopRunSpecific + 384
15 GraphicsServices               0x183678088 GSEventRunModal + 180
16 UIKit                          0x18707a088 UIApplicationMain + 204
17 ??????                         0x1000e2f04 main (main.m:14)
18 libdispatch.dylib              0x18192e8b8 (Missing)

It looks wired to me. I've no idea yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.