.TP
.B \-L \fILOCALPORT\fR, \fB\-\-localport \fILOCALPORT
The source port number for UDP traces. When this option is not given,
-UDP traces use the mtr process ID as the source port, unless
+UDP traces use the low 16 bits of the mtr process ID as the source port,
+rotating privileged ports into the high end of the UDP port range unless
.B \-\-port
was given; in that case, UDP traces encode the probe sequence number in
the source port instead.
#include <sys/capability.h>
#endif
+#define MIN_UNPRIVILEGED_PORT 1024
+#define UDP_PORT_RANGE 65536
+
/* A source of data for computing a checksum */
struct checksum_source_t {
const void *data;
size_t size;
};
+static
+uint16_t udp_source_port_from_pid(void)
+{
+ uint16_t port = getpid() & 0xffff;
+
+ if (port < MIN_UNPRIVILEGED_PORT) {
+ port += UDP_PORT_RANGE - MIN_UNPRIVILEGED_PORT;
+ }
+
+ return port;
+}
+
/* Compute the IP checksum (or ICMP checksum) of a packet. */
static
uint16_t compute_checksum(
if (param->local_port) {
udp->srcport = htons(param->local_port);
} else {
- udp->srcport = htons(getpid());
+ udp->srcport = htons(udp_source_port_from_pid());
}
udp->checksum = 0;