mirror of
https://github.com/akuker/RASCSI.git
synced 2025-01-11 09:29:53 +00:00
Fixed compilation issues of 64 bit Ubuntu
This commit is contained in:
parent
ebd31aa357
commit
a58a1cda15
@ -111,7 +111,7 @@ static bool is_interface_up(const string& interface) {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CTapDriver::Init()
|
bool CTapDriver::Init()
|
||||||
{
|
{
|
||||||
LOGTRACE("%s",__PRETTY_FUNCTION__);
|
LOGTRACE("%s",__PRETTY_FUNCTION__);
|
||||||
|
|
||||||
@ -123,8 +123,9 @@ BOOL CTapDriver::Init()
|
|||||||
// TAP device initilization
|
// TAP device initilization
|
||||||
if ((m_hTAP = open("/dev/net/tun", O_RDWR)) < 0) {
|
if ((m_hTAP = open("/dev/net/tun", O_RDWR)) < 0) {
|
||||||
LOGERROR("Error: can't open tun. Errno: %d %s", errno, strerror(errno));
|
LOGERROR("Error: can't open tun. Errno: %d %s", errno, strerror(errno));
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGTRACE("Opened tap device %d",m_hTAP);
|
LOGTRACE("Opened tap device %d",m_hTAP);
|
||||||
|
|
||||||
|
|
||||||
@ -136,7 +137,7 @@ BOOL CTapDriver::Init()
|
|||||||
if ((ret = ioctl(m_hTAP, TUNSETIFF, (void *)&ifr)) < 0) {
|
if ((ret = ioctl(m_hTAP, TUNSETIFF, (void *)&ifr)) < 0) {
|
||||||
LOGERROR("Error: can't ioctl TUNSETIFF. Errno: %d %s", errno, strerror(errno));
|
LOGERROR("Error: can't ioctl TUNSETIFF. Errno: %d %s", errno, strerror(errno));
|
||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
LOGTRACE("return code from ioctl was %d", ret);
|
LOGTRACE("return code from ioctl was %d", ret);
|
||||||
|
|
||||||
@ -144,7 +145,7 @@ BOOL CTapDriver::Init()
|
|||||||
if ((ip_fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
|
if ((ip_fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||||
LOGERROR("Error: can't open ip socket. Errno: %d %s", errno, strerror(errno));
|
LOGERROR("Error: can't open ip socket. Errno: %d %s", errno, strerror(errno));
|
||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int br_socket_fd = -1;
|
int br_socket_fd = -1;
|
||||||
@ -152,7 +153,7 @@ BOOL CTapDriver::Init()
|
|||||||
LOGERROR("Error: can't open bridge socket. Errno: %d %s", errno, strerror(errno));
|
LOGERROR("Error: can't open bridge socket. Errno: %d %s", errno, strerror(errno));
|
||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
close(ip_fd);
|
close(ip_fd);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the bridge has already been created
|
// Check if the bridge has already been created
|
||||||
@ -160,22 +161,27 @@ BOOL CTapDriver::Init()
|
|||||||
LOGINFO("rascsi_bridge is not yet available");
|
LOGINFO("rascsi_bridge is not yet available");
|
||||||
|
|
||||||
LOGTRACE("Checking which interface is available for creating the bridge");
|
LOGTRACE("Checking which interface is available for creating the bridge");
|
||||||
string interface;
|
|
||||||
for (auto it = interfaces.begin(); it != interfaces.end(); ++it) {
|
|
||||||
if (is_interface_up(*it)) {
|
|
||||||
LOGTRACE(string("Interface " + (*it) + " is up").c_str());
|
|
||||||
|
|
||||||
interface = *it;
|
string interface;
|
||||||
|
for (const auto& iface : interfaces) {
|
||||||
|
ostringstream error;
|
||||||
|
|
||||||
|
if (is_interface_up(iface)) {
|
||||||
|
error << "Interface " << iface << " is up";
|
||||||
|
LOGTRACE("%s", error.str().c_str());
|
||||||
|
|
||||||
|
interface = iface;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOGTRACE(string("Interface " + (*it) + " is not up").c_str());
|
error << "Interface " << iface << " is not up";
|
||||||
|
LOGTRACE("%s", error.str().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interface.empty()) {
|
if (interface.empty()) {
|
||||||
LOGERROR("No interface is up, not creating bridge");
|
LOGERROR("No interface is up, not creating bridge");
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGINFO("Creating rascsi_bridge for interface %s", interface.c_str());
|
LOGINFO("Creating rascsi_bridge for interface %s", interface.c_str());
|
||||||
@ -186,7 +192,7 @@ BOOL CTapDriver::Init()
|
|||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
close(ip_fd);
|
close(ip_fd);
|
||||||
close(br_socket_fd);
|
close(br_socket_fd);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interface == "eth0") {
|
if (interface == "eth0") {
|
||||||
@ -195,7 +201,7 @@ BOOL CTapDriver::Init()
|
|||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
close(ip_fd);
|
close(ip_fd);
|
||||||
close(br_socket_fd);
|
close(br_socket_fd);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -215,7 +221,7 @@ BOOL CTapDriver::Init()
|
|||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
close(ip_fd);
|
close(ip_fd);
|
||||||
close(br_socket_fd);
|
close(br_socket_fd);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGDEBUG("ip link set dev rascsi_bridge up");
|
LOGDEBUG("ip link set dev rascsi_bridge up");
|
||||||
@ -223,7 +229,7 @@ BOOL CTapDriver::Init()
|
|||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
close(ip_fd);
|
close(ip_fd);
|
||||||
close(br_socket_fd);
|
close(br_socket_fd);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -236,7 +242,7 @@ BOOL CTapDriver::Init()
|
|||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
close(ip_fd);
|
close(ip_fd);
|
||||||
close(br_socket_fd);
|
close(br_socket_fd);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGDEBUG("brctl addif rascsi_bridge ras0");
|
LOGDEBUG("brctl addif rascsi_bridge ras0");
|
||||||
@ -244,7 +250,7 @@ BOOL CTapDriver::Init()
|
|||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
close(ip_fd);
|
close(ip_fd);
|
||||||
close(br_socket_fd);
|
close(br_socket_fd);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get MAC address
|
// Get MAC address
|
||||||
@ -255,7 +261,7 @@ BOOL CTapDriver::Init()
|
|||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
close(ip_fd);
|
close(ip_fd);
|
||||||
close(br_socket_fd);
|
close(br_socket_fd);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
LOGTRACE("got the mac");
|
LOGTRACE("got the mac");
|
||||||
|
|
||||||
@ -266,7 +272,7 @@ BOOL CTapDriver::Init()
|
|||||||
close(ip_fd);
|
close(ip_fd);
|
||||||
close(br_socket_fd);
|
close(br_socket_fd);
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
|
|
||||||
@ -279,21 +285,21 @@ BOOL CTapDriver::Init()
|
|||||||
// TAP Device Initialization
|
// TAP Device Initialization
|
||||||
if ((m_hTAP = open("/dev/tap", O_RDWR)) < 0) {
|
if ((m_hTAP = open("/dev/tap", O_RDWR)) < 0) {
|
||||||
LOGERROR("Error: can't open tap. Errno: %d %s", errno, strerror(errno));
|
LOGERROR("Error: can't open tap. Errno: %d %s", errno, strerror(errno));
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get device name
|
// Get device name
|
||||||
if (ioctl(m_hTAP, TAPGIFNAME, (void *)&ifr) < 0) {
|
if (ioctl(m_hTAP, TAPGIFNAME, (void *)&ifr) < 0) {
|
||||||
LOGERROR("Error: can't ioctl TAPGIFNAME. Errno: %d %s", errno, strerror(errno));
|
LOGERROR("Error: can't ioctl TAPGIFNAME. Errno: %d %s", errno, strerror(errno));
|
||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get MAC address
|
// Get MAC address
|
||||||
if (getifaddrs(&ifa) == -1) {
|
if (getifaddrs(&ifa) == -1) {
|
||||||
LOGERROR("Error: can't getifaddrs. Errno: %d %s", errno, strerror(errno));
|
LOGERROR("Error: can't getifaddrs. Errno: %d %s", errno, strerror(errno));
|
||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
for (a = ifa; a != NULL; a = a->ifa_next)
|
for (a = ifa; a != NULL; a = a->ifa_next)
|
||||||
if (strcmp(ifr.ifr_name, a->ifa_name) == 0 &&
|
if (strcmp(ifr.ifr_name, a->ifa_name) == 0 &&
|
||||||
@ -302,7 +308,7 @@ BOOL CTapDriver::Init()
|
|||||||
if (a == NULL) {
|
if (a == NULL) {
|
||||||
LOGERROR("Error: can't get MAC addressErrno: %d %s", errno, strerror(errno));
|
LOGERROR("Error: can't get MAC addressErrno: %d %s", errno, strerror(errno));
|
||||||
close(m_hTAP);
|
close(m_hTAP);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save MAC address
|
// Save MAC address
|
||||||
@ -312,7 +318,7 @@ BOOL CTapDriver::Init()
|
|||||||
|
|
||||||
LOGINFO("Tap device : %s\n", ifr.ifr_name);
|
LOGINFO("Tap device : %s\n", ifr.ifr_name);
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
#endif // __NetBSD__
|
#endif // __NetBSD__
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class CTapDriver
|
|||||||
public:
|
public:
|
||||||
// Basic Functionality
|
// Basic Functionality
|
||||||
CTapDriver(const std::string&); // Constructor
|
CTapDriver(const std::string&); // Constructor
|
||||||
BOOL Init(); // Initialization
|
bool Init(); // Initialization
|
||||||
void OpenDump(const Filepath& path);
|
void OpenDump(const Filepath& path);
|
||||||
// Capture packets
|
// Capture packets
|
||||||
void Cleanup(); // Cleanup
|
void Cleanup(); // Cleanup
|
||||||
|
@ -70,7 +70,7 @@ private:
|
|||||||
void SendPacket(BYTE *buf, int len); // Send a packet
|
void SendPacket(BYTE *buf, int len); // Send a packet
|
||||||
|
|
||||||
CTapDriver *tap; // TAP driver
|
CTapDriver *tap; // TAP driver
|
||||||
BOOL m_bTapEnable; // TAP valid flag
|
bool m_bTapEnable; // TAP valid flag
|
||||||
BYTE mac_addr[6]; // MAC Addres
|
BYTE mac_addr[6]; // MAC Addres
|
||||||
int packet_len; // Receive packet size
|
int packet_len; // Receive packet size
|
||||||
BYTE packet_buf[0x1000]; // Receive packet buffer
|
BYTE packet_buf[0x1000]; // Receive packet buffer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user