~ubuntu-branches/debian/jessie/mtr/jessie

« back to all changes in this revision

Viewing changes to curses.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Woodcock
  • Date: 2008-04-16 19:38:12 UTC
  • mfrom: (1.2.1 upstream) (5.1.1 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080416193812-c9tw92dcxlc5gg0y
Tags: 0.73-1
New upstream version

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include <config.h>
21
21
#include <strings.h>
 
22
#include <unistd.h>
22
23
 
23
24
#ifndef NO_CURSES
24
25
#include <ctype.h>
70
71
extern char LocalHostname[];
71
72
extern int fstTTL;
72
73
extern int maxTTL;
73
 
extern int packetsize;
 
74
extern int cpacketsize;
74
75
extern int bitpattern;
75
76
extern int tos;
76
77
extern float WaitTime;
93
94
{
94
95
  int c = getch();
95
96
  int i=0;
 
97
  float f = 0.0;
96
98
  char buf[MAXFLD+1];
97
99
 
98
100
  if(c == 'q')
118
120
 
119
121
  /* more stuffs added by Min */
120
122
  if (tolower(c) == 's') {
121
 
    mvprintw(2, 0, "Change Packet Size: %d\n", packetsize );
122
 
    mvprintw(3, 0, "Size Range: %d-%d, <0 random.\n", MINPACKET, MAXPACKET);
 
123
    mvprintw(2, 0, "Change Packet Size: %d\n", cpacketsize );
 
124
    mvprintw(3, 0, "Size Range: %d-%d, < 0:random.\n", MINPACKET, MAXPACKET);
123
125
    move(2,20);
124
126
    refresh();
125
127
    while ( (c=getch ()) != '\n' && i < MAXFLD ) {
127
129
      buf[i++] = c;   /* need more checking on 'c' */
128
130
    }
129
131
    buf[i] = '\0';
130
 
    packetsize = atoi ( buf );
131
 
    if( packetsize >=0 ) {
132
 
      if ( packetsize < MINPACKET ) packetsize = MINPACKET;
133
 
      if ( packetsize > MAXPACKET ) packetsize = MAXPACKET;
134
 
    } else {
135
 
      packetsize =
136
 
      - (int)(MINPACKET + (MAXPACKET-MINPACKET)*(rand()/(RAND_MAX+0.1)));
137
 
    }
138
 
 
 
132
    cpacketsize = atoi ( buf );
139
133
    return ActionNone;
140
134
  }
141
135
  if (tolower(c) == 'b') {
177
171
      buf[i++] = c;   /* need more checking on 'c' */
178
172
    }
179
173
    buf[i] = '\0';
180
 
    i = atoi( buf );
181
 
 
182
 
    if ( i < 1 ) return ActionNone;
183
 
    WaitTime = (float) i;
 
174
 
 
175
    f = atof( buf );
 
176
 
 
177
    if (f <= 0.0) return ActionNone;
 
178
    if (getuid() != 0 && f < 1.0)
 
179
      return ActionNone;
 
180
    WaitTime = f;
184
181
 
185
182
    return ActionNone;
186
183
  }
498
495
  mvprintw(1, 0, "%s (%s)", LocalHostname, net_localaddr());
499
496
  /*
500
497
  printw("(tos=0x%X ", tos);
501
 
  printw("psize=%d ", abs(packetsize) );
 
498
  printw("psize=%d ", packetsize );
502
499
  printw("bitpattern=0x%02X)", (unsigned char)(abs(bitpattern)));
503
 
  if( packetsize>0 ){
504
 
    printw("psize=%d ", packetsize);
 
500
  if( cpacketsize > 0 ){
 
501
    printw("psize=%d ", cpacketsize);
505
502
  } else {
506
 
    printw("psize=rand(%d,%d) ",MINPACKET, MAXPACKET);
 
503
    printw("psize=rand(%d,%d) ",MINPACKET, -cpacketsize);
507
504
  }
508
505
  if( bitpattern>=0 ){
509
506
    printw("bitpattern=0x%02X)", (unsigned char)(bitpattern));