Ticket #21225: patch-macof.c.diff
File patch-macof.c.diff, 3.3 KB (added by hsivank@…, 15 years ago) |
---|
-
macof.c
old new 48 48 static void 49 49 gen_mac(u_char *mac) 50 50 { 51 *((in_addr_t *)mac) = libnet_get_prand( PRu32);52 *((u_short *)(mac + 4)) = libnet_get_prand( PRu16);51 *((in_addr_t *)mac) = libnet_get_prand(LIBNET_PRu32); 52 *((u_short *)(mac + 4)) = libnet_get_prand(LIBNET_PRu16); 53 53 } 54 54 55 55 int … … 59 59 extern int optind; 60 60 int c, i; 61 61 struct libnet_link_int *llif; 62 char ebuf[PCAP_ERRBUF_SIZE]; 62 char pcap_ebuf[PCAP_ERRBUF_SIZE]; 63 char libnet_ebuf[LIBNET_ERRBUF_SIZE]; 63 64 u_char sha[ETHER_ADDR_LEN], tha[ETHER_ADDR_LEN]; 64 65 in_addr_t src, dst; 65 66 u_short sport, dport; 66 67 u_int32_t seq; 67 u_char pkt[ETH_H + IP_H + TCP_H];68 libnet_t *l; 68 69 69 70 while ((c = getopt(argc, argv, "vs:d:e:x:y:i:n:h?V")) != -1) { 70 71 switch (c) { 71 72 case 'v': 72 73 break; 73 74 case 's': 74 Src = libnet_name _resolve(optarg, 0);75 Src = libnet_name2addr4(l, optarg, 0); 75 76 break; 76 77 case 'd': 77 Dst = libnet_name _resolve(optarg, 0);78 Dst = libnet_name2addr4(l, optarg, 0); 78 79 break; 79 80 case 'e': 80 81 Tha = (u_char *)ether_aton(optarg); … … 101 102 if (argc != 0) 102 103 usage(); 103 104 104 if (!Intf && (Intf = pcap_lookupdev( ebuf)) == NULL)105 errx(1, "%s", ebuf);105 if (!Intf && (Intf = pcap_lookupdev(pcap_ebuf)) == NULL) 106 errx(1, "%s", pcap_ebuf); 106 107 107 if ((l lif = libnet_open_link_interface(Intf, ebuf)) == 0)108 errx(1, "%s", ebuf);108 if ((l = libnet_init(LIBNET_LINK, Intf, libnet_ebuf)) == NULL) 109 errx(1, "%s", libnet_ebuf); 109 110 110 libnet_seed_prand( );111 libnet_seed_prand(l); 111 112 112 113 for (i = 0; i != Repeat; i++) { 113 114 … … 117 118 else memcpy(tha, Tha, sizeof(tha)); 118 119 119 120 if (Src != 0) src = Src; 120 else src = libnet_get_prand( PRu32);121 else src = libnet_get_prand(LIBNET_PRu32); 121 122 122 123 if (Dst != 0) dst = Dst; 123 else dst = libnet_get_prand( PRu32);124 else dst = libnet_get_prand(LIBNET_PRu32); 124 125 125 126 if (Sport != 0) sport = Sport; 126 else sport = libnet_get_prand( PRu16);127 else sport = libnet_get_prand(LIBNET_PRu16); 127 128 128 129 if (Dport != 0) dport = Dport; 129 else dport = libnet_get_prand( PRu16);130 else dport = libnet_get_prand(LIBNET_PRu16); 130 131 131 seq = libnet_get_prand(PRu32); 132 133 libnet_build_ethernet(tha, sha, ETHERTYPE_IP, NULL, 0, pkt); 134 135 libnet_build_ip(TCP_H, 0, libnet_get_prand(PRu16), 0, 64, 136 IPPROTO_TCP, src, dst, NULL, 0, pkt + ETH_H); 132 seq = libnet_get_prand(LIBNET_PRu32); 137 133 138 134 libnet_build_tcp(sport, dport, seq, 0, TH_SYN, 512, 139 0, NULL, 0, pkt + ETH_H + IP_H);135 0, 0, LIBNET_TCP_H, NULL, 0, l, 0); 140 136 141 libnet_do_checksum(pkt + ETH_H, IPPROTO_IP, IP_H); 142 libnet_do_checksum(pkt + ETH_H, IPPROTO_TCP, TCP_H); 137 libnet_build_ipv4(LIBNET_TCP_H, 0, 138 libnet_get_prand(LIBNET_PRu16), 0, 64, 139 IPPROTO_TCP, 0, src, dst, NULL, 0, l, 0); 143 140 144 if (libnet_write_link_layer(llif, Intf, pkt, sizeof(pkt)) < 0) 141 libnet_build_ethernet(tha, sha, ETHERTYPE_IP, NULL, 0, l, 0); 142 143 if (libnet_write(l) < 0) 145 144 errx(1, "write"); 146 145 146 libnet_clear_packet(l); 147 147 148 fprintf(stderr, "%s ", 148 149 ether_ntoa((struct ether_addr *)sha)); 149 150 fprintf(stderr, "%s %s.%d > %s.%d: S %u:%u(0) win 512\n", 150 151 ether_ntoa((struct ether_addr *)tha), 151 libnet_ host_lookup(Src, 0), sport,152 libnet_ host_lookup(Dst, 0), dport, seq, seq);152 libnet_addr2name4(Src, 0), sport, 153 libnet_addr2name4(Dst, 0), dport, seq, seq); 153 154 } 154 155 exit(0); 155 156 }