/**
- * nmrp-flash - Netgear Unbrick Utility
+ * nmrpflash - 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
+ * nmrpflash 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,
+ * nmrpflash 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/>.
+ * along with nmrpflash. If not, see <http://www.gnu.org/licenses/>.
*
*/
msg_hdr_ntoh(&pkt->msg);
len = pkt->msg.len + sizeof(pkt->eh);
- if (bytes != len) {
- fprintf(stderr, "Unexpected message length (%d bytes).\n", (int)len);
+ if (bytes < len) {
+ fprintf(stderr, "Short packet (expected %d, got %d).\n",
+ (int)len, (int)bytes);
return 1;
}
return 1;
}
- if (access(args->filename, R_OK) == -1) {
+ if (strcmp(args->filename, "-") && access(args->filename, R_OK) == -1) {
fprintf(stderr, "Error accessing file '%s'.\n", args->filename);
return 1;
}
switch (rx.msg.code) {
case NMRP_C_ADVERTISE:
- printf("Received NMRP advertisement from "
- "%02x:%02x:%02x:%02x:%02x:%02x.\n",
- rx.eh.ether_shost[0], rx.eh.ether_shost[1],
- rx.eh.ether_shost[2], rx.eh.ether_shost[3],
- rx.eh.ether_shost[4], rx.eh.ether_shost[5]);
+ printf("Received NMRP advertisement from %s.\n",
+ mac_to_str(rx.eh.ether_shost));
err = 1;
goto out;
case NMRP_C_CONF_REQ:
expect = NMRP_C_TFTP_UL_REQ;
- printf("Received configuration request from "
- "%02x:%02x:%02x:%02x:%02x:%02x.\n",
- rx.eh.ether_shost[0], rx.eh.ether_shost[1],
- rx.eh.ether_shost[2], rx.eh.ether_shost[3],
- rx.eh.ether_shost[4], rx.eh.ether_shost[5]);
+ printf("Received configuration request from %s.\n",
+ mac_to_str(rx.eh.ether_shost));
memcpy(tx.eh.ether_dhost, rx.eh.ether_shost, 6);
break;
}
- if (!args->tftpcmd) {
- printf("Uploading %s ... ", args->filename);
- fflush(stdout);
- err = tftp_put(args);
- } else {
- printf("Running %s ... ", args->tftpcmd);
+ err = 0;
+
+ if (args->tftpcmd) {
+ printf("Executing '%s' ... ", args->tftpcmd);
fflush(stdout);
err = system(args->tftpcmd);
+ if (!err) {
+ printf("OK\n");
+ } else {
+ printf("ERR\n");
+ }
+ }
+
+ if (!err && args->filename) {
+ if (!strcmp(args->filename, "-")) {
+ printf("Uploading from stdin ... ");
+ } else {
+ printf("Uploading %s ... ", args->filename);
+ }
+ fflush(stdout);
+ err = tftp_put(args);
}
if (!err) {
err = 0;
+ printf("Reboot your device now.\n");
+
out:
signal(SIGINT, sigh_orig);
gsock = NULL;