xref: /openbsd-src/usr.sbin/traceroute/traceroute.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: traceroute.h,v 1.1 2016/09/03 22:00:06 benno Exp $	*/
2 /*	$NetBSD: traceroute.c,v 1.10 1995/05/21 15:50:45 mycroft Exp $	*/
3 
4 /*
5  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the project nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 /*-
34  * Copyright (c) 1990, 1993
35  *	The Regents of the University of California.  All rights reserved.
36  *
37  * This code is derived from software contributed to Berkeley by
38  * Van Jacobson.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  * 1. Redistributions of source code must retain the above copyright
44  *    notice, this list of conditions and the following disclaimer.
45  * 2. Redistributions in binary form must reproduce the above copyright
46  *    notice, this list of conditions and the following disclaimer in the
47  *    documentation and/or other materials provided with the distribution.
48  * 3. Neither the name of the University nor the names of its contributors
49  *    may be used to endorse or promote products derived from this software
50  *    without specific prior written permission.
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62  * SUCH DAMAGE.
63  */
64 
65 
66 #include <netinet/ip_var.h>
67 #include <netmpls/mpls.h>
68 #include <sys/cdefs.h>
69 #include <sys/types.h>
70 
71 #define DUMMY_PORT 10010
72 
73 #define MAX_LSRR		((MAX_IPOPTLEN - 4) / 4)
74 
75 #define MPLS_LABEL(m)		((m & MPLS_LABEL_MASK) >> MPLS_LABEL_OFFSET)
76 #define MPLS_EXP(m)		((m & MPLS_EXP_MASK) >> MPLS_EXP_OFFSET)
77 
78 /*
79  * Format of the data in a (udp) probe packet.
80  */
81 struct packetdata {
82 	u_char seq;		/* sequence number of this packet */
83 	u_int8_t ttl;		/* ttl packet left with */
84 	u_char pad[2];
85 	u_int32_t sec;		/* time packet left */
86 	u_int32_t usec;
87 } __packed;
88 
89 extern struct in_addr	 gateway[MAX_LSRR + 1];
90 extern int		 lsrrlen;
91 extern int32_t		 sec_perturb;
92 extern int32_t		 usec_perturb;
93 
94 extern u_char		 packet[512];
95 extern u_char		*outpacket;	/* last inbound (icmp) packet */
96 
97 int		 wait_for_reply(int, struct msghdr *);
98 void		 dump_packet(void);
99 void		 build_probe4(int, u_int8_t, int);
100 void		 build_probe6(int, u_int8_t, int, struct sockaddr *);
101 void		 send_probe(int, u_int8_t, int, struct sockaddr *);
102 struct udphdr	*get_udphdr(struct ip6_hdr *, u_char *);
103 int		 packet_ok(int, struct msghdr *, int, int, int);
104 int		 packet_ok4(struct msghdr *, int, int, int);
105 int		 packet_ok6(struct msghdr *, int, int, int);
106 void		 icmp_code(int, int, int *, int *);
107 void		 icmp4_code(int, int *, int *);
108 void		 icmp6_code(int, int *, int *);
109 void		 dump_packet(void);
110 void		 print_exthdr(u_char *, int);
111 void		 check_tos(struct ip*);
112 void		 print(struct sockaddr *, int, const char *);
113 const char	*inetname(struct sockaddr*);
114 void		 print_asn(struct sockaddr_storage *);
115 u_short		 in_cksum(u_short *, int);
116 char		*pr_type(u_int8_t);
117 int		 map_tos(char *, int *);
118 double		 deltaT(struct timeval *, struct timeval *);
119 
120 void		 gettime(struct timeval *);
121 
122 extern int		 rcvsock;  /* receive (icmp) socket file descriptor */
123 extern int		 sndsock;  /* send (udp) socket file descriptor */
124 
125 extern int		 rcvhlim;
126 extern struct in6_pktinfo *rcvpktinfo;
127 
128 extern int		 datalen;  /* How much data */
129 
130 extern char		*hostname;
131 
132 extern u_short		 ident;
133 extern u_int16_t	 srcport;
134 extern u_int16_t	 port;	   /* start udp dest port # for probe packets */
135 extern u_char		 proto;
136 
137 #define ICMP_CODE 0;
138 
139 extern int verbose;
140 extern int waittime;		/* time to wait for response (in seconds) */
141 extern int nflag;		/* print addresses numerically */
142 extern int dump;
143 extern int Aflag;		/* lookup ASN */
144 extern int last_tos;
145 
146 extern char *__progname;
147