8 * Copyright (c) 2016 ETH Zurich.
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.
16 #include <barrelfish/barrelfish.h>
17 #include <tftp/tftp.h>
19 static char *file = "test";
20 static char *server = "127.0.0.1";
23 #define TFTP_BUF_SIZE (1<<20)
25 char buffer[TFTP_BUF_SIZE];
27 static void parse_uri(char *uri)
29 debug_printf("TFTP PARSE URI '%s'\n", uri);
34 if (strncmp(uri, "tftp://", 7)) {
40 /* format: tftp://10.110.4.4:69 */
41 char *del = strchr(uri, ':');
50 int main(int argc, char *argv[])
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) {
60 debug_printf("TFTP WARNING unknown argument '%s'\n", argv[i]);
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");
70 debug_printf("TFTP READFILE: %s\n", file);
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");
78 debug_printf("TFTP READFILE: %zu bytes\n", size);
80 debug_printf("TFTP TEST DONE.");