Ticket #21225: patch-tcpkill.c.diff
File patch-tcpkill.c.diff, 2.8 KB (added by hsivank@…, 15 years ago) |
---|
-
tcpkill.c
old new 39 39 static void 40 40 tcp_kill_cb(u_char *user, const struct pcap_pkthdr *pcap, const u_char *pkt) 41 41 { 42 struct libnet_ip _hdr *ip;42 struct libnet_ipv4_hdr *ip; 43 43 struct libnet_tcp_hdr *tcp; 44 u_char ctext[64] , buf[IP_H + TCP_H];44 u_char ctext[64]; 45 45 u_int32_t seq, win; 46 int i, *sock, len; 46 int i, len; 47 libnet_t *l; 47 48 48 sock = (int *)user;49 l = (libnet_t *)user; 49 50 pkt += pcap_off; 50 51 len = pcap->caplen - pcap_off; 51 52 52 ip = (struct libnet_ip _hdr *)pkt;53 ip = (struct libnet_ipv4_hdr *)pkt; 53 54 if (ip->ip_p != IPPROTO_TCP) 54 55 return; 55 56 … … 57 58 if (tcp->th_flags & (TH_SYN|TH_FIN|TH_RST)) 58 59 return; 59 60 60 libnet_build_ip(TCP_H, 0, 0, 0, 64, IPPROTO_TCP,61 ip->ip_dst.s_addr, ip->ip_src.s_addr,62 NULL, 0, buf);63 64 libnet_build_tcp(ntohs(tcp->th_dport), ntohs(tcp->th_sport),65 0, 0, TH_RST, 0, 0, NULL, 0, buf + IP_H);66 67 61 seq = ntohl(tcp->th_ack); 68 62 win = ntohs(tcp->th_win); 69 63 70 64 snprintf(ctext, sizeof(ctext), "%s:%d > %s:%d:", 71 libnet_ host_lookup(ip->ip_src.s_addr, 0),65 libnet_addr2name4(ip->ip_src.s_addr, LIBNET_DONT_RESOLVE), 72 66 ntohs(tcp->th_sport), 73 libnet_ host_lookup(ip->ip_dst.s_addr, 0),67 libnet_addr2name4(ip->ip_dst.s_addr, LIBNET_DONT_RESOLVE), 74 68 ntohs(tcp->th_dport)); 75 69 76 ip = (struct libnet_ip_hdr *)buf;77 tcp = (struct libnet_tcp_hdr *)(ip + 1);78 79 70 for (i = 0; i < Opt_severity; i++) { 80 ip->ip_id = libnet_get_prand(PRu16);81 71 seq += (i * win); 82 tcp->th_seq = htonl(seq);83 72 84 libnet_do_checksum(buf, IPPROTO_TCP, TCP_H); 73 libnet_clear_packet(l); 74 75 libnet_build_tcp(ntohs(tcp->th_dport), ntohs(tcp->th_sport), 76 seq, 0, TH_RST, 0, 0, 0, LIBNET_TCP_H, 77 NULL, 0, l, 0); 78 79 libnet_build_ipv4(LIBNET_IPV4_H + LIBNET_TCP_H, 0, 80 libnet_get_prand(LIBNET_PRu16), 0, 64, 81 IPPROTO_TCP, 0, ip->ip_dst.s_addr, 82 ip->ip_src.s_addr, NULL, 0, l, 0); 85 83 86 if (libnet_write _ip(*sock, buf, sizeof(buf)) < 0)87 warn("write _ip");84 if (libnet_write(l) < 0) 85 warn("write"); 88 86 89 87 fprintf(stderr, "%s R %lu:%lu(0) win 0\n", ctext, seq, seq); 90 88 } … … 95 93 { 96 94 extern char *optarg; 97 95 extern int optind; 98 int c , sock;96 int c; 99 97 char *p, *intf, *filter, ebuf[PCAP_ERRBUF_SIZE]; 98 char libnet_ebuf[LIBNET_ERRBUF_SIZE]; 99 libnet_t *l; 100 100 pcap_t *pd; 101 101 102 102 intf = NULL; … … 136 136 if ((pcap_off = pcap_dloff(pd)) < 0) 137 137 errx(1, "couldn't determine link layer offset"); 138 138 139 if (( sock = libnet_open_raw_sock(IPPROTO_RAW)) == -1)139 if ((l = libnet_init(LIBNET_RAW4, intf, libnet_ebuf)) == NULL) 140 140 errx(1, "couldn't initialize sending"); 141 141 142 libnet_seed_prand( );142 libnet_seed_prand(l); 143 143 144 144 warnx("listening on %s [%s]", intf, filter); 145 145 146 pcap_loop(pd, -1, tcp_kill_cb, (u_char *) &sock);146 pcap_loop(pd, -1, tcp_kill_cb, (u_char *)l); 147 147 148 148 /* NOTREACHED */ 149 149