~ubuntu-branches/debian/sid/mtr/sid

« back to all changes in this revision

Viewing changes to split.c.orig

  • Committer: Bazaar Package Importer
  • Author(s): Robert Woodcock
  • Date: 2008-09-22 07:30:21 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080922073021-worxo2arrx3glvtn
Tags: 0.75-2
Use rm -f in rules clean target where necessary, closes: #499789

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    mtr  --  a network diagnostic tool
3
 
    Copyright (C) 1997  Matt Kimball
4
 
 
5
 
    split.c -- raw output (for inclusion in KDE Network Utilities or others
6
 
                         GUI based tools)
7
 
    Copyright (C) 1998  Bertrand Leconte <B.Leconte@mail.dotcom.fr>
8
 
 
9
 
    This program is free software; you can redistribute it and/or modify
10
 
    it under the terms of the GNU General Public License as published by
11
 
    the Free Software Foundation; either version 2 of the License, or
12
 
    (at your option) any later version.
13
 
 
14
 
    This program is distributed in the hope that it will be useful,
15
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
    GNU General Public License for more details.
18
 
 
19
 
    You should have received a copy of the GNU General Public License
20
 
    along with this program; if not, write to the Free Software
21
 
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
 
*/
23
 
 
24
 
#include <config.h>
25
 
#include <ctype.h>
26
 
#include <stdlib.h>
27
 
#include <stdio.h>
28
 
#include <string.h>
29
 
#include <sys/types.h>
30
 
 
31
 
#include "mtr.h"
32
 
#include "display.h"
33
 
#include "dns.h"
34
 
 
35
 
#include "net.h"
36
 
#include "split.h"
37
 
 
38
 
#ifdef NO_CURSES
39
 
#include <sys/time.h>
40
 
#include <sys/types.h>
41
 
#include <unistd.h>
42
 
#else
43
 
/* Use the curses variant */
44
 
 
45
 
#if defined(HAVE_NCURSES_H)
46
 
#  include <ncurses.h>
47
 
#elif defined(HAVE_NCURSES_CURSES_H)
48
 
#  include <ncurses/curses.h>
49
 
#elif defined(HAVE_CURSES_H)
50
 
#  include <curses.h>
51
 
#else
52
 
#  error No curses header file available
53
 
#endif
54
 
 
55
 
#endif
56
 
 
57
 
 
58
 
extern char *Hostname;
59
 
extern int WaitTime;
60
 
extern int af;
61
 
 
62
 
/* There is 256 hops max in the IP header (coded with a byte) */
63
 
#define MAX_LINE_COUNT 256
64
 
#define MAX_LINE_SIZE  256
65
 
 
66
 
char Lines[MAX_LINE_COUNT][MAX_LINE_SIZE];
67
 
int  LineCount;
68
 
 
69
 
 
70
 
#define DEBUG 0
71
 
 
72
 
 
73
 
void split_redraw(void) 
74
 
{
75
 
  int   max;
76
 
  int   at;
77
 
  ip_t *addr;
78
 
  char *name;
79
 
  char  newLine[MAX_LINE_SIZE];
80
 
  int   i;
81
 
 
82
 
#if DEBUG
83
 
  fprintf(stderr, "split_redraw()\n"); 
84
 
#endif
85
 
 
86
 
  /* 
87
 
   * If there is less lines than last time, we delete them
88
 
   * TEST THIS PLEASE
89
 
   */
90
 
  max = net_max();
91
 
  for (i=LineCount; i>max; i--) {
92
 
    printf("-%d\n", i);
93
 
    LineCount--;
94
 
  }
95
 
 
96
 
  /*
97
 
   * For each line, we compute the new one and we compare it to the old one
98
 
   */
99
 
  for(at = 0; at < max; at++) {
100
 
    addr = net_addr(at);
101
 
    
102
 
    if( addrcmp( (void *) addr, (void *) &unspec_addr, af ) != 0 ) {
103
 
      name = dns_lookup(addr);
104
 
      if(name != NULL) {
105
 
        /* May be we should test name's length */
106
 
        sprintf(newLine, "%s %d %d %d %d %d %d", name,
107
 
                net_loss(at),
108
 
                net_returned(at), net_xmit(at),
109
 
                net_best(at) /1000, net_avg(at)/1000, 
110
 
                net_worst(at)/1000);
111
 
      } else {
112
 
        sprintf(newLine, "%s %d %d %d %d %d %d", 
113
 
                strlongip( addr ),
114
 
                net_loss(at),
115
 
                net_returned(at), net_xmit(at),
116
 
                net_best(at) /1000, net_avg(at)/1000, 
117
 
                net_worst(at)/1000);
118
 
      }
119
 
    } else {
120
 
      sprintf(newLine, "???");
121
 
    }
122
 
 
123
 
    if (strcmp(newLine, Lines[at]) == 0) {
124
 
      /* The same, so do nothing */
125
 
#if DEBUG
126
 
      printf("SAME LINE\n");
127
 
#endif
128
 
    } else {
129
 
      printf("%d %s\n", at+1, newLine);
130
 
      fflush(stdout);
131
 
      strcpy(Lines[at], newLine);
132
 
      if (LineCount < (at+1)) {
133
 
        LineCount = at+1;
134
 
      }
135
 
    }
136
 
  }
137
 
}
138
 
 
139
 
 
140
 
void split_open(void)
141
 
{
142
 
  int i;
143
 
#if DEBUG
144
 
  printf("split_open()\n");
145
 
#endif
146
 
  LineCount = -1;
147
 
  for (i=0; i<MAX_LINE_COUNT; i++) {
148
 
    strcpy(Lines[i], "???");
149
 
  }
150
 
}
151
 
 
152
 
 
153
 
void split_close(void)
154
 
{
155
 
#if DEBUG
156
 
  printf("split_close()\n");
157
 
#endif
158
 
}
159
 
 
160
 
 
161
 
int split_keyaction(void) 
162
 
{
163
 
#ifdef NO_CURSES
164
 
  fd_set readfds;
165
 
  struct timeval tv;
166
 
  char c;
167
 
 
168
 
  FD_ZERO (&readfds);
169
 
  FD_SET (0, &readfds);
170
 
  tv.tv_sec = 0;
171
 
  tv.tv_usec = 0;
172
 
 
173
 
  if (select (1, &readfds, NULL, NULL, &tv) > 0) {
174
 
    read (0, &c, 1);
175
 
  } else 
176
 
    return 0;
177
 
#else
178
 
  char c = getch();
179
 
#endif
180
 
 
181
 
#if DEBUG
182
 
  printf("split_keyaction()\n");
183
 
#endif
184
 
  if(tolower(c) == 'q')
185
 
    return ActionQuit;
186
 
  if(c==3)
187
 
    return ActionQuit;
188
 
  if(tolower(c) == 'r')
189
 
    return ActionReset;
190
 
  
191
 
  return 0;
192
 
}