-/* $OpenBSD: traceroute.c,v 1.98 2014/04/18 08:44:25 florian Exp $ */
+/* $OpenBSD: traceroute.c,v 1.99 2014/04/18 15:58:43 florian Exp $ */
/* $NetBSD: traceroute.c,v 1.10 1995/05/21 15:50:45 mycroft Exp $ */
/*-
int wait_for_reply(int, struct msghdr *);
void dump_packet(void);
-void send_probe(int, u_int8_t, int, struct sockaddr_in *);
+void build_probe4(int, u_int8_t, int);
+void send_probe(int, u_int8_t, int, struct sockaddr *);
int packet_ok(u_char *, int, struct sockaddr_in *, int, int);
void dump_packet(void);
void print_exthdr(u_char *, int);
int tflag; /* tos flag was set */
int Aflag; /* lookup ASN */
+extern char *__progname;
+
int
main(int argc, char *argv[])
{
int code;
(void) gettimeofday(&t1, NULL);
- send_probe(++seq, ttl, incflag, &to);
+ send_probe(++seq, ttl, incflag, (struct sockaddr*)&to);
while ((cc = wait_for_reply(rcvsock, &rcvmhdr))) {
(void) gettimeofday(&t2, NULL);
i = packet_ok(packet, cc, &from, seq, incflag);
}
void
-send_probe(int seq, u_int8_t ttl, int iflag, struct sockaddr_in *to)
+build_probe4(int seq, u_int8_t ttl, int iflag)
{
struct ip *ip = (struct ip *)outpacket;
u_char *p = (u_char *)(ip + 1);
struct icmp *icmpp = (struct icmp *)(p + lsrrlen);
struct packetdata *op;
struct timeval tv;
- int i;
ip->ip_len = htons(datalen);
ip->ip_ttl = ttl;
if (icmpp->icmp_cksum == 0)
icmpp->icmp_cksum = 0xffff;
}
+}
+
+void
+send_probe(int seq, u_int8_t ttl, int iflag, struct sockaddr *to)
+{
+ int i;
+
+ switch (to->sa_family) {
+ case AF_INET:
+ build_probe4(seq, ttl, iflag);
+ break;
+ default:
+ errx(1, "unsupported AF: %d", to->sa_family);
+ }
if (dump)
dump_packet();
- i = sendto(sndsock, outpacket, datalen, 0, (struct sockaddr *)to,
- sizeof(struct sockaddr_in));
+ i = sendto(sndsock, outpacket, datalen, 0, to, to->sa_len);
if (i < 0 || i != datalen) {
if (i < 0)
perror("sendto");
- printf("traceroute: wrote %s %d chars, ret=%d\n", hostname,
+ printf("%s: wrote %s %d chars, ret=%d\n", __progname, hostname,
datalen, i);
(void) fflush(stdout);
}
-/* $OpenBSD: traceroute6.c,v 1.69 2014/03/27 09:32:18 florian Exp $ */
+/* $OpenBSD: traceroute6.c,v 1.70 2014/04/18 15:58:43 florian Exp $ */
/* $KAME: traceroute6.c,v 1.63 2002/10/24 12:53:25 itojun Exp $ */
/*
} __packed;
u_char packet[512]; /* last inbound (icmp) packet */
-struct opacket *outpacket; /* last output (udp) packet */
+u_char *outpacket; /* last output (udp) packet */
int main(int, char *[]);
int wait_for_reply(int, struct msghdr *);
void dump_packet(void);
-void send_probe(int, u_int8_t, int);
+void build_probe6(int, u_int8_t, int, struct sockaddr *);
+void send_probe(int, u_int8_t, int, struct sockaddr *);
struct udphdr *get_udphdr(struct ip6_hdr *, u_char *);
int get_hoplim(struct msghdr *);
double deltaT(struct timeval *, struct timeval *);
int useicmp;
int Aflag; /* lookup ASN */
+extern char *__progname;
+
int
main(int argc, char *argv[])
{
struct timeval t1, t2;
(void) gettimeofday(&t1, NULL);
- send_probe(++seq, hops, incflag);
+ send_probe(++seq, hops, incflag, (struct sockaddr*)
+ &Dst);
while ((cc = wait_for_reply(rcvsock, &rcvmhdr))) {
(void) gettimeofday(&t2, NULL);
if ((i = packet_ok(&rcvmhdr, cc, seq,
}
void
-send_probe(int seq, u_int8_t hops, int iflag)
+build_probe6(int seq, u_int8_t hops, int iflag, struct sockaddr *to)
{
struct timeval tv;
struct tv32 tv32;
}
if (iflag)
- Dst.sin6_port = htons(port + seq);
+ ((struct sockaddr_in6*)to)->sin6_port = htons(port + seq);
else
- Dst.sin6_port = htons(port);
+ ((struct sockaddr_in6*)to)->sin6_port = htons(port);
(void) gettimeofday(&tv, NULL);
tv32.tv32_sec = htonl(tv.tv_sec);
tv32.tv32_usec = htonl(tv.tv_usec);
icp->icmp6_cksum = 0;
icp->icmp6_id = ident;
icp->icmp6_seq = htons(seq);
- bcopy(&tv32, ((u_int8_t *)outpacket + ICMP6ECHOLEN), sizeof tv32);
+ bcopy(&tv32, ((u_int8_t *)outpacket + ICMP6ECHOLEN),
+ sizeof tv32);
} else {
- struct opacket *op = outpacket;
+ struct opacket *op = (struct opacket *)outpacket;
op->seq = seq;
op->hops = hops;
bcopy(&tv32, &op->tv, sizeof tv32);
}
+}
+
+void
+send_probe(int seq, u_int8_t hops, int iflag, struct sockaddr *to)
+{
+ int i;
+
+ switch (to->sa_family) {
+ case AF_INET6:
+ build_probe6(seq, hops, iflag, to);
+ break;
+ default:
+ errx(1, "unsupported AF: %d", to->sa_family);
+ }
if (dump)
dump_packet();
- i = sendto(sndsock, (char *)outpacket, datalen, 0,
- (struct sockaddr *)&Dst, Dst.sin6_len);
+ i = sendto(sndsock, outpacket, datalen, 0, to, to->sa_len);
if (i < 0 || i != datalen) {
if (i < 0)
perror("sendto");
- printf("traceroute6: wrote %s %d chars, ret=%d\n",
- hostname, datalen, i);
+ printf("%s: wrote %s %d chars, ret=%d\n", __progname, hostname,
+ datalen, i);
(void) fflush(stdout);
}
}