1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
--- dsniff-2.4.orig/macof.c 2001-03-15 09:33:04.000000000 +0100
+++ dsniff-2.4/macof.c 2009-12-11 12:56:13.000000000 +0100
@@ -48,8 +48,8 @@ usage(void)
static void
gen_mac(u_char *mac)
{
- *((in_addr_t *)mac) = libnet_get_prand(PRu32);
- *((u_short *)(mac + 4)) = libnet_get_prand(PRu16);
+ *((in_addr_t *)mac) = libnet_get_prand(LIBNET_PRu32);
+ *((u_short *)(mac + 4)) = libnet_get_prand(LIBNET_PRu16);
}
int
@@ -59,22 +59,23 @@ main(int argc, char *argv[])
extern int optind;
int c, i;
struct libnet_link_int *llif;
- char ebuf[PCAP_ERRBUF_SIZE];
+ char pcap_ebuf[PCAP_ERRBUF_SIZE];
+ char libnet_ebuf[LIBNET_ERRBUF_SIZE];
u_char sha[ETHER_ADDR_LEN], tha[ETHER_ADDR_LEN];
in_addr_t src, dst;
u_short sport, dport;
u_int32_t seq;
- u_char pkt[ETH_H + IP_H + TCP_H];
+ libnet_t *l;
while ((c = getopt(argc, argv, "vs:d:e:x:y:i:n:h?V")) != -1) {
switch (c) {
case 'v':
break;
case 's':
- Src = libnet_name_resolve(optarg, 0);
+ Src = libnet_name2addr4(l, optarg, 0);
break;
case 'd':
- Dst = libnet_name_resolve(optarg, 0);
+ Dst = libnet_name2addr4(l, optarg, 0);
break;
case 'e':
Tha = (u_char *)ether_aton(optarg);
@@ -101,13 +102,13 @@ main(int argc, char *argv[])
if (argc != 0)
usage();
- if (!Intf && (Intf = pcap_lookupdev(ebuf)) == NULL)
- errx(1, "%s", ebuf);
+ if (!Intf && (Intf = pcap_lookupdev(pcap_ebuf)) == NULL)
+ errx(1, "%s", pcap_ebuf);
- if ((llif = libnet_open_link_interface(Intf, ebuf)) == 0)
- errx(1, "%s", ebuf);
+ if ((l = libnet_init(LIBNET_LINK, Intf, libnet_ebuf)) == NULL)
+ errx(1, "%s", libnet_ebuf);
- libnet_seed_prand();
+ libnet_seed_prand(l);
for (i = 0; i != Repeat; i++) {
@@ -117,39 +118,39 @@ main(int argc, char *argv[])
else memcpy(tha, Tha, sizeof(tha));
if (Src != 0) src = Src;
- else src = libnet_get_prand(PRu32);
+ else src = libnet_get_prand(LIBNET_PRu32);
if (Dst != 0) dst = Dst;
- else dst = libnet_get_prand(PRu32);
+ else dst = libnet_get_prand(LIBNET_PRu32);
if (Sport != 0) sport = Sport;
- else sport = libnet_get_prand(PRu16);
+ else sport = libnet_get_prand(LIBNET_PRu16);
if (Dport != 0) dport = Dport;
- else dport = libnet_get_prand(PRu16);
+ else dport = libnet_get_prand(LIBNET_PRu16);
- seq = libnet_get_prand(PRu32);
-
- libnet_build_ethernet(tha, sha, ETHERTYPE_IP, NULL, 0, pkt);
-
- libnet_build_ip(TCP_H, 0, libnet_get_prand(PRu16), 0, 64,
- IPPROTO_TCP, src, dst, NULL, 0, pkt + ETH_H);
+ seq = libnet_get_prand(LIBNET_PRu32);
libnet_build_tcp(sport, dport, seq, 0, TH_SYN, 512,
- 0, NULL, 0, pkt + ETH_H + IP_H);
+ 0, 0, LIBNET_TCP_H, NULL, 0, l, 0);
- libnet_do_checksum(pkt + ETH_H, IPPROTO_IP, IP_H);
- libnet_do_checksum(pkt + ETH_H, IPPROTO_TCP, TCP_H);
+ libnet_build_ipv4(LIBNET_TCP_H, 0,
+ libnet_get_prand(LIBNET_PRu16), 0, 64,
+ IPPROTO_TCP, 0, src, dst, NULL, 0, l, 0);
- if (libnet_write_link_layer(llif, Intf, pkt, sizeof(pkt)) < 0)
+ libnet_build_ethernet(tha, sha, ETHERTYPE_IP, NULL, 0, l, 0);
+
+ if (libnet_write(l) < 0)
errx(1, "write");
+ libnet_clear_packet(l);
+
fprintf(stderr, "%s ",
ether_ntoa((struct ether_addr *)sha));
fprintf(stderr, "%s %s.%d > %s.%d: S %u:%u(0) win 512\n",
ether_ntoa((struct ether_addr *)tha),
- libnet_host_lookup(Src, 0), sport,
- libnet_host_lookup(Dst, 0), dport, seq, seq);
+ libnet_addr2name4(Src, 0), sport,
+ libnet_addr2name4(Dst, 0), dport, seq, seq);
}
exit(0);
}
|