-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoriginal.c
33 lines (28 loc) · 897 Bytes
/
original.c
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
#include <pcap.h>
#include <stdio.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <linux/if_ether.h>
int main(int argc, char *argv[]) {
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *handle;
const unsigned char *packet;
struct pcap_pkthdr header;
struct iphdr *ip_header;
int packet_count = 0;
if (argc != 2) {
fprintf(stderr, "Usage: %s <pcap file>\n", argv[0]);
return 1;
}
handle = pcap_open_offline(argv[1], errbuf);
if (handle == NULL) {
fprintf(stderr, "Error opening pcap file: %s\n", errbuf);
return 1;
}
while ((packet = pcap_next(handle, &header)) != NULL) {
ip_header = (struct iphdr*)(packet + sizeof(struct ethhdr));
printf("Packet %d: IP destination address: %s\n", ++packet_count, inet_ntoa(*((struct in_addr*)ip_header->daddr)));
}
pcap_close(handle);
return 0;
}