Пример #1
0
void cpn_opts_usage(const struct cpn_opt *opts,
        const char *executable, FILE *out)
{
    fputs("USAGE: ", out);
    print_header(opts, executable, NULL, out);
    if (has_actions(opts) || has_options(opts))
        fputc('\n', out);
    print_arguments(opts, out, 1);
    if (has_actions(opts) && has_options(opts))
        fputc('\n', out);
    print_actions(opts, out, 1);
}
Пример #2
0
static void print_header(const struct cpn_opt *opts, const char *name, const char *description, FILE *out)
{
    const struct cpn_opt *it;

    fputs(name, out);

    if (has_options(opts))
        fputs(" [OPTIONS...]", out);

    if (has_actions(opts)) {
        bool first_action = true;

        fputs(" (", out);
        for (it = opts; it && it->type != CPN_OPTS_TYPE_END; it++) {
            if (it->type == CPN_OPTS_TYPE_ACTION) {
                fprintf(out, "%s%s", first_action ? "" : "|", it->long_name);
                first_action = false;
            }
        }
        fputs(")", out);
    }

    if (description) {
        fprintf(out, ": %s", description);
    }

    fputc('\n', out);
}
Пример #3
0
enum IP_STATUS ip_accept_finish(const struct ppam_rx_hash *ctxt,
                                struct annotations_t *notes,
                                struct iphdr *ip_hdr,
                                enum state source)
{
    if (unlikely(has_options(ip_hdr))) {
        /* TODO:
         Handle Preroute options */
    }
    return ip_route_input(ctxt, notes, ip_hdr, source);
}
Пример #4
0
static void print_actions(const struct cpn_opt *opts, FILE *out, int indent)
{
    const struct cpn_opt *it;
    int i;

    for (it = opts; it && it->type != CPN_OPTS_TYPE_END; it++) {
        if (it->type != CPN_OPTS_TYPE_ACTION)
            continue;

        for (i = indent; i; i--)
            fputc('\t', out);
        print_header(it->value.action_opts, it->long_name, it->description, out);
        print_arguments(it->value.action_opts, out, indent + 1);
        if (has_actions(it) && has_options(it))
            fputc('\n', out);
        print_actions(it->value.action_opts, out, indent + 1);
    }
}
Пример #5
0
ICMPv6::ICMPv6(const uint8_t *buffer, uint32_t total_sz) 
: _options_size(), reach_time(0), retrans_timer(0)
{
    if(total_sz < sizeof(_header))
        throw malformed_packet();
    std::memcpy(&_header, buffer, sizeof(_header));
    buffer += sizeof(_header);
    total_sz -= sizeof(_header);
    if(has_target_addr()) {
        if(total_sz < ipaddress_type::address_size)
            throw malformed_packet();
        target_addr(buffer);
        buffer += ipaddress_type::address_size;
        total_sz -= ipaddress_type::address_size;
    }
    if(has_dest_addr()) {
        if(total_sz < ipaddress_type::address_size)
            throw malformed_packet();
        dest_addr(buffer);
        buffer += ipaddress_type::address_size;
        total_sz -= ipaddress_type::address_size;
    }
    if(type() == ROUTER_ADVERT) {
        if(total_sz < sizeof(uint32_t) * 2)
            throw malformed_packet();
        const uint32_t *ptr_32 = (const uint32_t*)buffer;
        reach_time = *ptr_32++;
        retrans_timer = *ptr_32++;
        
        buffer += sizeof(uint32_t) * 2;
        total_sz -= sizeof(uint32_t) * 2;
    }
    if(has_options())
        parse_options(buffer, total_sz);
    if(total_sz > 0)
        inner_pdu(new RawPDU(buffer, total_sz));
}