2
* author: Darren Bounds <dbounds@intrusense.com>
3
* copyright: Copyright (C) 2002 by Darren Bounds
4
* license: This software is under GPL version 2 of license
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
* 4g8 official page at http://.net
26
capture_loop(u_int8_t *user, struct pcap_pkthdr *pkthdr, u_int8_t *packet)
29
process_packets(pkthdr, packet);
32
fatal_error("Unable to inject packet");
40
u_int8_t filter[255+1];
41
u_int32_t data_link, localnet, netmask;
42
pcap_dumper_t *p_dumper = NULL;
44
struct bpf_program bpf;
45
struct itimerval oval;
46
struct libnet_ether_addr *hw_addr;
49
fprintf(stdout, "DEBUG: init()\n");
52
memset(&oval, 0, sizeof(struct itimerval));
53
memset(&bpf, 0, sizeof(struct bpf_program));
55
signal(SIGTERM, clean_exit);
56
signal(SIGINT, clean_exit);
57
signal(SIGQUIT, clean_exit);
58
signal(SIGHUP, clean_exit);
59
signal(SIGALRM, arp_cache_alrm);
61
if((pkt_d = libnet_init(0, device, error_buf)) == NULL)
62
fatal_error("Unable to initialize packet injection");
65
if((device = pcap_lookupdev(error_buf)) == NULL)
66
fatal_error("%s: Check device permissions", error_buf);
68
if((pkt = pcap_open_live(device, 1500, 1, 500, error_buf)) == NULL)
69
fatal_error("Unable to open device: %s", error_buf);
71
if(strlen(w_file) > 0)
74
fprintf(stdout, "DEBUG: Writing to capture file: %s\n", w_file);
77
if((p_dumper = pcap_dump_open(pkt, w_file)) == NULL)
78
fatal_error("Unable to initialize packet capture: %s", pcap_geterr(pkt));
83
if(pcap_lookupnet(device, &localnet, &netmask, error_buf) < 0)
84
fprintf(stderr, "\nWarning: Unable to lookup network: %s\n", error_buf);
86
hw_addr = libnet_get_hwaddr(pkt_d);
87
snprintf(filter, 255, "(ip src host %s and ether dst %0x:%0x:%0x:%0x:%0x:%0x) or (ip dst host %s and ether dst %0x:%0x:%0x:%0x:%0x:%0x)",
89
hw_addr->ether_addr_octet[0],
90
hw_addr->ether_addr_octet[1],
91
hw_addr->ether_addr_octet[2],
92
hw_addr->ether_addr_octet[3],
93
hw_addr->ether_addr_octet[4],
94
hw_addr->ether_addr_octet[5],
96
hw_addr->ether_addr_octet[0],
97
hw_addr->ether_addr_octet[1],
98
hw_addr->ether_addr_octet[2],
99
hw_addr->ether_addr_octet[3],
100
hw_addr->ether_addr_octet[4],
101
hw_addr->ether_addr_octet[5]);
103
fprintf(stdout, "GW: %s\n", filter);
105
if(pcap_compile(pkt, &bpf, filter, 0, netmask) < 0)
106
fatal_error("Unable to compile packet filters: %s\n", pcap_geterr(pkt));
108
if(pcap_setfilter(pkt, &bpf) < 0)
109
fatal_error("Unable to set packet filters: %s", pcap_geterr(pkt));
113
#endif /* HAVE_FREECODE */
115
if((data_link = pcap_datalink(pkt)) < 0)
116
fatal_error("Unable to determine datalink type: %s", pcap_geterr(pkt));
118
hdr_len = retrieve_datalink_hdr_len(data_link);
120
fprintf(stdout, "4g8: Lets see what %s is up to. (Device: %s)\n", host_ip, device);
122
oval.it_interval.tv_sec = 2;
123
oval.it_value.tv_sec = 1;
124
setitimer(ITIMER_REAL, &oval, 0);
127
(display == 1) ? (pcap_handler)capture_loop : (pcap_handler)pcap_dump,
128
(display == 1) ? NULL : (u_int8_t *)p_dumper) < 0)
130
fatal_error("Unable to initialize pcap_loop: %s", pcap_geterr(pkt));