summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2014-03-18 10:11:37 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2014-03-18 10:11:37 +0000
commit5721fd177e5eed07c78ba3af33aa92587162bc05 (patch)
treefe6158bcf9f0997eecb34907bc74b1bc5a2383c7
parent19d345e24d500e76992da177c7a663ee98850685 (diff)
Make print AF independet and use it in traceroute and traceroute6.
OK benno
-rw-r--r--usr.sbin/traceroute/traceroute.c34
-rw-r--r--usr.sbin/traceroute6/traceroute6.c26
2 files changed, 30 insertions, 30 deletions
diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c
index 34c49ec13e3..97e427e4078 100644
--- a/usr.sbin/traceroute/traceroute.c
+++ b/usr.sbin/traceroute/traceroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: traceroute.c,v 1.93 2014/03/18 10:11:00 florian Exp $ */
+/* $OpenBSD: traceroute.c,v 1.94 2014/03/18 10:11:36 florian Exp $ */
/* $NetBSD: traceroute.c,v 1.10 1995/05/21 15:50:45 mycroft Exp $ */
/*-
@@ -261,7 +261,7 @@ void send_probe(int, u_int8_t, int, struct sockaddr_in *);
int packet_ok(u_char *, int, struct sockaddr_in *, int, int);
void dump_packet(void);
void print_exthdr(u_char *, int);
-void print(u_char *, int, struct sockaddr_in *);
+void print(struct sockaddr *, int, const char *);
const char *inetname(struct sockaddr*);
void print_asn(struct sockaddr_storage *);
u_short in_cksum(u_short *, int);
@@ -309,7 +309,7 @@ main(int argc, char *argv[])
struct ip *ip, *inner_ip;
struct icmp *icp;
u_int8_t ttl;
- char *ep;
+ char *ep, hbuf[NI_MAXHOST];
const char *errstr;
long l;
uid_t uid;
@@ -635,7 +635,11 @@ main(int argc, char *argv[])
if (i == 0)
continue;
if (from.sin_addr.s_addr != lastaddr) {
- print(packet, cc, &from);
+ print((struct sockaddr *)&from,
+ (cc - (((struct ip*)packet)->ip_hl
+ <<2)), inet_ntop(AF_INET,
+ &((struct ip*)packet)->ip_dst,
+ hbuf, sizeof(hbuf)));
lastaddr = from.sin_addr.s_addr;
}
dt = (quad_t)(t2.tv_sec - t1.tv_sec) * 1000000 +
@@ -1107,28 +1111,24 @@ packet_ok(u_char *buf, int cc, struct sockaddr_in *from, int seq, int iflag)
}
void
-print(u_char *buf, int cc, struct sockaddr_in *from)
+print(struct sockaddr *from, int cc, const char *to)
{
- struct ip *ip;
- int hlen;
-
- ip = (struct ip *) buf;
- hlen = ip->ip_hl << 2;
- cc -= hlen;
-
+ char hbuf[NI_MAXHOST];
+ if (getnameinfo(from, from->sa_len,
+ hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0)
+ strlcpy(hbuf, "invalid", sizeof(hbuf));
if (nflag)
- printf(" %s", inet_ntoa(from->sin_addr));
+ printf(" %s", hbuf);
else
- printf(" %s (%s)", inetname((struct sockaddr*)from),
- inet_ntoa(from->sin_addr));
+ printf(" %s (%s)", inetname(from), hbuf);
+
if (Aflag)
print_asn((struct sockaddr_storage *)from);
if (verbose)
- printf(" %d bytes to %s", cc, inet_ntoa(ip->ip_dst));
+ printf(" %d bytes to %s", cc, to);
}
-
/*
* Checksum routine for Internet Protocol family headers (C Version)
*/
diff --git a/usr.sbin/traceroute6/traceroute6.c b/usr.sbin/traceroute6/traceroute6.c
index 9bf9411a1ea..0013438c487 100644
--- a/usr.sbin/traceroute6/traceroute6.c
+++ b/usr.sbin/traceroute6/traceroute6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: traceroute6.c,v 1.66 2014/03/18 10:11:00 florian Exp $ */
+/* $OpenBSD: traceroute6.c,v 1.67 2014/03/18 10:11:36 florian Exp $ */
/* $KAME: traceroute6.c,v 1.63 2002/10/24 12:53:25 itojun Exp $ */
/*
@@ -295,7 +295,7 @@ int get_hoplim(struct msghdr *);
double deltaT(struct timeval *, struct timeval *);
char *pr_type(int);
int packet_ok(struct msghdr *, int, int, int);
-void print(struct msghdr *, int);
+void print(struct sockaddr *, int, const char *);
const char *inetname(struct sockaddr *);
void print_asn(struct sockaddr_storage *);
void usage(void);
@@ -736,7 +736,12 @@ main(int argc, char *argv[])
incflag))) {
if (!IN6_ARE_ADDR_EQUAL(&Rcv.sin6_addr,
&lastaddr)) {
- print(&rcvmhdr, cc);
+ print((struct sockaddr *)
+ rcvmhdr.msg_name, cc,
+ rcvpktinfo ? inet_ntop(
+ AF_INET6, &rcvpktinfo->
+ ipi6_addr, hbuf,
+ sizeof(hbuf)) : "?");
lastaddr = Rcv.sin6_addr;
}
printf(" %g ms", deltaT(&t1, &t2));
@@ -1099,27 +1104,22 @@ get_udphdr(struct ip6_hdr *ip6, u_char *lim)
}
void
-print(struct msghdr *mhdr, int cc)
+print(struct sockaddr *from, int cc, const char *to)
{
- struct sockaddr_in6 *from = (struct sockaddr_in6 *)mhdr->msg_name;
char hbuf[NI_MAXHOST];
-
- if (getnameinfo((struct sockaddr *)from, from->sin6_len,
+ if (getnameinfo(from, from->sa_len,
hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0)
strlcpy(hbuf, "invalid", sizeof(hbuf));
if (nflag)
printf(" %s", hbuf);
else
- printf(" %s (%s)", inetname((struct sockaddr *)from), hbuf);
+ printf(" %s (%s)", inetname(from), hbuf);
if (Aflag)
print_asn((struct sockaddr_storage *)from);
- if (verbose) {
- printf(" %d bytes of data to %s", cc,
- rcvpktinfo ? inet_ntop(AF_INET6, &rcvpktinfo->ipi6_addr,
- hbuf, sizeof(hbuf)) : "?");
- }
+ if (verbose)
+ printf(" %d bytes to %s", cc, to);
}
/*