xref: /titanic_52/usr/src/cmd/cmd-inet/usr.sbin/ping/ping.h (revision b08923d6c9c63a4f4b647b84d9454d8124fcedd7)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53c58dfd6Sjbeck  * Common Development and Distribution License, (the "License").
63c58dfd6Sjbeck  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
223c58dfd6Sjbeck  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _PING_H
287c478bd9Sstevel@tonic-gate #define	_PING_H
297c478bd9Sstevel@tonic-gate 
30*b08923d6SRobert Mustacchi #include <sys/types.h>
31*b08923d6SRobert Mustacchi #include <sys/socket.h>
32*b08923d6SRobert Mustacchi #include <sys/uio.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef __cplusplus
357c478bd9Sstevel@tonic-gate extern "C" {
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #define	MAX_PORT	65535   /* max port number for UDP probes */
397c478bd9Sstevel@tonic-gate #define	MAX_ICMP_SEQ	65535   /* max icmp sequence value */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * Maximum number of source route space. Please note that because of the API,
437c478bd9Sstevel@tonic-gate  * we can only specify 8 gateways, the last address has to be the target
447c478bd9Sstevel@tonic-gate  * address.
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate #define	MAX_GWS		9
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * This is the max it can be. But another limiting factor is the PMTU,
507c478bd9Sstevel@tonic-gate  * so in any instance, it can be less than 127.
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate #define	MAX_GWS6 	127
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /* maximum of above two */
557c478bd9Sstevel@tonic-gate #define	MAXMAX_GWS	MAX(MAX_GWS, MAX_GWS6)
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /* size of buffer to store the IPv4 gateway addresses */
587c478bd9Sstevel@tonic-gate #define	ROUTE_SIZE 	(IPOPT_OLEN + IPOPT_OFFSET + \
597c478bd9Sstevel@tonic-gate 			MAX_GWS * sizeof (struct in_addr))
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #define	A_CNT(ARRAY) (sizeof (ARRAY) / sizeof ((ARRAY)[0]))
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #define	Printf (void) printf
657c478bd9Sstevel@tonic-gate #define	Fprintf (void) fprintf
667c478bd9Sstevel@tonic-gate 
673c58dfd6Sjbeck #define	TIMEFORMAT "%#.3f"
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * For each target IP address we are going to probe, we store required info,
727c478bd9Sstevel@tonic-gate  * such as address family, IP address of target, source IP address to use
737c478bd9Sstevel@tonic-gate  * for that target address, and number of probes to send in the targetaddr
747c478bd9Sstevel@tonic-gate  * structure.
757c478bd9Sstevel@tonic-gate  * All target addresses are also linked to each other and used in
767c478bd9Sstevel@tonic-gate  * scheduling probes. Each targetaddr structure identifies a batch of probes to
777c478bd9Sstevel@tonic-gate  * send : where to send, how many to send. We capture state information, such as
787c478bd9Sstevel@tonic-gate  * number of probes already sent (in this batch only), whether target replied
797c478bd9Sstevel@tonic-gate  * as we probe it, whether we are done with probing this address (can happen
807c478bd9Sstevel@tonic-gate  * in regular (!stats) mode when we get a reply for a probe sent in current
817c478bd9Sstevel@tonic-gate  * batch), and starting sequence number which is used together with number of
827c478bd9Sstevel@tonic-gate  * probes sent to determine if the incoming reply is for a probe we sent in
837c478bd9Sstevel@tonic-gate  * current batch.
847c478bd9Sstevel@tonic-gate  */
857c478bd9Sstevel@tonic-gate struct targetaddr {
867c478bd9Sstevel@tonic-gate 	int family;
877c478bd9Sstevel@tonic-gate 	union any_in_addr dst_addr;	/* dst address for the probe */
887c478bd9Sstevel@tonic-gate 	union any_in_addr src_addr;	/* src addr to use for this dst addr */
897c478bd9Sstevel@tonic-gate 	int num_probes;			/* num of probes to send to this dst */
907c478bd9Sstevel@tonic-gate 	int num_sent;			/* number of probes already sent */
917c478bd9Sstevel@tonic-gate 	boolean_t got_reply;		/* received a reply from dst while */
927c478bd9Sstevel@tonic-gate 					/* still probing it */
937c478bd9Sstevel@tonic-gate 	boolean_t probing_done;		/* skip without sending all probes */
947c478bd9Sstevel@tonic-gate 	ushort_t starting_seq_num;	/* initial icmp_seq/UDP port, used */
957c478bd9Sstevel@tonic-gate 					/* for authenticating replies */
967c478bd9Sstevel@tonic-gate 	struct targetaddr *next;	/* next targetaddr item in the list */
977c478bd9Sstevel@tonic-gate };
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate struct hostinfo {
1007c478bd9Sstevel@tonic-gate 	char *name;			/* hostname */
1017c478bd9Sstevel@tonic-gate 	int family;			/* address family */
1027c478bd9Sstevel@tonic-gate 	int num_addr;			/* number of addresses */
1037c478bd9Sstevel@tonic-gate 	union any_in_addr *addrs;	/* address list */
1047c478bd9Sstevel@tonic-gate };
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate struct icmptype_table {
1077c478bd9Sstevel@tonic-gate 	int type;		/* ICMP type */
1087c478bd9Sstevel@tonic-gate 	char *message;		/* corresponding string message */
1097c478bd9Sstevel@tonic-gate };
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate extern struct targetaddr *current_targetaddr;
1127c478bd9Sstevel@tonic-gate extern int nreceived;
1137c478bd9Sstevel@tonic-gate extern int nreceived_last_target;
1147c478bd9Sstevel@tonic-gate extern int npackets;
1157c478bd9Sstevel@tonic-gate extern boolean_t is_alive;
1167c478bd9Sstevel@tonic-gate extern int datalen;
1177c478bd9Sstevel@tonic-gate extern boolean_t nflag;
1187c478bd9Sstevel@tonic-gate extern int ident;
1197c478bd9Sstevel@tonic-gate extern boolean_t probe_all;
1207c478bd9Sstevel@tonic-gate extern char *progname;
1217c478bd9Sstevel@tonic-gate extern boolean_t rr_option;
1227c478bd9Sstevel@tonic-gate extern boolean_t stats;
1237c478bd9Sstevel@tonic-gate extern boolean_t strict;
1247c478bd9Sstevel@tonic-gate extern char *targethost;
1257c478bd9Sstevel@tonic-gate extern long long tmax;
1267c478bd9Sstevel@tonic-gate extern long long tmin;
1277c478bd9Sstevel@tonic-gate extern int ts_flag;
1287c478bd9Sstevel@tonic-gate extern boolean_t ts_option;
1297c478bd9Sstevel@tonic-gate extern int64_t tsum;
1307c478bd9Sstevel@tonic-gate extern int64_t tsum2;
1317c478bd9Sstevel@tonic-gate extern boolean_t use_icmp_ts;
1327c478bd9Sstevel@tonic-gate extern boolean_t use_udp;
1337c478bd9Sstevel@tonic-gate extern boolean_t verbose;
1347c478bd9Sstevel@tonic-gate extern boolean_t send_reply;
1357c478bd9Sstevel@tonic-gate 
136*b08923d6SRobert Mustacchi extern void ping_gettime(struct msghdr *, struct timeval *);
137*b08923d6SRobert Mustacchi 
1387c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate #endif
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #endif /* _PING_H */
143