-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.h
46 lines (39 loc) · 1.06 KB
/
main.h
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
#include <cstdio>
#include <pcap.h>
#include "getHostInfo.h"
#include "ethhdr.h"
#include "arphdr.h"
#include <unistd.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/if_ether.h>
#include <netinet/ip.h>
#include <thread>
#pragma pack(push, 1)
struct EthArpPacket final
{
EthArpPacket(uint8_t mode, Mac ether_dmac, Mac ether_smac, uint16_t _type, uint16_t _hrd, uint16_t _pro, uint8_t _hln, uint8_t _pln, Mac arp_smac, Ip arp_sip, Mac arp_tmac, Ip arp_tip)
{
eth_.dmac_ = ether_dmac;
eth_.smac_ = ether_smac;
eth_.type_ = htons(EthHdr::Arp);
arp_.hrd_ = htons(ArpHdr::ETHER);
arp_.pro_ = htons(EthHdr::Ip4);
arp_.op_ = htons(mode);
arp_.hln_ = Mac::SIZE;
arp_.pln_ = Ip::SIZE;
arp_.smac_ = arp_smac;
arp_.sip_ = htonl(arp_sip);
arp_.tmac_ = arp_tmac;
arp_.tip_ = htonl(arp_tip);
}
EthHdr eth_;
ArpHdr arp_;
};
#pragma pack(pop)
void usage()
{
printf("syntax : send-arp <interface> <sender ip> <target ip> [<sender ip 2> <target ip 2> ...]\n");
printf("sample : send-arp wlan0 192.168.10.2 192.168.10.1\n");
}