xref: /titanic_50/usr/src/cmd/cmd-inet/usr.sbin/ping/ping.h (revision 372a60c34a6075464eaab2e7e079cbbc781f9215)
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 
27 #ifndef _PING_H
28 #define	_PING_H
29 
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <sys/uio.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #define	MAX_PORT	65535   /* max port number for UDP probes */
39 #define	MAX_ICMP_SEQ	65535   /* max icmp sequence value */
40 
41 /*
42  * Maximum number of source route space. Please note that because of the API,
43  * we can only specify 8 gateways, the last address has to be the target
44  * address.
45  */
46 #define	MAX_GWS		9
47 
48 /*
49  * This is the max it can be. But another limiting factor is the PMTU,
50  * so in any instance, it can be less than 127.
51  */
52 #define	MAX_GWS6 	127
53 
54 /* maximum of above two */
55 #define	MAXMAX_GWS	MAX(MAX_GWS, MAX_GWS6)
56 
57 /* size of buffer to store the IPv4 gateway addresses */
58 #define	ROUTE_SIZE 	(IPOPT_OLEN + IPOPT_OFFSET + \
59 			MAX_GWS * sizeof (struct in_addr))
60 
61 #define	A_CNT(ARRAY) (sizeof (ARRAY) / sizeof ((ARRAY)[0]))
62 
63 
64 #define	Printf (void) printf
65 #define	Fprintf (void) fprintf
66 
67 #define	TIMEFORMAT "%#.3f"
68 
69 
70 /*
71  * For each target IP address we are going to probe, we store required info,
72  * such as address family, IP address of target, source IP address to use
73  * for that target address, and number of probes to send in the targetaddr
74  * structure.
75  * All target addresses are also linked to each other and used in
76  * scheduling probes. Each targetaddr structure identifies a batch of probes to
77  * send : where to send, how many to send. We capture state information, such as
78  * number of probes already sent (in this batch only), whether target replied
79  * as we probe it, whether we are done with probing this address (can happen
80  * in regular (!stats) mode when we get a reply for a probe sent in current
81  * batch), and starting sequence number which is used together with number of
82  * probes sent to determine if the incoming reply is for a probe we sent in
83  * current batch.
84  */
85 struct targetaddr {
86 	int family;
87 	union any_in_addr dst_addr;	/* dst address for the probe */
88 	union any_in_addr src_addr;	/* src addr to use for this dst addr */
89 	int num_probes;			/* num of probes to send to this dst */
90 	int num_sent;			/* number of probes already sent */
91 	boolean_t got_reply;		/* received a reply from dst while */
92 					/* still probing it */
93 	boolean_t probing_done;		/* skip without sending all probes */
94 	ushort_t starting_seq_num;	/* initial icmp_seq/UDP port, used */
95 					/* for authenticating replies */
96 	struct targetaddr *next;	/* next targetaddr item in the list */
97 };
98 
99 struct hostinfo {
100 	char *name;			/* hostname */
101 	int family;			/* address family */
102 	int num_addr;			/* number of addresses */
103 	union any_in_addr *addrs;	/* address list */
104 };
105 
106 struct icmptype_table {
107 	int type;		/* ICMP type */
108 	char *message;		/* corresponding string message */
109 };
110 
111 extern struct targetaddr *current_targetaddr;
112 extern int nreceived;
113 extern int nreceived_last_target;
114 extern int npackets;
115 extern boolean_t is_alive;
116 extern int datalen;
117 extern boolean_t nflag;
118 extern int ident;
119 extern boolean_t probe_all;
120 extern char *progname;
121 extern boolean_t rr_option;
122 extern boolean_t stats;
123 extern boolean_t strict;
124 extern char *targethost;
125 extern long long tmax;
126 extern long long tmin;
127 extern int ts_flag;
128 extern boolean_t ts_option;
129 extern int64_t tsum;
130 extern int64_t tsum2;
131 extern boolean_t use_icmp_ts;
132 extern boolean_t use_udp;
133 extern boolean_t verbose;
134 extern boolean_t send_reply;
135 
136 extern void ping_gettime(struct msghdr *, struct timeval *);
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif /* _PING_H */
143