UniPRT SDK v2.0.0.0
 
載入中...
搜尋中...
無符合項目
SimplePing.h
1//
2// SimplePing.h
3// TSCPrinters SDK
4//
5// Created by Realbuber on 2024/4/11.
6//
7
8#ifndef SimplePing_h
9#define SimplePing_h
10
11
12#endif /* SimplePing_h */
13/*
14 Copyright (C) 2016 Apple Inc. All Rights Reserved.
15 See LICENSE.txt for this sample’s licensing information
16
17 Abstract:
18 An object wrapper around the low-level BSD Sockets ping function.
19 */
20#import <Foundation/Foundation.h>
21#include <sys/types.h>
22#include <sys/socket.h>
23//@import Foundation;
24
25#include <AssertMacros.h> // for __Check_Compile_Time
26
27NS_ASSUME_NONNULL_BEGIN
28
30
31@protocol SimplePingDelegate;
32
35
36typedef NS_ENUM(NSInteger, SimplePingAddressStyle) {
37 SimplePingAddressStyleAny,
38 SimplePingAddressStyleICMPv4,
39 SimplePingAddressStyleICMPv6
40};
41
53
54@interface SimplePing : NSObject
55
56- (instancetype)init NS_UNAVAILABLE;
57
63
64- (instancetype)initWithHostName:(NSString *)hostName NS_DESIGNATED_INITIALIZER;
65
68
69@property (nonatomic, copy, readonly) NSString * hostName;
70
75
76@property (nonatomic, weak, readwrite, nullable) id<SimplePingDelegate> delegate;
77
81
82@property (nonatomic, assign, readwrite) SimplePingAddressStyle addressStyle;
83
89
90@property (nonatomic, copy, readonly, nullable) NSData * hostAddress;
91
94
95@property (nonatomic, assign, readonly) sa_family_t hostAddressFamily;
96
101
102@property (nonatomic, assign, readonly) uint16_t identifier;
103
110
111@property (nonatomic, assign, readonly) uint16_t nextSequenceNumber;
112
128
129- (void)start;
130
140
141- (void)sendPingWithData:(nullable NSData *)data;
142
148
149- (void)stop;
150
151@end
152
155
156@protocol SimplePingDelegate <NSObject>
157
158@optional
159
170
171- (void)simplePing:(SimplePing *)pinger didStartWithAddress:(NSData *)address;
172
183
184- (void)simplePing:(SimplePing *)pinger didFailWithError:(NSError *)error;
185
198
199- (void)simplePing:(SimplePing *)pinger didSendPacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber;
200
214
215- (void)simplePing:(SimplePing *)pinger didFailToSendPacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber error:(NSError *)error;
216
226
227- (void)simplePing:(SimplePing *)pinger didReceivePingResponsePacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber;
228
246
247- (void)simplePing:(SimplePing *)pinger didReceiveUnexpectedPacket:(NSData *)packet;
248
249@end
250
251#pragma mark * ICMP On-The-Wire Format
252
260
261struct ICMPHeader {
262 uint8_t type;
263 uint8_t code;
264 uint16_t checksum;
265 uint16_t identifier;
266 uint16_t sequenceNumber;
267 // data...
268};
269typedef struct ICMPHeader ICMPHeader;
270
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);
277
278enum {
279 ICMPv4TypeEchoRequest = 8,
280 ICMPv4TypeEchoReply = 0
281};
282
283enum {
284 ICMPv6TypeEchoRequest = 128,
285 ICMPv6TypeEchoReply = 129
286};
287
289
290NS_ASSUME_NONNULL_END