+/**
+ * nmrp-flash - Netgear Unbrick Utility
+ * Copyright (C) 2016 Joseph Lehner <joseph.c.lehner@gmail.com>
+ *
+ * nmrp-flash 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * nmrp-flash 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 nmrp-flash. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
#define _BSD_SOURCE
#include <arpa/inet.h>
#include <sys/socket.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
+#include "nmrpd.h"
#define TFTP_PKT_SIZE 516
return 0;
}
-int tftp_put(const char *filename, const char *ipaddr, uint16_t port)
+int tftp_put(struct nmrpd_args *args)
{
struct sockaddr_in addr;
uint16_t block;
int fd, sock, err, timeout, last_len;
char rx[TFTP_PKT_SIZE], tx[TFTP_PKT_SIZE];
- fd = open(filename, O_RDONLY);
+ fd = open(args->filename, O_RDONLY);
if (fd < 0) {
perror("open");
err = fd;
goto cleanup;
}
- err = sock_set_rx_timeout(sock, 999);
+ err = sock_set_rx_timeout(sock, args->rx_timeout);
if (err) {
goto cleanup;
}
- err = !inet_aton(ipaddr, &addr.sin_addr);
+ err = !inet_aton(args->ipaddr, &addr.sin_addr);
if (err) {
perror("inet_aton");
goto cleanup;
}
addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
+ addr.sin_port = htons(args->port);
- pkt_mkwrq(tx, filename, "octet");
+ pkt_mkwrq(tx, args->filename, "octet");
len = tftp_sendto(sock, tx, 0, &addr);
if (len < 0) {
goto cleanup;
} else {
timeout = 0;
+ err = 0;
}
} while(1);