2
* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
3
* uptime.c - Tell how long the program has been running.
5
* Luca Deri <deri@ntop.org>
6
* Rocco Carbone <rocco@ntop.org>
7
* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36
static int days (time_t t1, time_t t2)
38
return ((t2 - t1) / SECS_PER_DAY);
45
static int hours (time_t t1, time_t t2)
47
return ((t2 - t1 - (days (t1, t2) * SECS_PER_DAY)) / SECS_PER_HOUR);
54
static int mins (time_t t1, time_t t2)
56
return ((t2 - t1 - (days (t1, t2) * SECS_PER_DAY) -
57
(hours (t1, t2) * SECS_PER_HOUR)) / SECS_PER_MIN);
62
* Tell how long the program has been running.
64
int intop_uptime (int argc, char * argv [])
67
* Notice the command name.
69
char * commandname = argv [0];
73
printf ("Usage: %s [-h]\n\
75
char * optstring = "h";
78
* Reserve here space for the local variables.
81
struct tm * tm = localtime (& now);
88
* Parse command line options to the application via standard system calls.
90
while ((c = getopt (argc, argv, optstring)) != -1)
106
printf ("\nWrong option(s): \" ");
107
while (optind < argc)
108
printf ("%s ", argv [optind ++]);
115
printf ("%2d:%02d%s up %3d days, %2d:%02d:%02d, %d interface%s\n\n",
118
tm -> tm_hour > 12 ? "pm" : "am",
119
days (boottime, now),
120
hours (boottime, now),
121
mins (boottime, now),
122
(int) (now - boottime) % 60,
123
netno (), netno () > 1 ? "s" : "");
125
while ((n = netnext()))
126
printf ("(%s) -- %s [%s], %d hosts, %s Pkts / %s\n",
127
n -> name, n -> fqdn, n -> ipdot,
129
cformatPkts (n -> ethernetPkts),
130
cformatBytes (n -> ethernetBytes));