1/** 2 * \file main.c 3 * \brief 4 */ 5 6 7/* 8 * Copyright (c) 2016 ETH Zurich. 9 * All rights reserved. 10 * 11 * This file is distributed under the terms in the attached LICENSE file. 12 * If you do not find this file, copies can be found by writing to: 13 * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group. 14 */ 15 16#include <barrelfish/barrelfish.h> 17#include <tftp/tftp.h> 18 19static char *file = "test"; 20static char *server = "127.0.0.1"; 21uint16_t port = 69; 22 23#define TFTP_BUF_SIZE (1<<20) 24 25char buffer[TFTP_BUF_SIZE]; 26 27static void parse_uri(char *uri) 28{ 29 debug_printf("TFTP PARSE URI '%s'\n", uri); 30 if (uri == NULL) { 31 return; 32 } 33 34 if (strncmp(uri, "tftp://", 7)) { 35 return; 36 } 37 38 uri += 7; 39 40 /* format: tftp://10.110.4.4:69 */ 41 char *del = strchr(uri, ':'); 42 if (del != NULL) { 43 port = atoi(del + 1); 44 *del = 0; 45 } 46 47 server = uri; 48} 49 50int main(int argc, char *argv[]) 51{ 52 errval_t err; 53 54 for (int i = 1; i < argc; i++) { 55 if (strncmp(argv[i], "--server=", 9) == 0) { 56 parse_uri(argv[i] + 9); 57 } else if (strncmp(argv[i], "--file=", 7) == 0) { 58 file = argv[i] + 7; 59 } else { 60 debug_printf("TFTP WARNING unknown argument '%s'\n", argv[i]); 61 } 62 } 63 64 debug_printf("TFTP SERVER: %s:%u\n", server, port); 65 err = tftp_client_connect(server, port); 66 if (err_is_fail(err)) { 67 USER_PANIC_ERR(err, "TFTP ERROR Could not connect to the tftp service"); 68 } 69 70 debug_printf("TFTP READFILE: %s\n", file); 71 72 size_t size; 73 err = tftp_client_read_file(file, buffer, TFTP_BUF_SIZE, &size); 74 if (err_is_fail(err)) { 75 USER_PANIC("TFTP ERRO: reading tftp file"); 76 } 77 78 debug_printf("TFTP READFILE: %zu bytes\n", size); 79 80 debug_printf("TFTP FILE CONTENTS: %s\n", buffer); 81 82 debug_printf("TFTP TEST DONE. \n"); 83 84 // prevent main exit since we do not have 85 // graceful flounder channel teardown 86 while(1) { 87 event_dispatch(get_default_waitset()); 88 } 89} 90