-.\" $OpenBSD: traceroute.8,v 1.54 2014/04/18 16:19:11 florian Exp $
+.\" $OpenBSD: traceroute.8,v 1.55 2014/04/21 14:26:10 florian Exp $
.\" $NetBSD: traceroute.8,v 1.6 1995/10/12 03:05:50 mycroft Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\"
.\" @(#)traceroute.8 8.1 (Berkeley) 6/6/93
.\"
-.Dd $Mdocdate: April 18 2014 $
+.Dd $Mdocdate: April 21 2014 $
.Dt TRACEROUTE 8
.Os
.Sh NAME
On hosts with more than one IP address, this option can be used to
force the source address to be something other than the IP address
of the interface the probe packet is sent on.
-If the IP address is not one of this machine's interface addresses an error is
-returned and nothing is sent.
+If the IP address
+is not one of this machine's interface addresses and the user is
+not the superuser, an error is returned and nothing is sent.
.It Fl t Ar toskeyword
Set the
.Em type-of-service
-/* $OpenBSD: traceroute.c,v 1.111 2014/04/19 14:06:10 florian Exp $ */
+/* $OpenBSD: traceroute.c,v 1.112 2014/04/21 14:26:10 florian Exp $ */
/* $NetBSD: traceroute.c,v 1.10 1995/05/21 15:50:45 mycroft Exp $ */
/*-
#include <string.h>
#include <unistd.h>
-#define DUMMY_PORT 10010
-
#define MAX_LSRR ((MAX_IPOPTLEN - 4) / 4)
#define MPLS_LABEL(m) ((m & MPLS_LABEL_MASK) >> MPLS_LABEL_OFFSET)
int nprobes = 3;
u_int8_t max_ttl = IPDEFTTL;
u_int8_t first_ttl = 1;
-u_int16_t srcport;
u_short ident;
u_int16_t port = 32768+666; /* start udp dest port # for probe packets */
u_char proto = IPPROTO_UDP;
setvbuf(stdout, NULL, _IOLBF, 0);
- ident = getpid() & 0xffff;
+ ident = (getpid() & 0xffff) | 0x8000;
tmprnd = arc4random();
sec_perturb = (tmprnd & 0x80000000) ? -(tmprnd & 0x7ff) :
(tmprnd & 0x7ff);
(void) setsockopt(sndsock, SOL_SOCKET, SO_DEBUG,
(char *)&on, sizeof(on));
- (void) memset(&from, 0, sizeof(struct sockaddr));
if (source) {
+ (void) memset(&from, 0, sizeof(struct sockaddr));
from.sin_family = AF_INET;
if (inet_aton(source, &from.sin_addr) == 0)
errx(1, "unknown host %s", source);
(ntohl(from.sin_addr.s_addr) & 0xff000000U) == 0x7f000000U &&
(ntohl(to.sin_addr.s_addr) & 0xff000000U) != 0x7f000000U)
errx(1, "source is on 127/8, destination is not");
- } else {
- struct sockaddr_in nxt;
- int dummy;
-
- nxt = to;
- nxt.sin_port = htons(DUMMY_PORT);
- if ((dummy = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- err(1, "socket");
- if (connect(dummy, (struct sockaddr *)&nxt, sizeof(nxt)) < 0)
- err(1, "connect");
- len = sizeof(from);
- if (getsockname(dummy, (struct sockaddr *)&from, &len) < 0)
- err(1, "getsockname");
- close(dummy);
+ if (getuid() &&
+ bind(sndsock, (struct sockaddr *)&from, sizeof(from)) < 0)
+ err(1, "bind");
}
- from.sin_port = htons(0);
- if (bind(sndsock, (struct sockaddr *)&from, sizeof(from)) < 0)
- err(1, "bind sndsock");
-
- len = sizeof(from);
- if (getsockname(sndsock, (struct sockaddr *)&from, &len) < 0)
- err(1, "getsockname");
- srcport = ntohs(from.sin_port);
if (getnameinfo((struct sockaddr *)&to, to.sin_len, hbuf,
sizeof(hbuf), NULL, 0, NI_NUMERICHOST))
op = (struct packetdata *)(icmpp + 1);
break;
case IPPROTO_UDP:
- up->uh_sport = htons(srcport);
+ up->uh_sport = htons(ident);
if (iflag)
up->uh_dport = htons(port+seq);
else
case IPPROTO_UDP:
up = (struct udphdr *)((u_char *)hip + hlen);
if (hlen + 12 <= cc && hip->ip_p == proto &&
- up->uh_sport == htons(srcport) &&
+ up->uh_sport == htons(ident) &&
((iflag && up->uh_dport == htons(port + seq)) ||
(!iflag && up->uh_dport == htons(port))))
return (type == ICMP_TIMXCEED? -1 : code + 1);