Add -d to set the IP 'DF' flag on outgoing packets.

Without -d it won't be set, regardless of the ip_no_pmtu_disc sysctl
setting on Linux.
This commit is contained in:
Matthieu Herrb 2015-09-29 18:53:51 +02:00
parent d84b68a63a
commit d625d804c6

16
echoc.c
View file

@ -40,7 +40,7 @@ size_t len = 10;
static void static void
usage(void) usage(void)
{ {
errx(2, "usage: echoc [-c nbr][-i ms][-l len][-p port][-t ms][-v] server"); errx(2, "usage: echoc [-c nbr][-d][-i ms][-l len][-p port][-t ms][-v] server");
} }
static void static void
@ -79,16 +79,20 @@ main(int argc, char *argv[])
int nfds, received = 0; int nfds, received = 0;
int error, buffer, last = -1; int error, buffer, last = -1;
int disconnected; int disconnected;
int nofragment = 0;
int we_count = 0, counter; /* don't loop forever */ int we_count = 0, counter; /* don't loop forever */
extern int optind; extern int optind;
setbuf(stdout, NULL); setbuf(stdout, NULL);
while ((ch = getopt(argc, argv, "c:i:l:p:t:v")) != -1) { while ((ch = getopt(argc, argv, "c:di:l:p:t:v")) != -1) {
switch (ch) { switch (ch) {
case 'c': case 'c':
we_count++; we_count++;
counter = atoi(optarg); counter = atoi(optarg);
break; break;
case 'd':
nofragment++;
break;
case 'i': case 'i':
interval = atoi(optarg); interval = atoi(optarg);
break; break;
@ -163,6 +167,14 @@ main(int argc, char *argv[])
if (buf == NULL) if (buf == NULL)
err(2, "malloc receive buffer"); err(2, "malloc receive buffer");
/* set the DF flag ? */
if (nofragment)
ch = IP_PMTUDISC_DO;
else
ch = IP_PMTUDISC_DONT;
if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &ch, sizeof(ch)) < 0)
err(2, "setsockopt IP_MTU_DISCOVER");
while (1) { while (1) {
/* poll() loop to handle interruptions by SIGALRM */ /* poll() loop to handle interruptions by SIGALRM */
while (1) { while (1) {