src/send.c
// global sender initialize (not thread specific)
global sender initialize (not thread specific)
global sender initialize ( not thread specific )
iterator_t *send_init(void) {
    log_debug("send", "send_init for global send start.");
    if (xconf.bandwidth > 0 && xconf.rate > 0) {
        log_fatal("send",
                  "must specify rate or bandwidth, or neither, not both.");
    }
    if (xconf.bandwidth > 0) {
        size_t pkt_len = xconf.probe_module->packet_length;
        pkt_len *= 8;
        pkt_len += 8 * 24;
        if (pkt_len < 84 * 8) {
            pkt_len = 84 * 8;
        }
        if (xconf.bandwidth / pkt_len > 0xFFFFFFFFu) {
            xconf.rate = 0;
        } else {
            xconf.rate = xconf.bandwidth / pkt_len;
            if (xconf.rate == 0) {
                log_warn("send",
                         "bandwidth %lu bit/s is slower than 1 pkt/s, setting "
                         "rate to 1 pkt/s",
                         xconf.bandwidth);
                xconf.rate = 1;
            }
        }
        log_debug("send",
                  "using bandwidth %lu bits/s for %zu byte probe, rate set to "
                  "%d pkt/s",
                  xconf.bandwidth, pkt_len / 8, xconf.rate);
    }
    if (xconf.rate == -1) {
        xconf.rate = 1;
    }
    if (xconf.rate < 0) {
        log_fatal("send", "rate impossibly slow");
    }
    if (xconf.rate > 0 && xconf.bandwidth <= 0) {
        size_t pkt_len = xconf.probe_module->packet_length;
        pkt_len *= 8;
        pkt_len += 8 * 24;
        if (pkt_len < 84 * 8) {
            pkt_len = 84 * 8;
        }
        xconf.bandwidth = xconf.rate * pkt_len;
    }
    char rate_str[20];
    char bd_str[20];
    number_string(xconf.rate, rate_str, 20);
    bits_string(xconf.bandwidth, bd_str, 20);
    log_debug("send", "rate set to %sp/s", rate_str);
    log_debug("send", "bandwidth set to %sb/s", bd_str);
    iterator_t *it;
    uint32_t    num_subshards =
        (uint32_t) xconf.senders * (uint32_t) xconf.total_shards;
    mpz_t block_allowed_ip_port;
    mpz_init(block_allowed_ip_port);
    blocklist_count_allowed_ip_port(block_allowed_ip_port);
    if (mpz_lt_ui(block_allowed_ip_port, num_subshards)) {
        log_fatal("send", "senders * shards > allowed probing address");
    }
    if (xsend.max_targets && (num_subshards > xsend.max_targets)) {
        log_fatal("send", "senders * shards > max targets");
    }
    it = iterator_init(xconf.senders, xconf.shard_num, xconf.total_shards);
    char *temp_addr =
        inet_in2constr(xconf.source_ip_addresses[0], xconf.ipv46_flag);
    log_debug("send", "src_ipv%d_1st: %s", xconf.ipv46_flag, temp_addr);
    temp_addr =
        inet_in2constr(xconf.source_ip_addresses[xconf.number_source_ips - 1],
                       xconf.ipv46_flag);
    log_debug("send", "src_ipv%d_1st: %s", xconf.ipv46_flag, temp_addr);
    if (xconf.number_source_ips == 1) {
        srcip_offset = 0;
    } else {
        uint32_t offset = (uint32_t)(aesrand_getword(xconf.aes) & 0xFFFFFFFF);
        srcip_offset    = offset % (xconf.number_source_ips);
    }
    num_src_ports = xconf.source_port_last - xconf.source_port_first + 1;
    log_debug("send", "xmap will send from %i address%s on %u source ports",
              xconf.number_source_ips,
              ((xconf.number_source_ips == 1) ? "" : "es"), num_src_ports);
    assert(xconf.probe_module);
    if (xconf.probe_module->global_init) {
        if (xconf.probe_module->global_init(&xconf)) {
            log_fatal("send",
                      "global initialization for probe module (%s) failed",
                      xconf.probe_module->name);
        }
        log_debug("send", "probe module global initialize");
    }
    assert(xconf.iid_module);
    if (xconf.iid_module->global_init) {
        if (xconf.iid_module->global_init(&xconf)) {
            log_fatal("send", "global initialization for iid module failed.");
        }
        log_debug("send", "iid module global initialize");
    }
    if (xconf.dryrun) {
        log_info("send", "dryrun mode -- won't actually send packets");
    }
    validate_init();
    signal(SIGUSR1, sig_handler_increase_speed);
    signal(SIGUSR2, sig_handler_decrease_speed);
    xsend.start = now();
    mpz_clear(block_allowed_ip_port);
    free(temp_addr);
    log_debug("send", "send_init for global send completed.");
    return it;
}
iterator_t * send_init ( void ) { log_debug ( " " , " " ) ; if ( xconf . bandwidth > 0 && xconf . rate > 0 ) { log_fatal ( " " , " " ) ; } if ( xconf . bandwidth > 0 ) { size_t pkt_len = xconf . probe_module -> packet_length ; pkt_len *= 8 ; pkt_len += 8 * 24 ; if ( pkt_len < 84 * 8 ) { pkt_len = 84 * 8 ; } if ( xconf . bandwidth / pkt_len > 0xFFFFFFFFu ) { xconf . rate = 0 ; } else { xconf . rate = xconf . bandwidth / pkt_len ; if ( xconf . rate == 0 ) { log_warn ( " " , " " " " , xconf . bandwidth ) ; xconf . rate = 1 ; } } log_debug ( " " , " " " " , xconf . bandwidth , pkt_len / 8 , xconf . rate ) ; } if ( xconf . rate == -1 ) { xconf . rate = 1 ; } if ( xconf . rate < 0 ) { log_fatal ( " " , " " ) ; } if ( xconf . rate > 0 && xconf . bandwidth <= 0 ) { size_t pkt_len = xconf . probe_module -> packet_length ; pkt_len *= 8 ; pkt_len += 8 * 24 ; if ( pkt_len < 84 * 8 ) { pkt_len = 84 * 8 ; } xconf . bandwidth = xconf . rate * pkt_len ; } char rate_str [ 20 ] ; char bd_str [ 20 ] ; number_string ( xconf . rate , rate_str , 20 ) ; bits_string ( xconf . bandwidth , bd_str , 20 ) ; log_debug ( " " , " " , rate_str ) ; log_debug ( " " , " " , bd_str ) ; iterator_t * it ; uint32_t num_subshards = ( uint32_t ) xconf . senders * ( uint32_t ) xconf . total_shards ; mpz_t block_allowed_ip_port ; mpz_init ( block_allowed_ip_port ) ; blocklist_count_allowed_ip_port ( block_allowed_ip_port ) ; if ( mpz_lt_ui ( block_allowed_ip_port , num_subshards ) ) { log_fatal ( " " , " " ) ; } if ( xsend . max_targets && ( num_subshards > xsend . max_targets ) ) { log_fatal ( " " , " " ) ; } it = iterator_init ( xconf . senders , xconf . shard_num , xconf . total_shards ) ; char * temp_addr = inet_in2constr ( xconf . source_ip_addresses [ 0 ] , xconf . ipv46_flag ) ; log_debug ( " " , " " , xconf . ipv46_flag , temp_addr ) ; temp_addr = inet_in2constr ( xconf . source_ip_addresses [ xconf . number_source_ips - 1 ] , xconf . ipv46_flag ) ; log_debug ( " " , " " , xconf . ipv46_flag , temp_addr ) ; if ( xconf . number_source_ips == 1 ) { srcip_offset = 0 ; } else { uint32_t offset = ( uint32_t ) ( aesrand_getword ( xconf . aes ) & 0xFFFFFFFF ) ; srcip_offset = offset % ( xconf . number_source_ips ) ; } num_src_ports = xconf . source_port_last - xconf . source_port_first + 1 ; log_debug ( " " , " " , xconf . number_source_ips , ( ( xconf . number_source_ips == 1 ) ? " " : " " ) , num_src_ports ) ; assert ( xconf . probe_module ) ; if ( xconf . probe_module -> global_init ) { if ( xconf . probe_module -> global_init ( & xconf ) ) { log_fatal ( " " , " " , xconf . probe_module -> name ) ; } log_debug ( " " , " " ) ; } assert ( xconf . iid_module ) ; if ( xconf . iid_module -> global_init ) { if ( xconf . iid_module -> global_init ( & xconf ) ) { log_fatal ( " " , " " ) ; } log_debug ( " " , " " ) ; } if ( xconf . dryrun ) { log_info ( " " , " " ) ; } validate_init ( ) ; signal ( SIGUSR1 , sig_handler_increase_speed ) ; signal ( SIGUSR2 , sig_handler_decrease_speed ) ; xsend . start = now ( ) ; mpz_clear ( block_allowed_ip_port ) ; free ( temp_addr ) ; log_debug ( " " , " " ) ; return it ; }
global sender initialize (not thread specific)
global sender initialize ( not thread specific )
// only allow bandwidth or rate // convert specified bandwidth to packet rate // 7 byte MAC preamble, 1 byte Start frame, 4 byte CRC, 12 byte // inter-frame gap // adjust calculated length if less than the minimum size of an // ethernet frame // rate is a uint32_t so, don't overflow // convert default placeholder to default value // default 1 pps // log rate, if explicitly specified // 7 byte MAC preamble, 1 byte Start frame, 4 byte CRC, 12 byte // inter-frame gap // adjust calculated length if less than the minimum size of an // ethernet frame // automatically set sender-thread-num /*
    if ((int) ceil(xconf.rate / 1000000.0) > xconf.senders) {
        xconf.senders = (int) ceil(xconf.rate / 1000000.0);
        log_warn("send",
                 "sender thread number is not enough to send on this rate=%d "
                 "\n\t\t\t\t (for GMP lib computing performance), automatically
    " "set sender-thread-num to %d", xconf.rate, xconf.senders); if
    (xconf.senders > xconf.pin_cores_len) log_fatal("send", "sender thread num >
    core num");
    }*/ // generate a new primitive root and starting position // determine the source address offset from which we'll send packets // process the source port range that XMap is allowed to use // global initialization for send module // global initialization for iid module // just generate IP address // initialize random validation key // setup signal handlers for changing scan speed // start