1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 /* 26 * Copyright 2024 Bill Sommerfeld <sommerfeld@hamachi.org> 27 */ 28 29 30 #ifndef _PING_H 31 #define _PING_H 32 33 #include <sys/types.h> 34 #include <sys/socket.h> 35 #include <sys/uio.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 #define MAX_PORT 65535 /* max port number for UDP probes */ 42 #define MAX_ICMP_SEQ 65535 /* max icmp sequence value */ 43 44 /* 45 * Maximum number of source route space. Please note that because of the API, 46 * we can only specify 8 gateways, the last address has to be the target 47 * address. 48 */ 49 #define MAX_GWS 9 50 51 /* 52 * This is the max it can be. But another limiting factor is the PMTU, 53 * so in any instance, it can be less than 127. 54 */ 55 #define MAX_GWS6 127 56 57 /* maximum of above two */ 58 #define MAXMAX_GWS MAX(MAX_GWS, MAX_GWS6) 59 60 /* size of buffer to store the IPv4 gateway addresses */ 61 #define ROUTE_SIZE (IPOPT_OLEN + IPOPT_OFFSET + \ 62 MAX_GWS * sizeof (struct in_addr)) 63 64 #define A_CNT(ARRAY) (sizeof (ARRAY) / sizeof ((ARRAY)[0])) 65 66 67 #define Printf (void) printf 68 #define Fprintf (void) fprintf 69 70 #define TIMEFORMAT "%#.3f" 71 72 73 /* 74 * For each target IP address we are going to probe, we store required info, 75 * such as address family, IP address of target, source IP address to use 76 * for that target address, and number of probes to send in the targetaddr 77 * structure. 78 * All target addresses are also linked to each other and used in 79 * scheduling probes. Each targetaddr structure identifies a batch of probes to 80 * send : where to send, how many to send. We capture state information, such as 81 * number of probes already sent (in this batch only), whether target replied 82 * as we probe it, whether we are done with probing this address (can happen 83 * in regular (!stats) mode when we get a reply for a probe sent in current 84 * batch), and starting sequence number which is used together with number of 85 * probes sent to determine if the incoming reply is for a probe we sent in 86 * current batch. 87 */ 88 struct targetaddr { 89 int family; 90 union any_in_addr dst_addr; /* dst address for the probe */ 91 union any_in_addr src_addr; /* src addr to use for this dst addr */ 92 int dst_scope; /* scope of dst addr or zero */ 93 int num_probes; /* num of probes to send to this dst */ 94 int num_sent; /* number of probes already sent */ 95 boolean_t got_reply; /* received a reply from dst while */ 96 /* still probing it */ 97 boolean_t probing_done; /* skip without sending all probes */ 98 ushort_t starting_seq_num; /* initial icmp_seq/UDP port, used */ 99 /* for authenticating replies */ 100 struct targetaddr *next; /* next targetaddr item in the list */ 101 }; 102 103 struct hostinfo { 104 char *name; /* hostname */ 105 int family; /* address family */ 106 int num_addr; /* number of addresses */ 107 union any_in_addr *addrs; /* address list */ 108 }; 109 110 struct icmptype_table { 111 int type; /* ICMP type */ 112 char *message; /* corresponding string message */ 113 }; 114 115 extern struct targetaddr *current_targetaddr; 116 extern int nreceived; 117 extern int nreceived_last_target; 118 extern int npackets; 119 extern boolean_t is_alive; 120 extern int datalen; 121 extern boolean_t nflag; 122 extern int ident; 123 extern boolean_t probe_all; 124 extern char *progname; 125 extern boolean_t rr_option; 126 extern boolean_t stats; 127 extern boolean_t strict; 128 extern char *targethost; 129 extern long long tmax; 130 extern long long tmin; 131 extern int ts_flag; 132 extern boolean_t ts_option; 133 extern int64_t tsum; 134 extern int64_t tsum2; 135 extern boolean_t use_icmp_ts; 136 extern boolean_t use_udp; 137 extern boolean_t verbose; 138 extern boolean_t send_reply; 139 140 extern void ping_gettime(struct msghdr *, struct timeval *); 141 extern void set_ancillary_data(struct msghdr *, int, union any_in_addr *, 142 int, uint_t); 143 extern void check_reply(struct addrinfo *, struct msghdr *, int, ushort_t); 144 extern void check_reply6(struct addrinfo *, struct msghdr *, int, ushort_t); 145 extern void find_dstaddr(ushort_t, union any_in_addr *); 146 extern boolean_t is_a_target(struct addrinfo *, union any_in_addr *); 147 extern char *pr_if(int); 148 extern char *pr_name(char *, int); 149 extern char *pr_name_sa(const struct sockaddr *); 150 extern char *pr_name4(const struct sockaddr_in *); 151 extern char *pr_name6(const struct sockaddr_in6 *); 152 extern char *pr_protocol(int); 153 extern void schedule_sigalrm(void); 154 extern void send_scheduled_probe(void); 155 extern boolean_t seq_match(ushort_t, int, ushort_t); 156 extern void set_IPv4_options(int, union any_in_addr *, int, struct in_addr *, 157 struct in_addr *); 158 extern void sigalrm_handler(); 159 extern void tvsub(struct timeval *, struct timeval *); 160 #ifdef __cplusplus 161 } 162 #endif 163 164 #endif /* _PING_H */ 165