代码
#include <iostream>
#include <cstring>
#include <unistd.h>
#include <netdb.h>
#include <errno.h>
#include <thread>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <sys/ioctl.h>
using namespace std;
#define uchar unsigned char
struct arp_packet{
char dest_MAC[6];
char srce_MAC[6];
uchar type[2];
uchar hw_t[2];
uchar protocol_t[2];
uchar hw_size;
uchar protocol_size;
uchar opcode[2];
char src_MAC[6];
u_int32_t src_IP;
char dst_MAC[6];
u_int32_t dst_IP;
};
extern int h_errno;
extern int errno;
static int sent_num = 0;
void recv_cout(int recv_socket){
unsigned char buf[80];
memset(buf, 0, 80);
struct in_addr convert;
arp_packet* tmp_packet = nullptr;
struct timeval tv = {
255, 0};
if(setsockopt(recv_socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0){
cout << "ERROR: failed to set socket receive timeout" << endl;
cout << strerror(errno) << endl;
}
for(int i