* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)netcmds.c 5.5 (Berkeley) %G%";
* Common network command support routines.
#include <sys/socketvar.h>
#include <netinet/in_systm.h>
#include <netinet/in_pcb.h>
#define streq(a,b) (strcmp(a,b)==0)
static void changeitems(), showprotos(), showports(), showhosts();
static int selectproto(), selectport(), selecthost();
if (prefix(cmd
, "tcp") || prefix(cmd
, "udp")) {
if (prefix(cmd
, "ignore") || prefix(cmd
, "display")) {
changeitems(args
, prefix(cmd
, "display"));
if (prefix(cmd
, "reset")) {
if (prefix(cmd
, "show")) {
move(CMDLINE
, 0); clrtoeol();
if (prefix(args
, "protos"))
else if (prefix(args
, "hosts"))
else if (prefix(args
, "ports"))
for (cp
= args
; *cp
&& isspace(*cp
); cp
++)
for (; *cp
&& !isspace(*cp
); cp
++)
protos
== TCP
? "tcp" : protos
== UDP
? "udp" : 0);
selectport(sp
->s_port
, onoff
);
hp
= gethostbyname(args
);
in
.s_addr
= inet_addr(args
);
error("%s: unknown host or port", args
);
in
= *(struct in_addr
*)hp
->h_addr
;
if (proto
== 0 || streq(proto
, "all"))
else if (streq(proto
, "tcp"))
else if (streq(proto
, "udp"))
return (new != protos
, protos
= new);
register struct pitem
*p
;
free((char *)ports
), ports
= 0;
for (p
= ports
; p
< ports
+nports
; p
++)
ports
= (struct pitem
*)malloc(sizeof (*p
));
ports
= (struct pitem
*)realloc(ports
, (nports
+1)*sizeof (*p
));
register struct inpcb
*inp
;
register struct pitem
*p
;
for (p
= ports
; p
< ports
+nports
; p
++)
if (p
->port
== inp
->inp_lport
|| p
->port
== inp
->inp_fport
)
register struct pitem
*p
;
for (p
= ports
; p
< ports
+nports
; p
++) {
sp
= getservbyport(p
->port
,
protos
== TCP
|UDP
? 0 : protos
== TCP
? "tcp" : "udp");
printw("%s ", sp
->s_name
);
register struct hitem
*p
;
free((char *)hosts
), hosts
= 0;
for (p
= hosts
; p
< hosts
+nhosts
; p
++)
if (p
->addr
.s_addr
== in
->s_addr
) {
hosts
= (struct hitem
*)malloc(sizeof (*p
));
hosts
= (struct hitem
*)realloc(hosts
, (nhosts
+1)*sizeof (*p
));
register struct inpcb
*inp
;
register struct hitem
*p
;
for (p
= hosts
; p
< hosts
+nhosts
; p
++)
if (p
->addr
.s_addr
== inp
->inp_laddr
.s_addr
||
p
->addr
.s_addr
== inp
->inp_faddr
.s_addr
)
register struct hitem
*p
;
for (p
= hosts
; p
< hosts
+nhosts
; p
++) {
hp
= gethostbyaddr(&p
->addr
, sizeof (p
->addr
), AF_INET
);
printw("%s ", hp
? hp
->h_name
: inet_ntoa(p
->addr
));