#include <windows.h>
#endif
#include <assert.h>
+#include <errno.h>
#include <strings.h>
#include <unistd.h>
return ActionNone;
case 'b':
mvprintw(2, 0, "Ping Bit Pattern: %d\n", ctl->bitpattern);
- mvprintw(3, 0, "Pattern Range: 0(0x00)-255(0xff), <0 random.\n");
+ mvprintw(3, 0, "Pattern Range: 0(0x00)-255(0xff), -1 random.\n");
move(2, 18);
refresh();
while ((c = getch()) != '\n' && i < MAXFLD) {
buf[i++] = c; /* need more checking on 'c' */
}
buf[i] = '\0';
- ctl->bitpattern = atoi(buf);
- if (ctl->bitpattern > 255)
- ctl->bitpattern = -1;
+ char *end = NULL;
+ errno = 0;
+ long new_bitpattern = strtol(buf, &end, 10);
+ if (errno != 0 || buf == end || *end != '\0' ||
+ new_bitpattern < -1 || new_bitpattern > 255) {
+ printf("\a");
+ return ActionNone;
+ }
+ ctl->bitpattern = new_bitpattern;
return ActionNone;
case 'i':
mvprintw(2, 0, "Interval : %0.0f\n\n", ctl->WaitTime);
(" m <n> set the max time-to-live, default n= # of hops\n");
printw(" s <n> set the packet size to n or random(n<0)\n");
printw
- (" b <c> set ping bit pattern to c(0..255) or random(c<0)\n");
+ (" b <c> set ping bit pattern to c(0..255) or random(c=-1)\n");
printw(" Q <t> set ping packet's TOS to t\n");
printw(" u switch between ICMP ECHO and UDP datagrams\n");
printw(" t switch between ICMP ECHO and TCP\n");