void handle_recv_event(pings_params *pings) { struct timeval current_time = {0}; int is_recv_packet; is_recv_packet = recv_packets(pings); if(pings->recv_error){ return; } if(PINGS_TRUE == is_recv_packet){ gettimeofday(&(pings->recv_last_packet_time), NULL); pings->recv_interval = 0.0; } else{ gettimeofday(¤t_time, NULL); pings->recv_interval = time_sub(¤t_time, &(pings->recv_last_packet_time)); } if(pings->resend_num < PINGS_RESEND_NUMBER){ pings->event.events = EPOLLOUT | EPOLLET; epoll_ctl(pings->epoll_fd, EPOLL_CTL_MOD, pings->sock_fd, &(pings->event)); } else{ pings->event.events = EPOLLIN | EPOLLET; epoll_ctl(pings->epoll_fd, EPOLL_CTL_MOD, pings->sock_fd, &(pings->event)); } }
int recv_run(pthread_mutex_t *recv_ready_mutex) { log_trace("recv", "recv thread started"); log_debug("recv", "capturing responses on %s", zconf.iface); if (!zconf.dryrun) { recv_init(); } if (zconf.send_ip_pkts) { struct ether_header *eth = (struct ether_header *) fake_eth_hdr; memset(fake_eth_hdr, 0, sizeof(fake_eth_hdr)); eth->ether_type = htons(ETHERTYPE_IP); } // initialize paged bitmap seen = pbm_init(); if (zconf.filter_duplicates) { log_debug("recv", "duplicate responses will be excluded from output"); } else { log_debug("recv", "duplicate responses will be included in output"); } if (zconf.filter_unsuccessful) { log_debug("recv", "unsuccessful responses will be excluded from output"); } else { log_debug("recv", "unsuccessful responses will be included in output"); } pthread_mutex_lock(recv_ready_mutex); zconf.recv_ready = 1; pthread_mutex_unlock(recv_ready_mutex); zrecv.start = now(); if (zconf.max_results == 0) { zconf.max_results = -1; } do { if (zconf.dryrun) { sleep(1); } else { recv_packets(); if (zconf.max_results && zrecv.success_unique >= zconf.max_results) { break; } } } while (!(zsend.complete && (now()-zsend.finish > zconf.cooldown_secs))); zrecv.finish = now(); // get final pcap statistics before closing recv_update_stats(); if (!zconf.dryrun) { pthread_mutex_lock(recv_ready_mutex); recv_cleanup(); pthread_mutex_unlock(recv_ready_mutex); } zrecv.complete = 1; log_debug("recv", "thread finished"); return 0; }
void c_protocol::tick() { recv_packets(); for (auto &input_packet : m_inbox) { process_input_packet(input_packet); } for (auto &output_packet : m_outbox) { _info("send packet to " << output_packet.m_address); m_network_device->write_to_nym(output_packet.m_address, output_packet.m_data); } _info("m_inbox size: " << m_inbox.size()); _info("m_outbox size: " << m_outbox.size()); m_outbox.clear(); m_inbox.clear(); }