예제 #1
0
static int sniffer_print_nlmsg(struct nlmsghdr *nlh, char *buf, int buf_len)
{
    int ret = 0;
	switch (nlh->nlmsg_type)
	{
		case SNIFFER_NLTYPE_KINFO:
			if (buf_len < sizeof(struct sniffer_match_info))
			{
				printf("Invalid packet info message\n");
				break;
			}
			printinfo((struct sniffer_match_info *)buf);
			break;
		case SNIFFER_NLTYPE_KCOUNT:
			printcount((struct sniffer_match_count *)buf);
            ret = 1;   /* kernel stoped, so we exit */
			break;
		case SNIFFER_NLTYPE_KFILTER:
			printfilter((struct sniffer_filter *)buf);
            ret = 1;
			break;
		default:
			printf("Warning:receive an unknown messge from kernel\n");
			break;
	}
    return ret;
}
예제 #2
0
파일: main.c 프로젝트: aahud/harvey
Filter*
compile(Filter *f)
{
	if(f == nil)
		return f;

	/* fill in the missing header filters */
	f = complete(f, nil);

	/* constant folding */
	f = optimize(f);
	if(!toflag)
		printfilter(f, "after optimize");

	/* protocol specific compilations */
	_compile(f, nil);

	/* at this point, the root had better be the root proto */
	if(findbogus(f)){
		fprint(2, "bogus filter\n");
		exits("bad filter");
	}

	return f;
}