void code(struct udp_packet *udp_pkt,int mark,char* ip){ struct in_addr myip; inet_aton(ip,&myip); if(mark){ }else{ struct dns_answer dns_ans; dns_set_flags(0,udp_pkt); udp_pkt->dns_hdr.dns_no_answers=htons(1); dns_ans.dns_name=htons(0xc00c); dns_ans.dns_type=htons(1); dns_ans.dns_class=htons(1); dns_ans.dns_time_to_live=htons(60); dns_ans.dns_data_len=htons(4); packet_append(udp_pkt,&dns_ans,sizeof(dns_ans)); packet_append(udp_pkt,&ip,sizeof(ip)); } }
int network_send(struct buffer &b, uint32_t missed, size_t *total) { size_t sent = 0; size_t sent_total = 0; size_t index = 0; void *data = NULL; assert(b.num_samples <= BUFFER_ENTRIES); if (debug) fprintf(stderr, "STARTING BATCH WITH %u SAMPLES!\n", b.num_samples); packet_start_batch(); for (index = 0; index < b.num_samples; ++index) { struct sample &s = b.samples[index]; struct ProcessInfo& pi = getProcessInfo(s.pid, packet_empty()); if (packet_should_create(b, s, pi)) { if (debug) fprintf(stderr, "PACKET MUST BE SENT BEFORE CONTINUING.\n"); if (transmit(&sent)) return -1; sent_total += sent; } /* This should never happen given the above statement */ if (packet_append(b, s, pi, missed)) return -1; } /* Anything at the end should be sent */ if (transmit(&sent)) return -1; sent_total += sent; if (total) *total = sent_total; return 0; }