2021-10-06 21:25:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-08-26 01:01:39 +00:00
|
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
2021-10-06 21:25:43 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2022-09-25 21:49:24 +00:00
|
|
|
// Copyright (C) 2021-2022 Uwe Seimet
|
2021-10-06 21:25:43 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
#include "rascsi_exceptions.h"
|
2022-10-08 17:26:04 +00:00
|
|
|
#include "protobuf_util.h"
|
2021-10-06 21:25:43 +00:00
|
|
|
#include "rasctl_commands.h"
|
2022-09-25 21:49:24 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <netdb.h>
|
2021-10-06 21:25:43 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace rascsi_interface;
|
2022-10-08 17:26:04 +00:00
|
|
|
using namespace protobuf_util;
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
// Separator for the INQUIRY name components
|
|
|
|
static const char COMPONENT_SEPARATOR = ':';
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::Execute(const string& log_level, const string& default_folder, const string& reserved_ids,
|
2022-09-25 21:49:24 +00:00
|
|
|
const string& image_params, const string& filename)
|
|
|
|
{
|
|
|
|
switch(command.operation()) {
|
|
|
|
case LOG_LEVEL:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandLogLevel(log_level);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case DEFAULT_FOLDER:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandDefaultImageFolder(default_folder);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case RESERVE_IDS:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandReserveIds(reserved_ids);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case CREATE_IMAGE:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandCreateImage(image_params);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case DELETE_IMAGE:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandDeleteImage(image_params);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case RENAME_IMAGE:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandRenameImage(image_params);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case COPY_IMAGE:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandCopyImage(image_params);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case DEVICES_INFO:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandDeviceInfo();
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case DEVICE_TYPES_INFO:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandDeviceTypesInfo();
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case VERSION_INFO:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandVersionInfo();
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case SERVER_INFO:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandServerInfo();
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case DEFAULT_IMAGE_FILES_INFO:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandDefaultImageFilesInfo();
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case IMAGE_FILE_INFO:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandImageFileInfo(filename);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case NETWORK_INTERFACES_INFO:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandNetworkInterfacesInfo();
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case LOG_LEVEL_INFO:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandLogLevelInfo();
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case RESERVED_IDS_INFO:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandReservedIdsInfo();
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case MAPPING_INFO:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandMappingInfo();
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
case OPERATION_INFO:
|
2022-10-23 19:51:39 +00:00
|
|
|
return CommandOperationInfo();
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
default:
|
2022-10-23 19:51:39 +00:00
|
|
|
return SendCommand();
|
2022-09-25 21:49:24 +00:00
|
|
|
}
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return false;
|
2022-09-25 21:49:24 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::SendCommand()
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
sockaddr_in server_addr = {};
|
|
|
|
if (!ResolveHostName(hostname, &server_addr)) {
|
|
|
|
throw io_exception("Can't resolve hostname '" + hostname + "'");
|
|
|
|
}
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
const int fd = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (fd == -1) {
|
|
|
|
throw io_exception("Can't create socket: " + string(strerror(errno)));
|
|
|
|
}
|
2021-10-25 23:04:10 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
server_addr.sin_port = htons(uint16_t(port));
|
|
|
|
if (connect(fd, (sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
|
|
|
|
close(fd);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
throw io_exception("Can't connect to rascsi on host '" + hostname + "', port " + to_string(port)
|
|
|
|
+ ": " + strerror(errno));
|
|
|
|
}
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
if (write(fd, "RASCSI", 6) != 6) {
|
|
|
|
close(fd);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
throw io_exception("Can't write magic");
|
|
|
|
}
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
serializer.SerializeMessage(fd, command);
|
|
|
|
serializer.DeserializeMessage(fd, result);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
close(fd);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
if (!result.status()) {
|
|
|
|
throw io_exception(result.msg());
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!result.msg().empty()) {
|
|
|
|
cout << result.msg() << endl;
|
|
|
|
}
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandDevicesInfo()
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
|
|
|
SendCommand();
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayDevicesInfo(result.devices_info()) << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandLogLevel(const string& log_level)
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
SetParam(command, "level", log_level);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
return SendCommand();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandReserveIds(const string& reserved_ids)
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
SetParam(command, "ids", reserved_ids);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
return SendCommand();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandCreateImage(const string& image_params)
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
if (const size_t separator_pos = image_params.find(COMPONENT_SEPARATOR); separator_pos != string::npos) {
|
2022-10-23 19:51:39 +00:00
|
|
|
SetParam(command, "file", string_view(image_params).substr(0, separator_pos));
|
|
|
|
SetParam(command, "size", string_view(image_params).substr(separator_pos + 1));
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
cerr << "Error: Invalid file descriptor '" << image_params << "', format is NAME:SIZE" << endl;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return false;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
SetParam(command, "read_only", "false");
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
return SendCommand();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandDeleteImage(const string& filename)
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
SetParam(command, "file", filename);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
return SendCommand();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandRenameImage(const string& image_params)
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
if (const size_t separator_pos = image_params.find(COMPONENT_SEPARATOR); separator_pos != string::npos) {
|
2022-10-23 19:51:39 +00:00
|
|
|
SetParam(command, "from", string_view(image_params).substr(0, separator_pos));
|
|
|
|
SetParam(command, "to", string_view(image_params).substr(separator_pos + 1));
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
cerr << "Error: Invalid file descriptor '" << image_params << "', format is CURRENT_NAME:NEW_NAME" << endl;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return false;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
return SendCommand();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandCopyImage(const string& image_params)
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
if (const size_t separator_pos = image_params.find(COMPONENT_SEPARATOR); separator_pos != string::npos) {
|
2022-10-23 19:51:39 +00:00
|
|
|
SetParam(command, "from", string_view(image_params).substr(0, separator_pos));
|
|
|
|
SetParam(command, "to", string_view(image_params).substr(separator_pos + 1));
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
cerr << "Error: Invalid file descriptor '" << image_params << "', format is CURRENT_NAME:NEW_NAME" << endl;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return false;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
return SendCommand();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandDefaultImageFolder(const string& folder)
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
SetParam(command, "folder", folder);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
return SendCommand();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandDeviceInfo()
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
|
|
|
SendCommand();
|
|
|
|
|
|
|
|
for (const auto& device : result.devices_info().devices()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayDeviceInfo(device);
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
cout << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandDeviceTypesInfo()
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
|
|
|
SendCommand();
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayDeviceTypesInfo(result.device_types_info()) << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandVersionInfo()
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
|
|
|
SendCommand();
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayVersionInfo(result.version_info()) << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandServerInfo()
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
|
|
|
SendCommand();
|
|
|
|
|
|
|
|
PbServerInfo server_info = result.server_info();
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayVersionInfo(server_info.version_info());
|
|
|
|
cout << rasctl_display.DisplayLogLevelInfo(server_info.log_level_info());
|
|
|
|
cout << rasctl_display.DisplayImageFilesInfo(server_info.image_files_info());
|
|
|
|
cout << rasctl_display.DisplayMappingInfo(server_info.mapping_info());
|
|
|
|
cout << rasctl_display.DisplayNetworkInterfaces(server_info.network_interfaces_info());
|
|
|
|
cout << rasctl_display.DisplayDeviceTypesInfo(server_info.device_types_info());
|
|
|
|
cout << rasctl_display.DisplayReservedIdsInfo(server_info.reserved_ids_info());
|
|
|
|
cout << rasctl_display.DisplayOperationInfo(server_info.operation_info());
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
if (server_info.devices_info().devices_size()) {
|
|
|
|
list<PbDevice> sorted_devices = { server_info.devices_info().devices().begin(), server_info.devices_info().devices().end() };
|
2022-10-04 15:23:42 +00:00
|
|
|
sorted_devices.sort([](const auto& a, const auto& b) { return a.id() < b.id() || a.unit() < b.unit(); });
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << "Attached devices:\n";
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
for (const auto& device : sorted_devices) {
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayDeviceInfo(device);
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
cout << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandDefaultImageFilesInfo()
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
|
|
|
SendCommand();
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayImageFilesInfo(result.image_files_info()) << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandImageFileInfo(const string& filename)
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
SetParam(command, "file", filename);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
SendCommand();
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayImageFile(result.image_file_info()) << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandNetworkInterfacesInfo()
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
|
|
|
SendCommand();
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayNetworkInterfaces(result.network_interfaces_info()) << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandLogLevelInfo()
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
|
|
|
SendCommand();
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayLogLevelInfo(result.log_level_info()) << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandReservedIdsInfo()
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
|
|
|
SendCommand();
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayReservedIdsInfo(result.reserved_ids_info()) << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandMappingInfo()
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
|
|
|
SendCommand();
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayMappingInfo(result.mapping_info()) << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2021-12-21 07:43:21 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool RasctlCommands::CommandOperationInfo()
|
2021-12-21 07:43:21 +00:00
|
|
|
{
|
|
|
|
SendCommand();
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
cout << rasctl_display.DisplayOperationInfo(result.operation_info()) << flush;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
return true;
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RasctlCommands::ResolveHostName(const string& host, sockaddr_in *addr)
|
|
|
|
{
|
|
|
|
addrinfo hints = {};
|
|
|
|
hints.ai_family = AF_INET;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
|
|
|
|
if (addrinfo *result; !getaddrinfo(host.c_str(), nullptr, &hints, &result)) {
|
|
|
|
*addr = *(sockaddr_in *)(result->ai_addr);
|
|
|
|
freeaddrinfo(result);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|