From d032af0d585b40eab3bae52b5b312ad9970791d7 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 12 Oct 2019 23:53:29 +0100 Subject: [PATCH] Add function to list devices. --- CMakeLists.txt | 2 +- dicmote.h | 2 ++ list_devices.c | 23 +++++++++++++++++++++++ main.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 4 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 list_devices.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 91925a1..bfe584b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,4 +3,4 @@ project(dicremote C) set(CMAKE_C_STANDARD 90) -add_executable(dicremote main.c) \ No newline at end of file +add_executable(dicremote main.c list_devices.c) \ No newline at end of file diff --git a/dicmote.h b/dicmote.h index f44a4b2..20c8ad9 100644 --- a/dicmote.h +++ b/dicmote.h @@ -81,4 +81,6 @@ typedef struct DeviceInfoList } DeviceInfoList; #pragma pack(pop) +DeviceInfoList* ListDevices(); + #endif diff --git a/list_devices.c b/list_devices.c new file mode 100644 index 0000000..54badca --- /dev/null +++ b/list_devices.c @@ -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 . + */ + +#include "dicmote.h" + +DeviceInfoList* ListDevices() +{ + return 0; +} \ No newline at end of file diff --git a/main.c b/main.c index 220e1bc..bec6376 100644 --- a/main.c +++ b/main.c @@ -29,19 +29,20 @@ int main() { - struct ifaddrs* ifa; - struct ifaddrs* ifa_start; - int ret; - char ipv4Address[INET_ADDRSTRLEN]; - int sockfd, cli_sock; - struct sockaddr_in serv_addr, cli_addr; - socklen_t cli_len; - struct utsname utsname; - DicPacketHello * pkt_server_hello, *pkt_client_hello; - DicPacketHeader* pkt_hdr; - ssize_t recv_size; - char* dummy_buf; - int skip_next_hdr; + struct ifaddrs* ifa; + struct ifaddrs* ifa_start; + int ret; + char ipv4Address[INET_ADDRSTRLEN]; + int sockfd, cli_sock; + struct sockaddr_in serv_addr, cli_addr; + socklen_t cli_len; + struct utsname utsname; + DicPacketHello * pkt_server_hello, *pkt_client_hello; + DicPacketHeader* pkt_hdr; + 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");