1: /*
2: mtr -- a network diagnostic tool
3: Copyright (C) 1997,1998 Matt Kimball
4:
5: This program is free software; you can redistribute it and/or modify
6: it under the terms of the GNU General Public License version 2 as
7: published by the Free Software Foundation.
8:
9: This program is distributed in the hope that it will be useful,
10: but WITHOUT ANY WARRANTY; without even the implied warranty of
11: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: GNU General Public License for more details.
13:
14: You should have received a copy of the GNU General Public License along
15: with this program; if not, write to the Free Software Foundation, Inc.,
16: 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17: */
18:
19: #include "config.h"
20:
21: #include <errno.h>
22: #include <stdio.h>
23: #include <stdlib.h>
24: #include <string.h>
25: #include <sys/types.h>
26: #include <time.h>
27:
28: #include "mtr.h"
29: #include "display.h"
30: #include "report.h"
31: #include "select.h"
32: #include "raw.h"
33: #include "dns.h"
34: #include "asn.h"
35:
36: #ifdef HAVE_CURSES
37: #include "mtr-curses.h"
38: #endif
39:
40: #ifdef HAVE_GTK
41: #include "mtr-gtk.h"
42: #endif
43:
44: #include "split.h"
45:
46: #ifdef HAVE_CURSES
47: #define DEFAULT_DISPLAY DisplayCurses
48: #else
49: #define DEFAULT_DISPLAY DisplayReport
50: #endif
51:
52: #ifdef HAVE_GTK
53: #define UNUSED_IF_NO_GTK /* empty */
54: #else
55: #define UNUSED_IF_NO_GTK ATTRIBUTE_UNUSED
56: #endif
57:
58: void display_detect(
59: struct mtr_ctl *ctl,
60: int *argc UNUSED_IF_NO_GTK,
61: char ***argv UNUSED_IF_NO_GTK)
62: {
63: ctl->DisplayMode = DEFAULT_DISPLAY;
64:
65: #ifdef HAVE_GTK
66: if (gtk_detect(argc, argv)) {
67: ctl->DisplayMode = DisplayGTK;
68: }
69: #endif
70: }
71:
72:
73: void display_open(
74: struct mtr_ctl *ctl)
75: {
76: switch (ctl->DisplayMode) {
77:
78: case DisplayReport:
79: report_open();
80: break;
81: case DisplayTXT:
82: txt_open();
83: break;
84: #ifdef HAVE_JANSSON
85: case DisplayJSON:
86: json_open();
87: break;
88: #endif
89: case DisplayXML:
90: xml_open();
91: break;
92: case DisplayCSV:
93: csv_open();
94: break;
95: #ifdef HAVE_CURSES
96: case DisplayCurses:
97: mtr_curses_open(ctl);
98: #ifdef HAVE_IPINFO
99: asn_open(ctl);
100: #endif
101: break;
102: #endif
103: case DisplaySplit:
104: split_open();
105: break;
106: #ifdef HAVE_GTK
107: case DisplayGTK:
108: gtk_open(ctl);
109: #ifdef HAVE_IPINFO
110: asn_open(ctl);
111: #endif
112: break;
113: #endif
114: }
115: }
116:
117:
118: void display_close(
119: struct mtr_ctl *ctl)
120: {
121: time_t now;
122:
123: now = time(NULL);
124:
125: switch (ctl->DisplayMode) {
126: case DisplayReport:
127: report_close(ctl);
128: break;
129: case DisplayTXT:
130: txt_close(ctl);
131: break;
132: #ifdef HAVE_JANSSON
133: case DisplayJSON:
134: json_close(ctl);
135: break;
136: #endif
137: case DisplayXML:
138: xml_close(ctl);
139: break;
140: case DisplayCSV:
141: csv_close(ctl, now);
142: break;
143: #ifdef HAVE_CURSES
144: case DisplayCurses:
145: #ifdef HAVE_IPINFO
146: asn_close(ctl);
147: #endif
148: mtr_curses_close();
149: break;
150: #endif
151: case DisplaySplit:
152: split_close();
153: break;
154: #ifdef HAVE_GTK
155: case DisplayGTK:
156: gtk_close();
157: break;
158: #endif
159: }
160: }
161:
162:
163: void display_redraw(
164: struct mtr_ctl *ctl)
165: {
166: switch (ctl->DisplayMode) {
167:
168: #ifdef HAVE_CURSES
169: case DisplayCurses:
170: mtr_curses_redraw(ctl);
171: break;
172: #endif
173:
174: case DisplaySplit:
175: split_redraw(ctl);
176: break;
177:
178: #ifdef HAVE_GTK
179: case DisplayGTK:
180: gtk_redraw(ctl);
181: break;
182: #endif
183: }
184: }
185:
186:
187: int display_keyaction(
188: struct mtr_ctl *ctl)
189: {
190: switch (ctl->DisplayMode) {
191: #ifdef HAVE_CURSES
192: case DisplayCurses:
193: return mtr_curses_keyaction(ctl);
194: #endif
195:
196: case DisplaySplit:
197: return split_keyaction();
198:
199: #ifdef HAVE_GTK
200: case DisplayGTK:
201: return gtk_keyaction();
202: #endif
203: }
204: return 0;
205: }
206:
207:
208: void display_rawxmit(
209: struct mtr_ctl *ctl,
210: int host,
211: int seq)
212: {
213: if (ctl->DisplayMode == DisplayRaw)
214: raw_rawxmit(host, seq);
215: }
216:
217:
218: void display_rawping(
219: struct mtr_ctl *ctl,
220: int host,
221: int msec,
222: int seq)
223: {
224: if (ctl->DisplayMode == DisplayRaw)
225: raw_rawping(ctl, host, msec, seq);
226: }
227:
228:
229: void display_rawhost(
230: struct mtr_ctl *ctl,
231: int host,
232: ip_t * ip_addr,
233: struct mplslen *mpls)
234: {
235: if (ctl->DisplayMode == DisplayRaw)
236: raw_rawhost(ctl, host, ip_addr, mpls);
237: }
238:
239:
240: void display_loop(
241: struct mtr_ctl *ctl)
242: {
243: #ifdef HAVE_GTK
244: if (ctl->DisplayMode == DisplayGTK)
245: gtk_loop(ctl);
246: else
247: #endif
248: select_loop(ctl);
249: }
250:
251:
252: void display_clear(
253: struct mtr_ctl *ctl)
254: {
255: #ifdef HAVE_CURSES
256: if (ctl->DisplayMode == DisplayCurses)
257: mtr_curses_clear(ctl);
258: #endif
259: }
260:
261:
262: /*
263: Given an errno error code corresponding to a host entry, return a
264: user readable error string.
265: */
266: char *host_error_to_string(
267: int err)
268: {
269: if (err == ENETUNREACH) {
270: return "no route to host";
271: }
272:
273: if (err == ENETDOWN) {
274: return "network down";
275: }
276:
277: if (err == 0) {
278: return "waiting for reply";
279: }
280:
281: return strerror(err);
282: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>