20#import <Foundation/Foundation.h>
22#include <sys/socket.h>
25#include <AssertMacros.h>
27NS_ASSUME_NONNULL_BEGIN
31@protocol SimplePingDelegate;
36typedef NS_ENUM(NSInteger, SimplePingAddressStyle) {
37 SimplePingAddressStyleAny,
38 SimplePingAddressStyleICMPv4,
39 SimplePingAddressStyleICMPv6
54@interface SimplePing : NSObject
56- (instancetype)init NS_UNAVAILABLE;
64- (instancetype)initWithHostName:(NSString *)hostName NS_DESIGNATED_INITIALIZER;
69@property (nonatomic, copy, readonly) NSString * hostName;
76@property (nonatomic, weak, readwrite, nullable) id<SimplePingDelegate> delegate;
82@property (nonatomic, assign, readwrite) SimplePingAddressStyle addressStyle;
90@property (nonatomic, copy, readonly, nullable) NSData * hostAddress;
95@property (nonatomic, assign, readonly) sa_family_t hostAddressFamily;
102@property (nonatomic, assign, readonly) uint16_t identifier;
111@property (nonatomic, assign, readonly) uint16_t nextSequenceNumber;
141- (void)sendPingWithData:(nullable NSData *)data;
156@protocol SimplePingDelegate <NSObject>
171- (void)simplePing:(SimplePing *)pinger didStartWithAddress:(NSData *)address;
184- (void)simplePing:(SimplePing *)pinger didFailWithError:(NSError *)error;
199- (void)simplePing:(SimplePing *)pinger didSendPacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber;
215- (void)simplePing:(SimplePing *)pinger didFailToSendPacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber error:(NSError *)error;
227- (void)simplePing:(SimplePing *)pinger didReceivePingResponsePacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber;
247- (void)simplePing:(SimplePing *)pinger didReceiveUnexpectedPacket:(NSData *)packet;
251#pragma mark * ICMP On-The-Wire Format
266 uint16_t sequenceNumber;
269typedef struct ICMPHeader ICMPHeader;
271__Check_Compile_Time(
sizeof(ICMPHeader) == 8);
272__Check_Compile_Time(offsetof(ICMPHeader, type) == 0);
273__Check_Compile_Time(offsetof(ICMPHeader, code) == 1);
274__Check_Compile_Time(offsetof(ICMPHeader, checksum) == 2);
275__Check_Compile_Time(offsetof(ICMPHeader, identifier) == 4);
276__Check_Compile_Time(offsetof(ICMPHeader, sequenceNumber) == 6);
279 ICMPv4TypeEchoRequest = 8,
280 ICMPv4TypeEchoReply = 0
284 ICMPv6TypeEchoRequest = 128,
285 ICMPv6TypeEchoReply = 129