]> the.earth.li Git - sersniff.git/blob - disp_ncurses.c
Use socklen_t rather than int for the length of the socket address.
[sersniff.git] / disp_ncurses.c
1 /*
2         disp_ncurses.c - Routines to do pretty ncurses output.
3         Copyright 2000 Project Purple. Written by Jonathan McDowell
4
5         This program is free software; you can redistribute it and/or
6         modify it under the terms of the GNU General Public License
7         as published by the Free Software Foundation; either version 2
8         of the License, or (at your option) any later version.
9
10         This program is distributed in the hope that it will be useful,
11         but WITHOUT ANY WARRANTY; without even the implied warranty of
12         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13         GNU General Public License for more details.
14
15         You should have received a copy of the GNU General Public License
16         along with this program; if not, write to the Free Software Foundation
17         Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18         http://www.gnu.org/copyleft/gpl.html
19
20         17/02/2000 - Started writing.
21 */
22
23 #include <stdio.h>
24 #include <ncurses.h>
25
26 #include "disp_ncurses.h"
27
28 /* Which port did we display last? */
29 static int last=-1;
30 /* Count of chars so far this line */
31 static int wrap=WRAPINIT;
32
33
34 /* Initialise the display */
35 int disp_init()
36 {
37         return 0;
38 }
39
40 /* Close the display */
41 int disp_close()
42 {
43         return 0;
44 }
45
46 /* Output a status string about what's happening */
47 void disp_outputstatus(char *string)
48 {
49         printf("\n%s\n\t", string);
50         last=-1;
51         wrap=WRAPINIT;
52 }
53
54 /* Output a string from the port. */
55 void disp_outputstr(int port, char *string,
56                 long usec_threshold, long usec_waited)
57 {
58         if (usec_waited>usec_threshold) {
59                 /* report how long we waited between the last port */
60                 if (wrap!=WRAPINIT) printf("\n");
61                 printf("\t<waited %0ld.%0ld seconds>\n",
62                         usec_waited / USEC,
63                         usec_waited % USEC);
64                 wrap=WRAPINIT;
65         }
66
67         if (last!=port) {
68                 /* If we didn't just send a CR, we need to now */
69                 if (wrap!=WRAPINIT) printf("\n");
70                 printf("\nPort%d:\t", port);
71                 last=port;
72                 wrap=WRAPINIT;
73         } else if (wrap==WRAPINIT) {
74                 /* We should indent since we're continuing the same port
75                         as last time */
76                 printf("\t");
77         }
78
79         /* If we'd go over the line end, wrap */
80         if (strlen(string)+wrap > SCREEN_WIDTH) {
81                 wrap=WRAPINIT;
82                 printf("\n\t");
83         }
84
85         wrap+=strlen(string);
86         printf("%s", string);
87
88         if (wrap % SCREEN_WIDTH == 0) {
89                 /* we hit the edge of the screen */
90                 wrap=WRAPINIT;
91                 printf("\n");
92         }
93         
94         /* flush all the time */
95         fflush(NULL);
96 }