Retire MINIX tcpstat(1), udpstat(1)
This needs to be done before retiring inet itself, since these utilities include headers from inet directly. Also retire the now-obsolete paramvalue(3). Change-Id: I9b27771190a6a32ee533b0c0d9d37f61a16ee36c
This commit is contained in:
parent
baa5830f28
commit
49bf8d5c6a
@ -529,7 +529,7 @@
|
||||
./usr/bin/tar minix-base
|
||||
./usr/bin/tcpd minix-base
|
||||
./usr/bin/tcpdp minix-base
|
||||
./usr/bin/tcpstat minix-base
|
||||
./usr/bin/tcpstat minix-base obsolete
|
||||
./usr/bin/tee minix-base
|
||||
./usr/bin/term minix-base
|
||||
./usr/bin/termcap minix-base
|
||||
@ -550,7 +550,7 @@
|
||||
./usr/bin/tsort minix-base
|
||||
./usr/bin/ttn minix-base
|
||||
./usr/bin/tty minix-base
|
||||
./usr/bin/udpstat minix-base
|
||||
./usr/bin/udpstat minix-base obsolete
|
||||
./usr/bin/ul minix-base
|
||||
./usr/bin/uname minix-base
|
||||
./usr/bin/uncompress minix-base
|
||||
|
@ -420,7 +420,7 @@
|
||||
./usr/libdata/debug/usr/bin/tail.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/tcpd.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/tcpdp.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/tcpstat.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/tcpstat.debug minix-debug debug,obsolete
|
||||
./usr/libdata/debug/usr/bin/tee.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/term.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/termcap.debug minix-debug debug
|
||||
@ -439,7 +439,7 @@
|
||||
./usr/libdata/debug/usr/bin/tsort.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/ttn.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/tty.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/udpstat.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/udpstat.debug minix-debug debug,obsolete
|
||||
./usr/libdata/debug/usr/bin/ul.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/uname.debug minix-debug debug
|
||||
./usr/libdata/debug/usr/bin/unexpand.debug minix-debug debug
|
||||
|
@ -9,7 +9,7 @@ CPPFLAGS.fslib.c+= -I${NETBSDSRCDIR}/minix/fs
|
||||
CPPFLAGS.fsversion.c+= -I${NETBSDSRCDIR}/minix/fs
|
||||
|
||||
SRCS+= dhcp_gettag.c dhcp_settag.c fsversion.c gcov.c itoa.c \
|
||||
oneC_sum.c paramvalue.c read_tsc_64.c servxcheck.c fslib.c
|
||||
oneC_sum.c read_tsc_64.c servxcheck.c fslib.c
|
||||
|
||||
.endif # defined(__MINIX)
|
||||
.PATH: ${ARCHDIR}/gen ${.CURDIR}/gen
|
||||
|
@ -24,9 +24,9 @@ SUBDIR= add_route arp at backup \
|
||||
rotate setup \
|
||||
slip spell sprofalyze sprofdiff srccrc \
|
||||
svrctl swifi synctree sysenv \
|
||||
tcpd tcpdp tcpstat telnet \
|
||||
tcpd tcpdp telnet \
|
||||
telnetd term termcap tget \
|
||||
truncate udpstat umount \
|
||||
truncate umount \
|
||||
update version vol \
|
||||
writeisofs fetch \
|
||||
zmodem pkgin_cd pkgin_all pkgin_sets \
|
||||
|
@ -1,6 +0,0 @@
|
||||
PROG= tcpstat
|
||||
CPPFLAGS+= -I${NETBSDSRCDIR}/minix/net -D'ARGS(a)=a'
|
||||
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,342 +0,0 @@
|
||||
/*
|
||||
tcpstat.c
|
||||
|
||||
Created: June 1995 by Philip Homburg <philip@f-mnx.phicoh.com>
|
||||
*/
|
||||
|
||||
#define _POSIX_C_SOURCE 2
|
||||
#define _NETBSD_SOURCE 1
|
||||
|
||||
#include <inet/inet.h>
|
||||
#undef printf
|
||||
#undef send
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#ifndef __minix_vmd
|
||||
#include <sys/times.h>
|
||||
#endif
|
||||
#include <net/netlib.h>
|
||||
#include <net/gen/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <net/gen/socket.h>
|
||||
#include <minix/queryparam.h>
|
||||
#include <minix/com.h>
|
||||
|
||||
#include <inet/generic/buf.h>
|
||||
#include <inet/generic/clock.h>
|
||||
#include <inet/generic/event.h>
|
||||
#include <inet/generic/type.h>
|
||||
#include <inet/generic/tcp.h>
|
||||
#include <inet/generic/tcp_int.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
u32_t system_hz;
|
||||
char *prog_name;
|
||||
tcp_conn_t tcp_conn_table[TCP_CONN_NR];
|
||||
char values[2 * sizeof(tcp_conn_table) + 1];
|
||||
int inclListen, numerical, verbose;
|
||||
|
||||
void print_conn(int i, clock_t now);
|
||||
void usage(void);
|
||||
|
||||
int main(int argc, char*argv[])
|
||||
{
|
||||
char *ipstat_device;
|
||||
int fd, i, r;
|
||||
char *query, *pval;
|
||||
size_t len;
|
||||
#ifdef __minix_vmd
|
||||
struct timeval uptime;
|
||||
#endif
|
||||
clock_t now;
|
||||
int fl;
|
||||
int a_flag, n_flag, v_flag;
|
||||
struct tms tmsbuf;
|
||||
|
||||
system_hz = (u32_t) sysconf(_SC_CLK_TCK);
|
||||
|
||||
(prog_name=strrchr(argv[0], '/')) ? prog_name++ : (prog_name=argv[0]);
|
||||
|
||||
a_flag= 0;
|
||||
n_flag= 0;
|
||||
v_flag= 0;
|
||||
while ((fl= getopt(argc, argv, "?anv")) != -1)
|
||||
{
|
||||
switch(fl)
|
||||
{
|
||||
case '?':
|
||||
usage();
|
||||
case 'a':
|
||||
a_flag= 1;
|
||||
break;
|
||||
case 'n':
|
||||
n_flag= 1;
|
||||
break;
|
||||
case 'v':
|
||||
v_flag= 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: getopt failed: '%c'\n",
|
||||
prog_name, fl);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
inclListen= !!a_flag;
|
||||
numerical= !!n_flag;
|
||||
verbose= !!v_flag;
|
||||
|
||||
ipstat_device= IPSTAT_DEVICE;
|
||||
if ((fd= open(ipstat_device, O_RDWR)) == -1)
|
||||
{
|
||||
fprintf(stderr, "%s: unable to open '%s': %s\n", prog_name,
|
||||
ipstat_device, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
query= "tcp_conn_table";
|
||||
len= strlen(query);
|
||||
r= write(fd, query, len);
|
||||
if (r != len)
|
||||
{
|
||||
fprintf(stderr, "%s: write to %s failed: %s\n",
|
||||
prog_name, ipstat_device, r < 0 ? strerror(errno) :
|
||||
"short write");
|
||||
exit(1);
|
||||
}
|
||||
r= read(fd, values, sizeof(values));
|
||||
if (r == -1)
|
||||
{
|
||||
fprintf(stderr, "%s: read from %s failed: %s\n", prog_name,
|
||||
ipstat_device, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
pval= values;
|
||||
if (paramvalue(&pval, tcp_conn_table, sizeof(tcp_conn_table)) !=
|
||||
sizeof(tcp_conn_table))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: unable to decode the results from queryparam\n",
|
||||
prog_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef __minix_vmd
|
||||
/* Get the uptime in clock ticks. */
|
||||
if (sysutime(UTIME_UPTIME, &uptime) == -1)
|
||||
{
|
||||
fprintf(stderr, "%s: sysutime failed: %s\n", prog_name,
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
now= uptime.tv_sec * HZ + (uptime.tv_usec*HZ/1000000);
|
||||
#else /* Minix 3 */
|
||||
now= times(&tmsbuf);
|
||||
#endif
|
||||
|
||||
for (i= 0; i<TCP_CONN_NR; i++)
|
||||
print_conn(i, now);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void print_conn(int i, clock_t now)
|
||||
{
|
||||
tcp_conn_t *tcp_conn;
|
||||
char *addr_str;
|
||||
struct hostent *hostent;
|
||||
struct servent *servent;
|
||||
ipaddr_t a1, a2;
|
||||
tcpport_t p1, p2;
|
||||
unsigned flags;
|
||||
int no_verbose;
|
||||
clock_t rtt, artt, drtt;
|
||||
|
||||
tcp_conn= &tcp_conn_table[i];
|
||||
if (!(tcp_conn->tc_flags & TCF_INUSE))
|
||||
return;
|
||||
if (tcp_conn->tc_state == TCS_LISTEN && !inclListen)
|
||||
return;
|
||||
if (tcp_conn->tc_state == TCS_CLOSED && tcp_conn->tc_fd == NULL &&
|
||||
tcp_conn->tc_senddis < now)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%3d", i);
|
||||
|
||||
a1= tcp_conn->tc_locaddr;
|
||||
p1= tcp_conn->tc_locport;
|
||||
a2= tcp_conn->tc_remaddr;
|
||||
p2= tcp_conn->tc_remport;
|
||||
|
||||
if (a1 == 0)
|
||||
addr_str= "*";
|
||||
else if (!numerical &&
|
||||
(hostent= gethostbyaddr((char *)&a1,
|
||||
sizeof(a1), AF_INET)) != NULL)
|
||||
{
|
||||
addr_str= hostent->h_name;
|
||||
}
|
||||
else
|
||||
addr_str= inet_ntoa(*(struct in_addr *)&a1);
|
||||
printf(" %s:", addr_str);
|
||||
|
||||
if (p1 == 0)
|
||||
printf("*");
|
||||
else if ((servent= getservbyport(p1, "tcp")) != NULL)
|
||||
{
|
||||
printf("%s", servent->s_name);
|
||||
}
|
||||
else
|
||||
printf("%u", ntohs(p1));
|
||||
|
||||
if (tcp_conn->tc_orglisten)
|
||||
printf(" <- ");
|
||||
else
|
||||
printf(" -> ");
|
||||
|
||||
if (a2 == 0)
|
||||
addr_str= "*";
|
||||
else if (!numerical &&
|
||||
(hostent= gethostbyaddr((char *)&a2,
|
||||
sizeof(a2), AF_INET)) != NULL)
|
||||
{
|
||||
addr_str= hostent->h_name;
|
||||
}
|
||||
else
|
||||
addr_str= inet_ntoa(*(struct in_addr *)&a2);
|
||||
printf("%s:", addr_str);
|
||||
|
||||
if (p2 == 0)
|
||||
printf("*");
|
||||
else if ((servent= getservbyport(p2, "tcp")) !=
|
||||
NULL)
|
||||
{
|
||||
printf("%s", servent->s_name);
|
||||
}
|
||||
else
|
||||
printf("%u", ntohs(p2));
|
||||
|
||||
printf(" ");
|
||||
no_verbose= 0;
|
||||
switch(tcp_conn->tc_state)
|
||||
{
|
||||
case TCS_CLOSED: printf("CLOSED");
|
||||
if (tcp_conn->tc_senddis >= now)
|
||||
{
|
||||
printf("(time wait %u s)",
|
||||
(tcp_conn->tc_senddis-now)/system_hz);
|
||||
}
|
||||
no_verbose= 1;
|
||||
break;
|
||||
case TCS_LISTEN: printf("LISTEN"); no_verbose= 1; break;
|
||||
case TCS_SYN_RECEIVED: printf("SYN_RECEIVED"); break;
|
||||
case TCS_SYN_SENT: printf("SYN_SENT"); break;
|
||||
case TCS_ESTABLISHED: printf("ESTABLISHED"); break;
|
||||
case TCS_CLOSING: printf("CLOSING"); break;
|
||||
default: printf("state(%d)", tcp_conn->tc_state);
|
||||
break;
|
||||
}
|
||||
|
||||
if (tcp_conn->tc_flags & TCF_FIN_RECV)
|
||||
printf(" F<");
|
||||
if (tcp_conn->tc_flags & TCF_FIN_SENT)
|
||||
{
|
||||
printf(" F>");
|
||||
if (tcp_conn->tc_SND_UNA == tcp_conn->tc_SND_NXT)
|
||||
printf("+");
|
||||
}
|
||||
if (tcp_conn->tc_state != TCS_CLOSED &&
|
||||
tcp_conn->tc_state != TCS_LISTEN)
|
||||
{
|
||||
printf("\n\t");
|
||||
printf("RQ: %u, SQ: %u, RWnd: %u, SWnd: %u, SWThresh: %u",
|
||||
tcp_conn->tc_RCV_NXT - tcp_conn->tc_RCV_LO,
|
||||
tcp_conn->tc_SND_NXT - tcp_conn->tc_SND_UNA,
|
||||
tcp_conn->tc_rcv_wnd,
|
||||
tcp_conn->tc_snd_cwnd - tcp_conn->tc_SND_UNA,
|
||||
tcp_conn->tc_snd_cthresh);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
if (!verbose || no_verbose)
|
||||
return;
|
||||
rtt= tcp_conn->tc_rtt;
|
||||
artt= tcp_conn->tc_artt;
|
||||
drtt= tcp_conn->tc_drtt;
|
||||
printf("\tmss %u, mtu %u%s, rtt %.3f (%.3f+%d*%.3f) s\n",
|
||||
tcp_conn->tc_max_mtu-IP_TCP_MIN_HDR_SIZE,
|
||||
tcp_conn->tc_mtu,
|
||||
(tcp_conn->tc_flags & TCF_PMTU) ? "" : " (no PMTU)",
|
||||
rtt/(system_hz+0.0),
|
||||
artt/(system_hz+0.0)/TCP_RTT_SCALE, TCP_DRTT_MULT,
|
||||
drtt/(system_hz+0.0)/TCP_RTT_SCALE);
|
||||
flags= tcp_conn->tc_flags;
|
||||
printf("\tflags:");
|
||||
if (!flags)
|
||||
printf(" TCF_EMPTY");
|
||||
if (flags & TCF_INUSE)
|
||||
flags &= ~TCF_INUSE;
|
||||
if (flags & TCF_FIN_RECV)
|
||||
{
|
||||
printf(" TCF_FIN_RECV");
|
||||
flags &= ~TCF_FIN_RECV;
|
||||
}
|
||||
if (flags & TCF_RCV_PUSH)
|
||||
{
|
||||
printf(" TCF_RCV_PUSH");
|
||||
flags &= ~TCF_RCV_PUSH;
|
||||
}
|
||||
if (flags & TCF_MORE2WRITE)
|
||||
{
|
||||
printf(" TCF_MORE2WRITE");
|
||||
flags &= ~TCF_MORE2WRITE;
|
||||
}
|
||||
if (flags & TCF_SEND_ACK)
|
||||
{
|
||||
printf(" TCF_SEND_ACK");
|
||||
flags &= ~TCF_SEND_ACK;
|
||||
}
|
||||
if (flags & TCF_FIN_SENT)
|
||||
{
|
||||
printf(" TCF_FIN_SENT");
|
||||
flags &= ~TCF_FIN_SENT;
|
||||
}
|
||||
if (flags & TCF_BSD_URG)
|
||||
{
|
||||
printf(" TCF_BSD_URG");
|
||||
flags &= ~TCF_BSD_URG;
|
||||
}
|
||||
if (flags & TCF_NO_PUSH)
|
||||
{
|
||||
printf(" TCF_NO_PUSH");
|
||||
flags &= ~TCF_NO_PUSH;
|
||||
}
|
||||
if (flags & TCF_PUSH_NOW)
|
||||
{
|
||||
printf(" TCF_PUSH_NOW");
|
||||
flags &= ~TCF_PUSH_NOW;
|
||||
}
|
||||
if (flags & TCF_PMTU)
|
||||
flags &= ~TCF_PMTU;
|
||||
if (flags)
|
||||
printf(" 0x%x", flags);
|
||||
printf("\n");
|
||||
printf("\ttimer: ref %d, time %f, active %d\n",
|
||||
tcp_conn->tc_transmit_timer.tim_ref,
|
||||
(0.0+tcp_conn->tc_transmit_timer.tim_time-now)/system_hz,
|
||||
tcp_conn->tc_transmit_timer.tim_active);
|
||||
}
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-anv]\n", prog_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* $PchId: tcpstat.c,v 1.8 2005/01/30 01:04:38 philip Exp $
|
||||
*/
|
@ -1,5 +0,0 @@
|
||||
PROG= udpstat
|
||||
CPPFLAGS+= -I${NETBSDSRCDIR}/minix/net -D'ARGS(a)=a'
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,327 +0,0 @@
|
||||
/*
|
||||
udpstat.c
|
||||
|
||||
Created: March 2001 by Philip Homburg <philip@f-mnx.phicoh.com>
|
||||
*/
|
||||
|
||||
#define _POSIX_C_SOURCE 2
|
||||
#define _NETBSD_SOURCE 1
|
||||
|
||||
#include <inet/inet.h>
|
||||
#undef printf
|
||||
#undef send
|
||||
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#ifndef __minix_vmd
|
||||
#include <sys/times.h>
|
||||
#endif
|
||||
#include <net/netlib.h>
|
||||
#include <net/gen/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <net/gen/socket.h>
|
||||
#include <minix/queryparam.h>
|
||||
|
||||
#include <inet/generic/buf.h>
|
||||
#include <inet/generic/clock.h>
|
||||
#include <inet/generic/event.h>
|
||||
#include <inet/generic/type.h>
|
||||
#include <inet/generic/udp_int.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
char *prog_name;
|
||||
udp_fd_t udp_fd_table[UDP_FD_NR];
|
||||
udp_port_t *udp_port_table;
|
||||
udp_port_t *udp_port_tablep;
|
||||
size_t udp_port_table_s;
|
||||
size_t udp_port_table_rs;
|
||||
int udp_port_nr;
|
||||
char values[6 * sizeof(void *) + 3];
|
||||
char *valuesl= NULL;
|
||||
size_t v_size;
|
||||
int inclSel, numerical;
|
||||
|
||||
void print_fd(int i, clock_t now);
|
||||
void usage(void);
|
||||
|
||||
int main(int argc, char*argv[])
|
||||
{
|
||||
char *ipstat_device;
|
||||
int fd, i, r;
|
||||
size_t psize;
|
||||
char *pval, *param;
|
||||
#ifdef __minix_vmd
|
||||
struct timeval uptime;
|
||||
#endif
|
||||
clock_t now;
|
||||
int fl;
|
||||
int a_flag, n_flag;
|
||||
struct tms tmsbuf;
|
||||
|
||||
(prog_name=strrchr(argv[0], '/')) ? prog_name++ : (prog_name=argv[0]);
|
||||
|
||||
a_flag= 0;
|
||||
n_flag= 0;
|
||||
while ((fl= getopt(argc, argv, "?an")) != -1)
|
||||
{
|
||||
switch(fl)
|
||||
{
|
||||
case '?':
|
||||
usage();
|
||||
case 'a':
|
||||
a_flag= 1;
|
||||
break;
|
||||
case 'n':
|
||||
n_flag= 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: getopt failed: '%c'\n",
|
||||
prog_name, fl);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
inclSel= !!a_flag;
|
||||
numerical= !!n_flag;
|
||||
|
||||
ipstat_device= IPSTAT_DEVICE;
|
||||
if ((fd= open(ipstat_device, O_RDWR)) == -1)
|
||||
{
|
||||
fprintf(stderr, "%s: unable to open '%s': %s\n", prog_name,
|
||||
ipstat_device, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
v_size= 2*sizeof(udp_fd_table)+1;
|
||||
valuesl= realloc(valuesl, v_size);
|
||||
if (!valuesl)
|
||||
{
|
||||
fprintf(stderr, "%s: unable to malloc %u bytes for valuesl\n",
|
||||
prog_name, v_size);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
param= "udp_fd_table";
|
||||
psize= strlen(param);
|
||||
r= write(fd, param, psize);
|
||||
if (r != psize)
|
||||
{
|
||||
fprintf(stderr, "%s: write to %s failed: %s\n", prog_name,
|
||||
ipstat_device,
|
||||
r < 0 ? strerror(errno) : "short write");
|
||||
exit(1);
|
||||
}
|
||||
r= read(fd, valuesl, v_size);
|
||||
if (r < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: read from %s failed: %s\n", prog_name,
|
||||
ipstat_device, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
pval= valuesl;
|
||||
if (paramvalue(&pval, udp_fd_table, sizeof(udp_fd_table)) !=
|
||||
sizeof(udp_fd_table))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: unable to decode the results from queryparam (udp_fd_table)\n",
|
||||
prog_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Get address, size, and element size of the UDP port table */
|
||||
param = "&udp_port_table,$udp_port_table,$udp_port_table[0]";
|
||||
psize = strlen(param);
|
||||
r= write(fd, param, psize);
|
||||
if (r != psize)
|
||||
{
|
||||
fprintf(stderr, "%s: write to %s failed: %s\n", prog_name,
|
||||
ipstat_device,
|
||||
r < 0 ? strerror(errno) : "short write");
|
||||
exit(1);
|
||||
}
|
||||
r= read(fd, values, sizeof(values));
|
||||
if (r < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: read from %s failed: %s\n", prog_name,
|
||||
ipstat_device, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
pval= values;
|
||||
if (paramvalue(&pval, &udp_port_tablep, sizeof(udp_port_tablep)) !=
|
||||
sizeof(udp_port_tablep) ||
|
||||
paramvalue(&pval, &udp_port_table_s, sizeof(udp_port_table_s))
|
||||
!= sizeof(udp_port_table_s) ||
|
||||
paramvalue(&pval, &udp_port_table_rs, sizeof(udp_port_table_rs))
|
||||
!= sizeof(udp_port_table_rs))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: unable to decode the results from queryparam (&udp_port_table, ...)\n",
|
||||
prog_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (udp_port_table_rs != sizeof(udp_port_table[0]))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: size mismatch in udp_port_table (different version of inet?)\n",
|
||||
prog_name);
|
||||
exit(1);
|
||||
}
|
||||
udp_port_nr= udp_port_table_s/udp_port_table_rs;
|
||||
assert(udp_port_table_s == udp_port_nr*udp_port_table_rs);
|
||||
udp_port_table= malloc(udp_port_table_s);
|
||||
if (!udp_port_table)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: unable to malloc %u bytes for udp_port_table\n",
|
||||
prog_name, udp_port_table_s);
|
||||
exit(1);
|
||||
}
|
||||
v_size= 2*udp_port_table_s+1;
|
||||
valuesl= realloc(valuesl, v_size);
|
||||
if (!valuesl)
|
||||
{
|
||||
fprintf(stderr, "%s: unable to malloc %u bytes for valuesl\n",
|
||||
prog_name, v_size);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
param = "udp_port_table";
|
||||
psize = strlen(param);
|
||||
r= write(fd, param, psize);
|
||||
if (r != psize)
|
||||
{
|
||||
fprintf(stderr, "%s: write to %s failed: %s\n", prog_name,
|
||||
ipstat_device,
|
||||
r < 0 ? strerror(errno) : "short write");
|
||||
exit(1);
|
||||
}
|
||||
r= read(fd, valuesl, v_size);
|
||||
if (r < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: read from %s failed: %s\n", prog_name,
|
||||
ipstat_device, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
pval= valuesl;
|
||||
if (paramvalue(&pval, udp_port_table, udp_port_table_s) !=
|
||||
udp_port_table_s)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: unable to decode the results from queryparam (udp_port_table)\n",
|
||||
prog_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Get the uptime in clock ticks. */
|
||||
#ifdef __minix_vmd
|
||||
if (sysutime(UTIME_UPTIME, &uptime) == -1)
|
||||
{
|
||||
fprintf(stderr, "%s: sysutime failed: %s\n", prog_name,
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
now= uptime.tv_sec * HZ + (uptime.tv_usec*HZ/1000000);
|
||||
#else /* Minix 3 */
|
||||
now= times(&tmsbuf);
|
||||
#endif
|
||||
|
||||
for (i= 0; i<UDP_FD_NR; i++)
|
||||
print_fd(i, now);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void print_fd(int i, clock_t now)
|
||||
{
|
||||
unsigned long nwuo_flags;
|
||||
int port_nr;
|
||||
udp_fd_t *udp_fd;
|
||||
udp_port_t *udp_port;
|
||||
char *locaddr_str, *remaddr_str;
|
||||
struct hostent *hostent;
|
||||
struct servent *servent;
|
||||
nwio_udpopt_t uf_udpopt;
|
||||
|
||||
udp_fd= &udp_fd_table[i];
|
||||
if (!(udp_fd->uf_flags & UFF_INUSE))
|
||||
return;
|
||||
uf_udpopt= udp_fd->uf_udpopt;
|
||||
nwuo_flags= uf_udpopt.nwuo_flags;
|
||||
if (((nwuo_flags & NWUO_LOCPORT_MASK) != NWUO_LP_SET) && !inclSel)
|
||||
return;
|
||||
|
||||
port_nr= udp_fd->uf_port-udp_port_tablep;
|
||||
udp_port= &udp_port_table[port_nr];
|
||||
|
||||
printf("%3d", i);
|
||||
|
||||
if (nwuo_flags & NWUO_EN_LOC)
|
||||
{
|
||||
if (!numerical && (hostent=
|
||||
gethostbyaddr((char *)&udp_port->up_ipaddr,
|
||||
sizeof(ipaddr_t), AF_INET)) != NULL)
|
||||
{
|
||||
locaddr_str= hostent->h_name;
|
||||
}
|
||||
else
|
||||
locaddr_str=
|
||||
inet_ntoa(*(struct in_addr *)&udp_port->up_ipaddr);
|
||||
}
|
||||
else if (nwuo_flags & NWUO_EN_BROAD)
|
||||
locaddr_str= "255.255.255.255";
|
||||
else
|
||||
locaddr_str= "0.0.0.0";
|
||||
|
||||
printf(" %s:", locaddr_str);
|
||||
|
||||
if ((nwuo_flags & NWUO_LOCPORT_MASK) != NWUO_LP_SEL &&
|
||||
(nwuo_flags & NWUO_LOCPORT_MASK) != NWUO_LP_SET)
|
||||
{
|
||||
printf("*");
|
||||
}
|
||||
else if ((servent= getservbyport(uf_udpopt.nwuo_locport, "udp")) !=
|
||||
NULL)
|
||||
{
|
||||
printf("%s", servent->s_name);
|
||||
}
|
||||
else
|
||||
printf("%u", ntohs(uf_udpopt.nwuo_locport));
|
||||
|
||||
printf(" -> ");
|
||||
|
||||
if (!(nwuo_flags & NWUO_RA_SET))
|
||||
remaddr_str= "*";
|
||||
else if (!numerical &&
|
||||
(hostent= gethostbyaddr((char *)&uf_udpopt.nwuo_remaddr,
|
||||
sizeof(ipaddr_t), AF_INET)) != NULL)
|
||||
{
|
||||
remaddr_str= hostent->h_name;
|
||||
}
|
||||
else
|
||||
remaddr_str=
|
||||
inet_ntoa(*(struct in_addr *)&uf_udpopt.nwuo_remaddr);
|
||||
printf("%s:", remaddr_str);
|
||||
|
||||
if (!(nwuo_flags & NWUO_RP_SET))
|
||||
printf("*");
|
||||
else if ((servent= getservbyport(uf_udpopt.nwuo_remport, "udp")) !=
|
||||
NULL)
|
||||
{
|
||||
printf("%s", servent->s_name);
|
||||
}
|
||||
else
|
||||
printf("%u", ntohs(uf_udpopt.nwuo_remport));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-a] [-n]\n", prog_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* $PchId: udpstat.c,v 1.4 2005/01/30 01:04:57 philip Exp $
|
||||
*/
|
@ -37,8 +37,6 @@ struct export_params {
|
||||
void qp_export(struct export_params *_ex_params);
|
||||
int queryparam(int (*_qgetc) (void), void **_paddress, _mnx_size_t
|
||||
*_psize);
|
||||
_mnx_size_t paramvalue(char **_value, void *_address, _mnx_size_t
|
||||
_size);
|
||||
#endif /* _MINIX__QUERYPARAM_H */
|
||||
|
||||
/* $PchId: queryparam.h,v 1.1 2005/06/28 14:31:26 philip Exp $ */
|
||||
|
@ -1,51 +0,0 @@
|
||||
/* paramvalue() - decode kernel parameter values Author: Kees J. Bot
|
||||
* 7 May 1994
|
||||
* The kernel returns the results of parameter queries
|
||||
* by the XXQUERYPARAM svrctl calls as an array of hex digits, like this:
|
||||
* "75020000,080C0000". These are the values of two four-byte variables.
|
||||
* Paramvalue() decodes such a string.
|
||||
*/
|
||||
#define nil 0
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <minix/queryparam.h>
|
||||
|
||||
size_t paramvalue(char **value, void *address, size_t size)
|
||||
/* Decode the string *value storing the result in the object at address with
|
||||
* the given size. *value is left at the next parameter, *address is padded
|
||||
* with zeros if needed, and the actual size of the value is returned.
|
||||
*/
|
||||
{
|
||||
unsigned char *addr= address;
|
||||
char *v= *value;
|
||||
int nibble;
|
||||
size_t n;
|
||||
|
||||
n= 0;
|
||||
|
||||
while (*v != 0 && *v != ',') {
|
||||
nibble= *v++ - '0';
|
||||
if (nibble > 0x9) nibble= nibble + '0' - 'A' + 0xA;
|
||||
if (nibble > 0xF) nibble= nibble + 'A' - 'a';
|
||||
if (size > 0) {
|
||||
if (n % 2 == 0) {
|
||||
*addr= nibble << 4;
|
||||
} else {
|
||||
*addr++|= nibble;
|
||||
size--;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
}
|
||||
while (size > 0) { *addr++= 0; size--; }
|
||||
while (*v != 0 && *v++ != ',') {}
|
||||
*value= v;
|
||||
return n / 2;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* $PchId: paramvalue.c,v 1.3 1996/02/22 09:15:56 philip Exp $
|
||||
*/
|
Loading…
x
Reference in New Issue
Block a user