intptr_t DzRawSocket( int fd ) { DzHost* host = GetHost(); assert( host ); assert( fd >= 0 ); assert( ( fd & HANDLE_HOST_ID_MASK ) == host->hostId ); return RawSocket( host, fd ); }
#include <iostream> #include "RawSocket.hh" #include "ARP.hpp" #include "IP.hpp" #include "IPV6.hpp" RawSocket::RawSocket() { this->buffer = new unsigned char[BUFFER_SIZE + 1]; } RawSocket RawSocket::instance = RawSocket(); RawSocket &RawSocket::getInstance() { return RawSocket::instance; } RawSocket::~RawSocket() { delete[] this->buffer; close(this->sockRead); } bool RawSocket::runPromiscious(std::string if_name) { this->if_name = if_name; this->sockRead = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); struct packet_mreq mr; ifr.ifr_ifindex = 0; strcpy(ifr.ifr_name, if_name.c_str()); if (setsockopt(this->sockRead, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0) { std::cout << "Fail to bind " << if_name << " to the raw socket" << std::endl; } if (ioctl(this->sockRead, SIOGIFINDEX, &ifr) < 0) {