version 1.61, 2009/08/04 03:45:47 |
version 1.62, 2009/11/22 22:22:14 |
|
|
#include "netstat.h" |
#include "netstat.h" |
|
|
static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data *); |
static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data *); |
static void sidewaysintpr(u_int); |
static void sidewaysintpr(u_int, int); |
static void catchalarm(int); |
static void catchalarm(int); |
static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **); |
static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **); |
static void fetchifs(void); |
static void fetchifs(void); |
|
|
* which is a TAILQ_HEAD. |
* which is a TAILQ_HEAD. |
*/ |
*/ |
void |
void |
intpr(int interval) |
intpr(int interval, int repeatcount) |
{ |
{ |
struct if_msghdr ifm; |
struct if_msghdr ifm; |
int mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 }; |
int mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 }; |
|
|
size_t len; |
size_t len; |
|
|
if (interval) { |
if (interval) { |
sidewaysintpr((unsigned)interval); |
sidewaysintpr((unsigned)interval, repeatcount); |
return; |
return; |
} |
} |
|
|
|
|
* First line printed at top of screen is always cumulative. |
* First line printed at top of screen is always cumulative. |
*/ |
*/ |
static void |
static void |
sidewaysintpr(unsigned int interval) |
sidewaysintpr(unsigned int interval, int repeatcount) |
{ |
{ |
sigset_t emptyset; |
sigset_t emptyset; |
int line; |
int line; |
|
|
|
|
putchar('\n'); |
putchar('\n'); |
fflush(stdout); |
fflush(stdout); |
|
if (repeatcount && --repeatcount == 0) |
|
return; |
line++; |
line++; |
sigemptyset(&emptyset); |
sigemptyset(&emptyset); |
if (!signalled) |
if (!signalled) |
sigsuspend(&emptyset); |
sigsuspend(&emptyset); |
signalled = 0; |
signalled = 0; |
(void)alarm(interval); |
(void)alarm(interval); |
if (line == 21) |
if (line == 21 && isatty(STDOUT_FILENO)) |
goto banner; |
goto banner; |
goto loop; |
goto loop; |
/*NOTREACHED*/ |
|
} |
} |
|
|
/* |
/* |