Add function to list devices.

This commit is contained in:
2019-10-12 23:53:29 +01:00
parent dcc02a1f1b
commit d032af0d58
4 changed files with 62 additions and 15 deletions

View File

@@ -3,4 +3,4 @@ project(dicremote C)
set(CMAKE_C_STANDARD 90)
add_executable(dicremote main.c)
add_executable(dicremote main.c list_devices.c)

View File

@@ -81,4 +81,6 @@ typedef struct DeviceInfoList
} DeviceInfoList;
#pragma pack(pop)
DeviceInfoList* ListDevices();
#endif

23
list_devices.c Normal file
View File

@@ -0,0 +1,23 @@
/*
* This file is part of the DiscImageChef Remote Server.
* Copyright (c) 2019 Natalia Portillo.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dicmote.h"
DeviceInfoList* ListDevices()
{
return 0;
}

24
main.c
View File

@@ -42,6 +42,7 @@ int main()
ssize_t recv_size;
char* dummy_buf;
int skip_next_hdr;
struct DeviceInfoList* deviceInfoList;
printf("DiscImageChef Remote Server %s\n", DICMOTE_VERSION);
printf("Copyright (C) 2019 Natalia Portillo\n");
@@ -295,8 +296,29 @@ int main()
skip_next_hdr = 1;
continue;
case DICMOTE_PACKET_TYPE_COMMAND_LIST_DEVICES:
deviceInfoList = ListDevices();
// Packet only contains header so, dummy
dummy_buf = malloc(pkt_hdr->len);
if(!dummy_buf)
{
printf("Fatal error %d allocating memory for packet, closing connection...\n", errno);
free(pkt_hdr);
close(cli_sock);
continue;
}
recv(cli_sock, dummy_buf, pkt_hdr->len, 0);
free(dummy_buf);
if(!deviceInfoList)
{
printf("Could not get device list, continuing...\n");
continue;
}
printf("List devices not yet implemented, skipping...\n");
skip_next_hdr = 1;
continue;
case DICMOTE_PACKET_TYPE_RESPONSE_LIST_DEVICES:
printf("Received response packet?! You should certainly not do that...\n");