예제 #1
0
int
netcmd(const char *cmd, char *args)
{

	if (prefix(cmd, "proto")) {
		if (*args == '\0') {
			move(CMDLINE, 0);
			clrtoeol();
			addstr("which proto?");
		} else if (!selectproto(args)) {
			error("%s: Unknown protocol.", args);
		}
		return (1);
	}
	if (prefix(cmd, "ignore") || prefix(cmd, "display")) {
		changeitems(args, prefix(cmd, "display"));
		return (1);
	}
	if (prefix(cmd, "reset")) {
		selectproto(0);
		selecthost(0, 0);
		selectport(-1, 0);
		return (1);
	}
	if (prefix(cmd, "show")) {
		move(CMDLINE, 0); clrtoeol();
		if (*args == '\0') {
			showprotos();
			showhosts();
			showports();
			return (1);
		}
		if (prefix(args, "protos"))
			showprotos();
		else if (prefix(args, "hosts"))
			showhosts();
		else if (prefix(args, "ports"))
			showports();
		else
			addstr("show what?");
		return (1);
	}
	return (0);
}
예제 #2
0
static void
changeitems(const char *args, int onoff)
{
	char *cp, *tmpstr, *tmpstr1;
	struct servent *sp;
	struct hostent *hp;
	struct in_addr in;

	tmpstr = tmpstr1 = strdup(args);
	cp = strchr(tmpstr1, '\n');
	if (cp)
		*cp = '\0';
	for (;;tmpstr1 = cp) {
		for (cp = tmpstr1; *cp && isspace(*cp); cp++)
			;
		tmpstr1 = cp;
		for (; *cp && !isspace(*cp); cp++)
			;
		if (*cp)
			*cp++ = '\0';
		if (cp - tmpstr1 == 0)
			break;
		sp = getservbyname(tmpstr1,
		    protos == TCP ? "tcp" : protos == UDP ? "udp" : 0);
		if (sp) {
			selectport(sp->s_port, onoff);
			continue;
		}
		hp = gethostbyname(tmpstr1);
		if (hp == 0) {
			in.s_addr = inet_addr(tmpstr1);
			if ((int)in.s_addr == -1) {
				error("%s: unknown host or port", tmpstr1);
				continue;
			}
		} else
			in = *(struct in_addr *)hp->h_addr;
		selecthost(&in, onoff);
	}
	free(tmpstr);
}