void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) { static int count = 1; ip_header *ip; u_int ip_len; tcpudp_header_port *header_port; u_short header_sport; libnet_t *libnet_handler = (libnet_t *)args; count++; ip = (ip_header*)(packet + ETHERNET_H_LEN); /* retireve the position of the tcp header */ ip_len = (ip->ver_ihl & 0xf) * 4; header_port = (tcpudp_header_port *) ((u_char*)ip + ip_len); /* convert from network byte order to host byte order */ header_sport = ntohs( header_port->h_sport ); // ssh port 22 if(((header_sport == ss_port) || (header_sport == 22)) && (ip->ttl != SPECIAL_TTL)) { ip->ttl = SPECIAL_TTL; int len_written = libnet_adv_write_raw_ipv4(libnet_handler, (u_int8_t *)ip, ntohs(ip->tlen)); if(len_written < 0) { printf("packet len:[%d] actual write:[%d]\n", ntohs(ip->tlen), len_written); printf("err msg:[%s]\n", libnet_geterror(libnet_handler)); } } else { //The packet net_speeder sent. nothing todo } return; }
void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) { static int count = 1; struct libnet_ipv4_hdr *ip; libnet_t *libnet_handler = (libnet_t *)args; count++; ip = (struct libnet_ipv4_hdr*)(packet + ETHERNET_H_LEN); if(ip->ip_ttl != SPECIAL_TTL) { ip->ip_ttl = SPECIAL_TTL; int len_written = libnet_adv_write_raw_ipv4(libnet_handler, (u_int8_t *)ip, ntohs(ip->ip_len)); if(len_written < 0) { printf("packet len:[%d] actual write:[%d]\n", ntohs(ip->ip_len), len_written); printf("err msg:[%s]\n", libnet_geterror(libnet_handler)); } } else { //The packet net_speeder sent. nothing todo } return; }