示例#1
0
static bool ecn_mt(const struct sk_buff *skb, const struct xt_match_param *par)
{
	const struct ipt_ecn_info *info = par->matchinfo;

	if (info->operation & IPT_ECN_OP_MATCH_IP)
		if (!match_ip(skb, info))
			return false;

	if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR)) {
		if (ip_hdr(skb)->protocol != IPPROTO_TCP)
			return false;
		if (!match_tcp(skb, info, par->hotdrop))
			return false;
	}

	return true;
}
示例#2
0
文件: socket_base.c 项目: antontest/c
/**
 * @brief convert mask to bits of mask
 *
 * @param mask [in] mask address
 *
 * @return bits of mask, if succ; -1, if failed
 */
int mask_to_bits(const char *mask)
{
    int i = 0;
    int n = 0;
    struct in_addr addr;
    int bits = sizeof(unsigned int) * 8;

    if (!match_ip(mask)) return -1;

    inet_pton(AF_INET, mask, &addr);
    for (i = bits - 1; i >=0; i--)
    {
        if (addr.s_addr & (0x01 << i))
            n++;
    }

    return n;
}
示例#3
0
static int match(const struct sk_buff *skb,
		 const struct net_device *in, const struct net_device *out,
		 const struct xt_match *match, const void *matchinfo,
		 int offset, unsigned int protoff, int *hotdrop)
{
	const struct ipt_ecn_info *info = matchinfo;

	if (info->operation & IPT_ECN_OP_MATCH_IP)
		if (!match_ip(skb, info))
			return 0;

	if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR)) {
		if (skb->nh.iph->protocol != IPPROTO_TCP)
			return 0;
		if (!match_tcp(skb, info, hotdrop))
			return 0;
	}

	return 1;
}
示例#4
0
文件: socket.c 项目: antontest/c
/**
 * @brief Get parameters from the command line 
 *
 * @param agrc   [in] the count of paramters
 * @param agrv[] [in] parameters array
 *
 * @return 0, if succ
 *        -1, if failed
 */
static int parser_args(int agrc, char *agrv[])
{
    int opt = 0;
    const char *optstr = "a:b:cd::eg::hi:m:n:p:q:rsu:w:";
    struct option opts[] = {
        { "agreement", 1, 0, 'a'},
        { "bam"      , 0, 0, 'b'},
        { "client"   , 0, 0, 'c'},
        { "hardware" , 2, 0, 'd'},
        { "ether"    , 2, 0, 'e'},
        { "gateway"  , 2, 0, 'g'},
        { "help"     , 0, 0, 'h'},
        { "ip"       , 1, 0, 'i'},
        { "message"  , 1, 0, 'm'},
        { "net_mac"  , 0, 0, 'n'},
        { "port"     , 1, 0, 'o'},
        { "interact" , 0, 0, 'q'},
        { "router"   , 0, 0, 'r'},
        { "server"   , 0, 0, 's'},
        { "times"    , 1, 0, 't'},
        { "up"       , 1, 0, 'u'},
        { "wait"     , 1, 0, 'w'},
        {     0      , 0, 0,  0 }
    };

    if (agrc < 2) return -1;

    while ( ( opt = getopt_long( agrc, agrv, optstr, opts, NULL ) ) != -1 ) {
        switch(opt) {
            case 'h':
                print_usage();
                exit(1);
                break;
                /*
            case 'a':
                printf("aaa\n");
                if (optarg != NULL)
                    proto = getprotobyname(optarg);
                break;
                */
            case 'b':
                cheat_flag = 1; 
                if (optarg != NULL) strcpy(ip, optarg);
                break;
            case 'c':
                cli_flag = 1; 
                break;
            case 'd':
                mac_flag = 1;
                if (optarg != NULL) strcpy(ether, optarg);
                break;
            case 'e':
                eth_flag = 1;
                if (optarg != NULL) strcpy(ether, optarg);
                break;
            case 'g':
                gateway_flag = 1;
                if (optarg != NULL) strcpy(gateway_ip, optarg);
                break;
            case 'i':
                if (optarg != NULL) strcpy(ip, optarg);
                if (strlen(ip)) {
                    if (!match_ip(ip)) {
                        printf("\033[0;31mPlease input right ip address!\033[0m\n");
                        exit(1);
                    }
                }
                break;
            case 'm':
                if (optarg != NULL) strcpy(message, optarg);
                break;
            case 'n':
                netmac_flag = 1;
                if (optarg != NULL) strcpy(ip, optarg);
                break;
            case 'p':
                if (optarg != NULL) port = atoi(optarg);
                if (port < 0 || port > 65535) 
                {
                    printf("port input error\n");
                    exit(1);
                }
                break;
            case 'q':
                interact_flag = 1; 
                if (optarg != NULL) strcpy(ip, optarg);
                break;
            case 'r':
                router_flag = 1; 
                //if (optarg != NULL) strcpy(ip, optarg);
                break;
            case 's':
                ser_flag = 1; 
                break;
            case 't':
                if (optarg != NULL)
                    times = atoi(optarg);
                break;
            case 'u':
                up_flag = 1;
                strcpy(up_range, optarg);
                break;
            case 'w':
                if (optarg != NULL)
                    sleep_time = atoi(optarg);
                break;
            case 'a':
                proto_flag = 1;
                if (!strcasecmp(optarg, "t") || !strcasecmp(optarg, "tcp")) {
                    protocol = PROTO_TCP;
                    strcpy(proto_str, "TCP");
                }
                else if (!strcasecmp(optarg, "u") || !strcasecmp(optarg, "udp")) {
                    protocol = PROTO_UDP;
                    strcpy(proto_str, "UDP");
                }
                else if (!strcasecmp(optarg, "s") || !strcasecmp(optarg, "sctp")) {
                    protocol = PROTO_SCTP;
                    strcpy(proto_str, "SCTP");
                }
                else if (!strcasecmp(optarg, "b") || !strcasecmp(optarg, "broadcast")) {
                    protocol = PROTO_BROADCAST;
                    strcpy(proto_str, "Broadcast");
                }
                else if (!strcasecmp(optarg, "m") || !strcasecmp(optarg, "multicast")) {
                    protocol = PROTO_MULTICAST;
                    strcpy(proto_str, "Multicast");
                }
                else {
                    printf("protocol type error\n");
                    exit(1);
                }
                break;
            case '?':
            default:
                return -1;
        }
    }

    return 0;
}